Skip to content

Commit 83877c2

Browse files
authored
Merge branch 'dev' into redirect-iframe-error-message-broker
2 parents 3b9fdf6 + 2501bd7 commit 83877c2

12 files changed

+111
-24
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": "Add errorCode and subErrorCode to client telemetry events (#4863)",
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": "preflightBrowserEnvironmentCheck should not always set interaction in progress #4893",
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": "minor",
3+
"comment": "Add errorCode and subErrorCode to performance telemetry events (#4863)",
4+
"packageName": "@azure/msal-common",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

lib/msal-browser/src/app/ClientApplication.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,16 @@ export abstract class ClientApplication {
364364
});
365365
atPopupMeasurement.flushMeasurement();
366366
return result;
367-
}).catch((e) => {
367+
}).catch((e: AuthError) => {
368368
if (loggedInAccounts.length > 0) {
369369
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Popup, null, e);
370370
} else {
371371
this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, InteractionType.Popup, null, e);
372372
}
373373

374374
atPopupMeasurement.endMeasurement({
375+
errorCode: e.errorCode,
376+
subErrorCode: e.subError,
375377
success: false
376378
});
377379
atPopupMeasurement.flushMeasurement();
@@ -432,13 +434,16 @@ export abstract class ClientApplication {
432434
return result.then((response) => {
433435
this.eventHandler.emitEvent(EventType.SSO_SILENT_SUCCESS, InteractionType.Silent, response);
434436
ssoSilentMeasurement.endMeasurement({
435-
success: true
437+
success: true,
438+
isNativeBroker: response.fromNativeBroker
436439
});
437440
ssoSilentMeasurement.flushMeasurement();
438441
return response;
439-
}).catch ((e) => {
442+
}).catch ((e: AuthError) => {
440443
this.eventHandler.emitEvent(EventType.SSO_SILENT_FAILURE, InteractionType.Silent, null, e);
441444
ssoSilentMeasurement.endMeasurement({
445+
errorCode: e.errorCode,
446+
subErrorCode: e.subError,
442447
success: false
443448
});
444449
ssoSilentMeasurement.flushMeasurement();
@@ -477,15 +482,18 @@ export abstract class ClientApplication {
477482
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_SUCCESS, InteractionType.Silent, result);
478483
this.hybridAuthCodeResponses.delete(hybridAuthCode);
479484
atbcMeasurement.endMeasurement({
480-
success: true
485+
success: true,
486+
isNativeBroker: result.fromNativeBroker
481487
});
482488
atbcMeasurement.flushMeasurement();
483489
return result;
484490
})
485-
.catch((error: Error) => {
491+
.catch((error: AuthError) => {
486492
this.hybridAuthCodeResponses.delete(hybridAuthCode);
487493
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, InteractionType.Silent, null, error);
488494
atbcMeasurement.endMeasurement({
495+
errorCode: error.errorCode,
496+
subErrorCode: error.subError,
489497
success: false
490498
});
491499
atbcMeasurement.flushMeasurement();
@@ -519,6 +527,8 @@ export abstract class ClientApplication {
519527
} catch (e) {
520528
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, InteractionType.Silent, null, e);
521529
atbcMeasurement.endMeasurement({
530+
errorCode: e instanceof AuthError && e.errorCode || undefined,
531+
subErrorCode: e instanceof AuthError && e.subError || undefined,
522532
success: false
523533
});
524534
throw e;
@@ -583,6 +593,8 @@ export abstract class ClientApplication {
583593
})
584594
.catch((error) => {
585595
atbrtMeasurement.endMeasurement({
596+
errorCode: error.errorCode,
597+
subErrorCode: error.subError,
586598
success: false
587599
});
588600
throw error;
@@ -733,12 +745,15 @@ export abstract class ClientApplication {
733745
// #endregion
734746

735747
// #region Helpers
736-
748+
737749
/**
738750
* Helper to validate app environment before making an auth request
739-
* * @param interactionType
751+
*
752+
* @protected
753+
* @param {InteractionType} interactionType What kind of interaction is being used
754+
* @param {boolean} [setInteractionInProgress=true] Whether to set interaction in progress temp cache flag
740755
*/
741-
protected preflightBrowserEnvironmentCheck(interactionType: InteractionType): void {
756+
protected preflightBrowserEnvironmentCheck(interactionType: InteractionType, setInteractionInProgress: boolean = true): void {
742757
this.logger.verbose("preflightBrowserEnvironmentCheck started");
743758
// Block request if not in browser environment
744759
BrowserUtils.blockNonBrowserEnvironment(this.isBrowserEnvironment);
@@ -763,22 +778,25 @@ export abstract class ClientApplication {
763778
}
764779

765780
if (interactionType === InteractionType.Redirect || interactionType === InteractionType.Popup) {
766-
this.preflightInteractiveRequest();
781+
this.preflightInteractiveRequest(setInteractionInProgress);
767782
}
768783
}
769-
784+
770785
/**
771-
* Helper to validate app environment before making a request.
772-
* @param request
773-
* @param interactionType
786+
* Preflight check for interactive requests
787+
*
788+
* @protected
789+
* @param {boolean} setInteractionInProgress Whether to set interaction in progress temp cache flag
774790
*/
775-
protected preflightInteractiveRequest(): void {
791+
protected preflightInteractiveRequest(setInteractionInProgress: boolean): void {
776792
this.logger.verbose("preflightInteractiveRequest called, validating app environment");
777793
// block the reload if it occurred inside a hidden iframe
778794
BrowserUtils.blockReloadInHiddenIframes();
779795

780796
// Set interaction in progress temporary cache or throw if alread set.
781-
this.browserStorage.setInteractionInProgress(true);
797+
if (setInteractionInProgress) {
798+
this.browserStorage.setInteractionInProgress(true);
799+
}
782800
}
783801

784802
/**

lib/msal-browser/src/app/PublicClientApplication.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,17 @@ export class PublicClientApplication extends ClientApplication implements IPubli
125125
this.activeSilentTokenRequests.delete(silentRequestKey);
126126
atsMeasurement.endMeasurement({
127127
success: true,
128-
fromCache: result.fromCache
128+
fromCache: result.fromCache,
129+
isNativeBroker: result.fromNativeBroker
129130
});
130131
atsMeasurement.flushMeasurement();
131132
return result;
132133
})
133-
.catch((error) => {
134+
.catch((error: AuthError) => {
134135
this.activeSilentTokenRequests.delete(silentRequestKey);
135136
atsMeasurement.endMeasurement({
137+
errorCode: error.errorCode,
138+
subErrorCode: error.subError,
136139
success: false
137140
});
138141
atsMeasurement.flushMeasurement();
@@ -193,12 +196,15 @@ export class PublicClientApplication extends ClientApplication implements IPubli
193196
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Silent, response);
194197
astsAsyncMeasurement.endMeasurement({
195198
success: true,
196-
fromCache: response.fromCache
199+
fromCache: response.fromCache,
200+
isNativeBroker: response.fromNativeBroker
197201
});
198202
return response;
199-
}).catch((tokenRenewalError) => {
203+
}).catch((tokenRenewalError: AuthError) => {
200204
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Silent, null, tokenRenewalError);
201205
astsAsyncMeasurement.endMeasurement({
206+
errorCode: tokenRenewalError.errorCode,
207+
subErrorCode: tokenRenewalError.subError,
202208
success: false
203209
});
204210
throw tokenRenewalError;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import { AuthenticationResult, Logger, ICrypto, PromptValue, AuthToken, Constants, AccountEntity, AuthorityType, ScopeSet, TimeUtils, AuthenticationScheme, UrlString, OIDC_DEFAULT_SCOPES, PopTokenGenerator, SignedHttpRequestParameters, IPerformanceClient, PerformanceEvents, ClientAuthError } from "@azure/msal-common";
6+
import { AuthenticationResult, Logger, ICrypto, PromptValue, AuthToken, Constants, AccountEntity, AuthorityType, ScopeSet, TimeUtils, AuthenticationScheme, UrlString, OIDC_DEFAULT_SCOPES, PopTokenGenerator, SignedHttpRequestParameters, IPerformanceClient, PerformanceEvents, ClientAuthError, AuthError } from "@azure/msal-common";
77
import { BaseInteractionClient } from "./BaseInteractionClient";
88
import { BrowserConfiguration } from "../config/Configuration";
99
import { BrowserCacheManager } from "../cache/BrowserCacheManager";
@@ -61,9 +61,11 @@ export class NativeInteractionClient extends BaseInteractionClient {
6161
});
6262
return result;
6363
})
64-
.catch((error) => {
64+
.catch((error: AuthError) => {
6565
nativeATMeasurement.endMeasurement({
6666
success: false,
67+
errorCode: error.errorCode,
68+
subErrorCode: error.subError,
6769
isNativeBroker: true
6870
});
6971
throw error;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { StandardInteractionClient } from "./StandardInteractionClient";
7-
import { CommonSilentFlowRequest, AuthenticationResult, SilentFlowClient, ServerTelemetryManager, AccountInfo, AzureCloudOptions, PerformanceEvents} from "@azure/msal-common";
7+
import { CommonSilentFlowRequest, AuthenticationResult, SilentFlowClient, ServerTelemetryManager, AccountInfo, AzureCloudOptions, PerformanceEvents, AuthError} from "@azure/msal-common";
88
import { SilentRequest } from "../request/SilentRequest";
99
import { ApiId } from "../utils/BrowserConstants";
1010
import { BrowserAuthError, BrowserAuthErrorMessage } from "../error/BrowserAuthError";
@@ -34,6 +34,8 @@ export class SilentCacheClient extends StandardInteractionClient {
3434
this.logger.verbose("Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair.");
3535
}
3636
acquireTokenMeasurement.endMeasurement({
37+
errorCode: error instanceof AuthError && error.errorCode || undefined,
38+
subErrorCode: error instanceof AuthError && error.subError || undefined,
3739
success: false
3840
});
3941
throw error;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export class SilentIframeClient extends StandardInteractionClient {
7373
serverTelemetryManager.cacheFailedRequest(e);
7474
this.browserStorage.cleanRequestByState(silentRequest.state);
7575
acquireTokenMeasurement.endMeasurement({
76+
errorCode: e instanceof AuthError && e.errorCode || undefined,
77+
subErrorCode: e instanceof AuthError && e.subError || undefined,
7678
success: false
7779
});
7880
throw e;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export class SilentRefreshClient extends StandardInteractionClient {
4040
}
4141
serverTelemetryManager.cacheFailedRequest(e);
4242
acquireTokenMeasurement.endMeasurement({
43+
errorCode: e.errorCode,
44+
subErrorCode: e.subError,
4345
success: false
4446
});
4547
throw e;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import { ServerTelemetryManager, CommonAuthorizationCodeRequest, Constants, AuthorizationCodeClient, ClientConfiguration, AuthorityOptions, Authority, AuthorityFactory, ServerAuthorizationCodeResponse, UrlString, CommonEndSessionRequest, ProtocolUtils, ResponseMode, StringUtils, IdTokenClaims, AccountInfo, AzureCloudOptions, PerformanceEvents } from "@azure/msal-common";
6+
import { ServerTelemetryManager, CommonAuthorizationCodeRequest, Constants, AuthorizationCodeClient, ClientConfiguration, AuthorityOptions, Authority, AuthorityFactory, ServerAuthorizationCodeResponse, UrlString, CommonEndSessionRequest, ProtocolUtils, ResponseMode, StringUtils, IdTokenClaims, AccountInfo, AzureCloudOptions, PerformanceEvents, AuthError } from "@azure/msal-common";
77
import { BaseInteractionClient } from "./BaseInteractionClient";
88
import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
99
import { BrowserConstants, InteractionType } from "../utils/BrowserConstants";
@@ -223,8 +223,10 @@ export abstract class StandardInteractionClient extends BaseInteractionClient {
223223

224224
return result;
225225
})
226-
.catch((error:Error) => {
226+
.catch((error:AuthError) => {
227227
getAuthorityMeasurement.endMeasurement({
228+
errorCode: error.errorCode,
229+
subErrorCode: error.subError,
228230
success: false
229231
});
230232

0 commit comments

Comments
 (0)