Skip to content

Commit 3e4c956

Browse files
authored
Don't use temporary cache for silent & popup flows (#6586)
Silent and Popup flows don't need to use temporary cache because they don't lose context the way the Redirect flow does. Applying this across the board causes unnecessary stringification, storage, lookup and parsing in those flows, especially since the code isn't shared across those flows anyway. This PR refactors the popup and silent flows to pass the request object through the stack instead of storing and looking up in sessionStorage. The redirect flow will continue to utilize sessionStorage for temp cache.
1 parent ce665da commit 3e4c956

15 files changed

+228
-342
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Don't use temporary cache for silent & popup flows #6586",
4+
"packageName": "@azure/msal-browser",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Don't use temporary cache for silent & popup flows #6586",
4+
"packageName": "@azure/msal-common",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

lib/msal-browser/src/interaction_client/PopupClient.ts

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,12 @@ import { INavigationClient } from "../navigation/INavigationClient";
4242
import { EventHandler } from "../event/EventHandler";
4343
import { BrowserCacheManager } from "../cache/BrowserCacheManager";
4444
import { BrowserConfiguration } from "../config/Configuration";
45-
import {
46-
InteractionHandler,
47-
InteractionParams,
48-
} from "../interaction_handler/InteractionHandler";
45+
import { InteractionHandler } from "../interaction_handler/InteractionHandler";
4946
import { PopupWindowAttributes } from "../request/PopupWindowAttributes";
5047
import { EventError } from "../event/EventMessage";
5148
import { AuthenticationResult } from "../response/AuthenticationResult";
5249

53-
export type PopupParams = InteractionParams & {
50+
export type PopupParams = {
5451
popup?: Window | null;
5552
popupName: string;
5653
popupWindowAttributes: PopupWindowAttributes;
@@ -212,13 +209,6 @@ export class PopupClient extends StandardInteractionClient {
212209
InteractionType.Popup
213210
);
214211
BrowserUtils.preconnect(validRequest.authority);
215-
this.browserStorage.updateCacheEntries(
216-
validRequest.state,
217-
validRequest.nonce,
218-
validRequest.authority,
219-
validRequest.loginHint || Constants.EMPTY_STRING,
220-
validRequest.account || null
221-
);
222212

223213
try {
224214
// Create auth code request and generate PKCE params
@@ -295,11 +285,6 @@ export class PopupClient extends StandardInteractionClient {
295285
// Deserialize hash fragment response parameters.
296286
const serverParams: ServerAuthorizationCodeResponse =
297287
UrlString.getDeserializedHash(hash);
298-
const state = this.validateAndExtractStateFromHash(
299-
serverParams,
300-
InteractionType.Popup,
301-
validRequest.correlationId
302-
);
303288
// Remove throttle if it exists
304289
ThrottlingUtils.removeThrottle(
305290
this.browserStorage,
@@ -340,25 +325,19 @@ export class PopupClient extends StandardInteractionClient {
340325
);
341326
const { userRequestState } = ProtocolUtils.parseRequestState(
342327
this.browserCrypto,
343-
state
328+
validRequest.state
344329
);
345-
return nativeInteractionClient
346-
.acquireToken({
347-
...validRequest,
348-
state: userRequestState,
349-
prompt: undefined, // Server should handle the prompt, ideally native broker can do this part silently
350-
})
351-
.finally(() => {
352-
this.browserStorage.cleanRequestByState(state);
353-
});
330+
return nativeInteractionClient.acquireToken({
331+
...validRequest,
332+
state: userRequestState,
333+
prompt: undefined, // Server should handle the prompt, ideally native broker can do this part silently
334+
});
354335
}
355336

356337
// Handle response from hash string.
357338
const result = await interactionHandler.handleCodeResponseFromHash(
358339
hash,
359-
state,
360-
authClient.authority,
361-
this.networkClient
340+
validRequest
362341
);
363342

364343
return result;
@@ -372,7 +351,6 @@ export class PopupClient extends StandardInteractionClient {
372351
(e as AuthError).setCorrelationId(this.correlationId);
373352
serverTelemetryManager.cacheFailedRequest(e);
374353
}
375-
this.browserStorage.cleanRequestByState(validRequest.state);
376354
throw e;
377355
}
378356
}

lib/msal-browser/src/interaction_client/RedirectClient.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ export class RedirectClient extends StandardInteractionClient {
139139
this.browserStorage,
140140
authCodeRequest,
141141
this.logger,
142-
this.browserCrypto,
143142
this.performanceClient
144143
);
145144

@@ -463,15 +462,9 @@ export class RedirectClient extends StandardInteractionClient {
463462
this.browserStorage,
464463
cachedRequest,
465464
this.logger,
466-
this.browserCrypto,
467465
this.performanceClient
468466
);
469-
return await interactionHandler.handleCodeResponseFromHash(
470-
hash,
471-
state,
472-
authClient.authority,
473-
this.networkClient
474-
);
467+
return await interactionHandler.handleCodeResponseFromHash(hash, state);
475468
}
476469

477470
/**

lib/msal-browser/src/interaction_client/SilentAuthCodeClient.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
Logger,
99
CommonAuthorizationCodeRequest,
1010
AuthError,
11-
Constants,
1211
IPerformanceClient,
1312
PerformanceEvents,
1413
invokeAsync,
@@ -81,13 +80,6 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
8180
this.performanceClient,
8281
request.correlationId
8382
)(request, InteractionType.Silent);
84-
this.browserStorage.updateCacheEntries(
85-
silentRequest.state,
86-
silentRequest.nonce,
87-
silentRequest.authority,
88-
silentRequest.loginHint || Constants.EMPTY_STRING,
89-
silentRequest.account || null
90-
);
9183

9284
const serverTelemetryManager = this.initializeServerTelemetryManager(
9385
this.apiId
@@ -137,17 +129,14 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
137129
cloud_graph_host_name: request.cloudGraphHostName,
138130
cloud_instance_host_name: request.cloudInstanceHostName,
139131
},
140-
silentRequest.state,
141-
authClient.authority,
142-
this.networkClient,
132+
silentRequest,
143133
false
144134
);
145135
} catch (e) {
146136
if (e instanceof AuthError) {
147137
(e as AuthError).setCorrelationId(this.correlationId);
148138
serverTelemetryManager.cacheFailedRequest(e);
149139
}
150-
this.browserStorage.cleanRequestByState(silentRequest.state);
151140
throw e;
152141
}
153142
}

lib/msal-browser/src/interaction_client/SilentIframeClient.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
CommonAuthorizationCodeRequest,
1111
AuthorizationCodeClient,
1212
AuthError,
13-
Constants,
1413
UrlString,
1514
ServerAuthorizationCodeResponse,
1615
ProtocolUtils,
@@ -120,13 +119,6 @@ export class SilentIframeClient extends StandardInteractionClient {
120119
InteractionType.Silent
121120
);
122121
BrowserUtils.preconnect(silentRequest.authority);
123-
this.browserStorage.updateCacheEntries(
124-
silentRequest.state,
125-
silentRequest.nonce,
126-
silentRequest.authority,
127-
silentRequest.loginHint || Constants.EMPTY_STRING,
128-
silentRequest.account || null
129-
);
130122

131123
const serverTelemetryManager = this.initializeServerTelemetryManager(
132124
this.apiId
@@ -158,7 +150,6 @@ export class SilentIframeClient extends StandardInteractionClient {
158150
(e as AuthError).setCorrelationId(this.correlationId);
159151
serverTelemetryManager.cacheFailedRequest(e);
160152
}
161-
this.browserStorage.cleanRequestByState(silentRequest.state);
162153
throw e;
163154
}
164155
}
@@ -273,11 +264,6 @@ export class SilentIframeClient extends StandardInteractionClient {
273264
// Deserialize hash fragment response parameters.
274265
const serverParams: ServerAuthorizationCodeResponse =
275266
UrlString.getDeserializedHash(hash);
276-
const state = this.validateAndExtractStateFromHash(
277-
serverParams,
278-
InteractionType.Silent,
279-
correlationId
280-
);
281267

282268
if (serverParams.accountId) {
283269
this.logger.verbose(
@@ -304,7 +290,7 @@ export class SilentIframeClient extends StandardInteractionClient {
304290
);
305291
const { userRequestState } = ProtocolUtils.parseRequestState(
306292
this.browserCrypto,
307-
state
293+
silentRequest.state
308294
);
309295
return invokeAsync(
310296
nativeInteractionClient.acquireToken.bind(
@@ -318,8 +304,6 @@ export class SilentIframeClient extends StandardInteractionClient {
318304
...silentRequest,
319305
state: userRequestState,
320306
prompt: silentRequest.prompt || PromptValue.NONE,
321-
}).finally(() => {
322-
this.browserStorage.cleanRequestByState(state);
323307
});
324308
}
325309

@@ -332,6 +316,6 @@ export class SilentIframeClient extends StandardInteractionClient {
332316
this.logger,
333317
this.performanceClient,
334318
correlationId
335-
)(hash, state, authClient.authority, this.networkClient);
319+
)(hash, silentRequest);
336320
}
337321
}

0 commit comments

Comments
 (0)