Last active
April 8, 2021 06:15
-
-
Save frdnrdb/afc6aa6ddc154d4c157f5f3cc176553f to your computer and use it in GitHub Desktop.
This file contains 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 { UserAgentApplication } from 'msal'; | |
const app = new UserAgentApplication({ | |
auth: { | |
clientId: process.env.AZURE_CLIENT_ID, | |
authority: `https://login.microsoftonline.com/${process.env.AZURE_TENANT_ID}` | |
}, | |
cache: { | |
cacheLocation: 'localStorage' | |
} | |
}); | |
app.handleRedirectCallback((err, payload) => { | |
if (err) return console.log('error', err.message); | |
return payload; | |
}); | |
const requestObject = { | |
scopes: [ 'User.Read' ] | |
}; | |
export default { | |
async signIn() { | |
return await app.loginRedirect(requestObject); | |
}, | |
async signOut() { | |
return await app.logout(); | |
}, | |
async getUser() { | |
return await app.getAccount(); | |
}, | |
async getToken() { | |
try { | |
return await app.acquireTokenSilent(requestObject); | |
} | |
catch(err) { | |
return await app.acquireTokenRedirect(requestObject) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment