@azure/msal-common 14.5.0 → 14.6.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 (135) hide show
  1. package/dist/account/AccountInfo.mjs +1 -1
  2. package/dist/account/AuthToken.mjs +1 -1
  3. package/dist/account/CcsCredential.mjs +1 -1
  4. package/dist/account/ClientInfo.mjs +1 -1
  5. package/dist/account/TokenClaims.mjs +1 -1
  6. package/dist/authority/Authority.d.ts.map +1 -1
  7. package/dist/authority/Authority.mjs +30 -15
  8. package/dist/authority/Authority.mjs.map +1 -1
  9. package/dist/authority/AuthorityFactory.mjs +1 -1
  10. package/dist/authority/AuthorityMetadata.mjs +1 -1
  11. package/dist/authority/AuthorityOptions.mjs +1 -1
  12. package/dist/authority/AuthorityType.mjs +1 -1
  13. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  14. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  15. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  16. package/dist/authority/ProtocolMode.mjs +1 -1
  17. package/dist/authority/RegionDiscovery.mjs +1 -1
  18. package/dist/cache/CacheManager.d.ts +0 -9
  19. package/dist/cache/CacheManager.d.ts.map +1 -1
  20. package/dist/cache/CacheManager.mjs +1 -27
  21. package/dist/cache/CacheManager.mjs.map +1 -1
  22. package/dist/cache/entities/AccountEntity.mjs +1 -1
  23. package/dist/cache/entities/AppMetadataEntity.d.ts +6 -34
  24. package/dist/cache/entities/AppMetadataEntity.d.ts.map +1 -1
  25. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +2 -35
  26. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  27. package/dist/cache/entities/CacheRecord.mjs +1 -1
  28. package/dist/cache/entities/RefreshTokenEntity.d.ts +3 -1
  29. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  30. package/dist/cache/entities/ThrottlingEntity.d.ts +2 -8
  31. package/dist/cache/entities/ThrottlingEntity.d.ts.map +1 -1
  32. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  33. package/dist/cache/utils/CacheHelpers.d.ts +31 -1
  34. package/dist/cache/utils/CacheHelpers.d.ts.map +1 -1
  35. package/dist/cache/utils/CacheHelpers.mjs +97 -4
  36. package/dist/cache/utils/CacheHelpers.mjs.map +1 -1
  37. package/dist/client/AuthorizationCodeClient.mjs +1 -1
  38. package/dist/client/BaseClient.mjs +1 -1
  39. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  40. package/dist/client/RefreshTokenClient.mjs +22 -3
  41. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  42. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  43. package/dist/client/SilentFlowClient.mjs +19 -8
  44. package/dist/client/SilentFlowClient.mjs.map +1 -1
  45. package/dist/config/ClientConfiguration.mjs +1 -1
  46. package/dist/constants/AADServerParamKeys.d.ts +1 -0
  47. package/dist/constants/AADServerParamKeys.d.ts.map +1 -1
  48. package/dist/constants/AADServerParamKeys.mjs +3 -2
  49. package/dist/constants/AADServerParamKeys.mjs.map +1 -1
  50. package/dist/crypto/ICrypto.mjs +1 -1
  51. package/dist/crypto/JoseHeader.mjs +1 -1
  52. package/dist/crypto/PopTokenGenerator.mjs +1 -1
  53. package/dist/error/AuthError.mjs +1 -1
  54. package/dist/error/AuthErrorCodes.mjs +1 -1
  55. package/dist/error/ClientAuthError.mjs +1 -1
  56. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  57. package/dist/error/ClientConfigurationError.mjs +1 -1
  58. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  59. package/dist/error/InteractionRequiredAuthError.d.ts +4 -0
  60. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  61. package/dist/error/InteractionRequiredAuthError.mjs +10 -2
  62. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
  63. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +2 -0
  64. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts.map +1 -1
  65. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +4 -2
  66. package/dist/error/InteractionRequiredAuthErrorCodes.mjs.map +1 -1
  67. package/dist/error/JoseHeaderError.mjs +1 -1
  68. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  69. package/dist/error/ServerError.mjs +1 -1
  70. package/dist/index.cjs +3065 -3088
  71. package/dist/index.cjs.map +1 -1
  72. package/dist/index.mjs +1 -4
  73. package/dist/index.mjs.map +1 -1
  74. package/dist/logger/Logger.mjs +1 -1
  75. package/dist/network/INetworkModule.mjs +1 -1
  76. package/dist/network/NetworkManager.mjs +1 -1
  77. package/dist/network/ThrottlingUtils.mjs +1 -1
  78. package/dist/packageMetadata.d.ts +1 -1
  79. package/dist/packageMetadata.mjs +2 -2
  80. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  81. package/dist/request/CommonSilentFlowRequest.d.ts +7 -0
  82. package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
  83. package/dist/request/RequestParameterBuilder.mjs +1 -1
  84. package/dist/request/RequestValidator.mjs +1 -1
  85. package/dist/request/ScopeSet.mjs +1 -1
  86. package/dist/response/ResponseHandler.d.ts +1 -1
  87. package/dist/response/ResponseHandler.d.ts.map +1 -1
  88. package/dist/response/ResponseHandler.mjs +22 -9
  89. package/dist/response/ResponseHandler.mjs.map +1 -1
  90. package/dist/response/ServerAuthorizationTokenResponse.d.ts +1 -0
  91. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  92. package/dist/telemetry/performance/IPerformanceClient.d.ts +6 -0
  93. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
  94. package/dist/telemetry/performance/PerformanceClient.d.ts +9 -2
  95. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  96. package/dist/telemetry/performance/PerformanceClient.mjs +17 -13
  97. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  98. package/dist/telemetry/performance/PerformanceEvent.mjs +1 -1
  99. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
  100. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  101. package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
  102. package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
  103. package/dist/url/UrlString.mjs +1 -1
  104. package/dist/utils/Constants.mjs +1 -1
  105. package/dist/utils/FunctionWrappers.mjs +1 -1
  106. package/dist/utils/ProtocolUtils.mjs +1 -1
  107. package/dist/utils/StringUtils.mjs +1 -1
  108. package/dist/utils/TimeUtils.mjs +1 -1
  109. package/dist/utils/UrlUtils.mjs +1 -1
  110. package/package.json +1 -1
  111. package/src/authority/Authority.ts +55 -16
  112. package/src/cache/CacheManager.ts +0 -54
  113. package/src/cache/entities/AppMetadataEntity.ts +6 -81
  114. package/src/cache/entities/AuthorityMetadataEntity.ts +2 -94
  115. package/src/cache/entities/RefreshTokenEntity.ts +3 -1
  116. package/src/cache/entities/ThrottlingEntity.ts +2 -24
  117. package/src/cache/utils/CacheHelpers.ts +137 -1
  118. package/src/client/RefreshTokenClient.ts +40 -7
  119. package/src/client/SilentFlowClient.ts +30 -10
  120. package/src/constants/AADServerParamKeys.ts +1 -0
  121. package/src/error/InteractionRequiredAuthError.ts +12 -0
  122. package/src/error/InteractionRequiredAuthErrorCodes.ts +2 -0
  123. package/src/packageMetadata.ts +1 -1
  124. package/src/request/CommonSilentFlowRequest.ts +7 -0
  125. package/src/response/ResponseHandler.ts +26 -10
  126. package/src/response/ServerAuthorizationTokenResponse.ts +1 -0
  127. package/src/telemetry/performance/IPerformanceClient.ts +6 -0
  128. package/src/telemetry/performance/PerformanceClient.ts +24 -31
  129. package/src/telemetry/performance/StubPerformanceClient.ts +0 -1
  130. package/dist/cache/entities/AppMetadataEntity.mjs +0 -73
  131. package/dist/cache/entities/AppMetadataEntity.mjs.map +0 -1
  132. package/dist/cache/entities/AuthorityMetadataEntity.mjs +0 -86
  133. package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +0 -1
  134. package/dist/cache/entities/ThrottlingEntity.mjs +0 -30
  135. package/dist/cache/entities/ThrottlingEntity.mjs.map +0 -1
@@ -47,6 +47,10 @@ import {
47
47
  import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
48
48
  import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
49
49
  import { invoke, invokeAsync } from "../utils/FunctionWrappers";
50
+ import { generateCredentialKey } from "../cache/utils/CacheHelpers";
51
+
52
+ const DEFAULT_REFRESH_TOKEN_EXPIRATION_OFFSET_SECONDS = 300; // 5 Minutes
53
+
50
54
  /**
51
55
  * OAuth2.0 refresh token client
52
56
  * @internal
@@ -215,6 +219,19 @@ export class RefreshTokenClient extends BaseClient {
215
219
  InteractionRequiredAuthErrorCodes.noTokensFound
216
220
  );
217
221
  }
222
+
223
+ if (
224
+ refreshToken.expiresOn &&
225
+ TimeUtils.isTokenExpired(
226
+ refreshToken.expiresOn,
227
+ request.refreshTokenExpirationOffsetSeconds ||
228
+ DEFAULT_REFRESH_TOKEN_EXPIRATION_OFFSET_SECONDS
229
+ )
230
+ ) {
231
+ throw createInteractionRequiredAuthError(
232
+ InteractionRequiredAuthErrorCodes.refreshTokenExpired
233
+ );
234
+ }
218
235
  // attach cached RT size to the current measurement
219
236
 
220
237
  const refreshTokenRequest: CommonRefreshTokenRequest = {
@@ -228,13 +245,29 @@ export class RefreshTokenClient extends BaseClient {
228
245
  },
229
246
  };
230
247
 
231
- return invokeAsync(
232
- this.acquireToken.bind(this),
233
- PerformanceEvents.RefreshTokenClientAcquireToken,
234
- this.logger,
235
- this.performanceClient,
236
- request.correlationId
237
- )(refreshTokenRequest);
248
+ try {
249
+ return await invokeAsync(
250
+ this.acquireToken.bind(this),
251
+ PerformanceEvents.RefreshTokenClientAcquireToken,
252
+ this.logger,
253
+ this.performanceClient,
254
+ request.correlationId
255
+ )(refreshTokenRequest);
256
+ } catch (e) {
257
+ if (
258
+ e instanceof InteractionRequiredAuthError &&
259
+ e.subError === InteractionRequiredAuthErrorCodes.badToken
260
+ ) {
261
+ // Remove bad refresh token from cache
262
+ this.logger.verbose(
263
+ "acquireTokenWithRefreshToken: bad refresh token, removing from cache"
264
+ );
265
+ const badRefreshTokenKey = generateCredentialKey(refreshToken);
266
+ this.cacheManager.removeRefreshToken(badRefreshTokenKey);
267
+ }
268
+
269
+ throw e;
270
+ }
238
271
  }
239
272
 
240
273
  /**
@@ -23,6 +23,7 @@ import { checkMaxAge, extractTokenClaims } from "../account/AuthToken";
23
23
  import { TokenClaims } from "../account/TokenClaims";
24
24
  import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
25
25
  import { invokeAsync } from "../utils/FunctionWrappers";
26
+ import { getTenantFromAuthorityString } from "../authority/Authority";
26
27
 
27
28
  /** @internal */
28
29
  export class SilentFlowClient extends BaseClient {
@@ -118,18 +119,20 @@ export class SilentFlowClient extends BaseClient {
118
119
  );
119
120
  }
120
121
 
121
- const environment =
122
- request.authority || this.authority.getPreferredCache();
123
-
124
- const cacheRecord = this.cacheManager.readCacheRecord(
122
+ const requestTenantId =
123
+ request.account.tenantId ||
124
+ getTenantFromAuthorityString(request.authority);
125
+ const tokenKeys = this.cacheManager.getTokenKeys();
126
+ const cachedAccessToken = this.cacheManager.getAccessToken(
125
127
  request.account,
126
128
  request,
127
- environment,
129
+ tokenKeys,
130
+ requestTenantId,
128
131
  this.performanceClient,
129
132
  request.correlationId
130
133
  );
131
134
 
132
- if (!cacheRecord.accessToken) {
135
+ if (!cachedAccessToken) {
133
136
  // must refresh due to non-existent access_token
134
137
  this.setCacheOutcome(
135
138
  CacheOutcome.NO_CACHED_ACCESS_TOKEN,
@@ -139,9 +142,9 @@ export class SilentFlowClient extends BaseClient {
139
142
  ClientAuthErrorCodes.tokenRefreshRequired
140
143
  );
141
144
  } else if (
142
- TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
145
+ TimeUtils.wasClockTurnedBack(cachedAccessToken.cachedAt) ||
143
146
  TimeUtils.isTokenExpired(
144
- cacheRecord.accessToken.expiresOn,
147
+ cachedAccessToken.expiresOn,
145
148
  this.config.systemOptions.tokenRenewalOffsetSeconds
146
149
  )
147
150
  ) {
@@ -154,8 +157,8 @@ export class SilentFlowClient extends BaseClient {
154
157
  ClientAuthErrorCodes.tokenRefreshRequired
155
158
  );
156
159
  } else if (
157
- cacheRecord.accessToken.refreshOn &&
158
- TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)
160
+ cachedAccessToken.refreshOn &&
161
+ TimeUtils.isTokenExpired(cachedAccessToken.refreshOn, 0)
159
162
  ) {
160
163
  // must refresh (in the background) due to the refresh_in value
161
164
  lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
@@ -163,6 +166,23 @@ export class SilentFlowClient extends BaseClient {
163
166
  // don't throw ClientAuthError.createRefreshRequiredError(), return cached token instead
164
167
  }
165
168
 
169
+ const environment =
170
+ request.authority || this.authority.getPreferredCache();
171
+ const cacheRecord: CacheRecord = {
172
+ account: this.cacheManager.readAccountFromCache(request.account),
173
+ accessToken: cachedAccessToken,
174
+ idToken: this.cacheManager.getIdToken(
175
+ request.account,
176
+ tokenKeys,
177
+ requestTenantId,
178
+ this.performanceClient,
179
+ request.correlationId
180
+ ),
181
+ refreshToken: null,
182
+ appMetadata:
183
+ this.cacheManager.readAppMetadataFromCache(environment),
184
+ };
185
+
166
186
  this.setCacheOutcome(lastCacheOutcome, request.correlationId);
167
187
 
168
188
  if (this.config.serverTelemetryManager) {
@@ -16,6 +16,7 @@ export const ACCESS_TOKEN = "access_token";
16
16
  export const ID_TOKEN = "id_token";
17
17
  export const REFRESH_TOKEN = "refresh_token";
18
18
  export const EXPIRES_IN = "expires_in";
19
+ export const REFRESH_TOKEN_EXPIRES_IN = "refresh_token_expires_in";
19
20
  export const STATE = "state";
20
21
  export const NONCE = "nonce";
21
22
  export const PROMPT = "prompt";
@@ -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,6 +24,7 @@ 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 = {
@@ -30,6 +32,10 @@ const InteractionRequiredAuthErrorMessages = {
30
32
  "No refresh token found in the cache. Please sign-in.",
31
33
  [InteractionRequiredAuthErrorCodes.nativeAccountUnavailable]:
32
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.",
33
39
  };
34
40
 
35
41
  /**
@@ -49,6 +55,12 @@ export const InteractionRequiredAuthErrorMessage = {
49
55
  InteractionRequiredAuthErrorCodes.nativeAccountUnavailable
50
56
  ],
51
57
  },
58
+ bad_token: {
59
+ code: InteractionRequiredAuthErrorCodes.badToken,
60
+ desc: InteractionRequiredAuthErrorMessages[
61
+ InteractionRequiredAuthErrorCodes.badToken
62
+ ],
63
+ },
52
64
  };
53
65
 
54
66
  /**
@@ -6,8 +6,10 @@
6
6
  // Codes defined by MSAL
7
7
  export const noTokensFound = "no_tokens_found";
8
8
  export const nativeAccountUnavailable = "native_account_unavailable";
9
+ export const refreshTokenExpired = "refresh_token_expired";
9
10
 
10
11
  // Codes potentially returned by server
11
12
  export const interactionRequired = "interaction_required";
12
13
  export const consentRequired = "consent_required";
13
14
  export const loginRequired = "login_required";
15
+ export const badToken = "bad_token";
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable header/header */
2
2
  export const name = "@azure/msal-common";
3
- export const version = "14.5.0";
3
+ export const version = "14.6.0";
@@ -20,7 +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;
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;
26
33
  };
@@ -435,9 +435,10 @@ export class ResponseHandler {
435
435
  idTokenClaims,
436
436
  this.cryptoObj.base64Decode,
437
437
  serverTokenResponse.client_info,
438
+ env,
438
439
  claimsTenantId,
439
440
  authCodePayload,
440
- undefined,
441
+ undefined, // nativeAccountId
441
442
  this.logger
442
443
  );
443
444
  }
@@ -497,24 +498,37 @@ export class ResponseHandler {
497
498
  // refreshToken
498
499
  let cachedRefreshToken: RefreshTokenEntity | null = null;
499
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
+ }
500
513
  cachedRefreshToken = CacheHelpers.createRefreshTokenEntity(
501
514
  this.homeAccountIdentifier,
502
515
  env,
503
516
  serverTokenResponse.refresh_token,
504
517
  this.clientId,
505
518
  serverTokenResponse.foci,
506
- userAssertionHash
519
+ userAssertionHash,
520
+ rtExpiresOn
507
521
  );
508
522
  }
509
523
 
510
524
  // appMetadata
511
525
  let cachedAppMetadata: AppMetadataEntity | null = null;
512
526
  if (serverTokenResponse.foci) {
513
- cachedAppMetadata = AppMetadataEntity.createAppMetadataEntity(
514
- this.clientId,
515
- env,
516
- serverTokenResponse.foci
517
- );
527
+ cachedAppMetadata = {
528
+ clientId: this.clientId,
529
+ environment: env,
530
+ familyId: serverTokenResponse.foci,
531
+ };
518
532
  }
519
533
 
520
534
  return new CacheRecord(
@@ -654,6 +668,7 @@ export function buildAccountToCache(
654
668
  idTokenClaims: TokenClaims,
655
669
  base64Decode: (input: string) => string,
656
670
  clientInfo?: string,
671
+ environment?: string,
657
672
  claimsTenantId?: string | null,
658
673
  authCodePayload?: AuthorizationCodePayload,
659
674
  nativeAccountId?: string,
@@ -676,9 +691,10 @@ export function buildAccountToCache(
676
691
  cachedAccount ||
677
692
  AccountEntity.createAccount(
678
693
  {
679
- homeAccountId: homeAccountId,
680
- idTokenClaims: idTokenClaims,
681
- clientInfo: clientInfo,
694
+ homeAccountId,
695
+ idTokenClaims,
696
+ clientInfo,
697
+ environment,
682
698
  cloudGraphHostName: authCodePayload?.cloud_graph_host_name,
683
699
  msGraphHost: authCodePayload?.msgraph_host,
684
700
  nativeAccountId: nativeAccountId,
@@ -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
  }
@@ -1,73 +0,0 @@
1
- /*! @azure/msal-common v14.5.0 2023-12-01 */
2
- 'use strict';
3
- import { Separators, APP_METADATA } from '../../utils/Constants.mjs';
4
-
5
- /*
6
- * Copyright (c) Microsoft Corporation. All rights reserved.
7
- * Licensed under the MIT License.
8
- */
9
- /**
10
- * APP_METADATA Cache
11
- *
12
- * Key:Value Schema:
13
- *
14
- * Key: appmetadata-<environment>-<client_id>
15
- *
16
- * Value:
17
- * {
18
- * clientId: client ID of the application
19
- * environment: entity that issued the token, represented as a full host
20
- * familyId: Family ID identifier, '1' represents Microsoft Family
21
- * }
22
- */
23
- class AppMetadataEntity {
24
- /**
25
- * Generate AppMetadata Cache Key as per the schema: appmetadata-<environment>-<client_id>
26
- */
27
- generateAppMetadataKey() {
28
- return AppMetadataEntity.generateAppMetadataCacheKey(this.environment, this.clientId);
29
- }
30
- /**
31
- * Generate AppMetadata Cache Key
32
- */
33
- static generateAppMetadataCacheKey(environment, clientId) {
34
- const appMetaDataKeyArray = [
35
- APP_METADATA,
36
- environment,
37
- clientId,
38
- ];
39
- return appMetaDataKeyArray
40
- .join(Separators.CACHE_KEY_SEPARATOR)
41
- .toLowerCase();
42
- }
43
- /**
44
- * Creates AppMetadataEntity
45
- * @param clientId
46
- * @param environment
47
- * @param familyId
48
- */
49
- static createAppMetadataEntity(clientId, environment, familyId) {
50
- const appMetadata = new AppMetadataEntity();
51
- appMetadata.clientId = clientId;
52
- appMetadata.environment = environment;
53
- if (familyId) {
54
- appMetadata.familyId = familyId;
55
- }
56
- return appMetadata;
57
- }
58
- /**
59
- * Validates an entity: checks for all expected params
60
- * @param entity
61
- */
62
- static isAppMetadataEntity(key, entity) {
63
- if (!entity) {
64
- return false;
65
- }
66
- return (key.indexOf(APP_METADATA) === 0 &&
67
- entity.hasOwnProperty("clientId") &&
68
- entity.hasOwnProperty("environment"));
69
- }
70
- }
71
-
72
- export { AppMetadataEntity };
73
- //# sourceMappingURL=AppMetadataEntity.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AppMetadataEntity.mjs","sources":["../../../src/cache/entities/AppMetadataEntity.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;;;AAGG;AAIH;;;;;;;;;;;;;AAaG;MACU,iBAAiB,CAAA;AAK1B;;AAEG;IACH,sBAAsB,GAAA;AAClB,QAAA,OAAO,iBAAiB,CAAC,2BAA2B,CAChD,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,QAAQ,CAChB,CAAC;KACL;AAED;;AAEG;AACH,IAAA,OAAO,2BAA2B,CAC9B,WAAmB,EACnB,QAAgB,EAAA;AAEhB,QAAA,MAAM,mBAAmB,GAAkB;YACvC,YAAY;YACZ,WAAW;YACX,QAAQ;SACX,CAAC;AACF,QAAA,OAAO,mBAAmB;AACrB,aAAA,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC;AACpC,aAAA,WAAW,EAAE,CAAC;KACtB;AAED;;;;;AAKG;AACH,IAAA,OAAO,uBAAuB,CAC1B,QAAgB,EAChB,WAAmB,EACnB,QAAiB,EAAA;AAEjB,QAAA,MAAM,WAAW,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAE5C,QAAA,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAChC,QAAA,WAAW,CAAC,WAAW,GAAG,WAAW,CAAC;AACtC,QAAA,IAAI,QAAQ,EAAE;AACV,YAAA,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACnC,SAAA;AAED,QAAA,OAAO,WAAW,CAAC;KACtB;AAED;;;AAGG;AACH,IAAA,OAAO,mBAAmB,CAAC,GAAW,EAAE,MAAc,EAAA;QAClD,IAAI,CAAC,MAAM,EAAE;AACT,YAAA,OAAO,KAAK,CAAC;AAChB,SAAA;QAED,QACI,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC;AAC/B,YAAA,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC;AACjC,YAAA,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,EACtC;KACL;AACJ;;;;"}
@@ -1,86 +0,0 @@
1
- /*! @azure/msal-common v14.5.0 2023-12-01 */
2
- 'use strict';
3
- import { AUTHORITY_METADATA_CONSTANTS } from '../../utils/Constants.mjs';
4
- import { TimeUtils } from '../../utils/TimeUtils.mjs';
5
-
6
- /*
7
- * Copyright (c) Microsoft Corporation. All rights reserved.
8
- * Licensed under the MIT License.
9
- */
10
- /** @internal */
11
- class AuthorityMetadataEntity {
12
- constructor() {
13
- this.expiresAt =
14
- TimeUtils.nowSeconds() +
15
- AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;
16
- }
17
- /**
18
- * Update the entity with new aliases, preferred_cache and preferred_network values
19
- * @param metadata
20
- * @param fromNetwork
21
- */
22
- updateCloudDiscoveryMetadata(metadata, fromNetwork) {
23
- this.aliases = metadata.aliases;
24
- this.preferred_cache = metadata.preferred_cache;
25
- this.preferred_network = metadata.preferred_network;
26
- this.aliasesFromNetwork = fromNetwork;
27
- }
28
- /**
29
- * Update the entity with new endpoints
30
- * @param metadata
31
- * @param fromNetwork
32
- */
33
- updateEndpointMetadata(metadata, fromNetwork) {
34
- this.authorization_endpoint = metadata.authorization_endpoint;
35
- this.token_endpoint = metadata.token_endpoint;
36
- this.end_session_endpoint = metadata.end_session_endpoint;
37
- this.issuer = metadata.issuer;
38
- this.endpointsFromNetwork = fromNetwork;
39
- this.jwks_uri = metadata.jwks_uri;
40
- }
41
- /**
42
- * Save the authority that was used to create this cache entry
43
- * @param authority
44
- */
45
- updateCanonicalAuthority(authority) {
46
- this.canonical_authority = authority;
47
- }
48
- /**
49
- * Reset the exiresAt value
50
- */
51
- resetExpiresAt() {
52
- this.expiresAt =
53
- TimeUtils.nowSeconds() +
54
- AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;
55
- }
56
- /**
57
- * Returns whether or not the data needs to be refreshed
58
- */
59
- isExpired() {
60
- return this.expiresAt <= TimeUtils.nowSeconds();
61
- }
62
- /**
63
- * Validates an entity: checks for all expected params
64
- * @param entity
65
- */
66
- static isAuthorityMetadataEntity(key, entity) {
67
- if (!entity) {
68
- return false;
69
- }
70
- return (key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) === 0 &&
71
- entity.hasOwnProperty("aliases") &&
72
- entity.hasOwnProperty("preferred_cache") &&
73
- entity.hasOwnProperty("preferred_network") &&
74
- entity.hasOwnProperty("canonical_authority") &&
75
- entity.hasOwnProperty("authorization_endpoint") &&
76
- entity.hasOwnProperty("token_endpoint") &&
77
- entity.hasOwnProperty("issuer") &&
78
- entity.hasOwnProperty("aliasesFromNetwork") &&
79
- entity.hasOwnProperty("endpointsFromNetwork") &&
80
- entity.hasOwnProperty("expiresAt") &&
81
- entity.hasOwnProperty("jwks_uri"));
82
- }
83
- }
84
-
85
- export { AuthorityMetadataEntity };
86
- //# sourceMappingURL=AuthorityMetadataEntity.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AuthorityMetadataEntity.mjs","sources":["../../../src/cache/entities/AuthorityMetadataEntity.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;AAGG;AAOH;MACa,uBAAuB,CAAA;AAchC,IAAA,WAAA,GAAA;AACI,QAAA,IAAI,CAAC,SAAS;YACV,SAAS,CAAC,UAAU,EAAE;gBACtB,4BAA4B,CAAC,oBAAoB,CAAC;KACzD;AAED;;;;AAIG;IACH,4BAA4B,CACxB,QAAgC,EAChC,WAAoB,EAAA;AAEpB,QAAA,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;AAChC,QAAA,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;AAChD,QAAA,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC;AACpD,QAAA,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC;KACzC;AAED;;;;AAIG;IACH,sBAAsB,CAClB,QAA8B,EAC9B,WAAoB,EAAA;AAEpB,QAAA,IAAI,CAAC,sBAAsB,GAAG,QAAQ,CAAC,sBAAsB,CAAC;AAC9D,QAAA,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC;AAC9C,QAAA,IAAI,CAAC,oBAAoB,GAAG,QAAQ,CAAC,oBAAoB,CAAC;AAC1D,QAAA,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;AAC9B,QAAA,IAAI,CAAC,oBAAoB,GAAG,WAAW,CAAC;AACxC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;KACrC;AAED;;;AAGG;AACH,IAAA,wBAAwB,CAAC,SAAiB,EAAA;AACtC,QAAA,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;KACxC;AAED;;AAEG;IACH,cAAc,GAAA;AACV,QAAA,IAAI,CAAC,SAAS;YACV,SAAS,CAAC,UAAU,EAAE;gBACtB,4BAA4B,CAAC,oBAAoB,CAAC;KACzD;AAED;;AAEG;IACH,SAAS,GAAA;QACL,OAAO,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC;KACnD;AAED;;;AAGG;AACH,IAAA,OAAO,yBAAyB,CAAC,GAAW,EAAE,MAAc,EAAA;QACxD,IAAI,CAAC,MAAM,EAAE;AACT,YAAA,OAAO,KAAK,CAAC;AAChB,SAAA;QAED,QACI,GAAG,CAAC,OAAO,CAAC,4BAA4B,CAAC,SAAS,CAAC,KAAK,CAAC;AACzD,YAAA,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC;AAChC,YAAA,MAAM,CAAC,cAAc,CAAC,iBAAiB,CAAC;AACxC,YAAA,MAAM,CAAC,cAAc,CAAC,mBAAmB,CAAC;AAC1C,YAAA,MAAM,CAAC,cAAc,CAAC,qBAAqB,CAAC;AAC5C,YAAA,MAAM,CAAC,cAAc,CAAC,wBAAwB,CAAC;AAC/C,YAAA,MAAM,CAAC,cAAc,CAAC,gBAAgB,CAAC;AACvC,YAAA,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC;AAC/B,YAAA,MAAM,CAAC,cAAc,CAAC,oBAAoB,CAAC;AAC3C,YAAA,MAAM,CAAC,cAAc,CAAC,sBAAsB,CAAC;AAC7C,YAAA,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC;AAClC,YAAA,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,EACnC;KACL;AACJ;;;;"}
@@ -1,30 +0,0 @@
1
- /*! @azure/msal-common v14.5.0 2023-12-01 */
2
- 'use strict';
3
- import { ThrottlingConstants } from '../../utils/Constants.mjs';
4
-
5
- /*
6
- * Copyright (c) Microsoft Corporation. All rights reserved.
7
- * Licensed under the MIT License.
8
- */
9
- class ThrottlingEntity {
10
- /**
11
- * validates if a given cache entry is "Throttling", parses <key,value>
12
- * @param key
13
- * @param entity
14
- */
15
- static isThrottlingEntity(key, entity) {
16
- let validateKey = false;
17
- if (key) {
18
- validateKey =
19
- key.indexOf(ThrottlingConstants.THROTTLING_PREFIX) === 0;
20
- }
21
- let validateEntity = true;
22
- if (entity) {
23
- validateEntity = entity.hasOwnProperty("throttleTime");
24
- }
25
- return validateKey && validateEntity;
26
- }
27
- }
28
-
29
- export { ThrottlingEntity };
30
- //# sourceMappingURL=ThrottlingEntity.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ThrottlingEntity.mjs","sources":["../../../src/cache/entities/ThrottlingEntity.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;;;AAGG;MAIU,gBAAgB,CAAA;AASzB;;;;AAIG;AACH,IAAA,OAAO,kBAAkB,CAAC,GAAW,EAAE,MAAe,EAAA;QAClD,IAAI,WAAW,GAAY,KAAK,CAAC;AACjC,QAAA,IAAI,GAAG,EAAE;YACL,WAAW;gBACP,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAChE,SAAA;QAED,IAAI,cAAc,GAAY,IAAI,CAAC;AACnC,QAAA,IAAI,MAAM,EAAE;AACR,YAAA,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;AAC1D,SAAA;QAED,OAAO,WAAW,IAAI,cAAc,CAAC;KACxC;AACJ;;;;"}