-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
23 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ myMSALObj.initialize().then(() => { | |
|
||
function handleResponse() { | ||
// when a filter is passed into getAllAccounts, it returns all cached accounts that match the filter. Use isHomeTenant filter to get the home accounts. | ||
const allAccounts = myMSALObj.getAllAccounts({ tenantId: homeTenant, username: "[email protected]" }); | ||
const allAccounts = myMSALObj.getAllAccounts(); | ||
console.log("Get all accounts: ", allAccounts); | ||
if (!allAccounts || allAccounts.length < 1) { | ||
return; | ||
|
@@ -77,17 +77,15 @@ function signOut(interactionType) { | |
async function requestGuestToken() { | ||
const currentAcc = myMSALObj.getAccountByHomeId(accountId); | ||
if (currentAcc) { | ||
const response = await getTokenRedirect({ ...guestTenantRequest, account: currentAcc }).catch(error => { | ||
console.log(error); | ||
}); | ||
|
||
const response = await sso(guestTenantRequest, currentAcc.idTokenClaims.login_hint); | ||
console.log(response); | ||
callMSGraph(graphConfig.graphMeEndpoint, response.accessToken, updateUI); | ||
guestProfileButton.style.display = 'none'; | ||
} | ||
} | ||
|
||
async function getTokenRedirect(request) { | ||
console.log("Request: ", request); | ||
return await myMSALObj.acquireTokenSilent(request).catch(async (error) => { | ||
console.log("silent token acquisition fails."); | ||
if (error instanceof msal.InteractionRequiredAuthError) { | ||
|
@@ -98,4 +96,17 @@ async function getTokenRedirect(request) { | |
console.error(error); | ||
} | ||
}); | ||
} | ||
|
||
async function sso(request, loginHint) { | ||
return await myMSALObj.ssoSilent(request, loginHint).catch(async (error) => { | ||
console.log("sso failed"); | ||
if (error instanceof msal.InteractionRequiredAuthError) { | ||
// fallback to interaction when silent call fails | ||
console.log("acquiring token using redirect"); | ||
myMSALObj.acquireTokenRedirect(request); | ||
} else { | ||
console.error(error); | ||
} | ||
}) | ||
} |
6 changes: 3 additions & 3 deletions
6
samples/msal-browser-samples/VanillaJSTestApp2.0/app/multi-tenant/authConfig.js
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