@azure/msal-common 14.2.0 → 14.4.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 (172) hide show
  1. package/dist/account/AuthToken.mjs +1 -1
  2. package/dist/account/CcsCredential.mjs +1 -1
  3. package/dist/account/ClientInfo.mjs +1 -1
  4. package/dist/authority/Authority.d.ts.map +1 -1
  5. package/dist/authority/Authority.mjs +4 -5
  6. package/dist/authority/Authority.mjs.map +1 -1
  7. package/dist/authority/AuthorityFactory.mjs +1 -1
  8. package/dist/authority/AuthorityMetadata.d.ts +29 -172
  9. package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
  10. package/dist/authority/AuthorityMetadata.mjs +79 -413
  11. package/dist/authority/AuthorityMetadata.mjs.map +1 -1
  12. package/dist/authority/AuthorityOptions.d.ts +2 -2
  13. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  14. package/dist/authority/AuthorityOptions.mjs +1 -1
  15. package/dist/authority/AuthorityOptions.mjs.map +1 -1
  16. package/dist/authority/AuthorityType.mjs +1 -1
  17. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  18. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  19. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  20. package/dist/authority/ProtocolMode.mjs +1 -1
  21. package/dist/authority/RegionDiscovery.mjs +1 -1
  22. package/dist/cache/CacheManager.d.ts +24 -19
  23. package/dist/cache/CacheManager.d.ts.map +1 -1
  24. package/dist/cache/CacheManager.mjs +51 -33
  25. package/dist/cache/CacheManager.mjs.map +1 -1
  26. package/dist/cache/entities/AccessTokenEntity.d.ts +12 -43
  27. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  28. package/dist/cache/entities/AccountEntity.mjs +1 -1
  29. package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
  30. package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
  31. package/dist/cache/entities/CacheRecord.mjs +1 -1
  32. package/dist/cache/entities/CredentialEntity.d.ts +15 -73
  33. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  34. package/dist/cache/entities/IdTokenEntity.d.ts +4 -30
  35. package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
  36. package/dist/cache/entities/RefreshTokenEntity.d.ts +2 -33
  37. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  38. package/dist/cache/entities/ServerTelemetryEntity.d.ts +2 -9
  39. package/dist/cache/entities/ServerTelemetryEntity.d.ts.map +1 -1
  40. package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
  41. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  42. package/dist/cache/utils/CacheHelpers.d.ts +65 -0
  43. package/dist/cache/utils/CacheHelpers.d.ts.map +1 -0
  44. package/dist/cache/utils/CacheHelpers.mjs +242 -0
  45. package/dist/cache/utils/CacheHelpers.mjs.map +1 -0
  46. package/dist/client/AuthorizationCodeClient.d.ts +2 -1
  47. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  48. package/dist/client/AuthorizationCodeClient.mjs +4 -10
  49. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  50. package/dist/client/BaseClient.d.ts +1 -1
  51. package/dist/client/BaseClient.d.ts.map +1 -1
  52. package/dist/client/BaseClient.mjs +8 -8
  53. package/dist/client/BaseClient.mjs.map +1 -1
  54. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  55. package/dist/client/RefreshTokenClient.mjs +2 -2
  56. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  57. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  58. package/dist/client/SilentFlowClient.mjs +5 -3
  59. package/dist/client/SilentFlowClient.mjs.map +1 -1
  60. package/dist/config/ClientConfiguration.mjs +1 -1
  61. package/dist/crypto/ICrypto.d.ts +3 -3
  62. package/dist/crypto/ICrypto.d.ts.map +1 -1
  63. package/dist/crypto/ICrypto.mjs +1 -1
  64. package/dist/crypto/ICrypto.mjs.map +1 -1
  65. package/dist/crypto/JoseHeader.d.ts +3 -3
  66. package/dist/crypto/JoseHeader.d.ts.map +1 -1
  67. package/dist/crypto/JoseHeader.mjs +3 -3
  68. package/dist/crypto/JoseHeader.mjs.map +1 -1
  69. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  70. package/dist/crypto/PopTokenGenerator.mjs +3 -3
  71. package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
  72. package/dist/crypto/SignedHttpRequest.d.ts +4 -0
  73. package/dist/crypto/SignedHttpRequest.d.ts.map +1 -1
  74. package/dist/error/AuthError.mjs +1 -1
  75. package/dist/error/AuthErrorCodes.mjs +1 -1
  76. package/dist/error/ClientAuthError.mjs +1 -1
  77. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  78. package/dist/error/ClientConfigurationError.mjs +1 -1
  79. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  80. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  81. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
  82. package/dist/error/JoseHeaderError.mjs +1 -1
  83. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  84. package/dist/error/ServerError.mjs +1 -1
  85. package/dist/index.cjs +2768 -3303
  86. package/dist/index.cjs.map +1 -1
  87. package/dist/index.d.ts +4 -2
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.mjs +6 -7
  90. package/dist/index.mjs.map +1 -1
  91. package/dist/logger/Logger.mjs +1 -1
  92. package/dist/network/INetworkModule.mjs +1 -1
  93. package/dist/network/NetworkManager.mjs +1 -1
  94. package/dist/network/RequestThumbprint.d.ts +2 -0
  95. package/dist/network/RequestThumbprint.d.ts.map +1 -1
  96. package/dist/network/ThrottlingUtils.mjs +1 -1
  97. package/dist/packageMetadata.d.ts +1 -1
  98. package/dist/packageMetadata.mjs +2 -2
  99. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  100. package/dist/request/BaseAuthRequest.d.ts +3 -0
  101. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  102. package/dist/request/RequestParameterBuilder.mjs +1 -1
  103. package/dist/request/RequestValidator.mjs +1 -1
  104. package/dist/request/ScopeSet.mjs +1 -1
  105. package/dist/response/ResponseHandler.d.ts +2 -2
  106. package/dist/response/ResponseHandler.d.ts.map +1 -1
  107. package/dist/response/ResponseHandler.mjs +23 -29
  108. package/dist/response/ResponseHandler.mjs.map +1 -1
  109. package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
  110. package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -1
  111. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  112. package/dist/telemetry/performance/PerformanceEvent.mjs +6 -2
  113. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  114. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  115. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  116. package/dist/telemetry/server/ServerTelemetryManager.mjs +11 -8
  117. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
  118. package/dist/url/UrlString.d.ts +2 -37
  119. package/dist/url/UrlString.d.ts.map +1 -1
  120. package/dist/url/UrlString.mjs +7 -126
  121. package/dist/url/UrlString.mjs.map +1 -1
  122. package/dist/utils/Constants.d.ts +2 -3
  123. package/dist/utils/Constants.d.ts.map +1 -1
  124. package/dist/utils/Constants.mjs +3 -4
  125. package/dist/utils/Constants.mjs.map +1 -1
  126. package/dist/utils/FunctionWrappers.mjs +1 -1
  127. package/dist/utils/ProtocolUtils.mjs +1 -1
  128. package/dist/utils/StringUtils.mjs +1 -1
  129. package/dist/utils/TimeUtils.mjs +1 -1
  130. package/dist/utils/UrlUtils.d.ts +11 -0
  131. package/dist/utils/UrlUtils.d.ts.map +1 -0
  132. package/dist/utils/UrlUtils.mjs +52 -0
  133. package/dist/utils/UrlUtils.mjs.map +1 -0
  134. package/package.json +1 -1
  135. package/src/authority/Authority.ts +5 -8
  136. package/src/authority/AuthorityMetadata.ts +109 -435
  137. package/src/authority/AuthorityOptions.ts +2 -2
  138. package/src/cache/CacheManager.ts +79 -42
  139. package/src/cache/entities/AccessTokenEntity.ts +13 -149
  140. package/src/cache/entities/CredentialEntity.ts +16 -200
  141. package/src/cache/entities/IdTokenEntity.ts +4 -64
  142. package/src/cache/entities/RefreshTokenEntity.ts +2 -69
  143. package/src/cache/entities/ServerTelemetryEntity.ts +2 -30
  144. package/src/cache/utils/CacheHelpers.ts +327 -0
  145. package/src/client/AuthorizationCodeClient.ts +4 -15
  146. package/src/client/BaseClient.ts +21 -10
  147. package/src/client/RefreshTokenClient.ts +7 -1
  148. package/src/client/SilentFlowClient.ts +8 -4
  149. package/src/crypto/ICrypto.ts +7 -2
  150. package/src/crypto/JoseHeader.ts +4 -4
  151. package/src/crypto/PopTokenGenerator.ts +2 -0
  152. package/src/crypto/SignedHttpRequest.ts +6 -0
  153. package/src/index.ts +4 -1
  154. package/src/network/RequestThumbprint.ts +2 -0
  155. package/src/packageMetadata.ts +1 -1
  156. package/src/request/BaseAuthRequest.ts +3 -0
  157. package/src/response/ResponseHandler.ts +36 -41
  158. package/src/telemetry/performance/PerformanceEvent.ts +12 -1
  159. package/src/telemetry/server/ServerTelemetryManager.ts +12 -6
  160. package/src/url/UrlString.ts +6 -153
  161. package/src/utils/Constants.ts +3 -3
  162. package/src/utils/UrlUtils.ts +60 -0
  163. package/dist/cache/entities/AccessTokenEntity.mjs +0 -121
  164. package/dist/cache/entities/AccessTokenEntity.mjs.map +0 -1
  165. package/dist/cache/entities/CredentialEntity.mjs +0 -145
  166. package/dist/cache/entities/CredentialEntity.mjs.map +0 -1
  167. package/dist/cache/entities/IdTokenEntity.mjs +0 -64
  168. package/dist/cache/entities/IdTokenEntity.mjs.map +0 -1
  169. package/dist/cache/entities/RefreshTokenEntity.mjs +0 -67
  170. package/dist/cache/entities/RefreshTokenEntity.mjs.map +0 -1
  171. package/dist/cache/entities/ServerTelemetryEntity.mjs +0 -34
  172. package/dist/cache/entities/ServerTelemetryEntity.mjs.map +0 -1
@@ -7,17 +7,17 @@ import {
7
7
  JoseHeaderErrorCodes,
8
8
  createJoseHeaderError,
9
9
  } from "../error/JoseHeaderError";
10
- import { JsonTypes } from "../utils/Constants";
10
+ import { JsonWebTokenTypes } from "../utils/Constants";
11
11
 
12
12
  export type JoseHeaderOptions = {
13
- typ?: JsonTypes;
13
+ typ?: JsonWebTokenTypes;
14
14
  alg?: string;
15
15
  kid?: string;
16
16
  };
17
17
 
18
18
  /** @internal */
19
19
  export class JoseHeader {
20
- public typ?: JsonTypes;
20
+ public typ?: JsonWebTokenTypes;
21
21
  public alg?: string;
22
22
  public kid?: string;
23
23
 
@@ -48,7 +48,7 @@ export class JoseHeader {
48
48
 
49
49
  const shrHeader = new JoseHeader({
50
50
  // Access Token PoP headers must have type pop, but the type header can be overriden for special cases
51
- typ: shrHeaderOptions.typ || JsonTypes.Pop,
51
+ typ: shrHeaderOptions.typ || JsonWebTokenTypes.Pop,
52
52
  kid: shrHeaderOptions.kid,
53
53
  alg: shrHeaderOptions.alg,
54
54
  });
@@ -133,6 +133,7 @@ export class PopTokenGenerator {
133
133
  resourceRequestUri,
134
134
  shrClaims,
135
135
  shrNonce,
136
+ shrOptions,
136
137
  } = request;
137
138
 
138
139
  const resourceUrlString = resourceRequestUri
@@ -154,6 +155,7 @@ export class PopTokenGenerator {
154
155
  ...claims,
155
156
  },
156
157
  keyId,
158
+ shrOptions,
157
159
  request.correlationId
158
160
  );
159
161
  }
@@ -3,6 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { JoseHeaderOptions } from "./JoseHeader";
7
+
6
8
  export type SignedHttpRequest = {
7
9
  at?: string;
8
10
  cnf?: object;
@@ -14,3 +16,7 @@ export type SignedHttpRequest = {
14
16
  nonce?: string;
15
17
  client_claims?: string;
16
18
  };
19
+
20
+ export type ShrOptions = {
21
+ header: JoseHeaderOptions;
22
+ };
package/src/index.ts CHANGED
@@ -71,6 +71,7 @@ export {
71
71
  } from "./cache/utils/CacheTypes";
72
72
  export { CacheRecord } from "./cache/entities/CacheRecord";
73
73
  export { CredentialEntity } from "./cache/entities/CredentialEntity";
74
+ export * as CacheHelpers from "./cache/utils/CacheHelpers";
74
75
  export { AppMetadataEntity } from "./cache/entities/AppMetadataEntity";
75
76
  export { AccountEntity } from "./cache/entities/AccountEntity";
76
77
  export { IdTokenEntity } from "./cache/entities/IdTokenEntity";
@@ -104,7 +105,7 @@ export {
104
105
  DEFAULT_CRYPTO_IMPLEMENTATION,
105
106
  SignedHttpRequestParameters,
106
107
  } from "./crypto/ICrypto";
107
- export { SignedHttpRequest } from "./crypto/SignedHttpRequest";
108
+ export { SignedHttpRequest, ShrOptions } from "./crypto/SignedHttpRequest";
108
109
  export { IGuidGenerator } from "./crypto/IGuidGenerator";
109
110
  export { JoseHeader } from "./crypto/JoseHeader";
110
111
  // Request
@@ -192,6 +193,7 @@ export {
192
193
  GrantType,
193
194
  AADAuthorityConstants,
194
195
  HttpStatus,
196
+ JsonWebTokenTypes,
195
197
  } from "./utils/Constants";
196
198
  export { StringUtils } from "./utils/StringUtils";
197
199
  export { StringDict } from "./utils/MsalTypes";
@@ -201,6 +203,7 @@ export {
201
203
  LibraryStateObject,
202
204
  } from "./utils/ProtocolUtils";
203
205
  export { TimeUtils } from "./utils/TimeUtils";
206
+ export * as UrlUtils from "./utils/UrlUtils";
204
207
  export * from "./utils/FunctionWrappers";
205
208
  // Server Telemetry
206
209
  export { ServerTelemetryManager } from "./telemetry/server/ServerTelemetryManager";
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { ShrOptions } from "../crypto/SignedHttpRequest";
6
7
  import { AuthenticationScheme } from "../utils/Constants";
7
8
 
8
9
  /**
@@ -19,4 +20,5 @@ export type RequestThumbprint = {
19
20
  resourceRequestUri?: string;
20
21
  shrClaims?: string;
21
22
  sshKid?: string;
23
+ shrOptions?: ShrOptions;
22
24
  };
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable header/header */
2
2
  export const name = "@azure/msal-common";
3
- export const version = "14.2.0";
3
+ export const version = "14.4.0";
@@ -7,6 +7,7 @@ import { AuthenticationScheme } from "../utils/Constants";
7
7
  import { AzureCloudOptions } from "../config/ClientConfiguration";
8
8
  import { StringDict } from "../utils/MsalTypes";
9
9
  import { StoreInCache } from "./StoreInCache";
10
+ import { ShrOptions } from "../crypto/SignedHttpRequest";
10
11
 
11
12
  /**
12
13
  * BaseAuthRequest
@@ -17,6 +18,7 @@ import { StoreInCache } from "./StoreInCache";
17
18
  * - claims - A stringified claims request which will be added to all /authorize and /token calls
18
19
  * - shrClaims - A stringified claims object which will be added to a Signed HTTP Request
19
20
  * - shrNonce - A server-generated timestamp that has been encrypted and base64URL encoded, which will be added to a Signed HTTP Request.
21
+ * - shrOptions - An object containing options for the Signed HTTP Request
20
22
  * - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
21
23
  * - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
22
24
  * - sshJwk - A stringified JSON Web Key representing a public key that can be signed by an SSH certificate.
@@ -34,6 +36,7 @@ export type BaseAuthRequest = {
34
36
  claims?: string;
35
37
  shrClaims?: string;
36
38
  shrNonce?: string;
39
+ shrOptions?: ShrOptions;
37
40
  resourceRequestMethod?: string;
38
41
  resourceRequestUri?: string;
39
42
  sshJwk?: string;
@@ -4,7 +4,6 @@
4
4
  */
5
5
 
6
6
  import { ServerAuthorizationTokenResponse } from "./ServerAuthorizationTokenResponse";
7
- import { buildClientInfo } from "../account/ClientInfo";
8
7
  import { ICrypto } from "../crypto/ICrypto";
9
8
  import {
10
9
  ClientAuthErrorCodes,
@@ -45,6 +44,7 @@ import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
45
44
  import { checkMaxAge, extractTokenClaims } from "../account/AuthToken";
46
45
  import { TokenClaims } from "../account/TokenClaims";
47
46
  import { AccountInfo } from "../account/AccountInfo";
47
+ import * as CacheHelpers from "../cache/utils/CacheHelpers";
48
48
 
49
49
  /**
50
50
  * Class that handles response parsing.
@@ -81,16 +81,15 @@ export class ResponseHandler {
81
81
  /**
82
82
  * Function which validates server authorization code response.
83
83
  * @param serverResponseHash
84
- * @param cachedState
84
+ * @param requestState
85
85
  * @param cryptoObj
86
86
  */
87
87
  validateServerAuthorizationCodeResponse(
88
- serverResponseHash: ServerAuthorizationCodeResponse,
89
- cachedState: string,
90
- cryptoObj: ICrypto
88
+ serverResponse: ServerAuthorizationCodeResponse,
89
+ requestState: string
91
90
  ): void {
92
- if (!serverResponseHash.state || !cachedState) {
93
- throw serverResponseHash.state
91
+ if (!serverResponse.state || !requestState) {
92
+ throw serverResponse.state
94
93
  ? createClientAuthError(
95
94
  ClientAuthErrorCodes.stateNotFound,
96
95
  "Cached State"
@@ -101,67 +100,63 @@ export class ResponseHandler {
101
100
  );
102
101
  }
103
102
 
104
- let decodedServerResponseHash: string;
105
- let decodedCachedState: string;
103
+ let decodedServerResponseState: string;
104
+ let decodedRequestState: string;
106
105
 
107
106
  try {
108
- decodedServerResponseHash = decodeURIComponent(
109
- serverResponseHash.state
107
+ decodedServerResponseState = decodeURIComponent(
108
+ serverResponse.state
110
109
  );
111
110
  } catch (e) {
112
111
  throw createClientAuthError(
113
112
  ClientAuthErrorCodes.invalidState,
114
- serverResponseHash.state
113
+ serverResponse.state
115
114
  );
116
115
  }
117
116
 
118
117
  try {
119
- decodedCachedState = decodeURIComponent(cachedState);
118
+ decodedRequestState = decodeURIComponent(requestState);
120
119
  } catch (e) {
121
120
  throw createClientAuthError(
122
121
  ClientAuthErrorCodes.invalidState,
123
- serverResponseHash.state
122
+ serverResponse.state
124
123
  );
125
124
  }
126
125
 
127
- if (decodedServerResponseHash !== decodedCachedState) {
126
+ if (decodedServerResponseState !== decodedRequestState) {
128
127
  throw createClientAuthError(ClientAuthErrorCodes.stateMismatch);
129
128
  }
130
129
 
131
130
  // Check for error
132
131
  if (
133
- serverResponseHash.error ||
134
- serverResponseHash.error_description ||
135
- serverResponseHash.suberror
132
+ serverResponse.error ||
133
+ serverResponse.error_description ||
134
+ serverResponse.suberror
136
135
  ) {
137
136
  if (
138
137
  isInteractionRequiredError(
139
- serverResponseHash.error,
140
- serverResponseHash.error_description,
141
- serverResponseHash.suberror
138
+ serverResponse.error,
139
+ serverResponse.error_description,
140
+ serverResponse.suberror
142
141
  )
143
142
  ) {
144
143
  throw new InteractionRequiredAuthError(
145
- serverResponseHash.error || Constants.EMPTY_STRING,
146
- serverResponseHash.error_description,
147
- serverResponseHash.suberror,
148
- serverResponseHash.timestamp || Constants.EMPTY_STRING,
149
- serverResponseHash.trace_id || Constants.EMPTY_STRING,
150
- serverResponseHash.correlation_id || Constants.EMPTY_STRING,
151
- serverResponseHash.claims || Constants.EMPTY_STRING
144
+ serverResponse.error || "",
145
+ serverResponse.error_description,
146
+ serverResponse.suberror,
147
+ serverResponse.timestamp || "",
148
+ serverResponse.trace_id || "",
149
+ serverResponse.correlation_id || "",
150
+ serverResponse.claims || ""
152
151
  );
153
152
  }
154
153
 
155
154
  throw new ServerError(
156
- serverResponseHash.error || Constants.EMPTY_STRING,
157
- serverResponseHash.error_description,
158
- serverResponseHash.suberror
155
+ serverResponse.error || "",
156
+ serverResponse.error_description,
157
+ serverResponse.suberror
159
158
  );
160
159
  }
161
-
162
- if (serverResponseHash.client_info) {
163
- buildClientInfo(serverResponseHash.client_info, cryptoObj);
164
- }
165
160
  }
166
161
 
167
162
  /**
@@ -415,7 +410,7 @@ export class ResponseHandler {
415
410
  let cachedIdToken: IdTokenEntity | undefined;
416
411
  let cachedAccount: AccountEntity | undefined;
417
412
  if (serverTokenResponse.id_token && !!idTokenClaims) {
418
- cachedIdToken = IdTokenEntity.createIdTokenEntity(
413
+ cachedIdToken = CacheHelpers.createIdTokenEntity(
419
414
  this.homeAccountIdentifier,
420
415
  env,
421
416
  serverTokenResponse.id_token,
@@ -468,16 +463,16 @@ export class ResponseHandler {
468
463
  : undefined;
469
464
 
470
465
  // non AAD scenarios can have empty realm
471
- cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(
466
+ cachedAccessToken = CacheHelpers.createAccessTokenEntity(
472
467
  this.homeAccountIdentifier,
473
468
  env,
474
- serverTokenResponse.access_token || Constants.EMPTY_STRING,
469
+ serverTokenResponse.access_token,
475
470
  this.clientId,
476
471
  idTokenClaims?.tid || authority.tenant,
477
472
  responseScopes.printScopes(),
478
473
  tokenExpirationSeconds,
479
474
  extendedTokenExpirationSeconds,
480
- this.cryptoObj,
475
+ this.cryptoObj.base64Decode,
481
476
  refreshOnSeconds,
482
477
  serverTokenResponse.token_type,
483
478
  userAssertionHash,
@@ -490,10 +485,10 @@ export class ResponseHandler {
490
485
  // refreshToken
491
486
  let cachedRefreshToken: RefreshTokenEntity | null = null;
492
487
  if (serverTokenResponse.refresh_token) {
493
- cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(
488
+ cachedRefreshToken = CacheHelpers.createRefreshTokenEntity(
494
489
  this.homeAccountIdentifier,
495
490
  env,
496
- serverTokenResponse.refresh_token || Constants.EMPTY_STRING,
491
+ serverTokenResponse.refresh_token,
497
492
  this.clientId,
498
493
  serverTokenResponse.foci,
499
494
  userAssertionHash
@@ -208,7 +208,7 @@ export const PerformanceEvents = {
208
208
  * Functions from InteractionHandler (msal-browser)
209
209
  */
210
210
  HandleCodeResponseFromServer: "handleCodeResponseFromServer",
211
- HandleCodeResponseFromHash: "handleCodeResponseFromHash",
211
+ HandleCodeResponse: "handleCodeResponse",
212
212
  UpdateTokenEndpointAuthority: "updateTokenEndpointAuthority",
213
213
 
214
214
  /**
@@ -229,6 +229,7 @@ export const PerformanceEvents = {
229
229
  * handleServerTokenResponse API in ResponseHandler (msal-common)
230
230
  */
231
231
  HandleServerTokenResponse: "handleServerTokenResponse",
232
+ DeserializeResponse: "deserializeResponse",
232
233
 
233
234
  /**
234
235
  * Authority functions
@@ -558,6 +559,13 @@ export type PerformanceEvent = {
558
559
  * Nested App Auth Fields
559
560
  */
560
561
  nestedAppAuthRequest?: boolean;
562
+
563
+ /**
564
+ * Multiple matched access/id/refresh tokens in the cache
565
+ */
566
+ multiMatchedAT?: number;
567
+ multiMatchedID?: number;
568
+ multiMatchedRT?: number;
561
569
  };
562
570
 
563
571
  export const IntFields: ReadonlySet<string> = new Set([
@@ -570,4 +578,7 @@ export const IntFields: ReadonlySet<string> = new Set([
570
578
  "queuedTimeMs",
571
579
  "startTimeMs",
572
580
  "status",
581
+ "multiMatchedAT",
582
+ "multiMatchedID",
583
+ "multiMatchedRT",
573
584
  ]);
@@ -160,7 +160,11 @@ export class ServerTelemetryManager {
160
160
  * Get the server telemetry entity from cache or initialize a new one
161
161
  */
162
162
  getLastRequests(): ServerTelemetryEntity {
163
- const initialValue: ServerTelemetryEntity = new ServerTelemetryEntity();
163
+ const initialValue: ServerTelemetryEntity = {
164
+ failedRequests: [],
165
+ errors: [],
166
+ cacheHits: 0,
167
+ };
164
168
  const lastRequests = this.cacheManager.getServerTelemetry(
165
169
  this.telemetryCacheKey
166
170
  ) as ServerTelemetryEntity;
@@ -181,11 +185,13 @@ export class ServerTelemetryManager {
181
185
  this.cacheManager.removeItem(this.telemetryCacheKey);
182
186
  } else {
183
187
  // Partial data was flushed to server, construct a new telemetry cache item with errors that were not flushed
184
- const serverTelemEntity = new ServerTelemetryEntity();
185
- serverTelemEntity.failedRequests =
186
- lastRequests.failedRequests.slice(numErrorsFlushed * 2); // failedRequests contains 2 items for each error
187
- serverTelemEntity.errors =
188
- lastRequests.errors.slice(numErrorsFlushed);
188
+ const serverTelemEntity: ServerTelemetryEntity = {
189
+ failedRequests: lastRequests.failedRequests.slice(
190
+ numErrorsFlushed * 2
191
+ ), // failedRequests contains 2 items for each error
192
+ errors: lastRequests.errors.slice(numErrorsFlushed),
193
+ cacheHits: 0,
194
+ };
189
195
 
190
196
  this.cacheManager.setServerTelemetry(
191
197
  this.telemetryCacheKey,
@@ -3,22 +3,14 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { ServerAuthorizationCodeResponse } from "../response/ServerAuthorizationCodeResponse";
7
6
  import {
8
7
  createClientConfigurationError,
9
8
  ClientConfigurationErrorCodes,
10
9
  } from "../error/ClientConfigurationError";
11
- import {
12
- ClientAuthErrorCodes,
13
- createClientAuthError,
14
- } from "../error/ClientAuthError";
15
10
  import { StringUtils } from "../utils/StringUtils";
16
11
  import { IUri } from "./IUri";
17
- import {
18
- AADAuthorityConstants,
19
- Constants,
20
- ServerResponseType,
21
- } from "../utils/Constants";
12
+ import { AADAuthorityConstants, Constants } from "../utils/Constants";
13
+ import * as UrlUtils from "../utils/UrlUtils";
22
14
 
23
15
  /**
24
16
  * Url object class which can perform various transformations on url strings.
@@ -39,7 +31,7 @@ export class UrlString {
39
31
  );
40
32
  }
41
33
 
42
- if (!this.getHash()) {
34
+ if (!url.includes("#")) {
43
35
  this._urlString = UrlString.canonicalizeUri(url);
44
36
  }
45
37
  }
@@ -142,13 +134,6 @@ export class UrlString {
142
134
  return UrlString.constructAuthorityUriFromObject(urlObject);
143
135
  }
144
136
 
145
- /**
146
- * Returns the anchor part(#) of the URL
147
- */
148
- getHash(): string {
149
- return UrlString.parseHash(this.urlString);
150
- }
151
-
152
137
  /**
153
138
  * Parses out the components from a url string.
154
139
  * @returns An object with the various components. Please cache this value insted of calling this multiple times on the same url.
@@ -221,58 +206,6 @@ export class UrlString {
221
206
  return relativeUrl;
222
207
  }
223
208
 
224
- /**
225
- * Parses hash string from given string. Returns empty string if no hash symbol is found.
226
- * @param hashString
227
- */
228
- static parseHash(hashString: string): string {
229
- const hashIndex1 = hashString.indexOf("#");
230
- const hashIndex2 = hashString.indexOf("#/");
231
- if (hashIndex2 > -1) {
232
- return hashString.substring(hashIndex2 + 2);
233
- } else if (hashIndex1 > -1) {
234
- return hashString.substring(hashIndex1 + 1);
235
- }
236
- return Constants.EMPTY_STRING;
237
- }
238
-
239
- /**
240
- * Parses query string from given string. Returns empty string if no query symbol is found.
241
- * @param queryString
242
- */
243
- static parseQueryString(queryString: string): string {
244
- const queryIndex1 = queryString.indexOf("?");
245
- const queryIndex2 = queryString.indexOf("/?");
246
- if (queryIndex2 > -1) {
247
- return queryString.substring(queryIndex2 + 2);
248
- } else if (queryIndex1 > -1) {
249
- return queryString.substring(queryIndex1 + 1);
250
- }
251
- return Constants.EMPTY_STRING;
252
- }
253
-
254
- /**
255
- * Parses query server response string from given string.
256
- * Extract hash between '?code=' and '#' if trailing '# is present.
257
- * Returns empty string if no query symbol is found.
258
- * @param queryString
259
- */
260
- static parseQueryServerResponse(queryString: string): string {
261
- const queryIndex1 = queryString.indexOf("?code");
262
- const queryIndex2 = queryString.indexOf("/?code");
263
- const hashIndex = queryString.indexOf("#");
264
- if (queryIndex2 > -1 && hashIndex > -1) {
265
- return queryString.substring(queryIndex2 + 2, hashIndex);
266
- } else if (queryIndex2 > -1) {
267
- return queryString.substring(queryIndex2 + 2);
268
- } else if (queryIndex1 > -1 && hashIndex > -1) {
269
- return queryString.substring(queryIndex1 + 1, hashIndex);
270
- } else if (queryIndex1 > -1) {
271
- return queryString.substring(queryIndex1 + 1);
272
- }
273
- return Constants.EMPTY_STRING;
274
- }
275
-
276
209
  static constructAuthorityUriFromObject(urlObject: IUri): UrlString {
277
210
  return new UrlString(
278
211
  urlObject.Protocol +
@@ -283,91 +216,11 @@ export class UrlString {
283
216
  );
284
217
  }
285
218
 
286
- /**
287
- * Returns URL hash as server auth code response object.
288
- */
289
- static getDeserializedHash(hash: string): ServerAuthorizationCodeResponse {
290
- // Check if given hash is empty
291
- if (!hash) {
292
- return {};
293
- }
294
- // Strip the # symbol if present
295
- const parsedHash = UrlString.parseHash(hash);
296
- // If # symbol was not present, above will return empty string, so give original hash value
297
- const deserializedHash: ServerAuthorizationCodeResponse =
298
- StringUtils.queryStringToObject<ServerAuthorizationCodeResponse>(
299
- parsedHash || hash
300
- );
301
- // Check if deserialization didn't work
302
- if (!deserializedHash) {
303
- throw createClientAuthError(
304
- ClientAuthErrorCodes.hashNotDeserialized
305
- );
306
- }
307
- return deserializedHash;
308
- }
309
-
310
- /**
311
- * Returns URL query string as server auth code response object.
312
- */
313
- static getDeserializedQueryString(
314
- query: string
315
- ): ServerAuthorizationCodeResponse {
316
- // Check if given query is empty
317
- if (!query) {
318
- return {};
319
- }
320
- // Strip the ? symbol if present
321
- const parsedQueryString = UrlString.parseQueryString(query);
322
- // If ? symbol was not present, above will return empty string, so give original query value
323
- const deserializedQueryString: ServerAuthorizationCodeResponse =
324
- StringUtils.queryStringToObject<ServerAuthorizationCodeResponse>(
325
- parsedQueryString || query
326
- );
327
- // Check if deserialization didn't work
328
- if (!deserializedQueryString) {
329
- throw createClientAuthError(
330
- ClientAuthErrorCodes.hashNotDeserialized
331
- );
332
- }
333
- return deserializedQueryString;
334
- }
335
- /**
336
- * Returns either deserialized query string or deserialized hash, depending on the serverResponseType
337
- * as a server auth code response object.
338
- */
339
- static getDeserializedCodeResponse(
340
- serverResponseType: ServerResponseType | undefined,
341
- hashFragment: string
342
- ): ServerAuthorizationCodeResponse {
343
- const hashUrlString = new UrlString(hashFragment);
344
- let serverParams: ServerAuthorizationCodeResponse;
345
- if (serverResponseType === ServerResponseType.QUERY) {
346
- serverParams = UrlString.getDeserializedQueryString(hashFragment);
347
- } else {
348
- serverParams = UrlString.getDeserializedHash(
349
- hashUrlString.getHash()
350
- );
351
- }
352
- return serverParams;
353
- }
354
-
355
219
  /**
356
220
  * Check if the hash of the URL string contains known properties
221
+ * @deprecated This API will be removed in a future version
357
222
  */
358
- static hashContainsKnownProperties(hash: string): boolean {
359
- if (!hash || hash.indexOf("=") < 0) {
360
- // Hash doesn't contain key/value pairs
361
- return false;
362
- }
363
-
364
- const parameters: ServerAuthorizationCodeResponse =
365
- UrlString.getDeserializedHash(hash);
366
- return !!(
367
- parameters.code ||
368
- parameters.error_description ||
369
- parameters.error ||
370
- parameters.state
371
- );
223
+ static hashContainsKnownProperties(response: string): boolean {
224
+ return !!UrlUtils.getDeserializedResponse(response);
372
225
  }
373
226
  }
@@ -51,7 +51,6 @@ export const Constants = {
51
51
  IMDS_TIMEOUT: 2000,
52
52
  AZURE_REGION_AUTO_DISCOVER_FLAG: "TryAutoDetect",
53
53
  REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX: "login.microsoft.com",
54
- REGIONAL_AUTH_NON_MSI_QUERY_STRING: "allowestsrnonmsi=true",
55
54
  KNOWN_PUBLIC_CLOUDS: [
56
55
  "login.microsoftonline.com",
57
56
  "login.windows.net",
@@ -434,11 +433,12 @@ export const CacheOutcome = {
434
433
  } as const;
435
434
  export type CacheOutcome = (typeof CacheOutcome)[keyof typeof CacheOutcome];
436
435
 
437
- export const JsonTypes = {
436
+ export const JsonWebTokenTypes = {
438
437
  Jwt: "JWT",
439
438
  Jwk: "JWK",
440
439
  Pop: "pop",
441
440
  } as const;
442
- export type JsonTypes = (typeof JsonTypes)[keyof typeof JsonTypes];
441
+ export type JsonWebTokenTypes =
442
+ (typeof JsonWebTokenTypes)[keyof typeof JsonWebTokenTypes];
443
443
 
444
444
  export const ONE_DAY_IN_MS = 86400000;
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ServerAuthorizationCodeResponse } from "../response/ServerAuthorizationCodeResponse";
7
+ import {
8
+ ClientAuthErrorCodes,
9
+ createClientAuthError,
10
+ } from "../error/ClientAuthError";
11
+
12
+ /**
13
+ * Parses hash string from given string. Returns empty string if no hash symbol is found.
14
+ * @param hashString
15
+ */
16
+ export function stripLeadingHashOrQuery(responseString: string): string {
17
+ if (responseString.startsWith("#/")) {
18
+ return responseString.substring(2);
19
+ } else if (
20
+ responseString.startsWith("#") ||
21
+ responseString.startsWith("?")
22
+ ) {
23
+ return responseString.substring(1);
24
+ }
25
+
26
+ return responseString;
27
+ }
28
+
29
+ /**
30
+ * Returns URL hash as server auth code response object.
31
+ */
32
+ export function getDeserializedResponse(
33
+ responseString: string
34
+ ): ServerAuthorizationCodeResponse | null {
35
+ // Check if given hash is empty
36
+ if (!responseString || responseString.indexOf("=") < 0) {
37
+ return null;
38
+ }
39
+ try {
40
+ // Strip the # or ? symbol if present
41
+ const normalizedResponse = stripLeadingHashOrQuery(responseString);
42
+ // If # symbol was not present, above will return empty string, so give original hash value
43
+ const deserializedHash: ServerAuthorizationCodeResponse =
44
+ Object.fromEntries(new URLSearchParams(normalizedResponse));
45
+
46
+ // Check for known response properties
47
+ if (
48
+ deserializedHash.code ||
49
+ deserializedHash.error ||
50
+ deserializedHash.error_description ||
51
+ deserializedHash.state
52
+ ) {
53
+ return deserializedHash;
54
+ }
55
+ } catch (e) {
56
+ throw createClientAuthError(ClientAuthErrorCodes.hashNotDeserialized);
57
+ }
58
+
59
+ return null;
60
+ }