feat(web): add client utilities
This commit is contained in:
1 parent
a796620b7f
commit
39f3221640
7 files changed
+335
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
isMsalConfigured,
|
||||
MSAL_API_SCOPE,
|
||||
MSAL_SILENT_REDIRECT_URI,
|
||||
msalInstance,
|
||||
} from './msal.config';
|
||||
|
||||
export async function acquireAccessToken(): Promise<string | null> {
|
||||
if (!isMsalConfigured || !msalInstance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const accounts = msalInstance.getAllAccounts();
|
||||
const account = msalInstance.getActiveAccount() ?? accounts[0];
|
||||
if (!account) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const response = await msalInstance.acquireTokenSilent({
|
||||
account,
|
||||
scopes: [MSAL_API_SCOPE],
|
||||
redirectUri: MSAL_SILENT_REDIRECT_URI,
|
||||
});
|
||||
|
||||
return response.accessToken;
|
||||
}
|
||||
Reference in new issue
Block a user