mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-10-13 23:38:45 +01:00
Attempt to aquire token via popup if silent fails
This commit is contained in:
parent
a298fd8389
commit
cfbbf115f1
@ -1,6 +1,6 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useBoolean } from "@uifabric/react-hooks";
|
import { useBoolean } from "@uifabric/react-hooks";
|
||||||
import { UserAgentApplication, Account, Configuration } from "msal";
|
import { UserAgentApplication, Account, Configuration, InteractionRequiredAuthError } from "msal";
|
||||||
|
|
||||||
const config: Configuration = {
|
const config: Configuration = {
|
||||||
cache: {
|
cache: {
|
||||||
@ -69,18 +69,42 @@ export function useAADAuth(): ReturnType {
|
|||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (account && tenantId) {
|
if (account && tenantId) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
msal.acquireTokenSilent({
|
msal
|
||||||
// There is a bug in MSALv1 that requires us to refresh the token. Their internal cache is not respecting authority
|
.acquireTokenSilent({
|
||||||
forceRefresh: true,
|
// There is a bug in MSALv1 that requires us to refresh the token. Their internal cache is not respecting authority
|
||||||
authority: `https://login.microsoftonline.com/${tenantId}`,
|
forceRefresh: true,
|
||||||
scopes: ["https://graph.windows.net//.default"],
|
authority: `https://login.microsoftonline.com/${tenantId}`,
|
||||||
}),
|
scopes: ["https://graph.windows.net//.default"],
|
||||||
msal.acquireTokenSilent({
|
})
|
||||||
// There is a bug in MSALv1 that requires us to refresh the token. Their internal cache is not respecting authority
|
.catch((error: unknown) => {
|
||||||
forceRefresh: true,
|
if (error instanceof InteractionRequiredAuthError) {
|
||||||
authority: `https://login.microsoftonline.com/${tenantId}`,
|
return msal.acquireTokenPopup({
|
||||||
scopes: ["https://management.azure.com//.default"],
|
// There is a bug in MSALv1 that requires us to refresh the token. Their internal cache is not respecting authority
|
||||||
}),
|
forceRefresh: true,
|
||||||
|
authority: `https://login.microsoftonline.com/${tenantId}`,
|
||||||
|
scopes: ["https://graph.windows.net//.default"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}),
|
||||||
|
msal
|
||||||
|
.acquireTokenSilent({
|
||||||
|
// There is a bug in MSALv1 that requires us to refresh the token. Their internal cache is not respecting authority
|
||||||
|
forceRefresh: true,
|
||||||
|
authority: `https://login.microsoftonline.com/${tenantId}`,
|
||||||
|
scopes: ["https://management.azure.com//.default"],
|
||||||
|
})
|
||||||
|
.catch((error: unknown) => {
|
||||||
|
if (error instanceof InteractionRequiredAuthError) {
|
||||||
|
return msal.acquireTokenPopup({
|
||||||
|
// There is a bug in MSALv1 that requires us to refresh the token. Their internal cache is not respecting authority
|
||||||
|
forceRefresh: true,
|
||||||
|
authority: `https://login.microsoftonline.com/${tenantId}`,
|
||||||
|
scopes: ["https://management.azure.com//.default"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}),
|
||||||
]).then(([graphTokenResponse, armTokenResponse]) => {
|
]).then(([graphTokenResponse, armTokenResponse]) => {
|
||||||
setGraphToken(graphTokenResponse.accessToken);
|
setGraphToken(graphTokenResponse.accessToken);
|
||||||
setArmToken(armTokenResponse.accessToken);
|
setArmToken(armTokenResponse.accessToken);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user