Skip to content

Commit

Permalink
Update popup & redirect flows to use invokeAsync (#6612)
Browse files Browse the repository at this point in the history
Updates remaining references to `setPreQueueTime` to use the
`invokeAsync` helper instead
  • Loading branch information
tnorling authored Oct 27, 2023
1 parent 13e8fc5 commit bf61f42
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Use invokeAsync in popup/redirect flows",
"packageName": "@azure/msal-browser",
"email": "[email protected]",
"dependentChangeType": "patch"
}
59 changes: 30 additions & 29 deletions lib/msal-browser/src/interaction_client/PopupClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ICrypto,
ProtocolMode,
ServerResponseType,
invokeAsync,
} from "@azure/msal-common";
import { StandardInteractionClient } from "./StandardInteractionClient";
import { EventType } from "../event/EventType";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
78 changes: 40 additions & 38 deletions lib/msal-browser/src/interaction_client/RedirectClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
IPerformanceClient,
PerformanceEvents,
ProtocolMode,
invokeAsync,
} from "@azure/msal-common";
import { StandardInteractionClient } from "./StandardInteractionClient";
import {
Expand Down Expand Up @@ -78,19 +79,19 @@ export class RedirectClient extends StandardInteractionClient {
* @param request
*/
async acquireToken(request: RedirectRequest): Promise<void> {
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(
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bf61f42

Please sign in to comment.