@azure/msal-common 7.1.0 → 7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/dist/_virtual/_tslib.js +1 -1
  2. package/dist/account/AccountInfo.d.ts +6 -0
  3. package/dist/account/AccountInfo.d.ts.map +1 -1
  4. package/dist/account/AuthToken.js +1 -1
  5. package/dist/account/AuthToken.js.map +1 -1
  6. package/dist/account/CcsCredential.js +1 -1
  7. package/dist/account/CcsCredential.js.map +1 -1
  8. package/dist/account/ClientInfo.js +3 -3
  9. package/dist/account/ClientInfo.js.map +1 -1
  10. package/dist/authority/Authority.js +1 -1
  11. package/dist/authority/Authority.js.map +1 -1
  12. package/dist/authority/AuthorityFactory.js +1 -1
  13. package/dist/authority/AuthorityFactory.js.map +1 -1
  14. package/dist/authority/AuthorityMetadata.js +1 -1
  15. package/dist/authority/AuthorityMetadata.js.map +1 -1
  16. package/dist/authority/AuthorityOptions.js +1 -1
  17. package/dist/authority/AuthorityOptions.js.map +1 -1
  18. package/dist/authority/AuthorityType.js +1 -1
  19. package/dist/authority/AuthorityType.js.map +1 -1
  20. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  21. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -1
  22. package/dist/authority/OpenIdConfigResponse.js +1 -1
  23. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  24. package/dist/authority/ProtocolMode.js +1 -1
  25. package/dist/authority/ProtocolMode.js.map +1 -1
  26. package/dist/authority/RegionDiscovery.js +1 -1
  27. package/dist/authority/RegionDiscovery.js.map +1 -1
  28. package/dist/cache/CacheManager.d.ts +13 -0
  29. package/dist/cache/CacheManager.d.ts.map +1 -1
  30. package/dist/cache/CacheManager.js +36 -3
  31. package/dist/cache/CacheManager.js.map +1 -1
  32. package/dist/cache/entities/AccessTokenEntity.js +1 -1
  33. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  34. package/dist/cache/entities/AccountEntity.js +1 -1
  35. package/dist/cache/entities/AccountEntity.js.map +1 -1
  36. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  37. package/dist/cache/entities/AppMetadataEntity.js.map +1 -1
  38. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
  39. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  40. package/dist/cache/entities/CacheRecord.js +1 -1
  41. package/dist/cache/entities/CacheRecord.js.map +1 -1
  42. package/dist/cache/entities/CredentialEntity.js +1 -1
  43. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  44. package/dist/cache/entities/IdTokenEntity.js +1 -1
  45. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  46. package/dist/cache/entities/RefreshTokenEntity.js +1 -1
  47. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  48. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  49. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -1
  50. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  51. package/dist/cache/entities/ThrottlingEntity.js.map +1 -1
  52. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  53. package/dist/cache/persistence/TokenCacheContext.js.map +1 -1
  54. package/dist/cache/utils/CacheTypes.d.ts +1 -0
  55. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  56. package/dist/client/AuthorizationCodeClient.d.ts +1 -0
  57. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  58. package/dist/client/AuthorizationCodeClient.js +30 -14
  59. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  60. package/dist/client/BaseClient.d.ts +3 -1
  61. package/dist/client/BaseClient.d.ts.map +1 -1
  62. package/dist/client/BaseClient.js +4 -2
  63. package/dist/client/BaseClient.js.map +1 -1
  64. package/dist/client/ClientCredentialClient.d.ts +3 -1
  65. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  66. package/dist/client/ClientCredentialClient.js +34 -9
  67. package/dist/client/ClientCredentialClient.js.map +1 -1
  68. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  69. package/dist/client/DeviceCodeClient.js +13 -7
  70. package/dist/client/DeviceCodeClient.js.map +1 -1
  71. package/dist/client/OnBehalfOfClient.js +1 -1
  72. package/dist/client/OnBehalfOfClient.js.map +1 -1
  73. package/dist/client/RefreshTokenClient.d.ts +2 -1
  74. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  75. package/dist/client/RefreshTokenClient.js +40 -16
  76. package/dist/client/RefreshTokenClient.js.map +1 -1
  77. package/dist/client/SilentFlowClient.d.ts +2 -1
  78. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  79. package/dist/client/SilentFlowClient.js +4 -4
  80. package/dist/client/SilentFlowClient.js.map +1 -1
  81. package/dist/client/UsernamePasswordClient.js +1 -1
  82. package/dist/client/UsernamePasswordClient.js.map +1 -1
  83. package/dist/config/AppTokenProvider.d.ts +39 -0
  84. package/dist/config/AppTokenProvider.d.ts.map +1 -0
  85. package/dist/config/ClientConfiguration.d.ts +1 -1
  86. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  87. package/dist/config/ClientConfiguration.js +2 -2
  88. package/dist/config/ClientConfiguration.js.map +1 -1
  89. package/dist/crypto/ICrypto.js +1 -1
  90. package/dist/crypto/ICrypto.js.map +1 -1
  91. package/dist/crypto/JoseHeader.js +1 -1
  92. package/dist/crypto/JoseHeader.js.map +1 -1
  93. package/dist/crypto/PopTokenGenerator.js +1 -1
  94. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  95. package/dist/error/AuthError.d.ts +10 -0
  96. package/dist/error/AuthError.d.ts.map +1 -1
  97. package/dist/error/AuthError.js +13 -1
  98. package/dist/error/AuthError.js.map +1 -1
  99. package/dist/error/ClientAuthError.js +1 -1
  100. package/dist/error/ClientAuthError.js.map +1 -1
  101. package/dist/error/ClientConfigurationError.js +1 -1
  102. package/dist/error/ClientConfigurationError.js.map +1 -1
  103. package/dist/error/InteractionRequiredAuthError.js +1 -1
  104. package/dist/error/InteractionRequiredAuthError.js.map +1 -1
  105. package/dist/error/JoseHeaderError.js +1 -1
  106. package/dist/error/JoseHeaderError.js.map +1 -1
  107. package/dist/error/ServerError.js +1 -1
  108. package/dist/error/ServerError.js.map +1 -1
  109. package/dist/index.cjs.js +344 -153
  110. package/dist/index.cjs.js.map +1 -1
  111. package/dist/index.d.ts +4 -2
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +3 -2
  114. package/dist/index.js.map +1 -1
  115. package/dist/logger/Logger.js +1 -1
  116. package/dist/logger/Logger.js.map +1 -1
  117. package/dist/network/INetworkModule.js +1 -1
  118. package/dist/network/INetworkModule.js.map +1 -1
  119. package/dist/network/NetworkManager.js +1 -1
  120. package/dist/network/NetworkManager.js.map +1 -1
  121. package/dist/network/ThrottlingUtils.js +1 -1
  122. package/dist/network/ThrottlingUtils.js.map +1 -1
  123. package/dist/packageMetadata.d.ts +1 -1
  124. package/dist/packageMetadata.js +2 -2
  125. package/dist/packageMetadata.js.map +1 -1
  126. package/dist/request/AuthenticationHeaderParser.js +1 -1
  127. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  128. package/dist/request/CommonRefreshTokenRequest.d.ts +4 -2
  129. package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
  130. package/dist/request/RequestParameterBuilder.js +1 -1
  131. package/dist/request/RequestParameterBuilder.js.map +1 -1
  132. package/dist/request/RequestValidator.js +1 -1
  133. package/dist/request/RequestValidator.js.map +1 -1
  134. package/dist/request/ScopeSet.js +1 -1
  135. package/dist/request/ScopeSet.js.map +1 -1
  136. package/dist/response/ResponseHandler.d.ts +1 -1
  137. package/dist/response/ResponseHandler.d.ts.map +1 -1
  138. package/dist/response/ResponseHandler.js +6 -5
  139. package/dist/response/ResponseHandler.js.map +1 -1
  140. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  141. package/dist/telemetry/performance/PerformanceClient.js +8 -2
  142. package/dist/telemetry/performance/PerformanceClient.js.map +1 -1
  143. package/dist/telemetry/performance/PerformanceEvent.d.ts +35 -1
  144. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  145. package/dist/telemetry/performance/PerformanceEvent.js +22 -1
  146. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -1
  147. package/dist/telemetry/performance/StubPerformanceClient.js +1 -1
  148. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -1
  149. package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
  150. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  151. package/dist/url/UrlString.d.ts +9 -0
  152. package/dist/url/UrlString.d.ts.map +1 -1
  153. package/dist/url/UrlString.js +34 -1
  154. package/dist/url/UrlString.js.map +1 -1
  155. package/dist/utils/Constants.d.ts +3 -1
  156. package/dist/utils/Constants.d.ts.map +1 -1
  157. package/dist/utils/Constants.js +4 -2
  158. package/dist/utils/Constants.js.map +1 -1
  159. package/dist/utils/ProtocolUtils.js +1 -1
  160. package/dist/utils/ProtocolUtils.js.map +1 -1
  161. package/dist/utils/StringUtils.js +1 -1
  162. package/dist/utils/StringUtils.js.map +1 -1
  163. package/dist/utils/TimeUtils.js +1 -1
  164. package/dist/utils/TimeUtils.js.map +1 -1
  165. package/package.json +4 -6
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v7.1.0 2022-07-05 */
1
+ /*! @azure/msal-common v7.4.0 2022-09-06 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -138,7 +138,8 @@ var Constants = {
138
138
  REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX: "login.microsoft.com",
139
139
  KNOWN_PUBLIC_CLOUDS: ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"],
140
140
  TOKEN_RESPONSE_TYPE: "token",
141
- ID_TOKEN_RESPONSE_TYPE: "id_token"
141
+ ID_TOKEN_RESPONSE_TYPE: "id_token",
142
+ SHR_NONCE_VALIDITY: 240
142
143
  };
143
144
  var OIDC_DEFAULT_SCOPES = [
144
145
  Constants.OPENID_SCOPE,
@@ -170,6 +171,7 @@ exports.PersistentCacheKeys = void 0;
170
171
  PersistentCacheKeys["ERROR"] = "error";
171
172
  PersistentCacheKeys["ERROR_DESC"] = "error.description";
172
173
  PersistentCacheKeys["ACTIVE_ACCOUNT"] = "active-account";
174
+ PersistentCacheKeys["ACTIVE_ACCOUNT_FILTERS"] = "active-account-filters"; // new cache entry for active_account for a more robust version for browser
173
175
  })(exports.PersistentCacheKeys || (exports.PersistentCacheKeys = {}));
174
176
  /**
175
177
  * String constants related to AAD Authority
@@ -283,6 +285,15 @@ var CodeChallengeMethodValues = {
283
285
  PLAIN: "plain",
284
286
  S256: "S256"
285
287
  };
288
+ /**
289
+ * The method used to encode the code verifier for the code challenge parameter. can be one
290
+ * of plain or s256. if excluded, code challenge is assumed to be plaintext. for more
291
+ * information, see the pkce rcf: https://tools.ietf.org/html/rfc7636
292
+ */
293
+ [
294
+ CodeChallengeMethodValues.PLAIN,
295
+ CodeChallengeMethodValues.S256
296
+ ];
286
297
  /**
287
298
  * allowed values for response_mode
288
299
  */
@@ -481,6 +492,10 @@ var AuthErrorMessage = {
481
492
  unexpectedError: {
482
493
  code: "unexpected_error",
483
494
  desc: "Unexpected error in authentication."
495
+ },
496
+ postRequestFailed: {
497
+ code: "post_request_failed",
498
+ desc: "Post request failed from the network, could be a 4xx/5xx or a network unavailability. Please check the exact error code for details."
484
499
  }
485
500
  };
486
501
  /**
@@ -509,6 +524,14 @@ var AuthError = /** @class */ (function (_super) {
509
524
  AuthError.createUnexpectedError = function (errDesc) {
510
525
  return new AuthError(AuthErrorMessage.unexpectedError.code, AuthErrorMessage.unexpectedError.desc + ": " + errDesc);
511
526
  };
527
+ /**
528
+ * Creates an error for post request failures.
529
+ * @param errDesc
530
+ * @returns
531
+ */
532
+ AuthError.createPostRequestFailed = function (errDesc) {
533
+ return new AuthError(AuthErrorMessage.postRequestFailed.code, AuthErrorMessage.postRequestFailed.desc + ": " + errDesc);
534
+ };
512
535
  return AuthError;
513
536
  }(Error));
514
537
 
@@ -1358,7 +1381,7 @@ var Logger = /** @class */ (function () {
1358
1381
 
1359
1382
  /* eslint-disable header/header */
1360
1383
  var name = "@azure/msal-common";
1361
- var version = "7.1.0";
1384
+ var version = "7.4.0";
1362
1385
 
1363
1386
  /*
1364
1387
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1990,7 +2013,7 @@ function buildClientInfo(rawClientInfo, crypto) {
1990
2013
  return JSON.parse(decodedClientInfo);
1991
2014
  }
1992
2015
  catch (e) {
1993
- throw ClientAuthError.createClientInfoDecodingError(e);
2016
+ throw ClientAuthError.createClientInfoDecodingError(e.message);
1994
2017
  }
1995
2018
  }
1996
2019
  /**
@@ -2319,6 +2342,7 @@ var CacheManager = /** @class */ (function () {
2319
2342
  var accountInfo = accountEntity.getAccountInfo();
2320
2343
  var idToken = _this.readIdTokenFromCache(_this.clientId, accountInfo);
2321
2344
  if (idToken && !accountInfo.idTokenClaims) {
2345
+ accountInfo.idToken = idToken.secret;
2322
2346
  accountInfo.idTokenClaims = new AuthToken(idToken.secret, _this.cryptoImpl).claims;
2323
2347
  }
2324
2348
  return accountInfo;
@@ -2410,7 +2434,7 @@ var CacheManager = /** @class */ (function () {
2410
2434
  * @param realm
2411
2435
  */
2412
2436
  CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
2413
- return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING);
2437
+ return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING, accountFilter ? accountFilter.nativeAccountId : Constants.EMPTY_STRING);
2414
2438
  };
2415
2439
  /**
2416
2440
  * retrieve accounts matching all provided filters; if no filter is set, get all accounts
@@ -2419,7 +2443,7 @@ var CacheManager = /** @class */ (function () {
2419
2443
  * @param environment
2420
2444
  * @param realm
2421
2445
  */
2422
- CacheManager.prototype.getAccountsFilteredByInternal = function (homeAccountId, environment, realm) {
2446
+ CacheManager.prototype.getAccountsFilteredByInternal = function (homeAccountId, environment, realm, nativeAccountId) {
2423
2447
  var _this = this;
2424
2448
  var allCacheKeys = this.getKeys();
2425
2449
  var matchingAccounts = {};
@@ -2437,6 +2461,9 @@ var CacheManager = /** @class */ (function () {
2437
2461
  if (!!realm && !_this.matchRealm(entity, realm)) {
2438
2462
  return;
2439
2463
  }
2464
+ if (!!nativeAccountId && !_this.matchNativeAccountId(entity, nativeAccountId)) {
2465
+ return;
2466
+ }
2440
2467
  matchingAccounts[cacheKey] = entity;
2441
2468
  });
2442
2469
  return matchingAccounts;
@@ -2765,6 +2792,26 @@ var CacheManager = /** @class */ (function () {
2765
2792
  var accountKey = AccountEntity.generateAccountCacheKey(account);
2766
2793
  return this.getAccount(accountKey);
2767
2794
  };
2795
+ /**
2796
+ * Retrieve AccountEntity from cache
2797
+ * @param nativeAccountId
2798
+ * @returns AccountEntity or Null
2799
+ */
2800
+ CacheManager.prototype.readAccountFromCacheWithNativeAccountId = function (nativeAccountId) {
2801
+ // fetch account from memory
2802
+ var accountFilter = {
2803
+ nativeAccountId: nativeAccountId
2804
+ };
2805
+ var accountCache = this.getAccountsFilteredBy(accountFilter);
2806
+ var accounts = Object.keys(accountCache).map(function (key) { return accountCache[key]; });
2807
+ if (accounts.length < 1) {
2808
+ return null;
2809
+ }
2810
+ else if (accounts.length > 1) {
2811
+ throw ClientAuthError.createMultipleMatchingAccountsInCacheError();
2812
+ }
2813
+ return accountCache[0];
2814
+ };
2768
2815
  /**
2769
2816
  * Retrieve IdTokenEntity from cache
2770
2817
  * @param clientId
@@ -2939,6 +2986,15 @@ var CacheManager = /** @class */ (function () {
2939
2986
  CacheManager.prototype.matchRealm = function (entity, realm) {
2940
2987
  return !!(entity.realm && realm === entity.realm);
2941
2988
  };
2989
+ /**
2990
+ * helper to match nativeAccountId
2991
+ * @param entity
2992
+ * @param nativeAccountId
2993
+ * @returns boolean indicating the match result
2994
+ */
2995
+ CacheManager.prototype.matchNativeAccountId = function (entity, nativeAccountId) {
2996
+ return !!(entity.nativeAccountId && nativeAccountId === entity.nativeAccountId);
2997
+ };
2942
2998
  /**
2943
2999
  * Returns true if the target scopes are a subset of the current entity's scopes, false otherwise.
2944
3000
  * @param entity
@@ -3211,7 +3267,7 @@ function buildClientConfiguration(_a) {
3211
3267
  telemetry: __assign(__assign({}, DEFAULT_TELEMETRY_OPTIONS), telemetry),
3212
3268
  serverTelemetryManager: serverTelemetryManager || null,
3213
3269
  persistencePlugin: persistencePlugin || null,
3214
- serializableCache: serializableCache || null
3270
+ serializableCache: serializableCache || null,
3215
3271
  };
3216
3272
  }
3217
3273
  /**
@@ -3399,7 +3455,7 @@ exports.CcsCredentialType = void 0;
3399
3455
  * Base application class which will construct requests to send to and handle responses from the Microsoft STS using the authorization code flow.
3400
3456
  */
3401
3457
  var BaseClient = /** @class */ (function () {
3402
- function BaseClient(configuration) {
3458
+ function BaseClient(configuration, performanceClient) {
3403
3459
  // Set the configuration
3404
3460
  this.config = buildClientConfiguration(configuration);
3405
3461
  // Initialize the logger
@@ -3416,6 +3472,8 @@ var BaseClient = /** @class */ (function () {
3416
3472
  this.serverTelemetryManager = this.config.serverTelemetryManager;
3417
3473
  // set Authority
3418
3474
  this.authority = this.config.authOptions.authority;
3475
+ // set performance telemetry client
3476
+ this.performanceClient = performanceClient;
3419
3477
  }
3420
3478
  /**
3421
3479
  * Creates default headers for requests to token endpoint
@@ -4544,6 +4602,21 @@ var UrlString = /** @class */ (function () {
4544
4602
  }
4545
4603
  return Constants.EMPTY_STRING;
4546
4604
  };
4605
+ /**
4606
+ * Parses query string from given string. Returns empty string if no query symbol is found.
4607
+ * @param queryString
4608
+ */
4609
+ UrlString.parseQueryString = function (queryString) {
4610
+ var queryIndex1 = queryString.indexOf("?");
4611
+ var queryIndex2 = queryString.indexOf("/?");
4612
+ if (queryIndex2 > -1) {
4613
+ return queryString.substring(queryIndex2 + 2);
4614
+ }
4615
+ else if (queryIndex1 > -1) {
4616
+ return queryString.substring(queryIndex1 + 1);
4617
+ }
4618
+ return Constants.EMPTY_STRING;
4619
+ };
4547
4620
  UrlString.constructAuthorityUriFromObject = function (urlObject) {
4548
4621
  return new UrlString(urlObject.Protocol + "//" + urlObject.HostNameAndPort + "/" + urlObject.PathSegments.join("/"));
4549
4622
  };
@@ -4565,6 +4638,24 @@ var UrlString = /** @class */ (function () {
4565
4638
  }
4566
4639
  return deserializedHash;
4567
4640
  };
4641
+ /**
4642
+ * Returns URL query string as server auth code response object.
4643
+ */
4644
+ UrlString.getDeserializedQueryString = function (query) {
4645
+ // Check if given query is empty
4646
+ if (StringUtils.isEmpty(query)) {
4647
+ return {};
4648
+ }
4649
+ // Strip the ? symbol if present
4650
+ var parsedQueryString = UrlString.parseQueryString(query);
4651
+ // If ? symbol was not present, above will return empty string, so give original query value
4652
+ var deserializedQueryString = StringUtils.queryStringToObject(StringUtils.isEmpty(parsedQueryString) ? query : parsedQueryString);
4653
+ // Check if deserialization didn't work
4654
+ if (!deserializedQueryString) {
4655
+ throw ClientAuthError.createHashNotDeserializedError(JSON.stringify(deserializedQueryString));
4656
+ }
4657
+ return deserializedQueryString;
4658
+ };
4568
4659
  /**
4569
4660
  * Check if the hash of the URL string contains known properties
4570
4661
  */
@@ -4843,7 +4934,7 @@ var ResponseHandler = /** @class */ (function () {
4843
4934
  * @param serverTokenResponse
4844
4935
  * @param authority
4845
4936
  */
4846
- ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, userAssertionHash, handlingRefreshTokenResponse) {
4937
+ ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, userAssertionHash, handlingRefreshTokenResponse, forceCacheRefreshTokenResponse) {
4847
4938
  return __awaiter(this, void 0, void 0, function () {
4848
4939
  var idTokenObj, requestStateObj, cacheRecord, cacheContext, key, account;
4849
4940
  return __generator(this, function (_a) {
@@ -4880,14 +4971,15 @@ var ResponseHandler = /** @class */ (function () {
4880
4971
  /*
4881
4972
  * When saving a refreshed tokens to the cache, it is expected that the account that was used is present in the cache.
4882
4973
  * If not present, we should return null, as it's the case that another application called removeAccount in between
4883
- * the calls to getAllAccounts and acquireTokenSilent. We should not overwrite that removal.
4974
+ * the calls to getAllAccounts and acquireTokenSilent. We should not overwrite that removal, unless explicitly flagged by
4975
+ * the developer, as in the case of refresh token flow used in ADAL Node to MSAL Node migration.
4884
4976
  */
4885
- if (handlingRefreshTokenResponse && cacheRecord.account) {
4977
+ if (handlingRefreshTokenResponse && !forceCacheRefreshTokenResponse && cacheRecord.account) {
4886
4978
  key = cacheRecord.account.generateAccountKey();
4887
4979
  account = this.cacheStorage.getAccount(key);
4888
4980
  if (!account) {
4889
4981
  this.logger.warning("Account used to refresh tokens not in persistence, refreshed tokens will not be stored in the cache");
4890
- return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj)];
4982
+ return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, undefined)];
4891
4983
  }
4892
4984
  }
4893
4985
  return [4 /*yield*/, this.cacheStorage.saveCacheRecord(cacheRecord)];
@@ -5151,7 +5243,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5151
5243
  throw ClientConfigurationError.createEmptyLogoutRequestError();
5152
5244
  }
5153
5245
  var queryString = this.createLogoutUrlQueryString(logoutRequest);
5154
- // Construct logout URI.
5246
+ // Construct logout URI
5155
5247
  return UrlString.appendQueryString(this.authority.endSessionEndpoint, queryString);
5156
5248
  };
5157
5249
  /**
@@ -5338,7 +5430,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5338
5430
  */
5339
5431
  AuthorizationCodeClient.prototype.createAuthCodeUrlQueryString = function (request) {
5340
5432
  return __awaiter(this, void 0, void 0, function () {
5341
- var parameterBuilder, requestScopes, correlationId, accountSid, clientInfo, clientInfo, popTokenGenerator, reqCnfData;
5433
+ var parameterBuilder, requestScopes, correlationId, accountSid, accountLoginHintClaim, clientInfo, clientInfo, clientInfo, popTokenGenerator, reqCnfData;
5342
5434
  return __generator(this, function (_a) {
5343
5435
  switch (_a.label) {
5344
5436
  case 0:
@@ -5368,7 +5460,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5368
5460
  if (request.domainHint) {
5369
5461
  parameterBuilder.addDomainHint(request.domainHint);
5370
5462
  }
5371
- // Add sid or loginHint with preference for sid -> loginHint -> username of AccountInfo object
5463
+ // Add sid or loginHint with preference for login_hint claim (in request) -> sid -> loginHint (upn/email) -> username of AccountInfo object
5372
5464
  if (request.prompt !== PromptValue.SELECT_ACCOUNT) {
5373
5465
  // AAD will throw if prompt=select_account is passed with an account hint
5374
5466
  if (request.sid && request.prompt === PromptValue.NONE) {
@@ -5378,9 +5470,24 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5378
5470
  }
5379
5471
  else if (request.account) {
5380
5472
  accountSid = this.extractAccountSid(request.account);
5381
- // If account and loginHint are provided, we will check account first for sid before adding loginHint
5382
- if (accountSid && request.prompt === PromptValue.NONE) {
5383
- // SessionId is only used in silent calls
5473
+ accountLoginHintClaim = this.extractLoginHint(request.account);
5474
+ // If login_hint claim is present, use it over sid/username
5475
+ if (accountLoginHintClaim) {
5476
+ this.logger.verbose("createAuthCodeUrlQueryString: login_hint claim present on account");
5477
+ parameterBuilder.addLoginHint(accountLoginHintClaim);
5478
+ try {
5479
+ clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5480
+ parameterBuilder.addCcsOid(clientInfo);
5481
+ }
5482
+ catch (e) {
5483
+ this.logger.verbose("createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header");
5484
+ }
5485
+ }
5486
+ else if (accountSid && request.prompt === PromptValue.NONE) {
5487
+ /*
5488
+ * If account and loginHint are provided, we will check account first for sid before adding loginHint
5489
+ * SessionId is only used in silent calls
5490
+ */
5384
5491
  this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from account");
5385
5492
  parameterBuilder.addSid(accountSid);
5386
5493
  try {
@@ -5388,7 +5495,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5388
5495
  parameterBuilder.addCcsOid(clientInfo);
5389
5496
  }
5390
5497
  catch (e) {
5391
- this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5498
+ this.logger.verbose("createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header");
5392
5499
  }
5393
5500
  }
5394
5501
  else if (request.loginHint) {
@@ -5405,7 +5512,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5405
5512
  parameterBuilder.addCcsOid(clientInfo);
5406
5513
  }
5407
5514
  catch (e) {
5408
- this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5515
+ this.logger.verbose("createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header");
5409
5516
  }
5410
5517
  }
5411
5518
  }
@@ -5476,11 +5583,12 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5476
5583
  * @param account
5477
5584
  */
5478
5585
  AuthorizationCodeClient.prototype.extractAccountSid = function (account) {
5479
- if (account.idTokenClaims) {
5480
- var tokenClaims = account.idTokenClaims;
5481
- return tokenClaims.sid || null;
5482
- }
5483
- return null;
5586
+ var _a;
5587
+ return ((_a = account.idTokenClaims) === null || _a === void 0 ? void 0 : _a.sid) || null;
5588
+ };
5589
+ AuthorizationCodeClient.prototype.extractLoginHint = function (account) {
5590
+ var _a;
5591
+ return ((_a = account.idTokenClaims) === null || _a === void 0 ? void 0 : _a.login_hint) || null;
5484
5592
  };
5485
5593
  return AuthorizationCodeClient;
5486
5594
  }(BaseClient));
@@ -5633,7 +5741,7 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5633
5741
  pollingIntervalMilli = deviceCodeResponse.interval * 1000;
5634
5742
  _a.label = 1;
5635
5743
  case 1:
5636
- if (!this.continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, request.cancel)) return [3 /*break*/, 6];
5744
+ if (!this.continuePolling(deviceCodeExpirationTime, userSpecifiedTimeout, request.cancel)) return [3 /*break*/, 8];
5637
5745
  thumbprint = {
5638
5746
  clientId: this.config.authOptions.clientId,
5639
5747
  authority: request.authority,
@@ -5648,18 +5756,23 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5648
5756
  return [4 /*yield*/, this.executePostToTokenEndpoint(this.authority.tokenEndpoint, requestBody, headers, thumbprint)];
5649
5757
  case 2:
5650
5758
  response = _a.sent();
5651
- if (!(response.body && response.body.error === Constants.AUTHORIZATION_PENDING)) return [3 /*break*/, 4];
5652
- // user authorization is pending. Sleep for polling interval and try again
5653
- this.logger.info(response.body.error_description || "Authorization pending. Continue polling.");
5759
+ if (!(response.body && response.body.error)) return [3 /*break*/, 6];
5760
+ if (!(response.body.error === Constants.AUTHORIZATION_PENDING)) return [3 /*break*/, 4];
5761
+ this.logger.info("Authorization pending. Continue polling.");
5654
5762
  return [4 /*yield*/, TimeUtils.delay(pollingIntervalMilli)];
5655
5763
  case 3:
5656
5764
  _a.sent();
5657
5765
  return [3 /*break*/, 5];
5658
5766
  case 4:
5767
+ // for any other error, throw
5768
+ this.logger.info("Unexpected error in polling from the server");
5769
+ throw ServerError.createPostRequestFailed(response.body.error);
5770
+ case 5: return [3 /*break*/, 7];
5771
+ case 6:
5659
5772
  this.logger.verbose("Authorization completed successfully. Polling stopped.");
5660
5773
  return [2 /*return*/, response.body];
5661
- case 5: return [3 /*break*/, 1];
5662
- case 6:
5774
+ case 7: return [3 /*break*/, 1];
5775
+ case 8:
5663
5776
  /*
5664
5777
  * The above code should've thrown by this point, but to satisfy TypeScript,
5665
5778
  * and in the rare case the conditionals in continuePolling() may not catch everything...
@@ -5698,6 +5811,123 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5698
5811
  return DeviceCodeClient;
5699
5812
  }(BaseClient));
5700
5813
 
5814
+ /*
5815
+ * Copyright (c) Microsoft Corporation. All rights reserved.
5816
+ * Licensed under the MIT License.
5817
+ */
5818
+ /**
5819
+ * Enumeration of operations that are instrumented by have their performance measured by the PerformanceClient.
5820
+ *
5821
+ * @export
5822
+ * @enum {number}
5823
+ */
5824
+ exports.PerformanceEvents = void 0;
5825
+ (function (PerformanceEvents) {
5826
+ /**
5827
+ * acquireTokenByCode API (msal-browser and msal-node).
5828
+ * Used to acquire tokens by trading an authorization code against the token endpoint.
5829
+ */
5830
+ PerformanceEvents["AcquireTokenByCode"] = "acquireTokenByCode";
5831
+ /**
5832
+ * acquireTokenByRefreshToken API (msal-browser and msal-node).
5833
+ * Used to renew an access token using a refresh token against the token endpoint.
5834
+ */
5835
+ PerformanceEvents["AcquireTokenByRefreshToken"] = "acquireTokenByRefreshToken";
5836
+ /**
5837
+ * acquireTokenSilent API (msal-browser and msal-node).
5838
+ * Used to silently acquire a new access token (from the cache or the network).
5839
+ */
5840
+ PerformanceEvents["AcquireTokenSilent"] = "acquireTokenSilent";
5841
+ /**
5842
+ * acquireTokenSilentAsync (msal-browser).
5843
+ * Internal API for acquireTokenSilent.
5844
+ */
5845
+ PerformanceEvents["AcquireTokenSilentAsync"] = "acquireTokenSilentAsync";
5846
+ /**
5847
+ * acquireTokenPopup (msal-browser).
5848
+ * Used to acquire a new access token interactively through pop ups
5849
+ */
5850
+ PerformanceEvents["AcquireTokenPopup"] = "acquireTokenPopup";
5851
+ /**
5852
+ * getPublicKeyThumbprint API in CryptoOpts class (msal-browser).
5853
+ * Used to generate a public/private keypair and generate a public key thumbprint for pop requests.
5854
+ */
5855
+ PerformanceEvents["CryptoOptsGetPublicKeyThumbprint"] = "cryptoOptsGetPublicKeyThumbprint";
5856
+ /**
5857
+ * signJwt API in CryptoOpts class (msal-browser).
5858
+ * Used to signed a pop token.
5859
+ */
5860
+ PerformanceEvents["CryptoOptsSignJwt"] = "cryptoOptsSignJwt";
5861
+ /**
5862
+ * acquireToken API in the SilentCacheClient class (msal-browser).
5863
+ * Used to read access tokens from the cache.
5864
+ */
5865
+ PerformanceEvents["SilentCacheClientAcquireToken"] = "silentCacheClientAcquireToken";
5866
+ /**
5867
+ * acquireToken API in the SilentIframeClient class (msal-browser).
5868
+ * Used to acquire a new set of tokens from the authorize endpoint in a hidden iframe.
5869
+ */
5870
+ PerformanceEvents["SilentIframeClientAcquireToken"] = "silentIframeClientAcquireToken";
5871
+ /**
5872
+ * acquireToken API in SilentRereshClient (msal-browser).
5873
+ * Used to acquire a new set of tokens from the token endpoint using a refresh token.
5874
+ */
5875
+ PerformanceEvents["SilentRefreshClientAcquireToken"] = "silentRefreshClientAcquireToken";
5876
+ /**
5877
+ * ssoSilent API (msal-browser).
5878
+ * Used to silently acquire an authorization code and set of tokens using a hidden iframe.
5879
+ */
5880
+ PerformanceEvents["SsoSilent"] = "ssoSilent";
5881
+ /**
5882
+ * getDiscoveredAuthority API in StandardInteractionClient class (msal-browser).
5883
+ * Used to load authority metadata for a request.
5884
+ */
5885
+ PerformanceEvents["StandardInteractionClientGetDiscoveredAuthority"] = "standardInteractionClientGetDiscoveredAuthority";
5886
+ /**
5887
+ * acquireToken APIs in msal-browser.
5888
+ * Used to make an /authorize endpoint call with native brokering enabled.
5889
+ */
5890
+ PerformanceEvents["FetchAccountIdWithNativeBroker"] = "fetchAccountIdWithNativeBroker";
5891
+ /**
5892
+ * acquireToken API in NativeInteractionClient class (msal-browser).
5893
+ * Used to acquire a token from Native component when native brokering is enabled.
5894
+ */
5895
+ PerformanceEvents["NativeInteractionClientAcquireToken"] = "nativeInteractionClientAcquireToken";
5896
+ /**
5897
+ * Time spent on the network for refresh token acquisition
5898
+ */
5899
+ PerformanceEvents["RefreshTokenClientExecuteTokenRequest"] = "refreshTokenClientExecuteTokenRequest";
5900
+ /**
5901
+ * Time spent creating default headers for requests to token endpoint
5902
+ */
5903
+ PerformanceEvents["BaseClientCreateTokenRequestHeaders"] = "baseClientCreateTokenRequestHeaders";
5904
+ /**
5905
+ * Used to measure the time taken for completing embedded-broker handshake (PW-Broker).
5906
+ */
5907
+ PerformanceEvents["BrokerHandhshake"] = "brokerHandshake";
5908
+ /**
5909
+ * acquireTokenByRefreshToken API in BrokerClientApplication (PW-Broker) .
5910
+ */
5911
+ PerformanceEvents["AcquireTokenByRefreshTokenInBroker"] = "acquireTokenByRefreshTokenInBroker";
5912
+ /**
5913
+ * acquireToken API in BrokerClientApplication.
5914
+ * Used to acquire a token on behalf of the embedded application (PW-Broker).
5915
+ */
5916
+ PerformanceEvents["AcquireTokenByBroker"] = "acquireTokenByBroker";
5917
+ })(exports.PerformanceEvents || (exports.PerformanceEvents = {}));
5918
+ /**
5919
+ * State of the performance event.
5920
+ *
5921
+ * @export
5922
+ * @enum {number}
5923
+ */
5924
+ exports.PerformanceEventStatus = void 0;
5925
+ (function (PerformanceEventStatus) {
5926
+ PerformanceEventStatus[PerformanceEventStatus["NotStarted"] = 0] = "NotStarted";
5927
+ PerformanceEventStatus[PerformanceEventStatus["InProgress"] = 1] = "InProgress";
5928
+ PerformanceEventStatus[PerformanceEventStatus["Completed"] = 2] = "Completed";
5929
+ })(exports.PerformanceEventStatus || (exports.PerformanceEventStatus = {}));
5930
+
5701
5931
  /*
5702
5932
  * Copyright (c) Microsoft Corporation. All rights reserved.
5703
5933
  * Licensed under the MIT License.
@@ -5707,8 +5937,8 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5707
5937
  */
5708
5938
  var RefreshTokenClient = /** @class */ (function (_super) {
5709
5939
  __extends(RefreshTokenClient, _super);
5710
- function RefreshTokenClient(configuration) {
5711
- return _super.call(this, configuration) || this;
5940
+ function RefreshTokenClient(configuration, performanceClient) {
5941
+ return _super.call(this, configuration, performanceClient) || this;
5712
5942
  }
5713
5943
  RefreshTokenClient.prototype.acquireToken = function (request) {
5714
5944
  return __awaiter(this, void 0, void 0, function () {
@@ -5722,7 +5952,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5722
5952
  response = _a.sent();
5723
5953
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
5724
5954
  responseHandler.validateTokenResponse(response.body);
5725
- return [2 /*return*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true)];
5955
+ return [2 /*return*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true, request.forceCache)];
5726
5956
  }
5727
5957
  });
5728
5958
  });
@@ -5794,13 +6024,16 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5794
6024
  * @param authority
5795
6025
  */
5796
6026
  RefreshTokenClient.prototype.executeTokenRequest = function (request, authority) {
6027
+ var _a;
5797
6028
  return __awaiter(this, void 0, void 0, function () {
5798
- var requestBody, queryParameters, headers, thumbprint, endpoint;
5799
- return __generator(this, function (_a) {
5800
- switch (_a.label) {
5801
- case 0: return [4 /*yield*/, this.createTokenRequestBody(request)];
6029
+ var acquireTokenMeasurement, requestBody, queryParameters, headers, thumbprint, endpoint;
6030
+ return __generator(this, function (_b) {
6031
+ switch (_b.label) {
6032
+ case 0:
6033
+ acquireTokenMeasurement = (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.startMeasurement(exports.PerformanceEvents.RefreshTokenClientExecuteTokenRequest, request.correlationId);
6034
+ return [4 /*yield*/, this.createTokenRequestBody(request)];
5802
6035
  case 1:
5803
- requestBody = _a.sent();
6036
+ requestBody = _b.sent();
5804
6037
  queryParameters = this.createTokenQueryParameters(request);
5805
6038
  headers = this.createTokenRequestHeaders(request.ccsCredential);
5806
6039
  thumbprint = {
@@ -5815,7 +6048,19 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5815
6048
  sshKid: request.sshKid
5816
6049
  };
5817
6050
  endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParameters);
5818
- return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)];
6051
+ return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)
6052
+ .then(function (result) {
6053
+ acquireTokenMeasurement === null || acquireTokenMeasurement === void 0 ? void 0 : acquireTokenMeasurement.endMeasurement({
6054
+ success: true
6055
+ });
6056
+ return result;
6057
+ })
6058
+ .catch(function (error) {
6059
+ acquireTokenMeasurement === null || acquireTokenMeasurement === void 0 ? void 0 : acquireTokenMeasurement.endMeasurement({
6060
+ success: false
6061
+ });
6062
+ throw error;
6063
+ })];
5819
6064
  }
5820
6065
  });
5821
6066
  });
@@ -5836,11 +6081,14 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5836
6081
  * @param request
5837
6082
  */
5838
6083
  RefreshTokenClient.prototype.createTokenRequestBody = function (request) {
6084
+ var _a;
5839
6085
  return __awaiter(this, void 0, void 0, function () {
5840
- var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, reqCnfData, clientInfo;
5841
- return __generator(this, function (_a) {
5842
- switch (_a.label) {
6086
+ var correlationId, acquireTokenMeasurement, parameterBuilder, clientAssertion, popTokenGenerator, reqCnfData, clientInfo;
6087
+ return __generator(this, function (_b) {
6088
+ switch (_b.label) {
5843
6089
  case 0:
6090
+ correlationId = request.correlationId;
6091
+ acquireTokenMeasurement = (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.startMeasurement(exports.PerformanceEvents.BaseClientCreateTokenRequestHeaders, correlationId);
5844
6092
  parameterBuilder = new RequestParameterBuilder();
5845
6093
  parameterBuilder.addClientId(this.config.authOptions.clientId);
5846
6094
  parameterBuilder.addScopes(request.scopes);
@@ -5852,7 +6100,6 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5852
6100
  if (this.serverTelemetryManager) {
5853
6101
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
5854
6102
  }
5855
- correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
5856
6103
  parameterBuilder.addCorrelationId(correlationId);
5857
6104
  parameterBuilder.addRefreshToken(request.refreshToken);
5858
6105
  if (this.config.clientCredentials.clientSecret) {
@@ -5867,7 +6114,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5867
6114
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5868
6115
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5869
6116
  case 1:
5870
- reqCnfData = _a.sent();
6117
+ reqCnfData = _b.sent();
5871
6118
  // SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
5872
6119
  parameterBuilder.addPopToken(reqCnfData.reqCnfString);
5873
6120
  return [3 /*break*/, 3];
@@ -5877,10 +6124,13 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5877
6124
  parameterBuilder.addSshJwk(request.sshJwk);
5878
6125
  }
5879
6126
  else {
6127
+ acquireTokenMeasurement === null || acquireTokenMeasurement === void 0 ? void 0 : acquireTokenMeasurement.endMeasurement({
6128
+ success: false
6129
+ });
5880
6130
  throw ClientConfigurationError.createMissingSshJwkError();
5881
6131
  }
5882
6132
  }
5883
- _a.label = 3;
6133
+ _b.label = 3;
5884
6134
  case 3:
5885
6135
  if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
5886
6136
  parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
@@ -5901,6 +6151,9 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5901
6151
  break;
5902
6152
  }
5903
6153
  }
6154
+ acquireTokenMeasurement === null || acquireTokenMeasurement === void 0 ? void 0 : acquireTokenMeasurement.endMeasurement({
6155
+ success: true
6156
+ });
5904
6157
  return [2 /*return*/, parameterBuilder.createQueryString()];
5905
6158
  }
5906
6159
  });
@@ -5918,8 +6171,10 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5918
6171
  */
5919
6172
  var ClientCredentialClient = /** @class */ (function (_super) {
5920
6173
  __extends(ClientCredentialClient, _super);
5921
- function ClientCredentialClient(configuration) {
5922
- return _super.call(this, configuration) || this;
6174
+ function ClientCredentialClient(configuration, appTokenProvider) {
6175
+ var _this = _super.call(this, configuration) || this;
6176
+ _this.appTokenProvider = appTokenProvider;
6177
+ return _this;
5923
6178
  }
5924
6179
  /**
5925
6180
  * Public API to acquire a token with ClientCredential Flow for Confidential clients
@@ -6007,10 +6262,30 @@ var ClientCredentialClient = /** @class */ (function (_super) {
6007
6262
  */
6008
6263
  ClientCredentialClient.prototype.executeTokenRequest = function (request, authority) {
6009
6264
  return __awaiter(this, void 0, void 0, function () {
6010
- var requestBody, headers, thumbprint, reqTimestamp, response, responseHandler, tokenResponse;
6265
+ var serverTokenResponse, reqTimestamp, appTokenPropviderParameters, appTokenProviderResult, requestBody, headers, thumbprint, response, responseHandler, tokenResponse;
6011
6266
  return __generator(this, function (_a) {
6012
6267
  switch (_a.label) {
6013
6268
  case 0:
6269
+ if (!this.appTokenProvider) return [3 /*break*/, 2];
6270
+ this.logger.info("Using appTokenProvider extensibility.");
6271
+ appTokenPropviderParameters = {
6272
+ correlationId: request.correlationId,
6273
+ tenantId: this.config.authOptions.authority.tenant,
6274
+ scopes: request.scopes,
6275
+ claims: request.claims,
6276
+ };
6277
+ reqTimestamp = TimeUtils.nowSeconds();
6278
+ return [4 /*yield*/, this.appTokenProvider(appTokenPropviderParameters)];
6279
+ case 1:
6280
+ appTokenProviderResult = _a.sent();
6281
+ serverTokenResponse = {
6282
+ access_token: appTokenProviderResult.accessToken,
6283
+ expires_in: appTokenProviderResult.expiresInSeconds,
6284
+ refresh_in: appTokenProviderResult.refreshInSeconds,
6285
+ token_type: exports.AuthenticationScheme.BEARER
6286
+ };
6287
+ return [3 /*break*/, 4];
6288
+ case 2:
6014
6289
  requestBody = this.createTokenRequestBody(request);
6015
6290
  headers = this.createTokenRequestHeaders();
6016
6291
  thumbprint = {
@@ -6026,12 +6301,15 @@ var ClientCredentialClient = /** @class */ (function (_super) {
6026
6301
  };
6027
6302
  reqTimestamp = TimeUtils.nowSeconds();
6028
6303
  return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
6029
- case 1:
6304
+ case 3:
6030
6305
  response = _a.sent();
6306
+ serverTokenResponse = response.body;
6307
+ _a.label = 4;
6308
+ case 4:
6031
6309
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
6032
- responseHandler.validateTokenResponse(response.body);
6033
- return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request)];
6034
- case 2:
6310
+ responseHandler.validateTokenResponse(serverTokenResponse);
6311
+ return [4 /*yield*/, responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request)];
6312
+ case 5:
6035
6313
  tokenResponse = _a.sent();
6036
6314
  return [2 /*return*/, tokenResponse];
6037
6315
  }
@@ -6308,8 +6586,8 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6308
6586
  */
6309
6587
  var SilentFlowClient = /** @class */ (function (_super) {
6310
6588
  __extends(SilentFlowClient, _super);
6311
- function SilentFlowClient(configuration) {
6312
- return _super.call(this, configuration) || this;
6589
+ function SilentFlowClient(configuration, performanceClient) {
6590
+ return _super.call(this, configuration, performanceClient) || this;
6313
6591
  }
6314
6592
  /**
6315
6593
  * Retrieves a token from cache if it is still valid, or uses the cached refresh token to renew
@@ -6328,7 +6606,7 @@ var SilentFlowClient = /** @class */ (function (_super) {
6328
6606
  case 2:
6329
6607
  e_1 = _a.sent();
6330
6608
  if (e_1 instanceof ClientAuthError && e_1.errorCode === ClientAuthErrorMessage.tokenRefreshRequired.code) {
6331
- refreshTokenClient = new RefreshTokenClient(this.config);
6609
+ refreshTokenClient = new RefreshTokenClient(this.config, this.performanceClient);
6332
6610
  return [2 /*return*/, refreshTokenClient.acquireTokenByRefreshToken(request)];
6333
6611
  }
6334
6612
  else {
@@ -7846,102 +8124,6 @@ var ServerTelemetryManager = /** @class */ (function () {
7846
8124
  return ServerTelemetryManager;
7847
8125
  }());
7848
8126
 
7849
- /*
7850
- * Copyright (c) Microsoft Corporation. All rights reserved.
7851
- * Licensed under the MIT License.
7852
- */
7853
- /**
7854
- * Enumeration of operations that are instrumented by have their performance measured by the PerformanceClient.
7855
- *
7856
- * @export
7857
- * @enum {number}
7858
- */
7859
- exports.PerformanceEvents = void 0;
7860
- (function (PerformanceEvents) {
7861
- /**
7862
- * acquireTokenByCode API (msal-browser and msal-node).
7863
- * Used to acquire tokens by trading an authorization code against the token endpoint.
7864
- */
7865
- PerformanceEvents["AcquireTokenByCode"] = "acquireTokenByCode";
7866
- /**
7867
- * acquireTokenByRefreshToken API (msal-browser and msal-node).
7868
- * Used to renew an access token using a refresh token against the token endpoint.
7869
- */
7870
- PerformanceEvents["AcquireTokenByRefreshToken"] = "acquireTokenByRefreshToken";
7871
- /**
7872
- * acquireTokenSilent API (msal-browser and msal-node).
7873
- * Used to silently acquire a new access token (from the cache or the network).
7874
- */
7875
- PerformanceEvents["AcquireTokenSilent"] = "acquireTokenSilent";
7876
- /**
7877
- * acquireTokenSilentAsync (msal-browser).
7878
- * Internal API for acquireTokenSilent.
7879
- */
7880
- PerformanceEvents["AcquireTokenSilentAsync"] = "acquireTokenSilentAsync";
7881
- /**
7882
- * acquireTokenPopup (msal-browser).
7883
- * Used to acquire a new access token interactively through pop ups
7884
- */
7885
- PerformanceEvents["AcquireTokenPopup"] = "acquireTokenPopup";
7886
- /**
7887
- * getPublicKeyThumbprint API in CryptoOpts class (msal-browser).
7888
- * Used to generate a public/private keypair and generate a public key thumbprint for pop requests.
7889
- */
7890
- PerformanceEvents["CryptoOptsGetPublicKeyThumbprint"] = "cryptoOptsGetPublicKeyThumbprint";
7891
- /**
7892
- * signJwt API in CryptoOpts class (msal-browser).
7893
- * Used to signed a pop token.
7894
- */
7895
- PerformanceEvents["CryptoOptsSignJwt"] = "cryptoOptsSignJwt";
7896
- /**
7897
- * acquireToken API in the SilentCacheClient class (msal-browser).
7898
- * Used to read access tokens from the cache.
7899
- */
7900
- PerformanceEvents["SilentCacheClientAcquireToken"] = "silentCacheClientAcquireToken";
7901
- /**
7902
- * acquireToken API in the SilentIframeClient class (msal-browser).
7903
- * Used to acquire a new set of tokens from the authorize endpoint in a hidden iframe.
7904
- */
7905
- PerformanceEvents["SilentIframeClientAcquireToken"] = "silentIframeClientAcquireToken";
7906
- /**
7907
- * acquireToken API in SilentRereshClient (msal-browser).
7908
- * Used to acquire a new set of tokens from the token endpoint using a refresh token.
7909
- */
7910
- PerformanceEvents["SilentRefreshClientAcquireToken"] = "silentRefreshClientAcquireToken";
7911
- /**
7912
- * ssoSilent API (msal-browser).
7913
- * Used to silently acquire an authorization code and set of tokens using a hidden iframe.
7914
- */
7915
- PerformanceEvents["SsoSilent"] = "ssoSilent";
7916
- /**
7917
- * getDiscoveredAuthority API in StandardInteractionClient class (msal-browser).
7918
- * Used to load authority metadata for a request.
7919
- */
7920
- PerformanceEvents["StandardInteractionClientGetDiscoveredAuthority"] = "standardInteractionClientGetDiscoveredAuthority";
7921
- /**
7922
- * acquireToken APIs in msal-browser.
7923
- * Used to make an /authorize endpoint call with native brokering enabled.
7924
- */
7925
- PerformanceEvents["FetchAccountIdWithNativeBroker"] = "fetchAccountIdWithNativeBroker";
7926
- /**
7927
- * acquireToken API in NativeInteractionClient class (msal-browser).
7928
- * Used to acquire a token from Native component when native brokering is enabled.
7929
- */
7930
- PerformanceEvents["NativeInteractionClientAcquireToken"] = "nativeInteractionClientAcquireToken";
7931
- })(exports.PerformanceEvents || (exports.PerformanceEvents = {}));
7932
- /**
7933
- * State of the performance event.
7934
- *
7935
- * @export
7936
- * @enum {number}
7937
- */
7938
- exports.PerformanceEventStatus = void 0;
7939
- (function (PerformanceEventStatus) {
7940
- PerformanceEventStatus[PerformanceEventStatus["NotStarted"] = 0] = "NotStarted";
7941
- PerformanceEventStatus[PerformanceEventStatus["InProgress"] = 1] = "InProgress";
7942
- PerformanceEventStatus[PerformanceEventStatus["Completed"] = 2] = "Completed";
7943
- })(exports.PerformanceEventStatus || (exports.PerformanceEventStatus = {}));
7944
-
7945
8127
  /*
7946
8128
  * Copyright (c) Microsoft Corporation. All rights reserved.
7947
8129
  * Licensed under the MIT License.
@@ -7998,7 +8180,7 @@ var PerformanceClient = /** @class */ (function () {
7998
8180
  clientId: this.clientId,
7999
8181
  name: measureName,
8000
8182
  startTimeMs: Date.now(),
8001
- correlationId: eventCorrelationId
8183
+ correlationId: eventCorrelationId,
8002
8184
  };
8003
8185
  // Store in progress events so they can be discarded if not ended properly
8004
8186
  this.cacheEventByCorrelationId(inProgressEvent);
@@ -8143,6 +8325,12 @@ var PerformanceClient = /** @class */ (function () {
8143
8325
  else {
8144
8326
  _this.logger.verbose("PerformanceClient: Submeasurement for " + measureName + " already exists for " + current.name + ", ignoring", correlationId);
8145
8327
  }
8328
+ if (current.accessTokenSize) {
8329
+ previous.accessTokenSize = current.accessTokenSize;
8330
+ }
8331
+ if (current.idTokenSize) {
8332
+ previous.idTokenSize = current.idTokenSize;
8333
+ }
8146
8334
  }
8147
8335
  return previous;
8148
8336
  }, topLevelEvent);
@@ -8257,6 +8445,7 @@ exports.ClientAuthErrorMessage = ClientAuthErrorMessage;
8257
8445
  exports.ClientConfigurationError = ClientConfigurationError;
8258
8446
  exports.ClientConfigurationErrorMessage = ClientConfigurationErrorMessage;
8259
8447
  exports.ClientCredentialClient = ClientCredentialClient;
8448
+ exports.CodeChallengeMethodValues = CodeChallengeMethodValues;
8260
8449
  exports.Constants = Constants;
8261
8450
  exports.CredentialEntity = CredentialEntity;
8262
8451
  exports.DEFAULT_CRYPTO_IMPLEMENTATION = DEFAULT_CRYPTO_IMPLEMENTATION;
@@ -8292,5 +8481,7 @@ exports.TimeUtils = TimeUtils;
8292
8481
  exports.TokenCacheContext = TokenCacheContext;
8293
8482
  exports.UrlString = UrlString;
8294
8483
  exports.UsernamePasswordClient = UsernamePasswordClient;
8484
+ exports.buildClientInfo = buildClientInfo;
8485
+ exports.buildClientInfoFromHomeAccountId = buildClientInfoFromHomeAccountId;
8295
8486
  exports.version = version;
8296
8487
  //# sourceMappingURL=index.cjs.js.map