Skip to content

Commit

Permalink
fix for #90 (#93)
Browse files Browse the repository at this point in the history
Also maybe fixes #91.
  • Loading branch information
idiidk authored and lieuwex committed Nov 7, 2018
1 parent a3cc44a commit 033a602
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions src/magister.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class Magister {
authorizeUrl += `&acr_values=tenant%3A${filteredName}`

if (!forceLogin && options.token) {
return setToken(options.token)
return setToken(options.token).then(retrieveAccount)
}

// extract returnUrl
Expand Down Expand Up @@ -459,30 +459,31 @@ class Magister {
}

// extract bearer token
const token =
await this.http.get(`https://accounts.magister.net${returnUrl}`, {
redirect: 'manual',
headers: {
Cookie: authRes.headers.get('set-cookie'),
'X-XSRF-TOKEN': xsrf,
},
})
.then(res => res.headers.get('Location')
.split('&access_token=')[1]
.split('&')[0])
.then(setToken)
const accountData =
await this.http.get(`${schoolUrl}/api/account`).then(res => res.json())
const id = accountData.Persoon.Id

// REVIEW: do we want to make profileInfo a function?
this.profileInfo = new ProfileInfo(this, accountData.Persoon)
this._privileges = new Privileges(this, accountData.Groep[0].Privileges)

this._personUrl = `${schoolUrl}/api/personen/${id}`
this._pupilUrl = `${schoolUrl}/api/leerlingen/${id}`

return token
return await this.http.get(`https://accounts.magister.net${returnUrl}`, {
redirect: 'manual',
headers: {
Cookie: authRes.headers.get('set-cookie'),
'X-XSRF-TOKEN': xsrf,
},
})
.then(res => res.headers.get('Location')
.split('&access_token=')[1]
.split('&')[0])
.then(setToken)
.then(retrieveAccount)

async function retrieveAccount() {
const accountData =
await self.http.get(`${schoolUrl}/api/account`).then(res => res.json())
const id = accountData.Persoon.Id

// REVIEW: do we want to make profileInfo a function?
self.profileInfo = new ProfileInfo(self, accountData.Persoon)
self._privileges = new Privileges(self, accountData.Groep[0].Privileges)

self._personUrl = `${schoolUrl}/api/personen/${id}`
self._pupilUrl = `${schoolUrl}/api/leerlingen/${id}`
}
}
}

Expand Down

0 comments on commit 033a602

Please sign in to comment.