Skip to content

Commit

Permalink
Enable redirect handler also in silent token acquisition (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
tigloo authored Jul 29, 2024
1 parent 63446c5 commit f9c5f85
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions assets/msalv2.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ var aadOauth = (function () {
// Will return the authentication result on success and update the
// global authResult variable.
async function silentlyAcquireToken() {
try {
// The redirect handler task will complete with auth results if we
// were redirected from AAD. If not, it will complete with null
// We must wait for it to complete before we allow the login to
// attempt to acquire a token silently, and then progress to interactive
// login (if silent acquisition fails).
let result = await redirectHandlerTask;
if (result !== null) {
authResult = result;
return authResult;
}
}
catch (error) {
authResultError = null;
}

const account = getAccount();
if (account == null) {
return null;
Expand Down Expand Up @@ -102,23 +118,6 @@ var aadOauth = (function () {
/// to attempt to refresh the token using an interactive login.

async function login(refreshIfAvailable, useRedirect, onSuccess, onError) {
try {
// The redirect handler task will complete with auth results if we
// were redirected from AAD. If not, it will complete with null
// We must wait for it to complete before we allow the login to
// attempt to acquire a token silently, and then progress to interactive
// login (if silent acquisition fails).
let result = await redirectHandlerTask;
if (result !== null) {
authResult = result;
}
}
catch (error) {
authResultError = error;
onError(authResultError);
return;
}

// Try to sign in silently, assuming we have already signed in and have
// a cached access token
await silentlyAcquireToken()
Expand Down

0 comments on commit f9c5f85

Please sign in to comment.