@azure/msal-common 14.4.1-beta.1 → 14.6.0-alpha.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 (209) hide show
  1. package/dist/account/AccountInfo.d.ts +27 -0
  2. package/dist/account/AccountInfo.d.ts.map +1 -1
  3. package/dist/account/AccountInfo.mjs +64 -0
  4. package/dist/account/AccountInfo.mjs.map +1 -0
  5. package/dist/account/AuthToken.mjs +1 -1
  6. package/dist/account/AuthToken.mjs.map +1 -1
  7. package/dist/account/CcsCredential.mjs +1 -1
  8. package/dist/account/CcsCredential.mjs.map +1 -1
  9. package/dist/account/ClientInfo.d.ts +1 -2
  10. package/dist/account/ClientInfo.d.ts.map +1 -1
  11. package/dist/account/ClientInfo.mjs +3 -3
  12. package/dist/account/ClientInfo.mjs.map +1 -1
  13. package/dist/account/TokenClaims.d.ts +18 -0
  14. package/dist/account/TokenClaims.d.ts.map +1 -1
  15. package/dist/account/TokenClaims.mjs +25 -0
  16. package/dist/account/TokenClaims.mjs.map +1 -0
  17. package/dist/authority/Authority.d.ts +7 -2
  18. package/dist/authority/Authority.d.ts.map +1 -1
  19. package/dist/authority/Authority.mjs +34 -7
  20. package/dist/authority/Authority.mjs.map +1 -1
  21. package/dist/authority/AuthorityFactory.mjs +1 -1
  22. package/dist/authority/AuthorityFactory.mjs.map +1 -1
  23. package/dist/authority/AuthorityMetadata.mjs +1 -1
  24. package/dist/authority/AuthorityMetadata.mjs.map +1 -1
  25. package/dist/authority/AuthorityOptions.mjs +1 -1
  26. package/dist/authority/AuthorityOptions.mjs.map +1 -1
  27. package/dist/authority/AuthorityType.mjs +1 -1
  28. package/dist/authority/AuthorityType.mjs.map +1 -1
  29. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  30. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs.map +1 -1
  31. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  32. package/dist/authority/CloudInstanceDiscoveryResponse.mjs.map +1 -1
  33. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  34. package/dist/authority/OpenIdConfigResponse.mjs.map +1 -1
  35. package/dist/authority/ProtocolMode.mjs +1 -1
  36. package/dist/authority/ProtocolMode.mjs.map +1 -1
  37. package/dist/authority/RegionDiscovery.mjs +1 -1
  38. package/dist/authority/RegionDiscovery.mjs.map +1 -1
  39. package/dist/cache/CacheManager.d.ts +50 -27
  40. package/dist/cache/CacheManager.d.ts.map +1 -1
  41. package/dist/cache/CacheManager.mjs +243 -107
  42. package/dist/cache/CacheManager.mjs.map +1 -1
  43. package/dist/cache/entities/AccountEntity.d.ts +9 -4
  44. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  45. package/dist/cache/entities/AccountEntity.mjs +56 -28
  46. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  47. package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
  48. package/dist/cache/entities/AppMetadataEntity.mjs.map +1 -1
  49. package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
  50. package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +1 -1
  51. package/dist/cache/entities/CacheRecord.mjs +1 -1
  52. package/dist/cache/entities/CacheRecord.mjs.map +1 -1
  53. package/dist/cache/entities/ThrottlingEntity.d.ts +2 -8
  54. package/dist/cache/entities/ThrottlingEntity.d.ts.map +1 -1
  55. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  56. package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -1
  57. package/dist/cache/utils/CacheHelpers.d.ts +7 -1
  58. package/dist/cache/utils/CacheHelpers.d.ts.map +1 -1
  59. package/dist/cache/utils/CacheHelpers.mjs +20 -4
  60. package/dist/cache/utils/CacheHelpers.mjs.map +1 -1
  61. package/dist/cache/utils/CacheTypes.d.ts +2 -0
  62. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  63. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  64. package/dist/client/AuthorizationCodeClient.mjs +10 -9
  65. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  66. package/dist/client/BaseClient.mjs +1 -1
  67. package/dist/client/BaseClient.mjs.map +1 -1
  68. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  69. package/dist/client/RefreshTokenClient.mjs +25 -11
  70. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  71. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  72. package/dist/client/SilentFlowClient.mjs +20 -9
  73. package/dist/client/SilentFlowClient.mjs.map +1 -1
  74. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  75. package/dist/config/ClientConfiguration.mjs +2 -4
  76. package/dist/config/ClientConfiguration.mjs.map +1 -1
  77. package/dist/constants/AADServerParamKeys.d.ts +53 -0
  78. package/dist/constants/AADServerParamKeys.d.ts.map +1 -0
  79. package/dist/constants/AADServerParamKeys.mjs +61 -0
  80. package/dist/constants/AADServerParamKeys.mjs.map +1 -0
  81. package/dist/crypto/ICrypto.mjs +1 -1
  82. package/dist/crypto/ICrypto.mjs.map +1 -1
  83. package/dist/crypto/JoseHeader.mjs +1 -1
  84. package/dist/crypto/JoseHeader.mjs.map +1 -1
  85. package/dist/crypto/PopTokenGenerator.mjs +2 -2
  86. package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
  87. package/dist/error/AuthError.mjs +1 -1
  88. package/dist/error/AuthError.mjs.map +1 -1
  89. package/dist/error/AuthErrorCodes.mjs +1 -1
  90. package/dist/error/AuthErrorCodes.mjs.map +1 -1
  91. package/dist/error/ClientAuthError.mjs +1 -1
  92. package/dist/error/ClientAuthError.mjs.map +1 -1
  93. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  94. package/dist/error/ClientAuthErrorCodes.mjs.map +1 -1
  95. package/dist/error/ClientConfigurationError.mjs +1 -1
  96. package/dist/error/ClientConfigurationError.mjs.map +1 -1
  97. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  98. package/dist/error/ClientConfigurationErrorCodes.mjs.map +1 -1
  99. package/dist/error/InteractionRequiredAuthError.d.ts +4 -0
  100. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  101. package/dist/error/InteractionRequiredAuthError.mjs +10 -3
  102. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
  103. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +1 -0
  104. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts.map +1 -1
  105. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +4 -3
  106. package/dist/error/InteractionRequiredAuthErrorCodes.mjs.map +1 -1
  107. package/dist/error/JoseHeaderError.mjs +1 -1
  108. package/dist/error/JoseHeaderError.mjs.map +1 -1
  109. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  110. package/dist/error/JoseHeaderErrorCodes.mjs.map +1 -1
  111. package/dist/error/ServerError.mjs +1 -1
  112. package/dist/error/ServerError.mjs.map +1 -1
  113. package/dist/index.cjs +797 -416
  114. package/dist/index.cjs.map +1 -1
  115. package/dist/index.d.ts +5 -4
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.mjs +7 -4
  118. package/dist/index.mjs.map +1 -1
  119. package/dist/logger/Logger.mjs +1 -1
  120. package/dist/logger/Logger.mjs.map +1 -1
  121. package/dist/network/INetworkModule.mjs +1 -1
  122. package/dist/network/INetworkModule.mjs.map +1 -1
  123. package/dist/network/NetworkManager.mjs +1 -1
  124. package/dist/network/NetworkManager.mjs.map +1 -1
  125. package/dist/network/ThrottlingUtils.mjs +1 -1
  126. package/dist/network/ThrottlingUtils.mjs.map +1 -1
  127. package/dist/packageMetadata.d.ts +1 -1
  128. package/dist/packageMetadata.d.ts.map +1 -1
  129. package/dist/packageMetadata.mjs +2 -2
  130. package/dist/packageMetadata.mjs.map +1 -1
  131. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  132. package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
  133. package/dist/request/CommonRefreshTokenRequest.d.ts +0 -1
  134. package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
  135. package/dist/request/CommonSilentFlowRequest.d.ts +7 -1
  136. package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
  137. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  138. package/dist/request/RequestParameterBuilder.mjs +46 -45
  139. package/dist/request/RequestParameterBuilder.mjs.map +1 -1
  140. package/dist/request/RequestValidator.mjs +1 -1
  141. package/dist/request/RequestValidator.mjs.map +1 -1
  142. package/dist/request/ScopeSet.mjs +1 -1
  143. package/dist/request/ScopeSet.mjs.map +1 -1
  144. package/dist/response/ResponseHandler.d.ts +3 -1
  145. package/dist/response/ResponseHandler.d.ts.map +1 -1
  146. package/dist/response/ResponseHandler.mjs +56 -20
  147. package/dist/response/ResponseHandler.mjs.map +1 -1
  148. package/dist/response/ServerAuthorizationTokenResponse.d.ts +1 -0
  149. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  150. package/dist/telemetry/performance/IPerformanceClient.d.ts +6 -0
  151. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
  152. package/dist/telemetry/performance/PerformanceClient.d.ts +9 -2
  153. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  154. package/dist/telemetry/performance/PerformanceClient.mjs +17 -13
  155. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  156. package/dist/telemetry/performance/PerformanceEvent.mjs +1 -1
  157. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  158. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
  159. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  160. package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
  161. package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
  162. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
  163. package/dist/url/UrlString.mjs +1 -1
  164. package/dist/url/UrlString.mjs.map +1 -1
  165. package/dist/utils/Constants.d.ts +2 -69
  166. package/dist/utils/Constants.d.ts.map +1 -1
  167. package/dist/utils/Constants.mjs +6 -70
  168. package/dist/utils/Constants.mjs.map +1 -1
  169. package/dist/utils/FunctionWrappers.mjs +1 -1
  170. package/dist/utils/FunctionWrappers.mjs.map +1 -1
  171. package/dist/utils/ProtocolUtils.mjs +1 -1
  172. package/dist/utils/ProtocolUtils.mjs.map +1 -1
  173. package/dist/utils/StringUtils.mjs +1 -1
  174. package/dist/utils/StringUtils.mjs.map +1 -1
  175. package/dist/utils/TimeUtils.mjs +1 -1
  176. package/dist/utils/TimeUtils.mjs.map +1 -1
  177. package/dist/utils/UrlUtils.mjs +1 -1
  178. package/dist/utils/UrlUtils.mjs.map +1 -1
  179. package/package.json +93 -92
  180. package/src/account/AccountInfo.ts +96 -0
  181. package/src/account/ClientInfo.ts +2 -3
  182. package/src/account/TokenClaims.ts +28 -0
  183. package/src/authority/Authority.ts +38 -5
  184. package/src/cache/CacheManager.ts +410 -162
  185. package/src/cache/entities/AccountEntity.ts +84 -33
  186. package/src/cache/entities/ThrottlingEntity.ts +2 -24
  187. package/src/cache/utils/CacheHelpers.ts +22 -2
  188. package/src/cache/utils/CacheTypes.ts +11 -0
  189. package/src/client/AuthorizationCodeClient.ts +4 -5
  190. package/src/client/RefreshTokenClient.ts +35 -14
  191. package/src/client/SilentFlowClient.ts +31 -11
  192. package/src/config/ClientConfiguration.ts +4 -4
  193. package/src/constants/AADServerParamKeys.ts +57 -0
  194. package/src/crypto/PopTokenGenerator.ts +1 -1
  195. package/src/error/InteractionRequiredAuthError.ts +12 -2
  196. package/src/error/InteractionRequiredAuthErrorCodes.ts +1 -0
  197. package/src/index.ts +18 -5
  198. package/src/packageMetadata.ts +1 -1
  199. package/src/request/CommonRefreshTokenRequest.ts +0 -1
  200. package/src/request/CommonSilentFlowRequest.ts +7 -1
  201. package/src/request/RequestParameterBuilder.ts +7 -5
  202. package/src/response/ResponseHandler.ts +109 -25
  203. package/src/response/ServerAuthorizationTokenResponse.ts +1 -0
  204. package/src/telemetry/performance/IPerformanceClient.ts +6 -0
  205. package/src/telemetry/performance/PerformanceClient.ts +24 -31
  206. package/src/telemetry/performance/StubPerformanceClient.ts +0 -1
  207. package/src/utils/Constants.ts +4 -72
  208. package/dist/cache/entities/ThrottlingEntity.mjs +0 -30
  209. package/dist/cache/entities/ThrottlingEntity.mjs.map +0 -1
@@ -15,6 +15,7 @@ export const InteractionRequiredServerErrorMessage = [
15
15
  InteractionRequiredAuthErrorCodes.interactionRequired,
16
16
  InteractionRequiredAuthErrorCodes.consentRequired,
17
17
  InteractionRequiredAuthErrorCodes.loginRequired,
18
+ InteractionRequiredAuthErrorCodes.badToken,
18
19
  ];
19
20
 
20
21
  export const InteractionRequiredAuthSubErrorMessage = [
@@ -23,15 +24,18 @@ export const InteractionRequiredAuthSubErrorMessage = [
23
24
  "basic_action",
24
25
  "user_password_expired",
25
26
  "consent_required",
27
+ "bad_token",
26
28
  ];
27
29
 
28
30
  const InteractionRequiredAuthErrorMessages = {
29
31
  [InteractionRequiredAuthErrorCodes.noTokensFound]:
30
32
  "No refresh token found in the cache. Please sign-in.",
31
- [InteractionRequiredAuthErrorCodes.refreshTokenExpired]:
32
- "Refresh token has expired.",
33
33
  [InteractionRequiredAuthErrorCodes.nativeAccountUnavailable]:
34
34
  "The requested account is not available in the native broker. It may have been deleted or logged out. Please sign-in again using an interactive API.",
35
+ [InteractionRequiredAuthErrorCodes.refreshTokenExpired]:
36
+ "Refresh token has expired.",
37
+ [InteractionRequiredAuthErrorCodes.badToken]:
38
+ "Identity provider returned bad_token due to an expired or invalid refresh token. Please invoke an interactive API to resolve.",
35
39
  };
36
40
 
37
41
  /**
@@ -51,6 +55,12 @@ export const InteractionRequiredAuthErrorMessage = {
51
55
  InteractionRequiredAuthErrorCodes.nativeAccountUnavailable
52
56
  ],
53
57
  },
58
+ bad_token: {
59
+ code: InteractionRequiredAuthErrorCodes.badToken,
60
+ desc: InteractionRequiredAuthErrorMessages[
61
+ InteractionRequiredAuthErrorCodes.badToken
62
+ ],
63
+ },
54
64
  };
55
65
 
56
66
  /**
@@ -12,3 +12,4 @@ export const refreshTokenExpired = "refresh_token_expired";
12
12
  export const interactionRequired = "interaction_required";
13
13
  export const consentRequired = "consent_required";
14
14
  export const loginRequired = "login_required";
15
+ export const badToken = "bad_token";
package/src/index.ts CHANGED
@@ -28,9 +28,19 @@ export {
28
28
  } from "./config/AppTokenProvider";
29
29
  export { ClientConfiguration } from "./config/ClientConfiguration";
30
30
  // Account
31
- export { AccountInfo, ActiveAccountFilters } from "./account/AccountInfo";
31
+ export {
32
+ AccountInfo,
33
+ ActiveAccountFilters,
34
+ TenantProfile,
35
+ updateAccountTenantProfileData,
36
+ tenantIdMatchesHomeTenant,
37
+ buildTenantProfileFromIdTokenClaims,
38
+ } from "./account/AccountInfo";
32
39
  export * as AuthToken from "./account/AuthToken";
33
- export { TokenClaims } from "./account/TokenClaims";
40
+ export {
41
+ TokenClaims,
42
+ getTenantIdFromIdTokenClaims,
43
+ } from "./account/TokenClaims";
34
44
  export { TokenClaims as IdTokenClaims } from "./account/TokenClaims";
35
45
  export { CcsCredential, CcsCredentialType } from "./account/CcsCredential";
36
46
  export {
@@ -136,7 +146,10 @@ export {
136
146
  DeviceCodeResponse,
137
147
  ServerDeviceCodeResponse,
138
148
  } from "./response/DeviceCodeResponse";
139
- export { ResponseHandler } from "./response/ResponseHandler";
149
+ export {
150
+ ResponseHandler,
151
+ buildAccountToCache,
152
+ } from "./response/ResponseHandler";
140
153
  export { ScopeSet } from "./request/ScopeSet";
141
154
  export { AuthenticationHeaderParser } from "./request/AuthenticationHeaderParser";
142
155
  // Logger Callback
@@ -181,20 +194,20 @@ export {
181
194
  CacheAccountType,
182
195
  AuthenticationScheme,
183
196
  CodeChallengeMethodValues,
184
- SSOTypes,
185
197
  PasswordGrantConstants,
186
198
  ThrottlingConstants,
187
199
  ClaimsRequestKeys,
188
200
  HeaderNames,
189
- AADServerParamKeys,
190
201
  Errors,
191
202
  THE_FAMILY_ID,
192
203
  ONE_DAY_IN_MS,
193
204
  GrantType,
194
205
  AADAuthorityConstants,
195
206
  HttpStatus,
207
+ DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
196
208
  JsonWebTokenTypes,
197
209
  } from "./utils/Constants";
210
+ export * as AADServerParamKeys from "./constants/AADServerParamKeys";
198
211
  export { StringUtils } from "./utils/StringUtils";
199
212
  export { StringDict } from "./utils/MsalTypes";
200
213
  export {
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable header/header */
2
2
  export const name = "@azure/msal-common";
3
- export const version = "14.4.1-beta.1";
3
+ export const version = "14.6.0-alpha.0";
@@ -21,7 +21,6 @@ import { StringDict } from "../utils/MsalTypes";
21
21
  */
22
22
  export type CommonRefreshTokenRequest = BaseAuthRequest & {
23
23
  refreshToken: string;
24
- expiresOn?: string;
25
24
  ccsCredential?: CcsCredential;
26
25
  forceCache?: boolean;
27
26
  tokenBodyParameters?: StringDict;
@@ -20,8 +20,14 @@ import { BaseAuthRequest } from "./BaseAuthRequest";
20
20
  * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
21
21
  */
22
22
  export type CommonSilentFlowRequest = BaseAuthRequest & {
23
+ /** Account object to lookup the credentials */
23
24
  account: AccountInfo;
25
+ /** Skip cache lookup and forces network call(s) to get fresh tokens */
24
26
  forceRefresh: boolean;
27
+ /** RedirectUri registered on the app registration - only required in brokering scenarios */
28
+ redirectUri?: string;
29
+ /** Key value pairs to include on the POST body to the /token endpoint */
25
30
  tokenBodyParameters?: StringDict;
26
- enableRTExpiryCheck?: boolean;
31
+ /** If refresh token will expire within the configured value, consider it already expired. Used to pre-emptively invoke interaction when cached refresh token is close to expiry. */
32
+ refreshTokenExpirationOffsetSeconds?: number;
27
33
  };
@@ -4,10 +4,8 @@
4
4
  */
5
5
 
6
6
  import {
7
- AADServerParamKeys,
8
7
  Constants,
9
8
  ResponseMode,
10
- SSOTypes,
11
9
  CLIENT_INFO,
12
10
  AuthenticationScheme,
13
11
  ClaimsRequestKeys,
@@ -16,6 +14,7 @@ import {
16
14
  ThrottlingConstants,
17
15
  HeaderNames,
18
16
  } from "../utils/Constants";
17
+ import * as AADServerParamKeys from "../constants/AADServerParamKeys";
19
18
  import { ScopeSet } from "./ScopeSet";
20
19
  import {
21
20
  createClientConfigurationError,
@@ -161,7 +160,7 @@ export class RequestParameterBuilder {
161
160
  */
162
161
  addDomainHint(domainHint: string): void {
163
162
  this.parameters.set(
164
- SSOTypes.DOMAIN_HINT,
163
+ AADServerParamKeys.DOMAIN_HINT,
165
164
  encodeURIComponent(domainHint)
166
165
  );
167
166
  }
@@ -171,7 +170,10 @@ export class RequestParameterBuilder {
171
170
  * @param loginHint
172
171
  */
173
172
  addLoginHint(loginHint: string): void {
174
- this.parameters.set(SSOTypes.LOGIN_HINT, encodeURIComponent(loginHint));
173
+ this.parameters.set(
174
+ AADServerParamKeys.LOGIN_HINT,
175
+ encodeURIComponent(loginHint)
176
+ );
175
177
  }
176
178
 
177
179
  /**
@@ -201,7 +203,7 @@ export class RequestParameterBuilder {
201
203
  * @param sid
202
204
  */
203
205
  addSid(sid: string): void {
204
- this.parameters.set(SSOTypes.SID, encodeURIComponent(sid));
206
+ this.parameters.set(AADServerParamKeys.SID, encodeURIComponent(sid));
205
207
  }
206
208
 
207
209
  /**
@@ -42,8 +42,15 @@ import { BaseAuthRequest } from "../request/BaseAuthRequest";
42
42
  import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
43
43
  import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
44
44
  import { checkMaxAge, extractTokenClaims } from "../account/AuthToken";
45
- import { TokenClaims } from "../account/TokenClaims";
46
- import { AccountInfo } from "../account/AccountInfo";
45
+ import {
46
+ TokenClaims,
47
+ getTenantIdFromIdTokenClaims,
48
+ } from "../account/TokenClaims";
49
+ import {
50
+ AccountInfo,
51
+ buildTenantProfileFromIdTokenClaims,
52
+ updateAccountTenantProfileData,
53
+ } from "../account/AccountInfo";
47
54
  import * as CacheHelpers from "../cache/utils/CacheHelpers";
48
55
 
49
56
  /**
@@ -245,8 +252,7 @@ export class ResponseHandler {
245
252
  userAssertionHash?: string,
246
253
  handlingRefreshTokenResponse?: boolean,
247
254
  forceCacheRefreshTokenResponse?: boolean,
248
- serverRequestId?: string,
249
- rtExpiresOn?: string
255
+ serverRequestId?: string
250
256
  ): Promise<AuthenticationResult> {
251
257
  this.performanceClient?.addQueueMeasurement(
252
258
  PerformanceEvents.HandleServerTokenResponse,
@@ -312,8 +318,7 @@ export class ResponseHandler {
312
318
  request,
313
319
  idTokenClaims,
314
320
  userAssertionHash,
315
- authCodePayload,
316
- rtExpiresOn
321
+ authCodePayload
317
322
  );
318
323
  let cacheContext;
319
324
  try {
@@ -339,12 +344,12 @@ export class ResponseHandler {
339
344
  cacheRecord.account
340
345
  ) {
341
346
  const key = cacheRecord.account.generateAccountKey();
342
- const account = this.cacheStorage.getAccount(key);
347
+ const account = this.cacheStorage.getAccount(key, this.logger);
343
348
  if (!account) {
344
349
  this.logger.warning(
345
350
  "Account used to refresh tokens not in persistence, refreshed tokens will not be stored in the cache"
346
351
  );
347
- return ResponseHandler.generateAuthenticationResult(
352
+ return await ResponseHandler.generateAuthenticationResult(
348
353
  this.cryptoObj,
349
354
  authority,
350
355
  cacheRecord,
@@ -373,6 +378,7 @@ export class ResponseHandler {
373
378
  await this.persistencePlugin.afterCacheAccess(cacheContext);
374
379
  }
375
380
  }
381
+
376
382
  return ResponseHandler.generateAuthenticationResult(
377
383
  this.cryptoObj,
378
384
  authority,
@@ -399,8 +405,7 @@ export class ResponseHandler {
399
405
  request: BaseAuthRequest,
400
406
  idTokenClaims?: TokenClaims,
401
407
  userAssertionHash?: string,
402
- authCodePayload?: AuthorizationCodePayload,
403
- rtExpiresOn?: string
408
+ authCodePayload?: AuthorizationCodePayload
404
409
  ): CacheRecord {
405
410
  const env = authority.getPreferredCache();
406
411
  if (!env) {
@@ -409,6 +414,8 @@ export class ResponseHandler {
409
414
  );
410
415
  }
411
416
 
417
+ const claimsTenantId = getTenantIdFromIdTokenClaims(idTokenClaims);
418
+
412
419
  // IdToken: non AAD scenarios can have empty realm
413
420
  let cachedIdToken: IdTokenEntity | undefined;
414
421
  let cachedAccount: AccountEntity | undefined;
@@ -418,18 +425,21 @@ export class ResponseHandler {
418
425
  env,
419
426
  serverTokenResponse.id_token,
420
427
  this.clientId,
421
- idTokenClaims.tid || ""
428
+ claimsTenantId || ""
422
429
  );
423
430
 
424
- cachedAccount = AccountEntity.createAccount(
425
- {
426
- homeAccountId: this.homeAccountIdentifier,
427
- idTokenClaims: idTokenClaims,
428
- clientInfo: serverTokenResponse.client_info,
429
- cloudGraphHostName: authCodePayload?.cloud_graph_host_name,
430
- msGraphHost: authCodePayload?.msgraph_host,
431
- },
432
- authority
431
+ cachedAccount = buildAccountToCache(
432
+ this.cacheStorage,
433
+ authority,
434
+ this.homeAccountIdentifier,
435
+ idTokenClaims,
436
+ this.cryptoObj.base64Decode,
437
+ serverTokenResponse.client_info,
438
+ env,
439
+ claimsTenantId,
440
+ authCodePayload,
441
+ undefined, // nativeAccountId
442
+ this.logger
433
443
  );
434
444
  }
435
445
 
@@ -471,7 +481,7 @@ export class ResponseHandler {
471
481
  env,
472
482
  serverTokenResponse.access_token,
473
483
  this.clientId,
474
- idTokenClaims?.tid || authority.tenant,
484
+ claimsTenantId || authority.tenant,
475
485
  responseScopes.printScopes(),
476
486
  tokenExpirationSeconds,
477
487
  extendedTokenExpirationSeconds,
@@ -488,6 +498,18 @@ export class ResponseHandler {
488
498
  // refreshToken
489
499
  let cachedRefreshToken: RefreshTokenEntity | null = null;
490
500
  if (serverTokenResponse.refresh_token) {
501
+ let rtExpiresOn: number | undefined;
502
+ if (serverTokenResponse.refresh_token_expires_in) {
503
+ const rtExpiresIn: number =
504
+ typeof serverTokenResponse.refresh_token_expires_in ===
505
+ "string"
506
+ ? parseInt(
507
+ serverTokenResponse.refresh_token_expires_in,
508
+ 10
509
+ )
510
+ : serverTokenResponse.refresh_token_expires_in;
511
+ rtExpiresOn = reqTimestamp + rtExpiresIn;
512
+ }
491
513
  cachedRefreshToken = CacheHelpers.createRefreshTokenEntity(
492
514
  this.homeAccountIdentifier,
493
515
  env,
@@ -600,10 +622,11 @@ export class ResponseHandler {
600
622
  }
601
623
 
602
624
  const accountInfo: AccountInfo | null = cacheRecord.account
603
- ? {
604
- ...cacheRecord.account.getAccountInfo(),
605
- idTokenClaims,
606
- }
625
+ ? updateAccountTenantProfileData(
626
+ cacheRecord.account.getAccountInfo(),
627
+ undefined, // tenantProfile optional
628
+ idTokenClaims
629
+ )
607
630
  : null;
608
631
 
609
632
  return {
@@ -637,3 +660,64 @@ export class ResponseHandler {
637
660
  };
638
661
  }
639
662
  }
663
+
664
+ export function buildAccountToCache(
665
+ cacheStorage: CacheManager,
666
+ authority: Authority,
667
+ homeAccountId: string,
668
+ idTokenClaims: TokenClaims,
669
+ base64Decode: (input: string) => string,
670
+ clientInfo?: string,
671
+ environment?: string,
672
+ claimsTenantId?: string | null,
673
+ authCodePayload?: AuthorizationCodePayload,
674
+ nativeAccountId?: string,
675
+ logger?: Logger
676
+ ): AccountEntity {
677
+ logger?.verbose("setCachedAccount called");
678
+
679
+ // Check if base account is already cached
680
+ const accountKeys = cacheStorage.getAccountKeys();
681
+ const baseAccountKey = accountKeys.find((accountKey: string) => {
682
+ return accountKey.startsWith(homeAccountId);
683
+ });
684
+
685
+ let cachedAccount: AccountEntity | null = null;
686
+ if (baseAccountKey) {
687
+ cachedAccount = cacheStorage.getAccount(baseAccountKey, logger);
688
+ }
689
+
690
+ const baseAccount =
691
+ cachedAccount ||
692
+ AccountEntity.createAccount(
693
+ {
694
+ homeAccountId,
695
+ idTokenClaims,
696
+ clientInfo,
697
+ environment,
698
+ cloudGraphHostName: authCodePayload?.cloud_graph_host_name,
699
+ msGraphHost: authCodePayload?.msgraph_host,
700
+ nativeAccountId: nativeAccountId,
701
+ },
702
+ authority,
703
+ base64Decode
704
+ );
705
+
706
+ const tenantProfiles = baseAccount.tenantProfiles || [];
707
+
708
+ if (
709
+ claimsTenantId &&
710
+ !tenantProfiles.find((tenantProfile) => {
711
+ return tenantProfile.tenantId === claimsTenantId;
712
+ })
713
+ ) {
714
+ const newTenantProfile = buildTenantProfileFromIdTokenClaims(
715
+ homeAccountId,
716
+ idTokenClaims
717
+ );
718
+ tenantProfiles.push(newTenantProfile);
719
+ }
720
+ baseAccount.tenantProfiles = tenantProfiles;
721
+
722
+ return baseAccount;
723
+ }
@@ -36,6 +36,7 @@ export type ServerAuthorizationTokenResponse = {
36
36
  ext_expires_in?: number;
37
37
  access_token?: string;
38
38
  refresh_token?: string;
39
+ refresh_token_expires_in?: number;
39
40
  id_token?: string;
40
41
  client_info?: string;
41
42
  foci?: string;
@@ -14,6 +14,9 @@ export type InProgressPerformanceEvent = {
14
14
  add: (fields: { [key: string]: {} | undefined }) => void;
15
15
  increment: (fields: { [key: string]: number | undefined }) => void;
16
16
  event: PerformanceEvent;
17
+ /**
18
+ * @deprecated This attribute will be removed in the next major version
19
+ */
17
20
  measurement: IPerformanceMeasurement;
18
21
  };
19
22
 
@@ -35,6 +38,9 @@ export interface IPerformanceClient {
35
38
  removePerformanceCallback(callbackId: string): boolean;
36
39
  addPerformanceCallback(callback: PerformanceCallbackFunction): string;
37
40
  emitEvents(events: PerformanceEvent[], correlationId: string): void;
41
+ /**
42
+ * @deprecated This method will be removed in the next major version
43
+ */
38
44
  startPerformanceMeasurement(
39
45
  measureName: string,
40
46
  correlationId: string
@@ -11,13 +11,14 @@ import {
11
11
  PerformanceCallbackFunction,
12
12
  QueueMeasurement,
13
13
  } from "./IPerformanceClient";
14
- import { IPerformanceMeasurement } from "./IPerformanceMeasurement";
15
14
  import {
16
15
  IntFields,
17
16
  PerformanceEvent,
18
17
  PerformanceEvents,
19
18
  PerformanceEventStatus,
20
19
  } from "./PerformanceEvent";
20
+ import { IPerformanceMeasurement } from "./IPerformanceMeasurement";
21
+ import { StubPerformanceMeasurement } from "./StubPerformanceClient";
21
22
 
22
23
  export interface PreQueueEvent {
23
24
  name: PerformanceEvents;
@@ -111,6 +112,7 @@ export abstract class PerformanceClient implements IPerformanceClient {
111
112
  * @param {string} measureName
112
113
  * @param {string} correlationId
113
114
  * @returns {IPerformanceMeasurement}
115
+ * @deprecated This method will be removed in the next major version
114
116
  */
115
117
  startPerformanceMeasurement(
116
118
  measureName: string, // eslint-disable-line @typescript-eslint/no-unused-vars
@@ -273,11 +275,6 @@ export abstract class PerformanceClient implements IPerformanceClient {
273
275
  `PerformanceClient: Performance measurement started for ${measureName}`,
274
276
  eventCorrelationId
275
277
  );
276
- const performanceMeasurement = this.startPerformanceMeasurement(
277
- measureName,
278
- eventCorrelationId
279
- );
280
- performanceMeasurement.startMeasurement();
281
278
 
282
279
  const inProgressEvent: PerformanceEvent = {
283
280
  eventId: this.generateId(),
@@ -301,15 +298,12 @@ export abstract class PerformanceClient implements IPerformanceClient {
301
298
  end: (
302
299
  event?: Partial<PerformanceEvent>
303
300
  ): PerformanceEvent | null => {
304
- return this.endMeasurement(
305
- {
306
- // Initial set of event properties
307
- ...inProgressEvent,
308
- // Properties set when event ends
309
- ...event,
310
- },
311
- performanceMeasurement
312
- );
301
+ return this.endMeasurement({
302
+ // Initial set of event properties
303
+ ...inProgressEvent,
304
+ // Properties set when event ends
305
+ ...event,
306
+ });
313
307
  },
314
308
  discard: () => {
315
309
  return this.discardMeasurements(inProgressEvent.correlationId);
@@ -323,8 +317,8 @@ export abstract class PerformanceClient implements IPerformanceClient {
323
317
  inProgressEvent.correlationId
324
318
  );
325
319
  },
326
- measurement: performanceMeasurement,
327
320
  event: inProgressEvent,
321
+ measurement: new StubPerformanceMeasurement(),
328
322
  };
329
323
  }
330
324
 
@@ -338,10 +332,7 @@ export abstract class PerformanceClient implements IPerformanceClient {
338
332
  * @param {IPerformanceMeasurement} measurement
339
333
  * @returns {(PerformanceEvent | null)}
340
334
  */
341
- endMeasurement(
342
- event: PerformanceEvent,
343
- measurement?: IPerformanceMeasurement
344
- ): PerformanceEvent | null {
335
+ endMeasurement(event: PerformanceEvent): PerformanceEvent | null {
345
336
  const rootEvent: PerformanceEvent | undefined =
346
337
  this.eventsByCorrelationId.get(event.correlationId);
347
338
  if (!rootEvent) {
@@ -365,17 +356,8 @@ export abstract class PerformanceClient implements IPerformanceClient {
365
356
  rootEvent.incompleteSubMeasurements?.delete(event.eventId);
366
357
  }
367
358
 
368
- measurement?.endMeasurement();
369
- const durationMs = measurement?.flushMeasurement();
370
- // null indicates no measurement was taken (e.g. needed performance APIs not present)
371
- if (!durationMs) {
372
- this.logger.trace(
373
- "PerformanceClient: Performance measurement not taken",
374
- rootEvent.correlationId
375
- );
376
- return null;
377
- }
378
-
359
+ const durationMs =
360
+ event.durationMs || this.getDurationMs(event.startTimeMs);
379
361
  this.logger.trace(
380
362
  `PerformanceClient: Performance measurement ended for ${event.name}: ${durationMs} ms`,
381
363
  event.correlationId
@@ -633,4 +615,15 @@ export abstract class PerformanceClient implements IPerformanceClient {
633
615
  }
634
616
  });
635
617
  }
618
+
619
+ /**
620
+ * Returns event duration in milliseconds
621
+ * @param startTimeMs {number}
622
+ * @returns {number}
623
+ */
624
+ private getDurationMs(startTimeMs: number): number {
625
+ const durationMs = Date.now() - startTimeMs;
626
+ // Handle clock skew
627
+ return durationMs < 0 ? durationMs : 0;
628
+ }
636
629
  }
@@ -54,7 +54,6 @@ export class StubPerformanceClient implements IPerformanceClient {
54
54
  startPerformanceMeasurement(): IPerformanceMeasurement {
55
55
  return new StubPerformanceMeasurement();
56
56
  }
57
-
58
57
  calculateQueuedTime(): number {
59
58
  return 0;
60
59
  }
@@ -68,6 +68,7 @@ export const HttpStatus = {
68
68
  SUCCESS_RANGE_END: 299,
69
69
  REDIRECT: 302,
70
70
  CLIENT_ERROR_RANGE_START: 400,
71
+ UNAUTHORIZED: 401,
71
72
  CLIENT_ERROR_RANGE_END: 499,
72
73
  SERVER_ERROR_RANGE_START: 500,
73
74
  SERVER_ERROR_RANGE_END: 599,
@@ -122,62 +123,6 @@ export const AADAuthorityConstants = {
122
123
  export type AADAuthorityConstants =
123
124
  (typeof AADAuthorityConstants)[keyof typeof AADAuthorityConstants];
124
125
 
125
- /**
126
- * Keys in the hashParams sent by AAD Server
127
- */
128
- export const AADServerParamKeys = {
129
- CLIENT_ID: "client_id",
130
- REDIRECT_URI: "redirect_uri",
131
- RESPONSE_TYPE: "response_type",
132
- RESPONSE_MODE: "response_mode",
133
- GRANT_TYPE: "grant_type",
134
- CLAIMS: "claims",
135
- SCOPE: "scope",
136
- ERROR: "error",
137
- ERROR_DESCRIPTION: "error_description",
138
- ACCESS_TOKEN: "access_token",
139
- ID_TOKEN: "id_token",
140
- REFRESH_TOKEN: "refresh_token",
141
- EXPIRES_IN: "expires_in",
142
- STATE: "state",
143
- NONCE: "nonce",
144
- PROMPT: "prompt",
145
- SESSION_STATE: "session_state",
146
- CLIENT_INFO: "client_info",
147
- CODE: "code",
148
- CODE_CHALLENGE: "code_challenge",
149
- CODE_CHALLENGE_METHOD: "code_challenge_method",
150
- CODE_VERIFIER: "code_verifier",
151
- CLIENT_REQUEST_ID: "client-request-id",
152
- X_CLIENT_SKU: "x-client-SKU",
153
- X_CLIENT_VER: "x-client-VER",
154
- X_CLIENT_OS: "x-client-OS",
155
- X_CLIENT_CPU: "x-client-CPU",
156
- X_CLIENT_CURR_TELEM: "x-client-current-telemetry",
157
- X_CLIENT_LAST_TELEM: "x-client-last-telemetry",
158
- X_MS_LIB_CAPABILITY: "x-ms-lib-capability",
159
- X_APP_NAME: "x-app-name",
160
- X_APP_VER: "x-app-ver",
161
- POST_LOGOUT_URI: "post_logout_redirect_uri",
162
- ID_TOKEN_HINT: "id_token_hint",
163
- DEVICE_CODE: "device_code",
164
- CLIENT_SECRET: "client_secret",
165
- CLIENT_ASSERTION: "client_assertion",
166
- CLIENT_ASSERTION_TYPE: "client_assertion_type",
167
- TOKEN_TYPE: "token_type",
168
- REQ_CNF: "req_cnf",
169
- OBO_ASSERTION: "assertion",
170
- REQUESTED_TOKEN_USE: "requested_token_use",
171
- ON_BEHALF_OF: "on_behalf_of",
172
- FOCI: "foci",
173
- CCS_HEADER: "X-AnchorMailbox",
174
- RETURN_SPA_CODE: "return_spa_code",
175
- NATIVE_BROKER: "nativebroker",
176
- LOGOUT_HINT: "logout_hint",
177
- } as const;
178
- export type AADServerParamKeys =
179
- (typeof AADServerParamKeys)[keyof typeof AADServerParamKeys];
180
-
181
126
  /**
182
127
  * Claims request keys
183
128
  */
@@ -202,22 +147,6 @@ export const PromptValue = {
202
147
  NO_SESSION: "no_session",
203
148
  };
204
149
 
205
- /**
206
- * SSO Types - generated to populate hints
207
- */
208
- export const SSOTypes = {
209
- ACCOUNT: "account",
210
- SID: "sid",
211
- LOGIN_HINT: "login_hint",
212
- ID_TOKEN: "id_token",
213
- DOMAIN_HINT: "domain_hint",
214
- ORGANIZATIONS: "organizations",
215
- CONSUMERS: "consumers",
216
- ACCOUNT_ID: "accountIdentifier",
217
- HOMEACCOUNT_ID: "homeAccountIdentifier",
218
- } as const;
219
- export type SSOTypes = (typeof SSOTypes)[keyof typeof SSOTypes];
220
-
221
150
  /**
222
151
  * allowed values for codeVerifier
223
152
  */
@@ -442,3 +371,6 @@ export type JsonWebTokenTypes =
442
371
  (typeof JsonWebTokenTypes)[keyof typeof JsonWebTokenTypes];
443
372
 
444
373
  export const ONE_DAY_IN_MS = 86400000;
374
+
375
+ // Token renewal offset default in seconds
376
+ export const DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;