From bf61f42aff220c33ae4b0e248cc4aa9009306f3a Mon Sep 17 00:00:00 2001 From: Thomas Norling Date: Fri, 27 Oct 2023 13:34:20 -0700 Subject: [PATCH] Update popup & redirect flows to use invokeAsync (#6612) Updates remaining references to `setPreQueueTime` to use the `invokeAsync` helper instead --- ...-80d74e84-d279-4360-89c4-f52fea3c6a4f.json | 7 ++ .../src/interaction_client/PopupClient.ts | 59 +++++++------- .../src/interaction_client/RedirectClient.ts | 78 ++++++++++--------- 3 files changed, 77 insertions(+), 67 deletions(-) create mode 100644 change/@azure-msal-browser-80d74e84-d279-4360-89c4-f52fea3c6a4f.json diff --git a/change/@azure-msal-browser-80d74e84-d279-4360-89c4-f52fea3c6a4f.json b/change/@azure-msal-browser-80d74e84-d279-4360-89c4-f52fea3c6a4f.json new file mode 100644 index 0000000000..9ae58ce055 --- /dev/null +++ b/change/@azure-msal-browser-80d74e84-d279-4360-89c4-f52fea3c6a4f.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Use invokeAsync in popup/redirect flows", + "packageName": "@azure/msal-browser", + "email": "thomas.norling@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/lib/msal-browser/src/interaction_client/PopupClient.ts b/lib/msal-browser/src/interaction_client/PopupClient.ts index 0027c4397a..26ca102dd2 100644 --- a/lib/msal-browser/src/interaction_client/PopupClient.ts +++ b/lib/msal-browser/src/interaction_client/PopupClient.ts @@ -20,6 +20,7 @@ import { ICrypto, ProtocolMode, ServerResponseType, + invokeAsync, } from "@azure/msal-common"; import { StandardInteractionClient } from "./StandardInteractionClient"; import { EventType } from "../event/EventType"; @@ -200,37 +201,39 @@ export class PopupClient extends StandardInteractionClient { ApiId.acquireTokenPopup ); - this.performanceClient.setPreQueueTime( + const validRequest = await invokeAsync( + this.initializeAuthorizationRequest.bind(this), PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest, - request.correlationId - ); - const validRequest = await this.initializeAuthorizationRequest( - request, - InteractionType.Popup - ); + this.logger, + this.performanceClient, + this.correlationId + )(request, InteractionType.Popup); + BrowserUtils.preconnect(validRequest.authority); try { // Create auth code request and generate PKCE params - this.performanceClient.setPreQueueTime( - PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest, - request.correlationId - ); const authCodeRequest: CommonAuthorizationCodeRequest = - await this.initializeAuthorizationCodeRequest(validRequest); + await invokeAsync( + this.initializeAuthorizationCodeRequest.bind(this), + PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest, + this.logger, + this.performanceClient, + this.correlationId + )(validRequest); // Initialize the client - this.performanceClient.setPreQueueTime( + const authClient: AuthorizationCodeClient = await invokeAsync( + this.createAuthCodeClient.bind(this), PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, - request.correlationId + this.logger, + this.performanceClient, + this.correlationId + )( + serverTelemetryManager, + validRequest.authority, + validRequest.azureCloudOptions ); - const authClient: AuthorizationCodeClient = - await this.createAuthCodeClient( - serverTelemetryManager, - validRequest.authority, - validRequest.azureCloudOptions - ); - this.logger.verbose("Auth code client created"); const isNativeBroker = NativeMessageHandler.isNativeAvailable( this.config, @@ -388,15 +391,13 @@ export class PopupClient extends StandardInteractionClient { await this.clearCacheOnLogout(validRequest.account); // Initialize the client - this.performanceClient.setPreQueueTime( + const authClient = await invokeAsync( + this.createAuthCodeClient.bind(this), PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, - validRequest.correlationId - ); - const authClient = await this.createAuthCodeClient( - serverTelemetryManager, - requestAuthority - ); - this.logger.verbose("Auth code client created"); + this.logger, + this.performanceClient, + this.correlationId + )(serverTelemetryManager, requestAuthority); try { authClient.authority.endSessionEndpoint; diff --git a/lib/msal-browser/src/interaction_client/RedirectClient.ts b/lib/msal-browser/src/interaction_client/RedirectClient.ts index f4b597403a..a8641b8a7b 100644 --- a/lib/msal-browser/src/interaction_client/RedirectClient.ts +++ b/lib/msal-browser/src/interaction_client/RedirectClient.ts @@ -18,6 +18,7 @@ import { IPerformanceClient, PerformanceEvents, ProtocolMode, + invokeAsync, } from "@azure/msal-common"; import { StandardInteractionClient } from "./StandardInteractionClient"; import { @@ -78,19 +79,19 @@ export class RedirectClient extends StandardInteractionClient { * @param request */ async acquireToken(request: RedirectRequest): Promise { - this.performanceClient.setPreQueueTime( + const validRequest = await invokeAsync( + this.initializeAuthorizationRequest.bind(this), PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest, - request.correlationId - ); - const validRequest = await this.initializeAuthorizationRequest( - request, - InteractionType.Redirect - ); + this.logger, + this.performanceClient, + this.correlationId + )(request, InteractionType.Redirect); + this.browserStorage.updateCacheEntries( validRequest.state, validRequest.nonce, validRequest.authority, - validRequest.loginHint || Constants.EMPTY_STRING, + validRequest.loginHint || "", validRequest.account || null ); const serverTelemetryManager = this.initializeServerTelemetryManager( @@ -113,25 +114,27 @@ export class RedirectClient extends StandardInteractionClient { try { // Create auth code request and generate PKCE params - this.performanceClient.setPreQueueTime( - PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest, - request.correlationId - ); const authCodeRequest: CommonAuthorizationCodeRequest = - await this.initializeAuthorizationCodeRequest(validRequest); + await invokeAsync( + this.initializeAuthorizationCodeRequest.bind(this), + PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest, + this.logger, + this.performanceClient, + this.correlationId + )(validRequest); // Initialize the client - this.performanceClient.setPreQueueTime( + const authClient: AuthorizationCodeClient = await invokeAsync( + this.createAuthCodeClient.bind(this), PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, - request.correlationId + this.logger, + this.performanceClient, + this.correlationId + )( + serverTelemetryManager, + validRequest.authority, + validRequest.azureCloudOptions ); - const authClient: AuthorizationCodeClient = - await this.createAuthCodeClient( - serverTelemetryManager, - validRequest.authority, - validRequest.azureCloudOptions - ); - this.logger.verbose("Auth code client created"); // Create redirect interaction handler. const interactionHandler = new RedirectHandler( @@ -443,15 +446,15 @@ export class RedirectClient extends StandardInteractionClient { BrowserAuthErrorCodes.noCachedAuthorityError ); } - this.performanceClient.setPreQueueTime( + + const authClient = await invokeAsync( + this.createAuthCodeClient.bind(this), PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, - cachedRequest.correlationId - ); - const authClient = await this.createAuthCodeClient( - serverTelemetryManager, - currentAuthority - ); - this.logger.verbose("Auth code client created"); + this.logger, + this.performanceClient, + this.correlationId + )(serverTelemetryManager, currentAuthority); + ThrottlingUtils.removeThrottle( this.browserStorage, this.config.auth.clientId, @@ -494,15 +497,14 @@ export class RedirectClient extends StandardInteractionClient { timeout: this.config.system.redirectNavigationTimeout, noHistory: false, }; - this.performanceClient.setPreQueueTime( + + const authClient = await invokeAsync( + this.createAuthCodeClient.bind(this), PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, - validLogoutRequest.correlationId - ); - const authClient = await this.createAuthCodeClient( - serverTelemetryManager, - logoutRequest && logoutRequest.authority - ); - this.logger.verbose("Auth code client created"); + this.logger, + this.performanceClient, + this.correlationId + )(serverTelemetryManager, logoutRequest && logoutRequest.authority); if (authClient.authority.protocolMode === ProtocolMode.OIDC) { try {