@azure/msal-common 14.8.1 → 14.9.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 (109) 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 +3 -2
  7. package/dist/authority/Authority.d.ts.map +1 -1
  8. package/dist/authority/Authority.mjs +8 -4
  9. package/dist/authority/Authority.mjs.map +1 -1
  10. package/dist/authority/AuthorityFactory.mjs +1 -1
  11. package/dist/authority/AuthorityMetadata.mjs +1 -1
  12. package/dist/authority/AuthorityOptions.mjs +1 -1
  13. package/dist/authority/AuthorityType.mjs +1 -1
  14. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  15. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  16. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  17. package/dist/authority/ProtocolMode.mjs +1 -1
  18. package/dist/authority/RegionDiscovery.mjs +1 -1
  19. package/dist/cache/CacheManager.d.ts +4 -2
  20. package/dist/cache/CacheManager.d.ts.map +1 -1
  21. package/dist/cache/CacheManager.mjs +43 -17
  22. package/dist/cache/CacheManager.mjs.map +1 -1
  23. package/dist/cache/entities/AccountEntity.mjs +1 -1
  24. package/dist/cache/entities/CacheRecord.mjs +1 -1
  25. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  26. package/dist/cache/utils/CacheHelpers.mjs +1 -1
  27. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  28. package/dist/client/AuthorizationCodeClient.mjs +6 -2
  29. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  30. package/dist/client/BaseClient.mjs +1 -1
  31. package/dist/client/RefreshTokenClient.mjs +1 -1
  32. package/dist/client/SilentFlowClient.mjs +1 -1
  33. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  34. package/dist/config/ClientConfiguration.mjs +2 -4
  35. package/dist/config/ClientConfiguration.mjs.map +1 -1
  36. package/dist/constants/AADServerParamKeys.mjs +1 -1
  37. package/dist/crypto/ICrypto.mjs +1 -1
  38. package/dist/crypto/JoseHeader.mjs +1 -1
  39. package/dist/crypto/PopTokenGenerator.mjs +1 -1
  40. package/dist/error/AuthError.mjs +1 -1
  41. package/dist/error/AuthErrorCodes.mjs +1 -1
  42. package/dist/error/CacheError.d.ts +21 -0
  43. package/dist/error/CacheError.d.ts.map +1 -0
  44. package/dist/error/CacheError.mjs +33 -0
  45. package/dist/error/CacheError.mjs.map +1 -0
  46. package/dist/error/CacheErrorCodes.d.ts +3 -0
  47. package/dist/error/CacheErrorCodes.d.ts.map +1 -0
  48. package/dist/error/CacheErrorCodes.mjs +11 -0
  49. package/dist/error/CacheErrorCodes.mjs.map +1 -0
  50. package/dist/error/ClientAuthError.mjs +1 -1
  51. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  52. package/dist/error/ClientConfigurationError.mjs +1 -1
  53. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  54. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  55. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
  56. package/dist/error/JoseHeaderError.mjs +1 -1
  57. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  58. package/dist/error/ServerError.mjs +1 -1
  59. package/dist/index.cjs +112 -25
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.ts +2 -1
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.mjs +5 -2
  64. package/dist/index.mjs.map +1 -1
  65. package/dist/logger/Logger.mjs +1 -1
  66. package/dist/network/INetworkModule.mjs +1 -1
  67. package/dist/network/NetworkManager.mjs +1 -1
  68. package/dist/network/ThrottlingUtils.mjs +1 -1
  69. package/dist/packageMetadata.d.ts +1 -1
  70. package/dist/packageMetadata.mjs +2 -2
  71. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  72. package/dist/request/RequestParameterBuilder.mjs +1 -1
  73. package/dist/request/RequestValidator.mjs +1 -1
  74. package/dist/request/ScopeSet.mjs +1 -1
  75. package/dist/response/ResponseHandler.d.ts.map +1 -1
  76. package/dist/response/ResponseHandler.mjs +2 -2
  77. package/dist/response/ResponseHandler.mjs.map +1 -1
  78. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  79. package/dist/telemetry/performance/PerformanceClient.mjs +6 -1
  80. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  81. package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -0
  82. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  83. package/dist/telemetry/performance/PerformanceEvent.mjs +2 -1
  84. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  85. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  86. package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
  87. package/dist/url/UrlString.mjs +1 -1
  88. package/dist/utils/Constants.d.ts +10 -0
  89. package/dist/utils/Constants.d.ts.map +1 -1
  90. package/dist/utils/Constants.mjs +13 -2
  91. package/dist/utils/Constants.mjs.map +1 -1
  92. package/dist/utils/FunctionWrappers.mjs +1 -1
  93. package/dist/utils/ProtocolUtils.mjs +1 -1
  94. package/dist/utils/StringUtils.mjs +1 -1
  95. package/dist/utils/TimeUtils.mjs +1 -1
  96. package/dist/utils/UrlUtils.mjs +1 -1
  97. package/package.json +3 -3
  98. package/src/authority/Authority.ts +9 -3
  99. package/src/cache/CacheManager.ts +58 -19
  100. package/src/client/AuthorizationCodeClient.ts +9 -1
  101. package/src/config/ClientConfiguration.ts +4 -4
  102. package/src/error/CacheError.ts +44 -0
  103. package/src/error/CacheErrorCodes.ts +7 -0
  104. package/src/index.ts +2 -0
  105. package/src/packageMetadata.ts +1 -1
  106. package/src/response/ResponseHandler.ts +2 -1
  107. package/src/telemetry/performance/PerformanceClient.ts +4 -0
  108. package/src/telemetry/performance/PerformanceEvent.ts +11 -0
  109. package/src/utils/Constants.ts +12 -0
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.8.1 2024-03-27 */
1
+ /*! @azure/msal-common v14.9.0 2024-04-11 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -66,11 +66,20 @@ const Constants = {
66
66
  };
67
67
  const HttpStatus = {
68
68
  SUCCESS_RANGE_START: 200,
69
+ SUCCESS: 200,
69
70
  SUCCESS_RANGE_END: 299,
70
71
  REDIRECT: 302,
71
72
  CLIENT_ERROR_RANGE_START: 400,
73
+ BAD_REQUEST: 400,
74
+ UNAUTHORIZED: 401,
75
+ NOT_FOUND: 404,
76
+ REQUEST_TIMEOUT: 408,
77
+ TOO_MANY_REQUESTS: 429,
72
78
  CLIENT_ERROR_RANGE_END: 499,
73
79
  SERVER_ERROR_RANGE_START: 500,
80
+ INTERNAL_SERVER_ERROR: 500,
81
+ SERVICE_UNAVAILABLE: 503,
82
+ GATEWAY_TIMEOUT: 504,
74
83
  SERVER_ERROR_RANGE_END: 599,
75
84
  };
76
85
  const OIDC_DEFAULT_SCOPES = [
@@ -310,6 +319,8 @@ const JsonWebTokenTypes = {
310
319
  Pop: "pop",
311
320
  };
312
321
  const ONE_DAY_IN_MS = 86400000;
322
+ // Token renewal offset default in seconds
323
+ const DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
313
324
 
314
325
  /*
315
326
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -943,7 +954,7 @@ class Logger {
943
954
 
944
955
  /* eslint-disable header/header */
945
956
  const name = "@azure/msal-common";
946
- const version = "14.8.1";
957
+ const version = "14.9.0";
947
958
 
948
959
  /*
949
960
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2653,6 +2664,44 @@ function getCloudDiscoveryMetadataFromNetworkResponse(response, authorityHost) {
2653
2664
  return null;
2654
2665
  }
2655
2666
 
2667
+ /*
2668
+ * Copyright (c) Microsoft Corporation. All rights reserved.
2669
+ * Licensed under the MIT License.
2670
+ */
2671
+ const cacheQuotaExceededErrorCode = "cache_quota_exceeded";
2672
+ const cacheUnknownErrorCode = "cache_error_unknown";
2673
+
2674
+ var CacheErrorCodes = /*#__PURE__*/Object.freeze({
2675
+ __proto__: null,
2676
+ cacheQuotaExceededErrorCode: cacheQuotaExceededErrorCode,
2677
+ cacheUnknownErrorCode: cacheUnknownErrorCode
2678
+ });
2679
+
2680
+ /*
2681
+ * Copyright (c) Microsoft Corporation. All rights reserved.
2682
+ * Licensed under the MIT License.
2683
+ */
2684
+ const CacheErrorMessages = {
2685
+ [cacheQuotaExceededErrorCode]: "Exceeded cache storage capacity.",
2686
+ [cacheUnknownErrorCode]: "Unexpected error occurred when using cache storage.",
2687
+ };
2688
+ /**
2689
+ * Error thrown when there is an error with the cache
2690
+ */
2691
+ class CacheError extends Error {
2692
+ constructor(errorCode, errorMessage) {
2693
+ const message = errorMessage ||
2694
+ (CacheErrorMessages[errorCode]
2695
+ ? CacheErrorMessages[errorCode]
2696
+ : CacheErrorMessages[cacheUnknownErrorCode]);
2697
+ super(`${errorCode}: ${message}`);
2698
+ Object.setPrototypeOf(this, CacheError.prototype);
2699
+ this.name = "CacheError";
2700
+ this.errorCode = errorCode;
2701
+ this.errorMessage = message;
2702
+ }
2703
+ }
2704
+
2656
2705
  /*
2657
2706
  * Copyright (c) Microsoft Corporation. All rights reserved.
2658
2707
  * Licensed under the MIT License.
@@ -2815,27 +2864,51 @@ class CacheManager {
2815
2864
  }
2816
2865
  /**
2817
2866
  * saves a cache record
2818
- * @param cacheRecord
2867
+ * @param cacheRecord {CacheRecord}
2868
+ * @param storeInCache {?StoreInCache}
2869
+ * @param correlationId {?string} correlation id
2819
2870
  */
2820
- async saveCacheRecord(cacheRecord, storeInCache) {
2871
+ async saveCacheRecord(cacheRecord, storeInCache, correlationId) {
2821
2872
  if (!cacheRecord) {
2822
2873
  throw createClientAuthError(invalidCacheRecord);
2823
2874
  }
2824
- if (!!cacheRecord.account) {
2825
- this.setAccount(cacheRecord.account);
2826
- }
2827
- if (!!cacheRecord.idToken && storeInCache?.idToken !== false) {
2828
- this.setIdTokenCredential(cacheRecord.idToken);
2829
- }
2830
- if (!!cacheRecord.accessToken && storeInCache?.accessToken !== false) {
2831
- await this.saveAccessToken(cacheRecord.accessToken);
2832
- }
2833
- if (!!cacheRecord.refreshToken &&
2834
- storeInCache?.refreshToken !== false) {
2835
- this.setRefreshTokenCredential(cacheRecord.refreshToken);
2875
+ try {
2876
+ if (!!cacheRecord.account) {
2877
+ this.setAccount(cacheRecord.account);
2878
+ }
2879
+ if (!!cacheRecord.idToken && storeInCache?.idToken !== false) {
2880
+ this.setIdTokenCredential(cacheRecord.idToken);
2881
+ }
2882
+ if (!!cacheRecord.accessToken &&
2883
+ storeInCache?.accessToken !== false) {
2884
+ await this.saveAccessToken(cacheRecord.accessToken);
2885
+ }
2886
+ if (!!cacheRecord.refreshToken &&
2887
+ storeInCache?.refreshToken !== false) {
2888
+ this.setRefreshTokenCredential(cacheRecord.refreshToken);
2889
+ }
2890
+ if (!!cacheRecord.appMetadata) {
2891
+ this.setAppMetadata(cacheRecord.appMetadata);
2892
+ }
2836
2893
  }
2837
- if (!!cacheRecord.appMetadata) {
2838
- this.setAppMetadata(cacheRecord.appMetadata);
2894
+ catch (e) {
2895
+ this.commonLogger?.error(`CacheManager.saveCacheRecord: failed`);
2896
+ if (e instanceof Error) {
2897
+ this.commonLogger?.errorPii(`CacheManager.saveCacheRecord: ${e.message}`, correlationId);
2898
+ if (e.name === "QuotaExceededError" ||
2899
+ e.name === "NS_ERROR_DOM_QUOTA_REACHED" ||
2900
+ e.message.includes("exceeded the quota")) {
2901
+ this.commonLogger?.error(`CacheManager.saveCacheRecord: exceeded storage quota`, correlationId);
2902
+ throw new CacheError(cacheQuotaExceededErrorCode);
2903
+ }
2904
+ else {
2905
+ throw new CacheError(e.name, e.message);
2906
+ }
2907
+ }
2908
+ else {
2909
+ this.commonLogger?.errorPii(`CacheManager.saveCacheRecord: ${e}`, correlationId);
2910
+ throw new CacheError(cacheUnknownErrorCode);
2911
+ }
2839
2912
  }
2840
2913
  }
2841
2914
  /**
@@ -3886,8 +3959,6 @@ class DefaultStorageClass extends CacheManager {
3886
3959
  * Copyright (c) Microsoft Corporation. All rights reserved.
3887
3960
  * Licensed under the MIT License.
3888
3961
  */
3889
- // Token renewal offset default in seconds
3890
- const DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
3891
3962
  const DEFAULT_SYSTEM_OPTIONS = {
3892
3963
  tokenRenewalOffsetSeconds: DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
3893
3964
  preventCorsPreflight: false,
@@ -4802,6 +4873,7 @@ const PerformanceEvents = {
4802
4873
  * Used to acquire a new set of tokens from the authorize endpoint in a hidden iframe.
4803
4874
  */
4804
4875
  SilentIframeClientAcquireToken: "silentIframeClientAcquireToken",
4876
+ AwaitConcurrentIframe: "awaitConcurrentIframe",
4805
4877
  /**
4806
4878
  * acquireToken API in SilentRereshClient (msal-browser).
4807
4879
  * Used to acquire a new set of tokens from the token endpoint using a refresh token.
@@ -5426,7 +5498,7 @@ RegionDiscovery.IMDS_OPTIONS = {
5426
5498
  * @internal
5427
5499
  */
5428
5500
  class Authority {
5429
- constructor(authority, networkInterface, cacheManager, authorityOptions, logger, correlationId, performanceClient) {
5501
+ constructor(authority, networkInterface, cacheManager, authorityOptions, logger, correlationId, performanceClient, managedIdentity) {
5430
5502
  this.canonicalAuthority = authority;
5431
5503
  this._canonicalAuthority.validateAsUri();
5432
5504
  this.networkInterface = networkInterface;
@@ -5440,6 +5512,7 @@ class Authority {
5440
5512
  this.logger = logger;
5441
5513
  this.performanceClient = performanceClient;
5442
5514
  this.correlationId = correlationId;
5515
+ this.managedIdentity = managedIdentity || false;
5443
5516
  this.regionDiscovery = new RegionDiscovery(networkInterface, this.logger, this.performanceClient, this.correlationId);
5444
5517
  }
5445
5518
  /**
@@ -5645,7 +5718,7 @@ class Authority {
5645
5718
  return `${this.canonicalAuthority}v2.0/.well-known/openid-configuration`;
5646
5719
  }
5647
5720
  /**
5648
- * Boolean that returns whethr or not tenant discovery has been completed.
5721
+ * Boolean that returns whether or not tenant discovery has been completed.
5649
5722
  */
5650
5723
  discoveryComplete() {
5651
5724
  return !!this.metadata;
@@ -6097,7 +6170,10 @@ class Authority {
6097
6170
  * helper function to generate environment from authority object
6098
6171
  */
6099
6172
  getPreferredCache() {
6100
- if (this.discoveryComplete()) {
6173
+ if (this.managedIdentity) {
6174
+ return Constants.DEFAULT_AUTHORITY_HOST;
6175
+ }
6176
+ else if (this.discoveryComplete()) {
6101
6177
  return this.metadata.preferred_cache;
6102
6178
  }
6103
6179
  else {
@@ -6841,7 +6917,7 @@ class ResponseHandler {
6841
6917
  return await ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenClaims, requestStateObj, undefined, serverRequestId);
6842
6918
  }
6843
6919
  }
6844
- await this.cacheStorage.saveCacheRecord(cacheRecord, request.storeInCache);
6920
+ await this.cacheStorage.saveCacheRecord(cacheRecord, request.storeInCache, request.correlationId);
6845
6921
  }
6846
6922
  finally {
6847
6923
  if (this.persistencePlugin &&
@@ -7322,7 +7398,11 @@ class AuthorizationCodeClient extends BaseClient {
7322
7398
  }
7323
7399
  else if (request.account) {
7324
7400
  const accountSid = this.extractAccountSid(request.account);
7325
- const accountLoginHintClaim = this.extractLoginHint(request.account);
7401
+ let accountLoginHintClaim = this.extractLoginHint(request.account);
7402
+ if (accountLoginHintClaim && request.domainHint) {
7403
+ this.logger.warning(`AuthorizationCodeClient.createAuthCodeUrlQueryString: "domainHint" param is set, skipping opaque "login_hint" claim. Please consider not passing domainHint`);
7404
+ accountLoginHintClaim = null;
7405
+ }
7326
7406
  // If login_hint claim is present, use it over sid/username
7327
7407
  if (accountLoginHintClaim) {
7328
7408
  this.logger.verbose("createAuthCodeUrlQueryString: login_hint claim present on account");
@@ -8295,6 +8375,10 @@ function addError(error, logger, event, stackMaxSize = 5) {
8295
8375
  event.subErrorCode = error.subError;
8296
8376
  return;
8297
8377
  }
8378
+ else if (error instanceof CacheError) {
8379
+ event.errorCode = error.errorCode;
8380
+ return;
8381
+ }
8298
8382
  else if (event.errorStack?.length) {
8299
8383
  logger.trace("PerformanceClient.addErrorStack: Stack already exist", event.correlationId);
8300
8384
  return;
@@ -8795,6 +8879,8 @@ exports.AuthorizationCodeClient = AuthorizationCodeClient;
8795
8879
  exports.AzureCloudInstance = AzureCloudInstance;
8796
8880
  exports.BaseClient = BaseClient;
8797
8881
  exports.CacheAccountType = CacheAccountType;
8882
+ exports.CacheError = CacheError;
8883
+ exports.CacheErrorCodes = CacheErrorCodes;
8798
8884
  exports.CacheHelpers = CacheHelpers;
8799
8885
  exports.CacheManager = CacheManager;
8800
8886
  exports.CacheOutcome = CacheOutcome;
@@ -8813,6 +8899,7 @@ exports.Constants = Constants;
8813
8899
  exports.CredentialType = CredentialType;
8814
8900
  exports.DEFAULT_CRYPTO_IMPLEMENTATION = DEFAULT_CRYPTO_IMPLEMENTATION;
8815
8901
  exports.DEFAULT_SYSTEM_OPTIONS = DEFAULT_SYSTEM_OPTIONS;
8902
+ exports.DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = DEFAULT_TOKEN_RENEWAL_OFFSET_SEC;
8816
8903
  exports.DefaultStorageClass = DefaultStorageClass;
8817
8904
  exports.Errors = Errors;
8818
8905
  exports.GrantType = GrantType;