Skip to content

Commit

Permalink
Force an update after acquiring a token interactively (#239539)
Browse files Browse the repository at this point in the history
* Force an update after acquiring a token interactively

This will make sure the account cache is up-to-date before the acquireTokenInteractive ends.

A greater fix is maybe turning the accounts cache to be a promise... bit this is the candidate fix for now.

Fixes #235327

* also delete event
  • Loading branch information
TylerLeonhardt authored Feb 3, 2025
1 parent 7e6c159 commit 5571308
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ export class MsalAuthProvider implements AuthenticationProvider {
const session = this.sessionFromAuthenticationResult(result, scopeData.originalScopes);
this._telemetryReporter.sendLoginEvent(session.scopes);
this._logger.info('[createSession]', `[${scopeData.scopeStr}]`, 'returned session');
this._onDidChangeSessionsEmitter.fire({ added: [session], changed: [], removed: [] });
return session;
} catch (e) {
lastError = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,29 @@ export class CachedPublicClientApplication implements ICachedPublicClientApplica

async acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult> {
this._logger.debug(`[acquireTokenInteractive] [${this._clientId}] [${this._authority}] [${request.scopes?.join(' ')}] loopbackClientOverride: ${request.loopbackClient ? 'true' : 'false'}`);
const result = await window.withProgress(
return await window.withProgress(
{
location: ProgressLocation.Notification,
cancellable: true,
title: l10n.t('Signing in to Microsoft...')
},
(_process, token) => this._sequencer.queue(() => raceCancellationAndTimeoutError(
this._pca.acquireTokenInteractive(request),
token,
1000 * 60 * 5
))
(_process, token) => this._sequencer.queue(async () => {
const result = await raceCancellationAndTimeoutError(
this._pca.acquireTokenInteractive(request),
token,
1000 * 60 * 5
);
if (this._isBrokerAvailable) {
await this._accountAccess.setAllowedAccess(result.account!, true);
}
// Force an update so that the account cache is updated.
// TODO:@TylerLeonhardt The problem is, we use the sequencer for
// change events but we _don't_ use it for the accounts cache.
// We should probably use it for the accounts cache as well.
await this._update();
return result;
})
);
if (this._isBrokerAvailable) {
await this._accountAccess.setAllowedAccess(result.account!, true);
}
return result;
}

/**
Expand Down

0 comments on commit 5571308

Please sign in to comment.