Newer
Older
<template>
<div id="app">
<app-header v-bind:modules="modules" v-bind:user="user"></app-header>
<router-view/>
<app-footer></app-footer>
</div>
</template>
<script>
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
import oidc from 'oidc-client'
import header from './components/Header.vue'
import footer from './components/Footer.vue'
export default {
name: 'app',
components: {
'app-header': header,
'app-footer': footer
},
data () {
return {
modules_logged_out: [
{ slug: 'home', title: 'Home' },
{ slug: 'credits', title: 'Credits' },
{ slug: 'debug', title: 'Debug' }
],
modules_logged_in: [
{ slug: 'home', title: 'Home' },
{ slug: 'shows', title: 'Sendungen verwalten' },
{ slug: 'files', title: 'Dateien und Playlists' },
{ slug: 'settings', title: 'Settings' },
{ slug: 'credits', title: 'Credits' },
{ slug: 'debug', title: 'Debug' }
user: {
name: '',
email: '',
access_token: '',
expires_at: 0,
logged_in: false
},
userOIDC: null,
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 + ''
client_id: process.env.OIDC_CLIENT_ID,
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',
accessTokenExpiringNotificationTime: process.env.API_STEERING_OIDC_EXPIRE_NOTIFICATION,
response_type: 'id_token token',
scope: 'openid profile email',
post_logout_redirect_uri: process.env.API_STEERING_OIDC_REDIRECT_URI_POSTLOGOUT,
},
computed: {
modules: function () {
if (this.user.logged_in === true) return this.modules_logged_in
else return this.modules_logged_out
}
},
methods: {
signIn () {
this.oidcmgr.signinRedirect().catch(function (err) {
console.log(err)
})
},
signOut () {
let self = this
this.oidcmgr.signoutRedirect().then(function (resp) {
self.user.logged_in = false
console.log('signed out', resp)
}).catch(function (err) {
console.log(err)
})
},
getOIDCUser () {
let self = this
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 {
// TODO: check user.expires_at
// if token already expired try to get a new one or mark the user as logged out
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
// TODO: remove debug info after thorough testing
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.oidcmgr.events.addAccessTokenExpiring(function () {
console.log('starting silent access_token renewal')
self.oidcmgr.signinSilent().then(function (user) {
self.user.access_token = user.access_token
console.log(self.user.access_token)
}).catch(function (err) {
console.log(err)
alert('Your OpenID access token could not be renewed automatically.\n' +
'You will be logged out in ' + process.env.API_STEERING_OIDC_EXPIRE_NOTIFICATION + ' seconds.')
})
this.oidcmgr.events.addAccessTokenExpired(function () {
console.log('expired!')
})
this.getOIDCUser()
}
}
</script>
<style>
#app {
/*
#app .content-width {
margin: auto;
width: 920px;
max-width: 920px;
}
*/