Created
April 17, 2018 10:49
-
-
Save postb99/a2f38c9352790ae0ff0d2f4977cbf23e to your computer and use it in GitHub Desktop.
Add adal token renewal to App startup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default Vue.extend({ | |
name: 'app', | |
created: function() { | |
// Add an utility method to check token on startup | |
// because the necessary renewal when expired etc isn't handled for now by vue-adal package. | |
// (see a comment in https://github.com/survirtual/vue-adal/issues/2). | |
const resource = AuthenticationContext.config.clientId | |
AuthenticationContext.acquireToken(resource, (err: any, token: any) => { | |
if (err) { | |
let errCode = err.split(':')[0] | |
switch (errCode) { | |
case 'AADSTS50058': // Need to prompt for user sign in | |
AuthenticationContext.login() | |
break | |
case 'AADSTS65001': // Token is invalid; grab a new one | |
AuthenticationContext.acquireTokenRedirect(resource) | |
break | |
case 'AADSTS16000': // No Access | |
default: | |
// Need a pop-up forcing a login | |
AuthenticationContext.login() | |
break | |
} | |
} | |
}) | |
}, | |
computed: { | |
isAuthenticated(): boolean { | |
return this.$adal.isAuthenticated() | |
} | |
}, | |
methods: { | |
logOut() { | |
this.$adal.logout() | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment