Commit 6332ae47 authored by Andrea Ida Malkah Klaura's avatar Andrea Ida Malkah Klaura
Browse files

FIX: set new access token after renewal + refactor

parent aa220d26
......@@ -42,7 +42,7 @@ export default {
logged_in: false
},
userOIDC: null,
mgr: new oidc.UserManager({
oidcmgr: new oidc.UserManager({
userStore: new oidc.WebStorageStateStore(),
authority: process.env.API_STEERING_OIDC_URI,
// the client id has to be a string, therefore we add the + ''
......@@ -54,7 +54,8 @@ export default {
scope: 'openid profile email',
post_logout_redirect_uri: process.env.API_STEERING_OIDC_REDIRECT_URI_POSTLOGOUT,
loadUserInfo: true,
automaticSilentRenew: true
// automaticSilentRenew: true
automaticSilentRenew: false
})
}
},
......@@ -66,68 +67,78 @@ export default {
},
methods: {
signIn () {
this.mgr.signinRedirect().catch(function (err) {
this.oidcmgr.signinRedirect().catch(function (err) {
console.log(err)
})
},
signOut () {
let self = this
this.mgr.signoutRedirect().then(function (resp) {
this.oidcmgr.signoutRedirect().then(function (resp) {
self.user.logged_in = false
console.log('signed out', resp)
}).catch(function (err) {
console.log(err)
})
},
getUser () {
getOIDCUser () {
let self = this
this.mgr.getUser().then(function (u) {
if (u == null) {
this.oidcmgr.getUser().then(function (user) {
if (user == null) {
self.user.logged_in = false
self.user.name = ''
self.user.email = ''
self.user.access_token = ''
} else {
self.userOIDC = u
self.user.logged_in = true
self.user.name = u.profile.nickname
self.user.email = u.profile.email
self.user.access_token = u.access_token
console.log(new Date(u.expires_at * 1000).toString())
console.log(new Date(u.expires_at * 1000).toUTCString())
console.log(u.access_token)
self.setUserProperties(user)
}
}).catch(function (err) {
console.log(err)
})
},
setUserProperties (user) {
this.userOIDC = user
this.user.logged_in = true
this.user.name = user.profile.nickname
this.user.email = user.profile.email
this.user.access_token = user.access_token
console.log(new Date(user.expires_at * 1000).toString())
console.log(new Date(user.expires_at * 1000).toUTCString())
console.log(user.access_token)
}
},
mounted () {
// TODO: remove oidc logging after thorough testing
oidc.Log.logger = console
let self = this
this.mgr.events.addSilentRenewError(function () {
// TODO: set accessTokenExpiringNotificationTime when this.mgr is created and insert this value here too
this.oidcmgr.events.addSilentRenewError(function () {
// TODO: set accessTokenExpiringNotificationTime when this.oidcmgr is created and insert this value here too
alert('Your OpenID access token could not be renewed automatically. You will be logged out in 60 seconds.')
})
this.mgr.events.addAccessTokenExpiring(function () {
this.oidcmgr.events.addAccessTokenExpiring(function () {
console.log('token will soon expire')
console.log(self)
/* Use the following code instead of silent renewal if you want to use popups
console.log('starting signinPopup')
self.mgr.signinPopup(function (user) {
self.oidcmgr.signinPopup(function (user) {
console.log('signinPopup result for user:')
console.log(user)
}).catch(function (err) {
console.log(err)
})
*/
console.log('starting signinSilent')
self.oidcmgr.signinSilent().then(function (user) {
console.log('signinPopup result for user:')
console.log(self.user.access_token)
self.user.access_token = user.access_token
console.log(self.user.access_token)
}).catch(function (err) {
console.log(err)
})
})
this.mgr.events.addAccessTokenExpired(function () {
this.oidcmgr.events.addAccessTokenExpired(function () {
console.log('expired!')
})
this.getUser()
this.mgr.startSilentRenew()
this.getOIDCUser()
}
}
</script>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment