@azure/msal-common 14.6.1 → 14.6.2-alpha.1

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 (91) 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.mjs +1 -1
  7. package/dist/authority/AuthorityFactory.mjs +1 -1
  8. package/dist/authority/AuthorityMetadata.mjs +1 -1
  9. package/dist/authority/AuthorityOptions.mjs +1 -1
  10. package/dist/authority/AuthorityType.mjs +1 -1
  11. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  12. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  13. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  14. package/dist/authority/ProtocolMode.mjs +1 -1
  15. package/dist/authority/RegionDiscovery.mjs +1 -1
  16. package/dist/cache/CacheManager.mjs +1 -1
  17. package/dist/cache/entities/AccountEntity.mjs +1 -1
  18. package/dist/cache/entities/CacheRecord.mjs +1 -1
  19. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  20. package/dist/cache/utils/CacheHelpers.mjs +5 -5
  21. package/dist/cache/utils/CacheHelpers.mjs.map +1 -1
  22. package/dist/client/AuthorizationCodeClient.mjs +3 -3
  23. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  24. package/dist/client/BaseClient.mjs +1 -1
  25. package/dist/client/RefreshTokenClient.mjs +4 -4
  26. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  27. package/dist/client/SilentFlowClient.mjs +5 -5
  28. package/dist/client/SilentFlowClient.mjs.map +1 -1
  29. package/dist/config/ClientConfiguration.mjs +1 -1
  30. package/dist/constants/AADServerParamKeys.mjs +1 -1
  31. package/dist/crypto/ICrypto.mjs +1 -1
  32. package/dist/crypto/JoseHeader.mjs +1 -1
  33. package/dist/crypto/PopTokenGenerator.mjs +3 -3
  34. package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
  35. package/dist/error/AuthError.mjs +1 -1
  36. package/dist/error/AuthErrorCodes.mjs +1 -1
  37. package/dist/error/ClientAuthError.mjs +1 -1
  38. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  39. package/dist/error/ClientConfigurationError.mjs +1 -1
  40. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  41. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  42. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
  43. package/dist/error/JoseHeaderError.mjs +1 -1
  44. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  45. package/dist/error/ServerError.mjs +1 -1
  46. package/dist/index.cjs +67 -51
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.ts +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.mjs +3 -2
  51. package/dist/index.mjs.map +1 -1
  52. package/dist/logger/Logger.mjs +1 -1
  53. package/dist/network/INetworkModule.mjs +1 -1
  54. package/dist/network/NetworkManager.mjs +1 -1
  55. package/dist/network/ThrottlingUtils.mjs +1 -1
  56. package/dist/packageMetadata.d.ts +1 -1
  57. package/dist/packageMetadata.d.ts.map +1 -1
  58. package/dist/packageMetadata.mjs +2 -2
  59. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  60. package/dist/request/RequestParameterBuilder.mjs +1 -1
  61. package/dist/request/RequestValidator.mjs +1 -1
  62. package/dist/request/ScopeSet.mjs +1 -1
  63. package/dist/response/ResponseHandler.mjs +2 -2
  64. package/dist/response/ResponseHandler.mjs.map +1 -1
  65. package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
  66. package/dist/telemetry/performance/PerformanceEvent.mjs +1 -1
  67. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  68. package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
  69. package/dist/url/UrlString.mjs +1 -1
  70. package/dist/utils/Constants.mjs +1 -1
  71. package/dist/utils/FunctionWrappers.d.ts.map +1 -1
  72. package/dist/utils/FunctionWrappers.mjs +11 -1
  73. package/dist/utils/FunctionWrappers.mjs.map +1 -1
  74. package/dist/utils/ProtocolUtils.mjs +1 -1
  75. package/dist/utils/StringUtils.mjs +1 -1
  76. package/dist/utils/TimeUtils.d.ts +23 -25
  77. package/dist/utils/TimeUtils.d.ts.map +1 -1
  78. package/dist/utils/TimeUtils.mjs +38 -40
  79. package/dist/utils/TimeUtils.mjs.map +1 -1
  80. package/dist/utils/UrlUtils.mjs +1 -1
  81. package/package.json +3 -3
  82. package/src/cache/utils/CacheHelpers.ts +1 -1
  83. package/src/client/AuthorizationCodeClient.ts +1 -1
  84. package/src/client/RefreshTokenClient.ts +1 -1
  85. package/src/client/SilentFlowClient.ts +1 -1
  86. package/src/crypto/PopTokenGenerator.ts +1 -1
  87. package/src/index.ts +1 -1
  88. package/src/packageMetadata.ts +1 -1
  89. package/src/response/ResponseHandler.ts +1 -1
  90. package/src/utils/FunctionWrappers.ts +16 -0
  91. package/src/utils/TimeUtils.ts +37 -38
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.6.1 2024-01-23 */
1
+ /*! @azure/msal-common v14.6.2-alpha.1 2024-01-30 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -943,7 +943,7 @@ class Logger {
943
943
 
944
944
  /* eslint-disable header/header */
945
945
  const name = "@azure/msal-common";
946
- const version = "14.6.1";
946
+ const version = "14.6.2-alpha.1";
947
947
 
948
948
  /*
949
949
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1035,47 +1035,53 @@ var AuthToken = /*#__PURE__*/Object.freeze({
1035
1035
  * Licensed under the MIT License.
1036
1036
  */
1037
1037
  /**
1038
- * Utility class which exposes functions for managing date and time operations.
1038
+ * Utility functions for managing date and time operations.
1039
1039
  */
1040
- class TimeUtils {
1041
- /**
1042
- * return the current time in Unix time (seconds).
1043
- */
1044
- static nowSeconds() {
1045
- // Date.getTime() returns in milliseconds.
1046
- return Math.round(new Date().getTime() / 1000.0);
1047
- }
1048
- /**
1049
- * check if a token is expired based on given UTC time in seconds.
1050
- * @param expiresOn
1051
- */
1052
- static isTokenExpired(expiresOn, offset) {
1053
- // check for access token expiry
1054
- const expirationSec = Number(expiresOn) || 0;
1055
- const offsetCurrentTimeSec = TimeUtils.nowSeconds() + offset;
1056
- // If current time + offset is greater than token expiration time, then token is expired.
1057
- return offsetCurrentTimeSec > expirationSec;
1058
- }
1059
- /**
1060
- * If the current time is earlier than the time that a token was cached at, we must discard the token
1061
- * i.e. The system clock was turned back after acquiring the cached token
1062
- * @param cachedAt
1063
- * @param offset
1064
- */
1065
- static wasClockTurnedBack(cachedAt) {
1066
- const cachedAtSec = Number(cachedAt);
1067
- return cachedAtSec > TimeUtils.nowSeconds();
1068
- }
1069
- /**
1070
- * Waits for t number of milliseconds
1071
- * @param t number
1072
- * @param value T
1073
- */
1074
- static delay(t, value) {
1075
- return new Promise((resolve) => setTimeout(() => resolve(value), t));
1076
- }
1040
+ /**
1041
+ * return the current time in Unix time (seconds).
1042
+ */
1043
+ function nowSeconds() {
1044
+ // Date.getTime() returns in milliseconds.
1045
+ return Math.round(new Date().getTime() / 1000.0);
1046
+ }
1047
+ /**
1048
+ * check if a token is expired based on given UTC time in seconds.
1049
+ * @param expiresOn
1050
+ */
1051
+ function isTokenExpired(expiresOn, offset) {
1052
+ // check for access token expiry
1053
+ const expirationSec = Number(expiresOn) || 0;
1054
+ const offsetCurrentTimeSec = nowSeconds() + offset;
1055
+ // If current time + offset is greater than token expiration time, then token is expired.
1056
+ return offsetCurrentTimeSec > expirationSec;
1057
+ }
1058
+ /**
1059
+ * If the current time is earlier than the time that a token was cached at, we must discard the token
1060
+ * i.e. The system clock was turned back after acquiring the cached token
1061
+ * @param cachedAt
1062
+ * @param offset
1063
+ */
1064
+ function wasClockTurnedBack(cachedAt) {
1065
+ const cachedAtSec = Number(cachedAt);
1066
+ return cachedAtSec > nowSeconds();
1067
+ }
1068
+ /**
1069
+ * Waits for t number of milliseconds
1070
+ * @param t number
1071
+ * @param value T
1072
+ */
1073
+ function delay(t, value) {
1074
+ return new Promise((resolve) => setTimeout(() => resolve(value), t));
1077
1075
  }
1078
1076
 
1077
+ var TimeUtils = /*#__PURE__*/Object.freeze({
1078
+ __proto__: null,
1079
+ delay: delay,
1080
+ isTokenExpired: isTokenExpired,
1081
+ nowSeconds: nowSeconds,
1082
+ wasClockTurnedBack: wasClockTurnedBack
1083
+ });
1084
+
1079
1085
  /*
1080
1086
  * Copyright (c) Microsoft Corporation. All rights reserved.
1081
1087
  * Licensed under the MIT License.
@@ -1132,7 +1138,7 @@ function createAccessTokenEntity(homeAccountId, environment, accessToken, client
1132
1138
  homeAccountId: homeAccountId,
1133
1139
  credentialType: CredentialType.ACCESS_TOKEN,
1134
1140
  secret: accessToken,
1135
- cachedAt: TimeUtils.nowSeconds().toString(),
1141
+ cachedAt: nowSeconds().toString(),
1136
1142
  expiresOn: expiresOn.toString(),
1137
1143
  extendedExpiresOn: extExpiresOn.toString(),
1138
1144
  environment: environment,
@@ -1376,7 +1382,7 @@ function isAuthorityMetadataEntity(key, entity) {
1376
1382
  * Reset the exiresAt value
1377
1383
  */
1378
1384
  function generateAuthorityMetadataExpiresAt() {
1379
- return (TimeUtils.nowSeconds() +
1385
+ return (nowSeconds() +
1380
1386
  AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS);
1381
1387
  }
1382
1388
  function updateAuthorityEndpointMetadata(authorityMetadata, updatedValues, fromNetwork) {
@@ -1398,7 +1404,7 @@ function updateCloudDiscoveryMetadata(authorityMetadata, updatedValues, fromNetw
1398
1404
  * Returns whether or not the data needs to be refreshed
1399
1405
  */
1400
1406
  function isAuthorityMetadataExpired(metadata) {
1401
- return metadata.expiresAt <= TimeUtils.nowSeconds();
1407
+ return metadata.expiresAt <= nowSeconds();
1402
1408
  }
1403
1409
 
1404
1410
  var CacheHelpers = /*#__PURE__*/Object.freeze({
@@ -5017,6 +5023,11 @@ const invoke = (callback, eventName, logger, telemetryClient, correlationId) =>
5017
5023
  return (...args) => {
5018
5024
  logger.trace(`Executing function ${eventName}`);
5019
5025
  const inProgressEvent = telemetryClient?.startMeasurement(eventName, correlationId);
5026
+ if (correlationId) {
5027
+ // Track number of times this API is called in a single request
5028
+ const eventCount = eventName + "CallCount";
5029
+ telemetryClient?.incrementFields({ [eventCount]: 1 }, correlationId);
5030
+ }
5020
5031
  try {
5021
5032
  const result = callback(...args);
5022
5033
  inProgressEvent?.end({
@@ -5057,6 +5068,11 @@ const invokeAsync = (callback, eventName, logger, telemetryClient, correlationId
5057
5068
  return (...args) => {
5058
5069
  logger.trace(`Executing function ${eventName}`);
5059
5070
  const inProgressEvent = telemetryClient?.startMeasurement(eventName, correlationId);
5071
+ if (correlationId) {
5072
+ // Track number of times this API is called in a single request
5073
+ const eventCount = eventName + "CallCount";
5074
+ telemetryClient?.incrementFields({ [eventCount]: 1 }, correlationId);
5075
+ }
5060
5076
  telemetryClient?.setPreQueueTime(eventName, correlationId);
5061
5077
  return callback(...args)
5062
5078
  .then((response) => {
@@ -6419,7 +6435,7 @@ class PopTokenGenerator {
6419
6435
  const resourceUrlComponents = resourceUrlString?.getUrlComponents();
6420
6436
  return this.cryptoUtils.signJwt({
6421
6437
  at: payload,
6422
- ts: TimeUtils.nowSeconds(),
6438
+ ts: nowSeconds(),
6423
6439
  m: resourceRequestMethod?.toUpperCase(),
6424
6440
  u: resourceUrlComponents?.HostNameAndPort,
6425
6441
  nonce: shrNonce || this.cryptoUtils.createNewGuid(),
@@ -6670,7 +6686,7 @@ class ResponseHandler {
6670
6686
  ? reqTimestamp + refreshIn
6671
6687
  : undefined;
6672
6688
  // non AAD scenarios can have empty realm
6673
- cachedAccessToken = createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token, this.clientId, claimsTenantId || authority.tenant, responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj.base64Decode, refreshOnSeconds, serverTokenResponse.token_type, userAssertionHash, serverTokenResponse.key_id, request.claims, request.requestedClaimsHash);
6689
+ cachedAccessToken = createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token, this.clientId, claimsTenantId || authority.tenant || "", responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj.base64Decode, refreshOnSeconds, serverTokenResponse.token_type, userAssertionHash, serverTokenResponse.key_id, request.claims, request.requestedClaimsHash);
6674
6690
  }
6675
6691
  // refreshToken
6676
6692
  let cachedRefreshToken = null;
@@ -6851,7 +6867,7 @@ class AuthorizationCodeClient extends BaseClient {
6851
6867
  if (!request.code) {
6852
6868
  throw createClientAuthError(requestCannotBeMade);
6853
6869
  }
6854
- const reqTimestamp = TimeUtils.nowSeconds();
6870
+ const reqTimestamp = nowSeconds();
6855
6871
  const response = await invokeAsync(this.executeTokenRequest.bind(this), PerformanceEvents.AuthClientExecuteTokenRequest, this.logger, this.performanceClient, request.correlationId)(this.authority, request);
6856
6872
  // Retrieve requestId from response headers
6857
6873
  const requestId = response.headers?.[HeaderNames.X_MS_REQUEST_ID];
@@ -7228,7 +7244,7 @@ class RefreshTokenClient extends BaseClient {
7228
7244
  }
7229
7245
  async acquireToken(request) {
7230
7246
  this.performanceClient?.addQueueMeasurement(PerformanceEvents.RefreshTokenClientAcquireToken, request.correlationId);
7231
- const reqTimestamp = TimeUtils.nowSeconds();
7247
+ const reqTimestamp = nowSeconds();
7232
7248
  const response = await invokeAsync(this.executeTokenRequest.bind(this), PerformanceEvents.RefreshTokenClientExecuteTokenRequest, this.logger, this.performanceClient, request.correlationId)(request, this.authority);
7233
7249
  // Retrieve requestId from response headers
7234
7250
  const requestId = response.headers?.[HeaderNames.X_MS_REQUEST_ID];
@@ -7289,7 +7305,7 @@ class RefreshTokenClient extends BaseClient {
7289
7305
  throw createInteractionRequiredAuthError(noTokensFound);
7290
7306
  }
7291
7307
  if (refreshToken.expiresOn &&
7292
- TimeUtils.isTokenExpired(refreshToken.expiresOn, request.refreshTokenExpirationOffsetSeconds ||
7308
+ isTokenExpired(refreshToken.expiresOn, request.refreshTokenExpirationOffsetSeconds ||
7293
7309
  DEFAULT_REFRESH_TOKEN_EXPIRATION_OFFSET_SECONDS)) {
7294
7310
  throw createInteractionRequiredAuthError(refreshTokenExpired);
7295
7311
  }
@@ -7487,14 +7503,14 @@ class SilentFlowClient extends BaseClient {
7487
7503
  this.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN, request.correlationId);
7488
7504
  throw createClientAuthError(tokenRefreshRequired);
7489
7505
  }
7490
- else if (TimeUtils.wasClockTurnedBack(cachedAccessToken.cachedAt) ||
7491
- TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
7506
+ else if (wasClockTurnedBack(cachedAccessToken.cachedAt) ||
7507
+ isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
7492
7508
  // must refresh due to the expires_in value
7493
7509
  this.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED, request.correlationId);
7494
7510
  throw createClientAuthError(tokenRefreshRequired);
7495
7511
  }
7496
7512
  else if (cachedAccessToken.refreshOn &&
7497
- TimeUtils.isTokenExpired(cachedAccessToken.refreshOn, 0)) {
7513
+ isTokenExpired(cachedAccessToken.refreshOn, 0)) {
7498
7514
  // must refresh (in the background) due to the refresh_in value
7499
7515
  lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
7500
7516
  // don't throw ClientAuthError.createRefreshRequiredError(), return cached token instead