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 { ...@@ -42,7 +42,7 @@ export default {
logged_in: false logged_in: false
}, },
userOIDC: null, userOIDC: null,
mgr: new oidc.UserManager({ oidcmgr: new oidc.UserManager({
userStore: new oidc.WebStorageStateStore(), userStore: new oidc.WebStorageStateStore(),
authority: process.env.API_STEERING_OIDC_URI, authority: process.env.API_STEERING_OIDC_URI,
// the client id has to be a string, therefore we add the + '' // the client id has to be a string, therefore we add the + ''
...@@ -54,7 +54,8 @@ export default { ...@@ -54,7 +54,8 @@ export default {
scope: 'openid profile email', scope: 'openid profile email',
post_logout_redirect_uri: process.env.API_STEERING_OIDC_REDIRECT_URI_POSTLOGOUT, post_logout_redirect_uri: process.env.API_STEERING_OIDC_REDIRECT_URI_POSTLOGOUT,
loadUserInfo: true, loadUserInfo: true,
automaticSilentRenew: true // automaticSilentRenew: true
automaticSilentRenew: false
}) })
} }
}, },
...@@ -66,68 +67,78 @@ export default { ...@@ -66,68 +67,78 @@ export default {
}, },
methods: { methods: {
signIn () { signIn () {
this.mgr.signinRedirect().catch(function (err) { this.oidcmgr.signinRedirect().catch(function (err) {
console.log(err) console.log(err)
}) })
}, },
signOut () { signOut () {
let self = this let self = this
this.mgr.signoutRedirect().then(function (resp) { this.oidcmgr.signoutRedirect().then(function (resp) {
self.user.logged_in = false self.user.logged_in = false
console.log('signed out', resp) console.log('signed out', resp)
}).catch(function (err) { }).catch(function (err) {
console.log(err) console.log(err)
}) })
}, },
getUser () { getOIDCUser () {
let self = this let self = this
this.mgr.getUser().then(function (u) { this.oidcmgr.getUser().then(function (user) {
if (u == null) { if (user == null) {
self.user.logged_in = false self.user.logged_in = false
self.user.name = '' self.user.name = ''
self.user.email = '' self.user.email = ''
self.user.access_token = '' self.user.access_token = ''
} else { } else {
self.userOIDC = u self.setUserProperties(user)
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)
} }
}).catch(function (err) { }).catch(function (err) {
console.log(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 () { mounted () {
// TODO: remove oidc logging after thorough testing // TODO: remove oidc logging after thorough testing
oidc.Log.logger = console oidc.Log.logger = console
let self = this let self = this
this.mgr.events.addSilentRenewError(function () { this.oidcmgr.events.addSilentRenewError(function () {
// TODO: set accessTokenExpiringNotificationTime when this.mgr is created and insert this value here too // 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.') 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('token will soon expire')
console.log(self)
/* Use the following code instead of silent renewal if you want to use popups /* Use the following code instead of silent renewal if you want to use popups
console.log('starting signinPopup') console.log('starting signinPopup')
self.mgr.signinPopup(function (user) { self.oidcmgr.signinPopup(function (user) {
console.log('signinPopup result for user:') console.log('signinPopup result for user:')
console.log(user) console.log(user)
}).catch(function (err) { }).catch(function (err) {
console.log(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!') console.log('expired!')
}) })
this.getUser() this.getOIDCUser()
this.mgr.startSilentRenew()
} }
} }
</script> </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