Last active
February 14, 2019 12:11
-
-
Save bietkul/d03ccb88241d85c94d2196fbfcf4279e to your computer and use it in GitHub Desktop.
Auth utility to instantiate the Auth0
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
| import auth0 from 'auth0-js'; | |
| export default class Auth { | |
| constructor({domain, clientID, audience}) | |
| { | |
| this.auth0 = new auth0.WebAuth({ | |
| domain, | |
| clientID, | |
| redirectUri: `${window.location.origin}/authenticate`, | |
| audience, | |
| responseType: 'token id_token', | |
| scope: 'openid profile email', | |
| }); | |
| } | |
| login() { | |
| this.auth0.authorize(); | |
| } | |
| parseTokens() { | |
| return new Promise((resolve, reject) => this.auth0.parseHash((err, | |
| result) => { | |
| if (err) { | |
| reject(err); | |
| } else { | |
| resolve({...result, expiresAt: (result.expiresIn * 1000) + new | |
| Date().getTime()}); | |
| } | |
| } | |
| )); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment