Skip to content

Commit a4815c3

Browse files
Force an update after acquiring a token interactively (microsoft#239535)
This will make sure the account cache is up-to-date before the `acquireTokenInteractive` ends. Fixes microsoft#235327
1 parent 3cc1b64 commit a4815c3

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

extensions/microsoft-authentication/src/node/authProvider.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ export class MsalAuthProvider implements AuthenticationProvider {
233233
const session = this.sessionFromAuthenticationResult(result, scopeData.originalScopes);
234234
this._telemetryReporter.sendLoginEvent(session.scopes);
235235
this._logger.info('[createSession]', `[${scopeData.scopeStr}]`, 'returned session');
236-
this._onDidChangeSessionsEmitter.fire({ added: [session], changed: [], removed: [] });
237236
return session;
238237
} catch (e) {
239238
lastError = e;

extensions/microsoft-authentication/src/node/cachedPublicClientApplication.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,26 @@ export class CachedPublicClientApplication implements ICachedPublicClientApplica
149149

150150
async acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult> {
151151
this._logger.debug(`[acquireTokenInteractive] [${this._clientId}] [${this._authority}] [${request.scopes?.join(' ')}] loopbackClientOverride: ${request.loopbackClient ? 'true' : 'false'}`);
152-
const result = await window.withProgress(
152+
return await window.withProgress(
153153
{
154154
location: ProgressLocation.Notification,
155155
cancellable: true,
156156
title: l10n.t('Signing in to Microsoft...')
157157
},
158-
(_process, token) => this._sequencer.queue(() => raceCancellationAndTimeoutError(
159-
this._pca.acquireTokenInteractive(request),
160-
token,
161-
1000 * 60 * 5
162-
))
158+
(_process, token) => this._sequencer.queue(async () => {
159+
const result = await raceCancellationAndTimeoutError(
160+
this._pca.acquireTokenInteractive(request),
161+
token,
162+
1000 * 60 * 5
163+
);
164+
if (this._isBrokerAvailable) {
165+
await this._accountAccess.setAllowedAccess(result.account!, true);
166+
}
167+
// Force an update so that the account cache is updated
168+
await this._update();
169+
return result;
170+
})
163171
);
164-
if (this._isBrokerAvailable) {
165-
await this._accountAccess.setAllowedAccess(result.account!, true);
166-
}
167-
return result;
168172
}
169173

170174
/**

0 commit comments

Comments
 (0)