@azure/msal-browser 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  2. package/dist/app/IPublicClientApplication.mjs +20 -19
  3. package/dist/app/IPublicClientApplication.mjs.map +1 -1
  4. package/dist/app/PublicClientApplication.d.ts +14 -6
  5. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  6. package/dist/app/PublicClientApplication.mjs +17 -7
  7. package/dist/app/PublicClientApplication.mjs.map +1 -1
  8. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +3 -4
  9. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
  10. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +13 -13
  11. package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
  12. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +8 -0
  13. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts.map +1 -0
  14. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +16 -0
  15. package/dist/broker/nativeBroker/NativeStatusCodes.mjs.map +1 -0
  16. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  17. package/dist/cache/BrowserCacheManager.d.ts +3 -3
  18. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  19. package/dist/cache/BrowserCacheManager.mjs +8 -7
  20. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  21. package/dist/cache/BrowserStorage.d.ts.map +1 -1
  22. package/dist/cache/BrowserStorage.mjs +7 -9
  23. package/dist/cache/BrowserStorage.mjs.map +1 -1
  24. package/dist/cache/CryptoKeyStore.mjs +1 -1
  25. package/dist/cache/DatabaseStorage.mjs +1 -1
  26. package/dist/cache/MemoryStorage.mjs +1 -1
  27. package/dist/cache/TokenCache.mjs +1 -1
  28. package/dist/config/Configuration.d.ts.map +1 -1
  29. package/dist/config/Configuration.mjs +7 -7
  30. package/dist/config/Configuration.mjs.map +1 -1
  31. package/dist/controllers/ControllerFactory.mjs +1 -1
  32. package/dist/controllers/IController.d.ts +3 -2
  33. package/dist/controllers/IController.d.ts.map +1 -1
  34. package/dist/controllers/StandardController.d.ts +11 -6
  35. package/dist/controllers/StandardController.d.ts.map +1 -1
  36. package/dist/controllers/StandardController.mjs +53 -34
  37. package/dist/controllers/StandardController.mjs.map +1 -1
  38. package/dist/crypto/BrowserCrypto.d.ts +44 -49
  39. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  40. package/dist/crypto/BrowserCrypto.mjs +76 -76
  41. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  42. package/dist/crypto/CryptoOps.d.ts +1 -7
  43. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  44. package/dist/crypto/CryptoOps.mjs +11 -19
  45. package/dist/crypto/CryptoOps.mjs.map +1 -1
  46. package/dist/crypto/PkceGenerator.d.ts +6 -21
  47. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  48. package/dist/crypto/PkceGenerator.mjs +45 -46
  49. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  50. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  51. package/dist/encode/Base64Decode.d.ts.map +1 -1
  52. package/dist/encode/Base64Decode.mjs +18 -2
  53. package/dist/encode/Base64Decode.mjs.map +1 -1
  54. package/dist/encode/Base64Encode.mjs +1 -1
  55. package/dist/error/BrowserAuthError.d.ts +10 -1
  56. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  57. package/dist/error/BrowserAuthError.mjs +12 -3
  58. package/dist/error/BrowserAuthError.mjs.map +1 -1
  59. package/dist/error/BrowserAuthErrorCodes.d.ts +1 -0
  60. package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -1
  61. package/dist/error/BrowserAuthErrorCodes.mjs +3 -2
  62. package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -1
  63. package/dist/error/BrowserConfigurationAuthError.d.ts +9 -46
  64. package/dist/error/BrowserConfigurationAuthError.d.ts.map +1 -1
  65. package/dist/error/BrowserConfigurationAuthError.mjs +20 -73
  66. package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
  67. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +4 -0
  68. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts.map +1 -0
  69. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +12 -0
  70. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs.map +1 -0
  71. package/dist/error/NativeAuthError.d.ts +17 -45
  72. package/dist/error/NativeAuthError.d.ts.map +1 -1
  73. package/dist/error/NativeAuthError.mjs +47 -78
  74. package/dist/error/NativeAuthError.mjs.map +1 -1
  75. package/dist/error/NativeAuthErrorCodes.d.ts +3 -0
  76. package/dist/error/NativeAuthErrorCodes.d.ts.map +1 -0
  77. package/dist/error/NativeAuthErrorCodes.mjs +11 -0
  78. package/dist/error/NativeAuthErrorCodes.mjs.map +1 -0
  79. package/dist/event/EventHandler.d.ts.map +1 -1
  80. package/dist/event/EventHandler.mjs +3 -2
  81. package/dist/event/EventHandler.mjs.map +1 -1
  82. package/dist/event/EventMessage.mjs +1 -1
  83. package/dist/event/EventType.mjs +1 -1
  84. package/dist/index.d.ts +2 -2
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.mjs +4 -2
  87. package/dist/index.mjs.map +1 -1
  88. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  89. package/dist/interaction_client/BaseInteractionClient.mjs +7 -8
  90. package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
  91. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  92. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  93. package/dist/interaction_client/NativeInteractionClient.mjs +12 -10
  94. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  95. package/dist/interaction_client/PopupClient.mjs +1 -1
  96. package/dist/interaction_client/RedirectClient.mjs +1 -1
  97. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  98. package/dist/interaction_client/SilentAuthCodeClient.mjs +5 -8
  99. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  100. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  101. package/dist/interaction_client/SilentCacheClient.mjs +10 -18
  102. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  103. package/dist/interaction_client/SilentIframeClient.mjs +2 -2
  104. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  105. package/dist/interaction_client/SilentRefreshClient.mjs +8 -18
  106. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  107. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  108. package/dist/interaction_client/StandardInteractionClient.mjs +12 -33
  109. package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
  110. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  111. package/dist/interaction_handler/InteractionHandler.mjs +6 -9
  112. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  113. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  114. package/dist/interaction_handler/RedirectHandler.mjs +3 -3
  115. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  116. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  117. package/dist/interaction_handler/SilentHandler.mjs +3 -4
  118. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  119. package/dist/navigation/NavigationClient.mjs +1 -1
  120. package/dist/network/FetchClient.mjs +1 -1
  121. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  122. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  123. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
  124. package/dist/packageMetadata.d.ts +1 -1
  125. package/dist/packageMetadata.mjs +2 -2
  126. package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
  127. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  128. package/dist/utils/BrowserConstants.mjs +1 -1
  129. package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
  130. package/dist/utils/BrowserProtocolUtils.mjs +3 -3
  131. package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
  132. package/dist/utils/BrowserStringUtils.mjs +1 -1
  133. package/dist/utils/BrowserUtils.mjs +1 -1
  134. package/lib/msal-browser.cjs +1413 -1727
  135. package/lib/msal-browser.cjs.map +1 -1
  136. package/lib/msal-browser.js +1413 -1727
  137. package/lib/msal-browser.js.map +1 -1
  138. package/lib/msal-browser.min.js +68 -65
  139. package/package.json +2 -2
  140. package/src/app/IPublicClientApplication.ts +55 -18
  141. package/src/app/PublicClientApplication.ts +18 -6
  142. package/src/broker/nativeBroker/NativeMessageHandler.ts +12 -15
  143. package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
  144. package/src/cache/BrowserCacheManager.ts +21 -6
  145. package/src/cache/BrowserStorage.ts +9 -11
  146. package/src/config/Configuration.ts +16 -8
  147. package/src/controllers/IController.ts +4 -1
  148. package/src/controllers/StandardController.ts +155 -92
  149. package/src/crypto/BrowserCrypto.ts +118 -102
  150. package/src/crypto/CryptoOps.ts +10 -22
  151. package/src/crypto/PkceGenerator.ts +93 -54
  152. package/src/encode/Base64Decode.ts +21 -1
  153. package/src/error/BrowserAuthError.ts +13 -1
  154. package/src/error/BrowserAuthErrorCodes.ts +1 -0
  155. package/src/error/BrowserConfigurationAuthError.ts +33 -102
  156. package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
  157. package/src/error/NativeAuthError.ts +73 -101
  158. package/src/error/NativeAuthErrorCodes.ts +7 -0
  159. package/src/event/EventHandler.ts +2 -1
  160. package/src/index.ts +5 -0
  161. package/src/interaction_client/BaseInteractionClient.ts +13 -7
  162. package/src/interaction_client/NativeInteractionClient.ts +29 -11
  163. package/src/interaction_client/SilentAuthCodeClient.ts +18 -16
  164. package/src/interaction_client/SilentCacheClient.ts +22 -30
  165. package/src/interaction_client/SilentIframeClient.ts +1 -1
  166. package/src/interaction_client/SilentRefreshClient.ts +26 -28
  167. package/src/interaction_client/StandardInteractionClient.ts +36 -67
  168. package/src/interaction_handler/InteractionHandler.ts +20 -15
  169. package/src/interaction_handler/RedirectHandler.ts +6 -2
  170. package/src/interaction_handler/SilentHandler.ts +6 -3
  171. package/src/packageMetadata.ts +1 -1
  172. package/src/utils/BrowserProtocolUtils.ts +3 -2
  173. package/dist/crypto/ISubtleCrypto.d.ts +0 -10
  174. package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
  175. package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
  176. package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
  177. package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
  178. package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
  179. package/src/crypto/ISubtleCrypto.ts +0 -30
  180. package/src/crypto/ModernBrowserCrypto.ts +0 -69
@@ -3,12 +3,21 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { AuthError, InteractionRequiredAuthError } from "@azure/msal-common";
6
+ import {
7
+ AuthError,
8
+ InteractionRequiredAuthError,
9
+ InteractionRequiredAuthErrorCodes,
10
+ createInteractionRequiredAuthError,
11
+ } from "@azure/msal-common";
7
12
  import {
8
13
  createBrowserAuthError,
9
14
  BrowserAuthErrorCodes,
10
15
  } from "./BrowserAuthError";
11
16
 
17
+ import * as NativeAuthErrorCodes from "./NativeAuthErrorCodes";
18
+ import * as NativeStatusCodes from "../broker/nativeBroker/NativeStatusCodes";
19
+ export { NativeAuthErrorCodes };
20
+
12
21
  export type OSError = {
13
22
  error?: number;
14
23
  protocol_error?: string;
@@ -19,123 +28,86 @@ export type OSError = {
19
28
 
20
29
  const INVALID_METHOD_ERROR = -2147186943;
21
30
 
22
- export const NativeStatusCode = {
23
- USER_INTERACTION_REQUIRED: "USER_INTERACTION_REQUIRED",
24
- USER_CANCEL: "USER_CANCEL",
25
- NO_NETWORK: "NO_NETWORK",
26
- TRANSIENT_ERROR: "TRANSIENT_ERROR",
27
- PERSISTENT_ERROR: "PERSISTENT_ERROR",
28
- DISABLED: "DISABLED",
29
- ACCOUNT_UNAVAILABLE: "ACCOUNT_UNAVAILABLE",
30
- } as const;
31
- export type NativeStatusCode =
32
- (typeof NativeStatusCode)[keyof typeof NativeStatusCode];
33
-
34
- export const NativeAuthErrorMessage = {
35
- extensionError: {
36
- code: "ContentError",
37
- },
38
- userSwitch: {
39
- code: "user_switch",
40
- desc: "User attempted to switch accounts in the native broker, which is not allowed. All new accounts must sign-in through the standard web flow first, please try again.",
41
- },
42
- tokensNotFoundInCache: {
43
- code: "tokens_not_found_in_internal_memory_cache",
44
- desc: "Tokens not cached in MSAL JS internal memory, please make the WAM request",
45
- },
31
+ export const NativeAuthErrorMessages = {
32
+ [NativeAuthErrorCodes.userSwitch]:
33
+ "User attempted to switch accounts in the native broker, which is not allowed. All new accounts must sign-in through the standard web flow first, please try again.",
46
34
  };
47
35
 
48
36
  export class NativeAuthError extends AuthError {
49
37
  ext: OSError | undefined;
50
38
 
51
- constructor(errorCode: string, description: string, ext?: OSError) {
39
+ constructor(errorCode: string, description?: string, ext?: OSError) {
52
40
  super(errorCode, description);
53
41
 
54
42
  Object.setPrototypeOf(this, NativeAuthError.prototype);
55
43
  this.name = "NativeAuthError";
56
44
  this.ext = ext;
57
45
  }
46
+ }
58
47
 
59
- /**
60
- * These errors should result in a fallback to the 'standard' browser based auth flow.
61
- */
62
- isFatal(): boolean {
63
- if (
64
- this.ext &&
65
- this.ext.status &&
66
- (this.ext.status === NativeStatusCode.PERSISTENT_ERROR ||
67
- this.ext.status === NativeStatusCode.DISABLED)
68
- ) {
69
- return true;
70
- }
71
-
72
- if (
73
- this.ext &&
74
- this.ext.error &&
75
- this.ext.error === INVALID_METHOD_ERROR
76
- ) {
77
- return true;
78
- }
79
-
80
- switch (this.errorCode) {
81
- case NativeAuthErrorMessage.extensionError.code:
82
- return true;
83
- default:
84
- return false;
85
- }
48
+ /**
49
+ * These errors should result in a fallback to the 'standard' browser based auth flow.
50
+ */
51
+ export function isFatalNativeAuthError(error: NativeAuthError): boolean {
52
+ if (
53
+ error.ext &&
54
+ error.ext.status &&
55
+ (error.ext.status === NativeStatusCodes.PERSISTENT_ERROR ||
56
+ error.ext.status === NativeStatusCodes.DISABLED)
57
+ ) {
58
+ return true;
86
59
  }
87
60
 
88
- /**
89
- * Create the appropriate error object based on the WAM status code.
90
- * @param code
91
- * @param description
92
- * @param ext
93
- * @returns
94
- */
95
- static createError(
96
- code: string,
97
- description: string,
98
- ext?: OSError
99
- ): AuthError {
100
- if (ext && ext.status) {
101
- switch (ext.status) {
102
- case NativeStatusCode.ACCOUNT_UNAVAILABLE:
103
- return InteractionRequiredAuthError.createNativeAccountUnavailableError();
104
- case NativeStatusCode.USER_INTERACTION_REQUIRED:
105
- return new InteractionRequiredAuthError(code, description);
106
- case NativeStatusCode.USER_CANCEL:
107
- return createBrowserAuthError(
108
- BrowserAuthErrorCodes.userCancelled
109
- );
110
- case NativeStatusCode.NO_NETWORK:
111
- return createBrowserAuthError(
112
- BrowserAuthErrorCodes.noNetworkConnectivity
113
- );
114
- }
115
- }
116
-
117
- return new NativeAuthError(code, description, ext);
61
+ if (
62
+ error.ext &&
63
+ error.ext.error &&
64
+ error.ext.error === INVALID_METHOD_ERROR
65
+ ) {
66
+ return true;
118
67
  }
119
68
 
120
- /**
121
- * Creates user switch error when the user chooses a different account in the native broker prompt
122
- * @returns
123
- */
124
- static createUserSwitchError(): NativeAuthError {
125
- return new NativeAuthError(
126
- NativeAuthErrorMessage.userSwitch.code,
127
- NativeAuthErrorMessage.userSwitch.desc
128
- );
69
+ switch (error.errorCode) {
70
+ case NativeAuthErrorCodes.contentError:
71
+ return true;
72
+ default:
73
+ return false;
129
74
  }
75
+ }
130
76
 
131
- /**
132
- * Creates a tokens not found error when the internal cache look up fails
133
- * @returns NativeAuthError: tokensNotFoundInCache
134
- */
135
- static createTokensNotFoundInCacheError(): NativeAuthError {
136
- return new NativeAuthError(
137
- NativeAuthErrorMessage.tokensNotFoundInCache.code,
138
- NativeAuthErrorMessage.tokensNotFoundInCache.desc
139
- );
77
+ /**
78
+ * Create the appropriate error object based on the WAM status code.
79
+ * @param code
80
+ * @param description
81
+ * @param ext
82
+ * @returns
83
+ */
84
+ export function createNativeAuthError(
85
+ code: string,
86
+ description?: string,
87
+ ext?: OSError
88
+ ): AuthError {
89
+ if (ext && ext.status) {
90
+ switch (ext.status) {
91
+ case NativeStatusCodes.ACCOUNT_UNAVAILABLE:
92
+ return createInteractionRequiredAuthError(
93
+ InteractionRequiredAuthErrorCodes.nativeAccountUnavailable
94
+ );
95
+ case NativeStatusCodes.USER_INTERACTION_REQUIRED:
96
+ return new InteractionRequiredAuthError(code, description);
97
+ case NativeStatusCodes.USER_CANCEL:
98
+ return createBrowserAuthError(
99
+ BrowserAuthErrorCodes.userCancelled
100
+ );
101
+ case NativeStatusCodes.NO_NETWORK:
102
+ return createBrowserAuthError(
103
+ BrowserAuthErrorCodes.noNetworkConnectivity
104
+ );
105
+ }
140
106
  }
107
+
108
+ return new NativeAuthError(
109
+ code,
110
+ NativeAuthErrorMessages[code] || description,
111
+ ext
112
+ );
141
113
  }
@@ -0,0 +1,7 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ export const contentError = "ContentError";
7
+ export const userSwitch = "user_switch";
@@ -17,6 +17,7 @@ import {
17
17
  EventPayload,
18
18
  } from "./EventMessage";
19
19
  import { EventType } from "./EventType";
20
+ import { createNewGuid } from "../crypto/BrowserCrypto";
20
21
 
21
22
  export class EventHandler {
22
23
  // Callback for subscribing to events
@@ -40,7 +41,7 @@ export class EventHandler {
40
41
  */
41
42
  addEventCallback(callback: EventCallbackFunction): string | null {
42
43
  if (typeof window !== "undefined") {
43
- const callbackId = this.browserCrypto.createNewGuid();
44
+ const callbackId = createNewGuid();
44
45
  this.eventCallbacks.set(callbackId, callback);
45
46
  this.logger.verbose(
46
47
  `Event callback registered with id: ${callbackId}`
package/src/index.ts CHANGED
@@ -47,6 +47,7 @@ export {
47
47
  } from "./error/BrowserAuthError";
48
48
  export {
49
49
  BrowserConfigurationAuthError,
50
+ BrowserConfigurationAuthErrorCodes,
50
51
  BrowserConfigurationAuthErrorMessage,
51
52
  } from "./error/BrowserConfigurationAuthError";
52
53
 
@@ -112,12 +113,16 @@ export {
112
113
  IdTokenClaims,
113
114
  // Error
114
115
  AuthError,
116
+ AuthErrorCodes,
115
117
  AuthErrorMessage,
116
118
  ClientAuthError,
119
+ ClientAuthErrorCodes,
117
120
  ClientAuthErrorMessage,
118
121
  ClientConfigurationError,
122
+ ClientConfigurationErrorCodes,
119
123
  ClientConfigurationErrorMessage,
120
124
  InteractionRequiredAuthError,
125
+ InteractionRequiredAuthErrorCodes,
121
126
  InteractionRequiredAuthErrorMessage,
122
127
  ServerError,
123
128
  // Network
@@ -14,7 +14,8 @@ import {
14
14
  UrlString,
15
15
  ServerTelemetryManager,
16
16
  ServerTelemetryRequest,
17
- ClientConfigurationError,
17
+ createClientConfigurationError,
18
+ ClientConfigurationErrorCodes,
18
19
  Authority,
19
20
  AuthorityOptions,
20
21
  AuthorityFactory,
@@ -36,6 +37,7 @@ import { INavigationClient } from "../navigation/INavigationClient";
36
37
  import { NativeMessageHandler } from "../broker/nativeBroker/NativeMessageHandler";
37
38
  import { AuthenticationResult } from "../response/AuthenticationResult";
38
39
  import { ClearCacheRequest } from "../request/ClearCacheRequest";
40
+ import { createNewGuid } from "../crypto/BrowserCrypto";
39
41
 
40
42
  export abstract class BaseInteractionClient {
41
43
  protected config: BrowserConfiguration;
@@ -67,8 +69,7 @@ export abstract class BaseInteractionClient {
67
69
  this.eventHandler = eventHandler;
68
70
  this.navigationClient = navigationClient;
69
71
  this.nativeMessageHandler = nativeMessageHandler;
70
- this.correlationId =
71
- correlationId || this.browserCrypto.createNewGuid();
72
+ this.correlationId = correlationId || createNewGuid();
72
73
  this.logger = logger.clone(
73
74
  BrowserConstants.MSAL_SKU,
74
75
  version,
@@ -142,7 +143,6 @@ export abstract class BaseInteractionClient {
142
143
  PerformanceEvents.InitializeBaseRequest,
143
144
  request.correlationId
144
145
  );
145
- this.logger.verbose("Initializing BaseAuthRequest");
146
146
  const authority = request.authority || this.config.auth.authority;
147
147
 
148
148
  if (account) {
@@ -170,10 +170,14 @@ export abstract class BaseInteractionClient {
170
170
  AuthenticationScheme.SSH
171
171
  ) {
172
172
  if (!request.sshJwk) {
173
- throw ClientConfigurationError.createMissingSshJwkError();
173
+ throw createClientConfigurationError(
174
+ ClientConfigurationErrorCodes.missingSshJwk
175
+ );
174
176
  }
175
177
  if (!request.sshKid) {
176
- throw ClientConfigurationError.createMissingSshKidError();
178
+ throw createClientConfigurationError(
179
+ ClientConfigurationErrorCodes.missingSshKid
180
+ );
177
181
  }
178
182
  }
179
183
  this.logger.verbose(
@@ -227,7 +231,9 @@ export abstract class BaseInteractionClient {
227
231
  );
228
232
 
229
233
  if (!discoveredAuthority.isAlias(account.environment)) {
230
- throw ClientConfigurationError.createAuthorityMismatchError();
234
+ throw createClientConfigurationError(
235
+ ClientConfigurationErrorCodes.authorityMismatch
236
+ );
231
237
  }
232
238
  }
233
239
 
@@ -22,13 +22,17 @@ import {
22
22
  PerformanceEvents,
23
23
  IdTokenEntity,
24
24
  AccessTokenEntity,
25
- ClientAuthError,
26
25
  AuthError,
27
26
  CommonSilentFlowRequest,
28
27
  AccountInfo,
29
28
  CacheRecord,
30
29
  AADServerParamKeys,
31
30
  TokenClaims,
31
+ createClientAuthError,
32
+ ClientAuthErrorCodes,
33
+ invokeAsync,
34
+ createAuthError,
35
+ AuthErrorCodes,
32
36
  } from "@azure/msal-common";
33
37
  import { BaseInteractionClient } from "./BaseInteractionClient";
34
38
  import { BrowserConfiguration } from "../config/Configuration";
@@ -49,7 +53,12 @@ import {
49
53
  NativeTokenRequest,
50
54
  } from "../broker/nativeBroker/NativeRequest";
51
55
  import { MATS, NativeResponse } from "../broker/nativeBroker/NativeResponse";
52
- import { NativeAuthError } from "../error/NativeAuthError";
56
+ import {
57
+ NativeAuthError,
58
+ NativeAuthErrorCodes,
59
+ createNativeAuthError,
60
+ isFatalNativeAuthError,
61
+ } from "../error/NativeAuthError";
53
62
  import { RedirectRequest } from "../request/RedirectRequest";
54
63
  import { NavigationOptions } from "../navigation/NavigationOptions";
55
64
  import { INavigationClient } from "../navigation/INavigationClient";
@@ -122,6 +131,10 @@ export class NativeInteractionClient extends BaseInteractionClient {
122
131
  async acquireToken(
123
132
  request: PopupRequest | SilentRequest | SsoSilentRequest
124
133
  ): Promise<AuthenticationResult> {
134
+ this.performanceClient.addQueueMeasurement(
135
+ PerformanceEvents.NativeInteractionClientAcquireToken,
136
+ request.correlationId
137
+ );
125
138
  this.logger.trace("NativeInteractionClient - acquireToken called.");
126
139
 
127
140
  // start the perf measurement
@@ -222,14 +235,14 @@ export class NativeInteractionClient extends BaseInteractionClient {
222
235
  this.logger.warning(
223
236
  "NativeInteractionClient:acquireTokensFromCache - No nativeAccountId provided"
224
237
  );
225
- throw ClientAuthError.createNoAccountFoundError();
238
+ throw createClientAuthError(ClientAuthErrorCodes.noAccountFound);
226
239
  }
227
240
  // fetch the account from browser cache
228
241
  const account = this.browserStorage.getAccountInfoFilteredBy({
229
242
  nativeAccountId,
230
243
  });
231
244
  if (!account) {
232
- throw ClientAuthError.createNoAccountFoundError();
245
+ throw createClientAuthError(ClientAuthErrorCodes.noAccountFound);
233
246
  }
234
247
 
235
248
  // leverage silent flow for cached tokens retrieval
@@ -271,7 +284,7 @@ export class NativeInteractionClient extends BaseInteractionClient {
271
284
  this.validateNativeResponse(response);
272
285
  } catch (e) {
273
286
  // Only throw fatal errors here to allow application to fallback to regular redirect. Otherwise proceed and the error will be thrown in handleRedirectPromise
274
- if (e instanceof NativeAuthError && e.isFatal()) {
287
+ if (e instanceof NativeAuthError && isFatalNativeAuthError(e)) {
275
288
  throw e;
276
289
  }
277
290
  }
@@ -384,7 +397,7 @@ export class NativeInteractionClient extends BaseInteractionClient {
384
397
 
385
398
  if (response.account.id !== request.accountId) {
386
399
  // User switch in native broker prompt is not supported. All users must first sign in through web flow to ensure server state is in sync
387
- throw NativeAuthError.createUserSwitchError();
400
+ throw createNativeAuthError(NativeAuthErrorCodes.userSwitch);
388
401
  }
389
402
 
390
403
  // Get the preferred_cache domain for the given authority
@@ -510,7 +523,7 @@ export class NativeInteractionClient extends BaseInteractionClient {
510
523
  * PopTokenGenerator to query the full key for signing
511
524
  */
512
525
  if (!request.keyId) {
513
- throw ClientAuthError.createKeyIdMissingError();
526
+ throw createClientAuthError(ClientAuthErrorCodes.keyIdMissing);
514
527
  }
515
528
  return await popTokenGenerator.signPopToken(
516
529
  response.access_token,
@@ -719,7 +732,8 @@ export class NativeInteractionClient extends BaseInteractionClient {
719
732
  ) {
720
733
  return response as NativeResponse;
721
734
  } else {
722
- throw NativeAuthError.createUnexpectedError(
735
+ throw createAuthError(
736
+ AuthErrorCodes.unexpectedError,
723
737
  "Response missing expected properties."
724
738
  );
725
739
  }
@@ -859,9 +873,13 @@ export class NativeInteractionClient extends BaseInteractionClient {
859
873
  };
860
874
 
861
875
  const popTokenGenerator = new PopTokenGenerator(this.browserCrypto);
862
- const reqCnfData = await popTokenGenerator.generateCnf(
863
- shrParameters
864
- );
876
+ const reqCnfData = await invokeAsync(
877
+ popTokenGenerator.generateCnf.bind(popTokenGenerator),
878
+ PerformanceEvents.PopTokenGenerateCnf,
879
+ this.logger,
880
+ this.performanceClient,
881
+ this.correlationId
882
+ )(shrParameters, this.logger);
865
883
 
866
884
  // to reduce the URL length, it is recommended to send the hash of the req_cnf instead of the whole string
867
885
  validatedRequest.reqCnf = reqCnfData.reqCnfHash;
@@ -11,6 +11,7 @@ import {
11
11
  Constants,
12
12
  IPerformanceClient,
13
13
  PerformanceEvents,
14
+ invokeAsync,
14
15
  } from "@azure/msal-common";
15
16
  import { StandardInteractionClient } from "./StandardInteractionClient";
16
17
  import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
@@ -65,8 +66,6 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
65
66
  async acquireToken(
66
67
  request: AuthorizationCodeRequest
67
68
  ): Promise<AuthenticationResult> {
68
- this.logger.trace("SilentAuthCodeClient.acquireToken called");
69
-
70
69
  // Auth code payload is required
71
70
  if (!request.code) {
72
71
  throw createBrowserAuthError(
@@ -75,15 +74,13 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
75
74
  }
76
75
 
77
76
  // Create silent request
78
- this.performanceClient.setPreQueueTime(
77
+ const silentRequest: AuthorizationUrlRequest = await invokeAsync(
78
+ this.initializeAuthorizationRequest.bind(this),
79
79
  PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest,
80
+ this.logger,
81
+ this.performanceClient,
80
82
  request.correlationId
81
- );
82
- const silentRequest: AuthorizationUrlRequest =
83
- await this.initializeAuthorizationRequest(
84
- request,
85
- InteractionType.Silent
86
- );
83
+ )(request, InteractionType.Silent);
87
84
  this.browserStorage.updateCacheEntries(
88
85
  silentRequest.state,
89
86
  silentRequest.nonce,
@@ -104,14 +101,13 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
104
101
  };
105
102
 
106
103
  // Initialize the client
107
- this.performanceClient.setPreQueueTime(
104
+ const clientConfig = await invokeAsync(
105
+ this.getClientConfiguration.bind(this),
108
106
  PerformanceEvents.StandardInteractionClientGetClientConfiguration,
107
+ this.logger,
108
+ this.performanceClient,
109
109
  request.correlationId
110
- );
111
- const clientConfig = await this.getClientConfiguration(
112
- serverTelemetryManager,
113
- silentRequest.authority
114
- );
110
+ )(serverTelemetryManager, silentRequest.authority);
115
111
  const authClient: HybridSpaAuthorizationCodeClient =
116
112
  new HybridSpaAuthorizationCodeClient(clientConfig);
117
113
  this.logger.verbose("Auth code client created");
@@ -127,7 +123,13 @@ export class SilentAuthCodeClient extends StandardInteractionClient {
127
123
  );
128
124
 
129
125
  // Handle auth code parameters from request
130
- return silentHandler.handleCodeResponseFromServer(
126
+ return invokeAsync(
127
+ silentHandler.handleCodeResponseFromServer.bind(silentHandler),
128
+ PerformanceEvents.HandleCodeResponseFromServer,
129
+ this.logger,
130
+ this.performanceClient,
131
+ request.correlationId
132
+ )(
131
133
  {
132
134
  code: request.code,
133
135
  msgraph_host: request.msGraphHost,
@@ -11,7 +11,7 @@ import {
11
11
  AccountInfo,
12
12
  AzureCloudOptions,
13
13
  PerformanceEvents,
14
- AuthError,
14
+ invokeAsync,
15
15
  } from "@azure/msal-common";
16
16
  import { SilentRequest } from "../request/SilentRequest";
17
17
  import { ApiId } from "../utils/BrowserConstants";
@@ -30,10 +30,6 @@ export class SilentCacheClient extends StandardInteractionClient {
30
30
  async acquireToken(
31
31
  silentRequest: CommonSilentFlowRequest
32
32
  ): Promise<AuthenticationResult> {
33
- const acquireTokenMeasurement = this.performanceClient.startMeasurement(
34
- PerformanceEvents.SilentCacheClientAcquireToken,
35
- silentRequest.correlationId
36
- );
37
33
  // Telemetry manager only used to increment cacheHits here
38
34
  const serverTelemetryManager = this.initializeServerTelemetryManager(
39
35
  ApiId.acquireTokenSilent_silentFlow
@@ -47,15 +43,18 @@ export class SilentCacheClient extends StandardInteractionClient {
47
43
  this.logger.verbose("Silent auth client created");
48
44
 
49
45
  try {
50
- const cachedToken = (await silentAuthClient.acquireCachedToken(
46
+ const response = await silentAuthClient.acquireCachedToken(
51
47
  silentRequest
52
- )) as AuthenticationResult;
48
+ );
49
+ const authResponse = response[0] as AuthenticationResult;
53
50
 
54
- acquireTokenMeasurement.end({
55
- success: true,
56
- fromCache: true,
57
- });
58
- return cachedToken;
51
+ this.performanceClient.addFields(
52
+ {
53
+ fromCache: true,
54
+ },
55
+ silentRequest.correlationId
56
+ );
57
+ return authResponse;
59
58
  } catch (error) {
60
59
  if (
61
60
  error instanceof BrowserAuthError &&
@@ -65,14 +64,6 @@ export class SilentCacheClient extends StandardInteractionClient {
65
64
  "Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair."
66
65
  );
67
66
  }
68
- acquireTokenMeasurement.end({
69
- errorCode:
70
- (error instanceof AuthError && error.errorCode) ||
71
- undefined,
72
- subErrorCode:
73
- (error instanceof AuthError && error.subError) || undefined,
74
- success: false,
75
- });
76
67
  throw error;
77
68
  }
78
69
  }
@@ -98,15 +89,13 @@ export class SilentCacheClient extends StandardInteractionClient {
98
89
  azureCloudOptions?: AzureCloudOptions
99
90
  ): Promise<SilentFlowClient> {
100
91
  // Create auth module.
101
- this.performanceClient.setPreQueueTime(
92
+ const clientConfig = await invokeAsync(
93
+ this.getClientConfiguration.bind(this),
102
94
  PerformanceEvents.StandardInteractionClientGetClientConfiguration,
95
+ this.logger,
96
+ this.performanceClient,
103
97
  this.correlationId
104
- );
105
- const clientConfig = await this.getClientConfiguration(
106
- serverTelemetryManager,
107
- authorityUrl,
108
- azureCloudOptions
109
- );
98
+ )(serverTelemetryManager, authorityUrl, azureCloudOptions);
110
99
  return new SilentFlowClient(clientConfig, this.performanceClient);
111
100
  }
112
101
 
@@ -119,13 +108,16 @@ export class SilentCacheClient extends StandardInteractionClient {
119
108
  this.correlationId
120
109
  );
121
110
 
122
- this.performanceClient.setPreQueueTime(
111
+ const baseRequest = await invokeAsync(
112
+ this.initializeBaseRequest.bind(this),
123
113
  PerformanceEvents.InitializeBaseRequest,
114
+ this.logger,
115
+ this.performanceClient,
124
116
  this.correlationId
125
- );
117
+ )(request, account);
126
118
  return {
127
119
  ...request,
128
- ...(await this.initializeBaseRequest(request, account)),
120
+ ...baseRequest,
129
121
  account: account,
130
122
  forceRefresh: request.forceRefresh || false,
131
123
  };
@@ -231,7 +231,7 @@ export class SilentIframeClient extends StandardInteractionClient {
231
231
  // Monitor the window for the hash. Return the string value and close the popup when the hash is received. Default timeout is 60 seconds.
232
232
  const hash = await invokeAsync(
233
233
  silentHandler.monitorIframeForHash.bind(silentHandler),
234
- PerformanceEvents.SilentHandlerInitiateAuthRequest,
234
+ PerformanceEvents.SilentHandlerMonitorIframeForHash,
235
235
  this.logger,
236
236
  this.performanceClient,
237
237
  silentRequest.correlationId