Skip to content

Instantly share code, notes, and snippets.

@anton-gorbikov
Last active July 1, 2019 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anton-gorbikov/f12dd83ddd3bc947eb972947cc603427 to your computer and use it in GitHub Desktop.
Save anton-gorbikov/f12dd83ddd3bc947eb972947cc603427 to your computer and use it in GitHub Desktop.
return new Promise((resolve) => {
let scopes = {
// To acquire Sharepoint token
scopes: ['https://{{tenant ID}}.sharepoint.com/.default', 'openid', 'profile'],
// To acquire Graph API token
scopes: ['.default', 'openid', 'profile'],
loginHint: null
};
context.handleRedirectCallback((error, response) => {
if (error) {
// TODO: e.g. track into analytics
} else if (window.parent === window) {
if (response.tokenType === 'access_token' && response.accessToken) {
resolve(response.accessToken);
}
}
});
if (!context.isCallback(window.location.hash)) {
if (context.getAccount()) {
context.acquireTokenSilent(scopes).then((response) => {
if (response.accessToken) {
resolve(response.accessToken);
}
}).catch((_error) => {
context.acquireTokenRedirect(scopes);
});
} else {
context.loginRedirect(scopes);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment