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

added oidc access token renewal with debug code

parent c75a659a
...@@ -4,6 +4,7 @@ const prodEnv = require('./prod.env') ...@@ -4,6 +4,7 @@ const prodEnv = require('./prod.env')
module.exports = merge(prodEnv, { module.exports = merge(prodEnv, {
NODE_ENV: '"development"', NODE_ENV: '"development"',
OIDC_CLIENT_ID: '"174626"',
API_STEERING: '"http://127.0.0.1:8000/api/v1/"', API_STEERING: '"http://127.0.0.1:8000/api/v1/"',
API_STEERING_SHOWS: '"http://127.0.0.1:8000/api/v1/shows/"', API_STEERING_SHOWS: '"http://127.0.0.1:8000/api/v1/shows/"',
// OIDC endpoint of the pv/steering module // OIDC endpoint of the pv/steering module
......
...@@ -38,19 +38,23 @@ export default { ...@@ -38,19 +38,23 @@ export default {
name: '', name: '',
email: '', email: '',
access_token: '', access_token: '',
expires_at: 0,
logged_in: false logged_in: false
}, },
userOIDC: null, userOIDC: null,
mgr: new oidc.UserManager({ mgr: 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,
client_id: '174626', // the client id has to be a string, therefore we add the + ''
client_id: process.env.OIDC_CLIENT_ID,
redirect_uri: process.env.API_STEERING_OIDC_REDIRECT_URI, redirect_uri: process.env.API_STEERING_OIDC_REDIRECT_URI,
// redirect_uri: process.env.API_STEERING_OIDC_REDIRECT_URI, silent_redirect_uri: 'http://localhost:8080/static/oidc_callback_silentRenew.html',
popup_redirect_uri: 'http://localhost:8080/static/oidc_callback_popupRenew.html',
response_type: 'id_token token', response_type: 'id_token token',
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
}) })
} }
}, },
...@@ -89,6 +93,9 @@ export default { ...@@ -89,6 +93,9 @@ export default {
self.user.name = u.profile.nickname self.user.name = u.profile.nickname
self.user.email = u.profile.email self.user.email = u.profile.email
self.user.access_token = u.access_token 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)
...@@ -96,7 +103,31 @@ export default { ...@@ -96,7 +103,31 @@ export default {
} }
}, },
mounted () { 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
alert('Your OpenID access token could not be renewed automatically. You will be logged out in 60 seconds.')
})
this.mgr.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) {
console.log('signinPopup result for user:')
console.log(user)
}).catch(function (err) {
console.log(err)
})
*/
})
this.mgr.events.addAccessTokenExpired(function () {
console.log('expired!')
})
this.getUser() this.getUser()
this.mgr.startSilentRenew()
} }
} }
</script> </script>
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<b-dropdown-item href="#">Profile</b-dropdown-item> <b-dropdown-item href="#">Profile</b-dropdown-item>
<b-dropdown-item @click='$parent.signOut'>Signout</b-dropdown-item> <b-dropdown-item @click='$parent.signOut'>Signout</b-dropdown-item>
</b-nav-item-dropdown> </b-nav-item-dropdown>
<b-nav-item v-if="! user.logged_in" to="login"><img src="../assets/16x16/system-users.png" alt="log-in symbol" title="Log in"></b-nav-item> <b-nav-item v-if="! user.logged_in" to="home"><img src="../assets/16x16/system-users.png" alt="log-in symbol" title="Log in"></b-nav-item>
<div class="help-image-container"> <div class="help-image-container">
<b-nav-item> <b-nav-item>
<router-link to="help"><img class="help-image" src="../assets/help-browser-32x32.png" alt="Help symbol" title="Go to help pages"></router-link> <router-link to="help"><img class="help-image" src="../assets/help-browser-32x32.png" alt="Help symbol" title="Go to help pages"></router-link>
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<script> <script>
var mgr = new Oidc.UserManager({userStore: new Oidc.WebStorageStateStore()}) var mgr = new Oidc.UserManager({userStore: new Oidc.WebStorageStateStore()})
mgr.signinRedirectCallback().then(function (user) { mgr.signinRedirectCallback().then(function (user) {
console.log(user)
window.location.href = '../' window.location.href = '../'
}).catch(function (err) { }).catch(function (err) {
console.log(err) console.log(err)
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Waiting...</title>
</head>
<body>
<script src="oidc-client.js"></script>
<script>
var mgr = new Oidc.UserManager()
mgr.signinPopupCallback()
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Waiting...</title>
</head>
<body>
<script src="oidc-client.js"></script>
<script>
var mgr = new Oidc.UserManager()
mgr.signinSilentCallback()
</script>
</body>
</html>
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