Skip to content

Instantly share code, notes, and snippets.

@anton-gorbikov
Last active Jul 1, 2019
Embed
What would you like to do?
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