Skip to content

Instantly share code, notes, and snippets.

@bietkul
Last active February 14, 2019 12:11
Show Gist options
  • Save bietkul/d03ccb88241d85c94d2196fbfcf4279e to your computer and use it in GitHub Desktop.
Save bietkul/d03ccb88241d85c94d2196fbfcf4279e to your computer and use it in GitHub Desktop.
Auth utility to instantiate the Auth0
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