@azure/msal-common 6.4.0 → 7.2.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 (185) hide show
  1. package/dist/_virtual/_tslib.js +1 -1
  2. package/dist/account/AccountInfo.d.ts +4 -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/ClientCredentials.d.ts +15 -0
  9. package/dist/account/ClientCredentials.d.ts.map +1 -0
  10. package/dist/account/ClientInfo.js +1 -1
  11. package/dist/account/ClientInfo.js.map +1 -1
  12. package/dist/authority/Authority.d.ts +20 -1
  13. package/dist/authority/Authority.d.ts.map +1 -1
  14. package/dist/authority/Authority.js +108 -35
  15. package/dist/authority/Authority.js.map +1 -1
  16. package/dist/authority/AuthorityFactory.js +1 -1
  17. package/dist/authority/AuthorityFactory.js.map +1 -1
  18. package/dist/authority/AuthorityMetadata.d.ts +623 -0
  19. package/dist/authority/AuthorityMetadata.d.ts.map +1 -0
  20. package/dist/authority/AuthorityMetadata.js +12 -0
  21. package/dist/authority/AuthorityMetadata.js.map +1 -0
  22. package/dist/authority/AuthorityOptions.d.ts +1 -0
  23. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  24. package/dist/authority/AuthorityOptions.js +1 -1
  25. package/dist/authority/AuthorityOptions.js.map +1 -1
  26. package/dist/authority/AuthorityType.js +1 -1
  27. package/dist/authority/AuthorityType.js.map +1 -1
  28. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  29. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -1
  30. package/dist/authority/OpenIdConfigResponse.d.ts +1 -0
  31. package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -1
  32. package/dist/authority/OpenIdConfigResponse.js +3 -2
  33. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  34. package/dist/authority/ProtocolMode.js +1 -1
  35. package/dist/authority/ProtocolMode.js.map +1 -1
  36. package/dist/authority/RegionDiscovery.js +1 -1
  37. package/dist/authority/RegionDiscovery.js.map +1 -1
  38. package/dist/cache/CacheManager.d.ts +15 -2
  39. package/dist/cache/CacheManager.d.ts.map +1 -1
  40. package/dist/cache/CacheManager.js +43 -11
  41. package/dist/cache/CacheManager.js.map +1 -1
  42. package/dist/cache/entities/AccessTokenEntity.d.ts +1 -1
  43. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  44. package/dist/cache/entities/AccessTokenEntity.js +3 -3
  45. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  46. package/dist/cache/entities/AccountEntity.d.ts +2 -4
  47. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  48. package/dist/cache/entities/AccountEntity.js +3 -6
  49. package/dist/cache/entities/AccountEntity.js.map +1 -1
  50. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  51. package/dist/cache/entities/AppMetadataEntity.js.map +1 -1
  52. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -0
  53. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  54. package/dist/cache/entities/AuthorityMetadataEntity.js +4 -2
  55. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  56. package/dist/cache/entities/CacheRecord.js +1 -1
  57. package/dist/cache/entities/CacheRecord.js.map +1 -1
  58. package/dist/cache/entities/CredentialEntity.d.ts +2 -2
  59. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  60. package/dist/cache/entities/CredentialEntity.js +2 -2
  61. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  62. package/dist/cache/entities/IdTokenEntity.d.ts +1 -1
  63. package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
  64. package/dist/cache/entities/IdTokenEntity.js +2 -3
  65. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  66. package/dist/cache/entities/RefreshTokenEntity.d.ts +1 -1
  67. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  68. package/dist/cache/entities/RefreshTokenEntity.js +3 -3
  69. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  70. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  71. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -1
  72. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  73. package/dist/cache/entities/ThrottlingEntity.js.map +1 -1
  74. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  75. package/dist/cache/persistence/TokenCacheContext.js.map +1 -1
  76. package/dist/cache/utils/CacheTypes.d.ts +2 -1
  77. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  78. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  79. package/dist/client/AuthorizationCodeClient.js +4 -4
  80. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  81. package/dist/client/BaseClient.js +1 -1
  82. package/dist/client/BaseClient.js.map +1 -1
  83. package/dist/client/ClientCredentialClient.d.ts +3 -1
  84. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  85. package/dist/client/ClientCredentialClient.js +34 -9
  86. package/dist/client/ClientCredentialClient.js.map +1 -1
  87. package/dist/client/DeviceCodeClient.js +1 -1
  88. package/dist/client/DeviceCodeClient.js.map +1 -1
  89. package/dist/client/OnBehalfOfClient.d.ts +12 -9
  90. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  91. package/dist/client/OnBehalfOfClient.js +89 -62
  92. package/dist/client/OnBehalfOfClient.js.map +1 -1
  93. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  94. package/dist/client/RefreshTokenClient.js +4 -4
  95. package/dist/client/RefreshTokenClient.js.map +1 -1
  96. package/dist/client/SilentFlowClient.js +1 -1
  97. package/dist/client/SilentFlowClient.js.map +1 -1
  98. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  99. package/dist/client/UsernamePasswordClient.js +3 -4
  100. package/dist/client/UsernamePasswordClient.js.map +1 -1
  101. package/dist/config/AppTokenProvider.d.ts +39 -0
  102. package/dist/config/AppTokenProvider.d.ts.map +1 -0
  103. package/dist/config/ClientConfiguration.d.ts +4 -12
  104. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  105. package/dist/config/ClientConfiguration.js +3 -3
  106. package/dist/config/ClientConfiguration.js.map +1 -1
  107. package/dist/crypto/ICrypto.js +1 -1
  108. package/dist/crypto/ICrypto.js.map +1 -1
  109. package/dist/crypto/JoseHeader.js +1 -1
  110. package/dist/crypto/JoseHeader.js.map +1 -1
  111. package/dist/crypto/PopTokenGenerator.js +1 -1
  112. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  113. package/dist/error/AuthError.js +1 -1
  114. package/dist/error/AuthError.js.map +1 -1
  115. package/dist/error/ClientAuthError.js +1 -1
  116. package/dist/error/ClientAuthError.js.map +1 -1
  117. package/dist/error/ClientConfigurationError.js +1 -1
  118. package/dist/error/ClientConfigurationError.js.map +1 -1
  119. package/dist/error/InteractionRequiredAuthError.d.ts +9 -0
  120. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  121. package/dist/error/InteractionRequiredAuthError.js +12 -1
  122. package/dist/error/InteractionRequiredAuthError.js.map +1 -1
  123. package/dist/error/JoseHeaderError.js +1 -1
  124. package/dist/error/JoseHeaderError.js.map +1 -1
  125. package/dist/error/ServerError.js +1 -1
  126. package/dist/error/ServerError.js.map +1 -1
  127. package/dist/index.cjs.js +356 -156
  128. package/dist/index.cjs.js.map +1 -1
  129. package/dist/index.d.ts +2 -1
  130. package/dist/index.d.ts.map +1 -1
  131. package/dist/index.js +1 -1
  132. package/dist/logger/Logger.js +1 -1
  133. package/dist/logger/Logger.js.map +1 -1
  134. package/dist/network/INetworkModule.js +1 -1
  135. package/dist/network/INetworkModule.js.map +1 -1
  136. package/dist/network/NetworkManager.js +1 -1
  137. package/dist/network/NetworkManager.js.map +1 -1
  138. package/dist/network/ThrottlingUtils.js +1 -1
  139. package/dist/network/ThrottlingUtils.js.map +1 -1
  140. package/dist/packageMetadata.d.ts +1 -1
  141. package/dist/packageMetadata.js +2 -2
  142. package/dist/packageMetadata.js.map +1 -1
  143. package/dist/request/AuthenticationHeaderParser.js +1 -1
  144. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  145. package/dist/request/BaseAuthRequest.d.ts +1 -3
  146. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  147. package/dist/request/CommonClientCredentialRequest.d.ts +2 -0
  148. package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
  149. package/dist/request/CommonRefreshTokenRequest.d.ts +4 -2
  150. package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
  151. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  152. package/dist/request/RequestParameterBuilder.js +7 -3
  153. package/dist/request/RequestParameterBuilder.js.map +1 -1
  154. package/dist/request/RequestValidator.js +1 -1
  155. package/dist/request/RequestValidator.js.map +1 -1
  156. package/dist/request/ScopeSet.js +1 -1
  157. package/dist/request/ScopeSet.js.map +1 -1
  158. package/dist/response/ResponseHandler.d.ts +1 -1
  159. package/dist/response/ResponseHandler.d.ts.map +1 -1
  160. package/dist/response/ResponseHandler.js +16 -15
  161. package/dist/response/ResponseHandler.js.map +1 -1
  162. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  163. package/dist/telemetry/performance/PerformanceClient.js +8 -2
  164. package/dist/telemetry/performance/PerformanceClient.js.map +1 -1
  165. package/dist/telemetry/performance/PerformanceEvent.d.ts +39 -1
  166. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  167. package/dist/telemetry/performance/PerformanceEvent.js +14 -1
  168. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -1
  169. package/dist/telemetry/performance/StubPerformanceClient.js +1 -1
  170. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -1
  171. package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
  172. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  173. package/dist/url/UrlString.js +1 -1
  174. package/dist/url/UrlString.js.map +1 -1
  175. package/dist/utils/Constants.d.ts +5 -2
  176. package/dist/utils/Constants.d.ts.map +1 -1
  177. package/dist/utils/Constants.js +5 -2
  178. package/dist/utils/Constants.js.map +1 -1
  179. package/dist/utils/ProtocolUtils.js +1 -1
  180. package/dist/utils/ProtocolUtils.js.map +1 -1
  181. package/dist/utils/StringUtils.js +1 -1
  182. package/dist/utils/StringUtils.js.map +1 -1
  183. package/dist/utils/TimeUtils.js +1 -1
  184. package/dist/utils/TimeUtils.js.map +1 -1
  185. package/package.json +9 -5
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v6.4.0 2022-06-06 */
1
+ /*! @azure/msal-common v7.2.0 2022-07-18 */
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
@@ -379,6 +381,7 @@ var AuthorityMetadataSource;
379
381
  AuthorityMetadataSource["CONFIG"] = "config";
380
382
  AuthorityMetadataSource["CACHE"] = "cache";
381
383
  AuthorityMetadataSource["NETWORK"] = "network";
384
+ AuthorityMetadataSource["HARDCODED_VALUES"] = "hardcoded_values";
382
385
  })(AuthorityMetadataSource || (AuthorityMetadataSource = {}));
383
386
  var SERVER_TELEM_CONSTANTS = {
384
387
  SCHEMA_VERSION: 5,
@@ -1357,7 +1360,7 @@ var Logger = /** @class */ (function () {
1357
1360
 
1358
1361
  /* eslint-disable header/header */
1359
1362
  var name = "@azure/msal-common";
1360
- var version = "6.4.0";
1363
+ var version = "7.2.0";
1361
1364
 
1362
1365
  /*
1363
1366
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1400,9 +1403,9 @@ exports.AzureCloudInstance = void 0;
1400
1403
  * familyId: Family ID identifier, usually only used for refresh tokens
1401
1404
  * realm: Full tenant or organizational identifier that the account belongs to
1402
1405
  * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
1403
- * oboAssertion: access token passed in as part of OBO request
1404
1406
  * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
1405
1407
  * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
1408
+ * userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
1406
1409
  * }
1407
1410
  */
1408
1411
  var CredentialEntity = /** @class */ (function () {
@@ -2043,7 +2046,6 @@ exports.AuthorityType = void 0;
2043
2046
  * clientInfo: Full base64 encoded client info received from ESTS
2044
2047
  * lastModificationTime: last time this entity was modified in the cache
2045
2048
  * lastModificationApp:
2046
- * oboAssertion: access token passed in as part of OBO request
2047
2049
  * idTokenClaims: Object containing claims parsed from ID token
2048
2050
  * nativeAccountId: Account identifier on the native device
2049
2051
  * }
@@ -2122,7 +2124,7 @@ var AccountEntity = /** @class */ (function () {
2122
2124
  * @param idToken
2123
2125
  * @param policy
2124
2126
  */
2125
- AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2127
+ AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2126
2128
  var _a, _b, _c, _d, _e, _f;
2127
2129
  var account = new AccountEntity();
2128
2130
  account.authorityType = exports.CacheAccountType.MSSTS_ACCOUNT_TYPE;
@@ -2136,7 +2138,6 @@ var AccountEntity = /** @class */ (function () {
2136
2138
  account.environment = env;
2137
2139
  // non AAD scenarios can have empty realm
2138
2140
  account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || Constants.EMPTY_STRING;
2139
- account.oboAssertion = oboAssertion;
2140
2141
  if (idToken) {
2141
2142
  account.idTokenClaims = idToken.claims;
2142
2143
  // How do you account for MSA CID here?
@@ -2157,14 +2158,13 @@ var AccountEntity = /** @class */ (function () {
2157
2158
  * @param authority
2158
2159
  * @param idToken
2159
2160
  */
2160
- AccountEntity.createGenericAccount = function (homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment) {
2161
+ AccountEntity.createGenericAccount = function (homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment) {
2161
2162
  var _a, _b, _c, _d;
2162
2163
  var account = new AccountEntity();
2163
2164
  account.authorityType = (authority && authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
2164
2165
  account.homeAccountId = homeAccountId;
2165
2166
  // non AAD scenarios can have empty realm
2166
2167
  account.realm = Constants.EMPTY_STRING;
2167
- account.oboAssertion = oboAssertion;
2168
2168
  var env = environment || authority && authority.getPreferredCache();
2169
2169
  if (!env) {
2170
2170
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -2412,7 +2412,7 @@ var CacheManager = /** @class */ (function () {
2412
2412
  * @param realm
2413
2413
  */
2414
2414
  CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
2415
- return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING);
2415
+ 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);
2416
2416
  };
2417
2417
  /**
2418
2418
  * retrieve accounts matching all provided filters; if no filter is set, get all accounts
@@ -2421,7 +2421,7 @@ var CacheManager = /** @class */ (function () {
2421
2421
  * @param environment
2422
2422
  * @param realm
2423
2423
  */
2424
- CacheManager.prototype.getAccountsFilteredByInternal = function (homeAccountId, environment, realm) {
2424
+ CacheManager.prototype.getAccountsFilteredByInternal = function (homeAccountId, environment, realm, nativeAccountId) {
2425
2425
  var _this = this;
2426
2426
  var allCacheKeys = this.getKeys();
2427
2427
  var matchingAccounts = {};
@@ -2439,6 +2439,9 @@ var CacheManager = /** @class */ (function () {
2439
2439
  if (!!realm && !_this.matchRealm(entity, realm)) {
2440
2440
  return;
2441
2441
  }
2442
+ if (!!nativeAccountId && !_this.matchNativeAccountId(entity, nativeAccountId)) {
2443
+ return;
2444
+ }
2442
2445
  matchingAccounts[cacheKey] = entity;
2443
2446
  });
2444
2447
  return matchingAccounts;
@@ -2453,7 +2456,7 @@ var CacheManager = /** @class */ (function () {
2453
2456
  * @param target
2454
2457
  */
2455
2458
  CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
2456
- return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.oboAssertion, filter.tokenType, filter.keyId, filter.requestedClaimsHash);
2459
+ return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.userAssertionHash, filter.tokenType, filter.keyId, filter.requestedClaimsHash);
2457
2460
  };
2458
2461
  /**
2459
2462
  * Support function to help match credentials
@@ -2463,10 +2466,10 @@ var CacheManager = /** @class */ (function () {
2463
2466
  * @param clientId
2464
2467
  * @param realm
2465
2468
  * @param target
2466
- * @param oboAssertion
2469
+ * @param userAssertionHash
2467
2470
  * @param tokenType
2468
2471
  */
2469
- CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType, keyId, requestedClaimsHash) {
2472
+ CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, userAssertionHash, tokenType, keyId, requestedClaimsHash) {
2470
2473
  var _this = this;
2471
2474
  var allCacheKeys = this.getKeys();
2472
2475
  var matchingCredentials = {
@@ -2485,7 +2488,7 @@ var CacheManager = /** @class */ (function () {
2485
2488
  if (!entity) {
2486
2489
  return;
2487
2490
  }
2488
- if (!!oboAssertion && !_this.matchOboAssertion(entity, oboAssertion)) {
2491
+ if (!!userAssertionHash && !_this.matchUserAssertionHash(entity, userAssertionHash)) {
2489
2492
  return;
2490
2493
  }
2491
2494
  if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
@@ -2767,6 +2770,26 @@ var CacheManager = /** @class */ (function () {
2767
2770
  var accountKey = AccountEntity.generateAccountCacheKey(account);
2768
2771
  return this.getAccount(accountKey);
2769
2772
  };
2773
+ /**
2774
+ * Retrieve AccountEntity from cache
2775
+ * @param nativeAccountId
2776
+ * @returns AccountEntity or Null
2777
+ */
2778
+ CacheManager.prototype.readAccountFromCacheWithNativeAccountId = function (nativeAccountId) {
2779
+ // fetch account from memory
2780
+ var accountFilter = {
2781
+ nativeAccountId: nativeAccountId
2782
+ };
2783
+ var accountCache = this.getAccountsFilteredBy(accountFilter);
2784
+ var accounts = Object.keys(accountCache).map(function (key) { return accountCache[key]; });
2785
+ if (accounts.length < 1) {
2786
+ return null;
2787
+ }
2788
+ else if (accounts.length > 1) {
2789
+ throw ClientAuthError.createMultipleMatchingAccountsInCacheError();
2790
+ }
2791
+ return accountCache[0];
2792
+ };
2770
2793
  /**
2771
2794
  * Retrieve IdTokenEntity from cache
2772
2795
  * @param clientId
@@ -2816,7 +2839,7 @@ var CacheManager = /** @class */ (function () {
2816
2839
  target: scopes.printScopesLowerCase(),
2817
2840
  tokenType: authScheme,
2818
2841
  keyId: request.sshKid,
2819
- requestedClaimsHash: request.requestedClaimsHash
2842
+ requestedClaimsHash: request.requestedClaimsHash,
2820
2843
  };
2821
2844
  var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
2822
2845
  var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
@@ -2842,7 +2865,7 @@ var CacheManager = /** @class */ (function () {
2842
2865
  environment: account.environment,
2843
2866
  credentialType: exports.CredentialType.REFRESH_TOKEN,
2844
2867
  clientId: clientId,
2845
- familyId: id
2868
+ familyId: id,
2846
2869
  };
2847
2870
  var credentialCache = this.getCredentialsFilteredBy(refreshTokenFilter);
2848
2871
  var refreshTokens = Object.keys(credentialCache.refreshTokens).map(function (key) { return credentialCache.refreshTokens[key]; });
@@ -2894,8 +2917,8 @@ var CacheManager = /** @class */ (function () {
2894
2917
  * @param value
2895
2918
  * @param oboAssertion
2896
2919
  */
2897
- CacheManager.prototype.matchOboAssertion = function (entity, oboAssertion) {
2898
- return !!(entity.oboAssertion && oboAssertion === entity.oboAssertion);
2920
+ CacheManager.prototype.matchUserAssertionHash = function (entity, userAssertionHash) {
2921
+ return !!(entity.userAssertionHash && userAssertionHash === entity.userAssertionHash);
2899
2922
  };
2900
2923
  /**
2901
2924
  * helper to match environment
@@ -2941,6 +2964,15 @@ var CacheManager = /** @class */ (function () {
2941
2964
  CacheManager.prototype.matchRealm = function (entity, realm) {
2942
2965
  return !!(entity.realm && realm === entity.realm);
2943
2966
  };
2967
+ /**
2968
+ * helper to match nativeAccountId
2969
+ * @param entity
2970
+ * @param nativeAccountId
2971
+ * @returns boolean indicating the match result
2972
+ */
2973
+ CacheManager.prototype.matchNativeAccountId = function (entity, nativeAccountId) {
2974
+ return !!(entity.nativeAccountId && nativeAccountId === entity.nativeAccountId);
2975
+ };
2944
2976
  /**
2945
2977
  * Returns true if the target scopes are a subset of the current entity's scopes, false otherwise.
2946
2978
  * @param entity
@@ -3213,7 +3245,7 @@ function buildClientConfiguration(_a) {
3213
3245
  telemetry: __assign(__assign({}, DEFAULT_TELEMETRY_OPTIONS), telemetry),
3214
3246
  serverTelemetryManager: serverTelemetryManager || null,
3215
3247
  persistencePlugin: persistencePlugin || null,
3216
- serializableCache: serializableCache || null
3248
+ serializableCache: serializableCache || null,
3217
3249
  };
3218
3250
  }
3219
3251
  /**
@@ -3221,7 +3253,7 @@ function buildClientConfiguration(_a) {
3221
3253
  * @param authOptions
3222
3254
  */
3223
3255
  function buildAuthOptions(authOptions) {
3224
- return __assign({ clientCapabilities: [], azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS }, authOptions);
3256
+ return __assign({ clientCapabilities: [], azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS, skipAuthorityMetadataCache: false }, authOptions);
3225
3257
  }
3226
3258
 
3227
3259
  /*
@@ -3796,14 +3828,18 @@ var RequestParameterBuilder = /** @class */ (function () {
3796
3828
  * @param clientAssertion
3797
3829
  */
3798
3830
  RequestParameterBuilder.prototype.addClientAssertion = function (clientAssertion) {
3799
- this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION, encodeURIComponent(clientAssertion));
3831
+ if (!StringUtils.isEmpty(clientAssertion)) {
3832
+ this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION, encodeURIComponent(clientAssertion));
3833
+ }
3800
3834
  };
3801
3835
  /**
3802
3836
  * add clientAssertionType for confidential client flows
3803
3837
  * @param clientAssertionType
3804
3838
  */
3805
3839
  RequestParameterBuilder.prototype.addClientAssertionType = function (clientAssertionType) {
3806
- this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION_TYPE, encodeURIComponent(clientAssertionType));
3840
+ if (!StringUtils.isEmpty(clientAssertionType)) {
3841
+ this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION_TYPE, encodeURIComponent(clientAssertionType));
3842
+ }
3807
3843
  };
3808
3844
  /**
3809
3845
  * add OBO assertion for confidential client flows
@@ -3969,7 +4005,7 @@ var IdTokenEntity = /** @class */ (function (_super) {
3969
4005
  * @param clientId
3970
4006
  * @param authority
3971
4007
  */
3972
- IdTokenEntity.createIdTokenEntity = function (homeAccountId, environment, idToken, clientId, tenantId, oboAssertion) {
4008
+ IdTokenEntity.createIdTokenEntity = function (homeAccountId, environment, idToken, clientId, tenantId) {
3973
4009
  var idTokenEntity = new IdTokenEntity();
3974
4010
  idTokenEntity.credentialType = exports.CredentialType.ID_TOKEN;
3975
4011
  idTokenEntity.homeAccountId = homeAccountId;
@@ -3977,7 +4013,6 @@ var IdTokenEntity = /** @class */ (function (_super) {
3977
4013
  idTokenEntity.clientId = clientId;
3978
4014
  idTokenEntity.secret = idToken;
3979
4015
  idTokenEntity.realm = tenantId;
3980
- idTokenEntity.oboAssertion = oboAssertion;
3981
4016
  return idTokenEntity;
3982
4017
  };
3983
4018
  /**
@@ -4092,7 +4127,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
4092
4127
  * @param expiresOn
4093
4128
  * @param extExpiresOn
4094
4129
  */
4095
- AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion, keyId, requestedClaims, requestedClaimsHash) {
4130
+ AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, userAssertionHash, keyId, requestedClaims, requestedClaimsHash) {
4096
4131
  var _a, _b;
4097
4132
  var atEntity = new AccessTokenEntity();
4098
4133
  atEntity.homeAccountId = homeAccountId;
@@ -4113,7 +4148,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
4113
4148
  atEntity.clientId = clientId;
4114
4149
  atEntity.realm = tenantId;
4115
4150
  atEntity.target = scopes;
4116
- atEntity.oboAssertion = oboAssertion;
4151
+ atEntity.userAssertionHash = userAssertionHash;
4117
4152
  atEntity.tokenType = StringUtils.isEmpty(tokenType) ? exports.AuthenticationScheme.BEARER : tokenType;
4118
4153
  if (requestedClaims) {
4119
4154
  atEntity.requestedClaims = requestedClaims;
@@ -4195,14 +4230,14 @@ var RefreshTokenEntity = /** @class */ (function (_super) {
4195
4230
  * @param clientId
4196
4231
  * @param authority
4197
4232
  */
4198
- RefreshTokenEntity.createRefreshTokenEntity = function (homeAccountId, environment, refreshToken, clientId, familyId, oboAssertion) {
4233
+ RefreshTokenEntity.createRefreshTokenEntity = function (homeAccountId, environment, refreshToken, clientId, familyId, userAssertionHash) {
4199
4234
  var rtEntity = new RefreshTokenEntity();
4200
4235
  rtEntity.clientId = clientId;
4201
4236
  rtEntity.credentialType = exports.CredentialType.REFRESH_TOKEN;
4202
4237
  rtEntity.environment = environment;
4203
4238
  rtEntity.homeAccountId = homeAccountId;
4204
4239
  rtEntity.secret = refreshToken;
4205
- rtEntity.oboAssertion = oboAssertion;
4240
+ rtEntity.userAssertionHash = userAssertionHash;
4206
4241
  if (familyId)
4207
4242
  rtEntity.familyId = familyId;
4208
4243
  return rtEntity;
@@ -4251,6 +4286,10 @@ var InteractionRequiredAuthErrorMessage = {
4251
4286
  noTokensFoundError: {
4252
4287
  code: "no_tokens_found",
4253
4288
  desc: "No refresh token found in the cache. Please sign-in."
4289
+ },
4290
+ native_account_unavailable: {
4291
+ code: "native_account_unavailable",
4292
+ desc: "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."
4254
4293
  }
4255
4294
  };
4256
4295
  /**
@@ -4284,6 +4323,13 @@ var InteractionRequiredAuthError = /** @class */ (function (_super) {
4284
4323
  InteractionRequiredAuthError.createNoTokensFoundError = function () {
4285
4324
  return new InteractionRequiredAuthError(InteractionRequiredAuthErrorMessage.noTokensFoundError.code, InteractionRequiredAuthErrorMessage.noTokensFoundError.desc);
4286
4325
  };
4326
+ /**
4327
+ * Creates an error thrown when the native broker returns ACCOUNT_UNAVAILABLE status, indicating that the account was removed and interactive sign-in is required
4328
+ * @returns
4329
+ */
4330
+ InteractionRequiredAuthError.createNativeAccountUnavailableError = function () {
4331
+ return new InteractionRequiredAuthError(InteractionRequiredAuthErrorMessage.native_account_unavailable.code, InteractionRequiredAuthErrorMessage.native_account_unavailable.desc);
4332
+ };
4287
4333
  return InteractionRequiredAuthError;
4288
4334
  }(AuthError));
4289
4335
 
@@ -4831,7 +4877,7 @@ var ResponseHandler = /** @class */ (function () {
4831
4877
  * @param serverTokenResponse
4832
4878
  * @param authority
4833
4879
  */
4834
- ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, oboAssertion, handlingRefreshTokenResponse) {
4880
+ ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, userAssertionHash, handlingRefreshTokenResponse, forceCacheRefreshTokenResponse) {
4835
4881
  return __awaiter(this, void 0, void 0, function () {
4836
4882
  var idTokenObj, requestStateObj, cacheRecord, cacheContext, key, account;
4837
4883
  return __generator(this, function (_a) {
@@ -4853,7 +4899,7 @@ var ResponseHandler = /** @class */ (function () {
4853
4899
  }
4854
4900
  // Add keyId from request to serverTokenResponse if defined
4855
4901
  serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
4856
- cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload);
4902
+ cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, userAssertionHash, authCodePayload);
4857
4903
  _a.label = 1;
4858
4904
  case 1:
4859
4905
  _a.trys.push([1, , 5, 8]);
@@ -4868,14 +4914,15 @@ var ResponseHandler = /** @class */ (function () {
4868
4914
  /*
4869
4915
  * When saving a refreshed tokens to the cache, it is expected that the account that was used is present in the cache.
4870
4916
  * If not present, we should return null, as it's the case that another application called removeAccount in between
4871
- * the calls to getAllAccounts and acquireTokenSilent. We should not overwrite that removal.
4917
+ * the calls to getAllAccounts and acquireTokenSilent. We should not overwrite that removal, unless explicitly flagged by
4918
+ * the developer, as in the case of refresh token flow used in ADAL Node to MSAL Node migration.
4872
4919
  */
4873
- if (handlingRefreshTokenResponse && cacheRecord.account) {
4920
+ if (handlingRefreshTokenResponse && !forceCacheRefreshTokenResponse && cacheRecord.account) {
4874
4921
  key = cacheRecord.account.generateAccountKey();
4875
4922
  account = this.cacheStorage.getAccount(key);
4876
4923
  if (!account) {
4877
4924
  this.logger.warning("Account used to refresh tokens not in persistence, refreshed tokens will not be stored in the cache");
4878
- return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj)];
4925
+ return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, undefined)];
4879
4926
  }
4880
4927
  }
4881
4928
  return [4 /*yield*/, this.cacheStorage.saveCacheRecord(cacheRecord)];
@@ -4901,7 +4948,7 @@ var ResponseHandler = /** @class */ (function () {
4901
4948
  * @param idTokenObj
4902
4949
  * @param authority
4903
4950
  */
4904
- ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload) {
4951
+ ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, userAssertionHash, authCodePayload) {
4905
4952
  var env = authority.getPreferredCache();
4906
4953
  if (StringUtils.isEmpty(env)) {
4907
4954
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -4910,8 +4957,8 @@ var ResponseHandler = /** @class */ (function () {
4910
4957
  var cachedIdToken;
4911
4958
  var cachedAccount;
4912
4959
  if (!StringUtils.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {
4913
- cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING, oboAssertion);
4914
- cachedAccount = this.generateAccountEntity(serverTokenResponse, idTokenObj, authority, oboAssertion, authCodePayload);
4960
+ cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING);
4961
+ cachedAccount = this.generateAccountEntity(serverTokenResponse, idTokenObj, authority, authCodePayload);
4915
4962
  }
4916
4963
  // AccessToken
4917
4964
  var cachedAccessToken = null;
@@ -4929,12 +4976,12 @@ var ResponseHandler = /** @class */ (function () {
4929
4976
  var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
4930
4977
  var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
4931
4978
  // non AAD scenarios can have empty realm
4932
- cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token || Constants.EMPTY_STRING, this.clientId, idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant, responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj, refreshOnSeconds, serverTokenResponse.token_type, oboAssertion, serverTokenResponse.key_id, request.claims, request.requestedClaimsHash);
4979
+ cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token || Constants.EMPTY_STRING, this.clientId, idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant, responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj, refreshOnSeconds, serverTokenResponse.token_type, userAssertionHash, serverTokenResponse.key_id, request.claims, request.requestedClaimsHash);
4933
4980
  }
4934
4981
  // refreshToken
4935
4982
  var cachedRefreshToken = null;
4936
4983
  if (!StringUtils.isEmpty(serverTokenResponse.refresh_token)) {
4937
- cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.refresh_token || Constants.EMPTY_STRING, this.clientId, serverTokenResponse.foci, oboAssertion);
4984
+ cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.refresh_token || Constants.EMPTY_STRING, this.clientId, serverTokenResponse.foci, userAssertionHash);
4938
4985
  }
4939
4986
  // appMetadata
4940
4987
  var cachedAppMetadata = null;
@@ -4949,22 +4996,22 @@ var ResponseHandler = /** @class */ (function () {
4949
4996
  * @param idToken
4950
4997
  * @param authority
4951
4998
  */
4952
- ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, oboAssertion, authCodePayload) {
4999
+ ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, authCodePayload) {
4953
5000
  var authorityType = authority.authorityType;
4954
5001
  var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;
4955
5002
  var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;
4956
5003
  // ADFS does not require client_info in the response
4957
5004
  if (authorityType === exports.AuthorityType.Adfs) {
4958
5005
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
4959
- return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
5006
+ return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
4960
5007
  }
4961
5008
  // This fallback applies to B2C as well as they fall under an AAD account type.
4962
5009
  if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === "AAD") {
4963
5010
  throw ClientAuthError.createClientInfoEmptyError();
4964
5011
  }
4965
5012
  return serverTokenResponse.client_info ?
4966
- AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost) :
4967
- AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
5013
+ AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost) :
5014
+ AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
4968
5015
  };
4969
5016
  /**
4970
5017
  * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
@@ -5139,7 +5186,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5139
5186
  throw ClientConfigurationError.createEmptyLogoutRequestError();
5140
5187
  }
5141
5188
  var queryString = this.createLogoutUrlQueryString(logoutRequest);
5142
- // Construct logout URI.
5189
+ // Construct logout URI
5143
5190
  return UrlString.appendQueryString(this.authority.endSessionEndpoint, queryString);
5144
5191
  };
5145
5192
  /**
@@ -5242,8 +5289,8 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5242
5289
  if (this.config.clientCredentials.clientSecret) {
5243
5290
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
5244
5291
  }
5245
- clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
5246
- if (clientAssertion) {
5292
+ if (this.config.clientCredentials.clientAssertion) {
5293
+ clientAssertion = this.config.clientCredentials.clientAssertion;
5247
5294
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
5248
5295
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
5249
5296
  }
@@ -5710,7 +5757,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5710
5757
  response = _a.sent();
5711
5758
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
5712
5759
  responseHandler.validateTokenResponse(response.body);
5713
- return [2 /*return*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true)];
5760
+ return [2 /*return*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, undefined, true, request.forceCache)];
5714
5761
  }
5715
5762
  });
5716
5763
  });
@@ -5846,8 +5893,8 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5846
5893
  if (this.config.clientCredentials.clientSecret) {
5847
5894
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
5848
5895
  }
5849
- clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
5850
- if (clientAssertion) {
5896
+ if (this.config.clientCredentials.clientAssertion) {
5897
+ clientAssertion = this.config.clientCredentials.clientAssertion;
5851
5898
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
5852
5899
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
5853
5900
  }
@@ -5906,8 +5953,10 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5906
5953
  */
5907
5954
  var ClientCredentialClient = /** @class */ (function (_super) {
5908
5955
  __extends(ClientCredentialClient, _super);
5909
- function ClientCredentialClient(configuration) {
5910
- return _super.call(this, configuration) || this;
5956
+ function ClientCredentialClient(configuration, appTokenProvider) {
5957
+ var _this = _super.call(this, configuration) || this;
5958
+ _this.appTokenProvider = appTokenProvider;
5959
+ return _this;
5911
5960
  }
5912
5961
  /**
5913
5962
  * Public API to acquire a token with ClientCredential Flow for Confidential clients
@@ -5995,10 +6044,30 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5995
6044
  */
5996
6045
  ClientCredentialClient.prototype.executeTokenRequest = function (request, authority) {
5997
6046
  return __awaiter(this, void 0, void 0, function () {
5998
- var requestBody, headers, thumbprint, reqTimestamp, response, responseHandler, tokenResponse;
6047
+ var serverTokenResponse, reqTimestamp, appTokenPropviderParameters, appTokenProviderResult, requestBody, headers, thumbprint, response, responseHandler, tokenResponse;
5999
6048
  return __generator(this, function (_a) {
6000
6049
  switch (_a.label) {
6001
6050
  case 0:
6051
+ if (!this.appTokenProvider) return [3 /*break*/, 2];
6052
+ this.logger.info("Using appTokenProvider extensibility.");
6053
+ appTokenPropviderParameters = {
6054
+ correlationId: request.correlationId,
6055
+ tenantId: this.config.authOptions.authority.tenant,
6056
+ scopes: request.scopes,
6057
+ claims: request.claims,
6058
+ };
6059
+ reqTimestamp = TimeUtils.nowSeconds();
6060
+ return [4 /*yield*/, this.appTokenProvider(appTokenPropviderParameters)];
6061
+ case 1:
6062
+ appTokenProviderResult = _a.sent();
6063
+ serverTokenResponse = {
6064
+ access_token: appTokenProviderResult.accessToken,
6065
+ expires_in: appTokenProviderResult.expiresInSeconds,
6066
+ refresh_in: appTokenProviderResult.refreshInSeconds,
6067
+ token_type: exports.AuthenticationScheme.BEARER
6068
+ };
6069
+ return [3 /*break*/, 4];
6070
+ case 2:
6002
6071
  requestBody = this.createTokenRequestBody(request);
6003
6072
  headers = this.createTokenRequestHeaders();
6004
6073
  thumbprint = {
@@ -6014,12 +6083,15 @@ var ClientCredentialClient = /** @class */ (function (_super) {
6014
6083
  };
6015
6084
  reqTimestamp = TimeUtils.nowSeconds();
6016
6085
  return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
6017
- case 1:
6086
+ case 3:
6018
6087
  response = _a.sent();
6088
+ serverTokenResponse = response.body;
6089
+ _a.label = 4;
6090
+ case 4:
6019
6091
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
6020
- responseHandler.validateTokenResponse(response.body);
6021
- return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request)];
6022
- case 2:
6092
+ responseHandler.validateTokenResponse(serverTokenResponse);
6093
+ return [4 /*yield*/, responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request)];
6094
+ case 5:
6023
6095
  tokenResponse = _a.sent();
6024
6096
  return [2 /*return*/, tokenResponse];
6025
6097
  }
@@ -6078,44 +6150,64 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6078
6150
  */
6079
6151
  OnBehalfOfClient.prototype.acquireToken = function (request) {
6080
6152
  return __awaiter(this, void 0, void 0, function () {
6081
- var cachedAuthenticationResult;
6082
- return __generator(this, function (_a) {
6083
- switch (_a.label) {
6153
+ var _a;
6154
+ return __generator(this, function (_b) {
6155
+ switch (_b.label) {
6084
6156
  case 0:
6085
6157
  this.scopeSet = new ScopeSet(request.scopes || []);
6086
- if (!request.skipCache) return [3 /*break*/, 2];
6087
- return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
6088
- case 1: return [2 /*return*/, _a.sent()];
6089
- case 2: return [4 /*yield*/, this.getCachedAuthenticationResult(request)];
6158
+ // generate the user_assertion_hash for OBOAssertion
6159
+ _a = this;
6160
+ return [4 /*yield*/, this.cryptoUtils.hashString(request.oboAssertion)];
6161
+ case 1:
6162
+ // generate the user_assertion_hash for OBOAssertion
6163
+ _a.userAssertionHash = _b.sent();
6164
+ if (!request.skipCache) return [3 /*break*/, 3];
6165
+ return [4 /*yield*/, this.executeTokenRequest(request, this.authority, this.userAssertionHash)];
6166
+ case 2: return [2 /*return*/, _b.sent()];
6090
6167
  case 3:
6091
- cachedAuthenticationResult = _a.sent();
6092
- if (!cachedAuthenticationResult) return [3 /*break*/, 4];
6093
- return [2 /*return*/, cachedAuthenticationResult];
6094
- case 4: return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
6095
- case 5: return [2 /*return*/, _a.sent()];
6168
+ _b.trys.push([3, 5, , 7]);
6169
+ return [4 /*yield*/, this.getCachedAuthenticationResult(request)];
6170
+ case 4: return [2 /*return*/, _b.sent()];
6171
+ case 5:
6172
+ _b.sent();
6173
+ return [4 /*yield*/, this.executeTokenRequest(request, this.authority, this.userAssertionHash)];
6174
+ case 6:
6175
+ // Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT
6176
+ return [2 /*return*/, _b.sent()];
6177
+ case 7: return [2 /*return*/];
6096
6178
  }
6097
6179
  });
6098
6180
  });
6099
6181
  };
6100
6182
  /**
6101
6183
  * look up cache for tokens
6184
+ * Find idtoken in the cache
6185
+ * Find accessToken based on user assertion and account info in the cache
6186
+ * Please note we are not yet supported OBO tokens refreshed with long lived RT. User will have to send a new assertion if the current access token expires
6187
+ * This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
6102
6188
  * @param request
6103
6189
  */
6104
6190
  OnBehalfOfClient.prototype.getCachedAuthenticationResult = function (request) {
6105
- var _a;
6191
+ var _a, _b;
6106
6192
  return __awaiter(this, void 0, void 0, function () {
6107
6193
  var cachedAccessToken, cachedIdToken, idTokenObject, cachedAccount, localAccountId, accountInfo;
6108
- return __generator(this, function (_b) {
6109
- switch (_b.label) {
6194
+ return __generator(this, function (_c) {
6195
+ switch (_c.label) {
6110
6196
  case 0:
6111
- cachedAccessToken = this.readAccessTokenFromCache();
6112
- if (!cachedAccessToken ||
6113
- TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
6114
- // Update the server telemetry outcome
6115
- (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(!cachedAccessToken ? CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED : CacheOutcome.NO_CACHED_ACCESS_TOKEN);
6116
- return [2 /*return*/, null];
6197
+ cachedAccessToken = this.readAccessTokenFromCacheForOBO(this.config.authOptions.clientId, request);
6198
+ if (!cachedAccessToken) {
6199
+ // Must refresh due to non-existent access_token.
6200
+ (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
6201
+ this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
6202
+ throw ClientAuthError.createRefreshRequiredError();
6117
6203
  }
6118
- cachedIdToken = this.readIdTokenFromCache(request);
6204
+ else if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
6205
+ // Access token expired, will need to renewed
6206
+ (_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
6207
+ this.logger.info("OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within " + this.config.systemOptions.tokenRenewalOffsetSeconds + " seconds.");
6208
+ throw ClientAuthError.createRefreshRequiredError();
6209
+ }
6210
+ cachedIdToken = this.readIdTokenFromCacheForOBO(request, cachedAccessToken.homeAccountId);
6119
6211
  cachedAccount = null;
6120
6212
  if (cachedIdToken) {
6121
6213
  idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);
@@ -6127,7 +6219,11 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6127
6219
  username: Constants.EMPTY_STRING,
6128
6220
  localAccountId: localAccountId || Constants.EMPTY_STRING
6129
6221
  };
6130
- cachedAccount = this.readAccountFromCache(accountInfo);
6222
+ cachedAccount = this.cacheManager.readAccountFromCache(accountInfo);
6223
+ }
6224
+ // increment telemetry cache hit counter
6225
+ if (this.config.serverTelemetryManager) {
6226
+ this.config.serverTelemetryManager.incrementCacheHits();
6131
6227
  }
6132
6228
  return [4 /*yield*/, ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
6133
6229
  account: cachedAccount,
@@ -6136,45 +6232,23 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6136
6232
  refreshToken: null,
6137
6233
  appMetadata: null
6138
6234
  }, true, request, idTokenObject)];
6139
- case 1: return [2 /*return*/, _b.sent()];
6235
+ case 1: return [2 /*return*/, _c.sent()];
6140
6236
  }
6141
6237
  });
6142
6238
  });
6143
6239
  };
6144
6240
  /**
6145
- * read access token from cache TODO: CacheManager API should be used here
6146
- * @param request
6147
- */
6148
- OnBehalfOfClient.prototype.readAccessTokenFromCache = function () {
6149
- var accessTokenFilter = {
6150
- environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
6151
- credentialType: exports.CredentialType.ACCESS_TOKEN,
6152
- clientId: this.config.authOptions.clientId,
6153
- realm: this.authority.tenant,
6154
- target: this.scopeSet.printScopesLowerCase(),
6155
- };
6156
- var credentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);
6157
- var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
6158
- var numAccessTokens = accessTokens.length;
6159
- if (numAccessTokens < 1) {
6160
- return null;
6161
- }
6162
- else if (numAccessTokens > 1) {
6163
- throw ClientAuthError.createMultipleMatchingTokensInCacheError();
6164
- }
6165
- return accessTokens[0];
6166
- };
6167
- /**
6168
- * read idtoken from cache TODO: CacheManager API should be used here instead
6241
+ * read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
6242
+ * Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
6169
6243
  * @param request
6170
6244
  */
6171
- OnBehalfOfClient.prototype.readIdTokenFromCache = function (request) {
6245
+ OnBehalfOfClient.prototype.readIdTokenFromCacheForOBO = function (request, atHomeAccountId) {
6172
6246
  var idTokenFilter = {
6247
+ homeAccountId: atHomeAccountId,
6173
6248
  environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
6174
6249
  credentialType: exports.CredentialType.ID_TOKEN,
6175
6250
  clientId: this.config.authOptions.clientId,
6176
- realm: this.authority.tenant,
6177
- oboAssertion: request.oboAssertion
6251
+ realm: this.authority.tenant
6178
6252
  };
6179
6253
  var credentialCache = this.cacheManager.getCredentialsFilteredBy(idTokenFilter);
6180
6254
  var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
@@ -6185,18 +6259,44 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6185
6259
  return idTokens[0];
6186
6260
  };
6187
6261
  /**
6188
- * read account from cache, TODO: CacheManager API should be used here instead
6189
- * @param account
6262
+ * Fetches the cached access token based on incoming assertion
6263
+ * @param clientId
6264
+ * @param request
6265
+ * @param userAssertionHash
6190
6266
  */
6191
- OnBehalfOfClient.prototype.readAccountFromCache = function (account) {
6192
- return this.cacheManager.readAccountFromCache(account);
6267
+ OnBehalfOfClient.prototype.readAccessTokenFromCacheForOBO = function (clientId, request) {
6268
+ var authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
6269
+ /*
6270
+ * Distinguish between Bearer and PoP/SSH token cache types
6271
+ * Cast to lowercase to handle "bearer" from ADFS
6272
+ */
6273
+ var credentialType = (authScheme && authScheme.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : exports.CredentialType.ACCESS_TOKEN;
6274
+ var accessTokenFilter = {
6275
+ credentialType: credentialType,
6276
+ clientId: clientId,
6277
+ target: this.scopeSet.printScopesLowerCase(),
6278
+ tokenType: authScheme,
6279
+ keyId: request.sshKid,
6280
+ requestedClaimsHash: request.requestedClaimsHash,
6281
+ userAssertionHash: this.userAssertionHash
6282
+ };
6283
+ var credentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);
6284
+ var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
6285
+ var numAccessTokens = accessTokens.length;
6286
+ if (numAccessTokens < 1) {
6287
+ return null;
6288
+ }
6289
+ else if (numAccessTokens > 1) {
6290
+ throw ClientAuthError.createMultipleMatchingTokensInCacheError();
6291
+ }
6292
+ return accessTokens[0];
6193
6293
  };
6194
6294
  /**
6195
6295
  * Make a network call to the server requesting credentials
6196
6296
  * @param request
6197
6297
  * @param authority
6198
6298
  */
6199
- OnBehalfOfClient.prototype.executeTokenRequest = function (request, authority) {
6299
+ OnBehalfOfClient.prototype.executeTokenRequest = function (request, authority, userAssertionHash) {
6200
6300
  return __awaiter(this, void 0, void 0, function () {
6201
6301
  var requestBody, headers, thumbprint, reqTimestamp, response, responseHandler, tokenResponse;
6202
6302
  return __generator(this, function (_a) {
@@ -6221,7 +6321,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6221
6321
  response = _a.sent();
6222
6322
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
6223
6323
  responseHandler.validateTokenResponse(response.body);
6224
- return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request)];
6324
+ return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, userAssertionHash)];
6225
6325
  case 2:
6226
6326
  tokenResponse = _a.sent();
6227
6327
  return [2 /*return*/, tokenResponse];
@@ -6252,9 +6352,8 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6252
6352
  if (this.config.clientCredentials.clientSecret) {
6253
6353
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
6254
6354
  }
6255
- // Use clientAssertion from request, fallback to client assertion in base configuration
6256
- var clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
6257
- if (clientAssertion) {
6355
+ if (this.config.clientCredentials.clientAssertion) {
6356
+ var clientAssertion = this.config.clientCredentials.clientAssertion;
6258
6357
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
6259
6358
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
6260
6359
  }
@@ -6468,9 +6567,8 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6468
6567
  if (this.config.clientCredentials.clientSecret) {
6469
6568
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
6470
6569
  }
6471
- // Use clientAssertion from request, fallback to client assertion in base configuration
6472
- var clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
6473
- if (clientAssertion) {
6570
+ if (this.config.clientCredentials.clientAssertion) {
6571
+ var clientAssertion = this.config.clientCredentials.clientAssertion;
6474
6572
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
6475
6573
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
6476
6574
  }
@@ -6492,9 +6590,18 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6492
6590
  function isOpenIdConfigResponse(response) {
6493
6591
  return (response.hasOwnProperty("authorization_endpoint") &&
6494
6592
  response.hasOwnProperty("token_endpoint") &&
6495
- response.hasOwnProperty("issuer"));
6593
+ response.hasOwnProperty("issuer") &&
6594
+ response.hasOwnProperty("jwks_uri"));
6496
6595
  }
6497
6596
 
6597
+ /*
6598
+ * Copyright (c) Microsoft Corporation. All rights reserved.
6599
+ * Licensed under the MIT License.
6600
+ */
6601
+ var rawMetdataJSON = { "endpointMetadata": { "https://login.microsoftonline.com/common/": { "token_endpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.microsoftonline.com/common/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.microsoftonline.com/{tenantid}/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://graph.microsoft.com/oidc/userinfo", "authorization_endpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.microsoftonline.com/common/kerberos", "tenant_region_scope": null, "cloud_instance_name": "microsoftonline.com", "cloud_graph_host_name": "graph.windows.net", "msgraph_host": "graph.microsoft.com", "rbac_url": "https://pas.windows.net" }, "https://login.chinacloudapi.cn/common/": { "token_endpoint": "https://login.chinacloudapi.cn/common/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.chinacloudapi.cn/common/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.partner.microsoftonline.cn/{tenantid}/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://microsoftgraph.chinacloudapi.cn/oidc/userinfo", "authorization_endpoint": "https://login.chinacloudapi.cn/common/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.chinacloudapi.cn/common/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.chinacloudapi.cn/common/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.chinacloudapi.cn/common/kerberos", "tenant_region_scope": null, "cloud_instance_name": "partner.microsoftonline.cn", "cloud_graph_host_name": "graph.chinacloudapi.cn", "msgraph_host": "microsoftgraph.chinacloudapi.cn", "rbac_url": "https://pas.chinacloudapi.cn" }, "https://login.microsoftonline.us/common/": { "token_endpoint": "https://login.microsoftonline.us/common/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.microsoftonline.us/common/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.microsoftonline.us/{tenantid}/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://graph.microsoft.com/oidc/userinfo", "authorization_endpoint": "https://login.microsoftonline.us/common/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.microsoftonline.us/common/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.microsoftonline.us/common/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.microsoftonline.us/common/kerberos", "tenant_region_scope": null, "cloud_instance_name": "microsoftonline.us", "cloud_graph_host_name": "graph.windows.net", "msgraph_host": "graph.microsoft.com", "rbac_url": "https://pasff.usgovcloudapi.net" }, "https://login.microsoftonline.com/consumers/": { "token_endpoint": "https://login.microsoftonline.com/consumers/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.microsoftonline.com/consumers/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://graph.microsoft.com/oidc/userinfo", "authorization_endpoint": "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.microsoftonline.com/consumers/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.microsoftonline.com/consumers/kerberos", "tenant_region_scope": null, "cloud_instance_name": "microsoftonline.com", "cloud_graph_host_name": "graph.windows.net", "msgraph_host": "graph.microsoft.com", "rbac_url": "https://pas.windows.net" }, "https://login.chinacloudapi.cn/consumers/": { "token_endpoint": "https://login.chinacloudapi.cn/consumers/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.chinacloudapi.cn/consumers/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.partner.microsoftonline.cn/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://microsoftgraph.chinacloudapi.cn/oidc/userinfo", "authorization_endpoint": "https://login.chinacloudapi.cn/consumers/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.chinacloudapi.cn/consumers/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.chinacloudapi.cn/consumers/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.chinacloudapi.cn/consumers/kerberos", "tenant_region_scope": null, "cloud_instance_name": "partner.microsoftonline.cn", "cloud_graph_host_name": "graph.chinacloudapi.cn", "msgraph_host": "microsoftgraph.chinacloudapi.cn", "rbac_url": "https://pas.chinacloudapi.cn" }, "https://login.microsoftonline.us/consumers/": { "token_endpoint": "https://login.microsoftonline.us/consumers/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.microsoftonline.us/consumers/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.microsoftonline.us/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://graph.microsoft.com/oidc/userinfo", "authorization_endpoint": "https://login.microsoftonline.us/consumers/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.microsoftonline.us/consumers/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.microsoftonline.us/consumers/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.microsoftonline.us/consumers/kerberos", "tenant_region_scope": null, "cloud_instance_name": "microsoftonline.us", "cloud_graph_host_name": "graph.windows.net", "msgraph_host": "graph.microsoft.com", "rbac_url": "https://pasff.usgovcloudapi.net" }, "https://login.microsoftonline.com/organizations/": { "token_endpoint": "https://login.microsoftonline.com/organizations/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.microsoftonline.com/organizations/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.microsoftonline.com/{tenantid}/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://graph.microsoft.com/oidc/userinfo", "authorization_endpoint": "https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.microsoftonline.com/organizations/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.microsoftonline.com/organizations/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.microsoftonline.com/organizations/kerberos", "tenant_region_scope": null, "cloud_instance_name": "microsoftonline.com", "cloud_graph_host_name": "graph.windows.net", "msgraph_host": "graph.microsoft.com", "rbac_url": "https://pas.windows.net" }, "https://login.chinacloudapi.cn/organizations/": { "token_endpoint": "https://login.chinacloudapi.cn/organizations/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.chinacloudapi.cn/organizations/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.partner.microsoftonline.cn/{tenantid}/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://microsoftgraph.chinacloudapi.cn/oidc/userinfo", "authorization_endpoint": "https://login.chinacloudapi.cn/organizations/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.chinacloudapi.cn/organizations/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.chinacloudapi.cn/organizations/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.chinacloudapi.cn/organizations/kerberos", "tenant_region_scope": null, "cloud_instance_name": "partner.microsoftonline.cn", "cloud_graph_host_name": "graph.chinacloudapi.cn", "msgraph_host": "microsoftgraph.chinacloudapi.cn", "rbac_url": "https://pas.chinacloudapi.cn" }, "https://login.microsoftonline.us/organizations/": { "token_endpoint": "https://login.microsoftonline.us/organizations/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.microsoftonline.us/organizations/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.microsoftonline.us/{tenantid}/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://graph.microsoft.com/oidc/userinfo", "authorization_endpoint": "https://login.microsoftonline.us/organizations/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.microsoftonline.us/organizations/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.microsoftonline.us/organizations/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.microsoftonline.us/organizations/kerberos", "tenant_region_scope": null, "cloud_instance_name": "microsoftonline.us", "cloud_graph_host_name": "graph.windows.net", "msgraph_host": "graph.microsoft.com", "rbac_url": "https://pasff.usgovcloudapi.net" } }, "instanceDiscoveryMetadata": { "https://login.microsoftonline.com/common/": { "tenant_discovery_endpoint": "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] }, "https://login.chinacloudapi.cn/common/": { "tenant_discovery_endpoint": "https://login.chinacloudapi.cn/common/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] }, "https://login.microsoftonline.us/common/": { "tenant_discovery_endpoint": "https://login.microsoftonline.us/common/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] }, "https://login.microsoftonline.com/consumers/": { "tenant_discovery_endpoint": "https://login.microsoftonline.com/consumers/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] }, "https://login.chinacloudapi.cn/consumers/": { "tenant_discovery_endpoint": "https://login.chinacloudapi.cn/consumers/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] }, "https://login.microsoftonline.us/consumers/": { "tenant_discovery_endpoint": "https://login.microsoftonline.us/consumers/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] }, "https://login.microsoftonline.com/organizations/": { "tenant_discovery_endpoint": "https://login.microsoftonline.com/organizations/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] }, "https://login.chinacloudapi.cn/organizations/": { "tenant_discovery_endpoint": "https://login.chinacloudapi.cn/organizations/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] }, "https://login.microsoftonline.us/organizations/": { "tenant_discovery_endpoint": "https://login.microsoftonline.us/organizations/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] } } };
6602
+ var EndpointMetadata = rawMetdataJSON.endpointMetadata;
6603
+ var InstanceDiscoveryMetadata = rawMetdataJSON.instanceDiscoveryMetadata;
6604
+
6498
6605
  /*
6499
6606
  * Copyright (c) Microsoft Corporation. All rights reserved.
6500
6607
  * Licensed under the MIT License.
@@ -6538,6 +6645,7 @@ var AuthorityMetadataEntity = /** @class */ (function () {
6538
6645
  this.end_session_endpoint = metadata.end_session_endpoint;
6539
6646
  this.issuer = metadata.issuer;
6540
6647
  this.endpointsFromNetwork = fromNetwork;
6648
+ this.jwks_uri = metadata.jwks_uri;
6541
6649
  };
6542
6650
  /**
6543
6651
  * Save the authority that was used to create this cache entry
@@ -6576,7 +6684,8 @@ var AuthorityMetadataEntity = /** @class */ (function () {
6576
6684
  entity.hasOwnProperty("issuer") &&
6577
6685
  entity.hasOwnProperty("aliasesFromNetwork") &&
6578
6686
  entity.hasOwnProperty("endpointsFromNetwork") &&
6579
- entity.hasOwnProperty("expiresAt"));
6687
+ entity.hasOwnProperty("expiresAt") &&
6688
+ entity.hasOwnProperty("jwks_uri"));
6580
6689
  };
6581
6690
  return AuthorityMetadataEntity;
6582
6691
  }());
@@ -6893,6 +7002,22 @@ var Authority = /** @class */ (function () {
6893
7002
  enumerable: false,
6894
7003
  configurable: true
6895
7004
  });
7005
+ Object.defineProperty(Authority.prototype, "jwksUri", {
7006
+ /**
7007
+ * Jwks_uri for token signing keys
7008
+ */
7009
+ get: function () {
7010
+ if (this.discoveryComplete()) {
7011
+ var endpoint = this.replacePath(this.metadata.jwks_uri);
7012
+ return this.replaceTenant(endpoint);
7013
+ }
7014
+ else {
7015
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
7016
+ }
7017
+ },
7018
+ enumerable: false,
7019
+ configurable: true
7020
+ });
6896
7021
  /**
6897
7022
  * Replaces tenant in url path with current tenant. Defaults to common.
6898
7023
  * @param urlString
@@ -6976,11 +7101,11 @@ var Authority = /** @class */ (function () {
6976
7101
  * @param metadataEntity
6977
7102
  */
6978
7103
  Authority.prototype.updateEndpointMetadata = function (metadataEntity) {
6979
- var _a;
7104
+ var _a, _b;
6980
7105
  return __awaiter(this, void 0, void 0, function () {
6981
- var metadata, autodetectedRegionName, azureRegion;
6982
- return __generator(this, function (_b) {
6983
- switch (_b.label) {
7106
+ var metadata, harcodedMetadata;
7107
+ return __generator(this, function (_c) {
7108
+ switch (_c.label) {
6984
7109
  case 0:
6985
7110
  metadata = this.getEndpointMetadataFromConfig();
6986
7111
  if (metadata) {
@@ -6991,41 +7116,30 @@ var Authority = /** @class */ (function () {
6991
7116
  // No need to update
6992
7117
  return [2 /*return*/, AuthorityMetadataSource.CACHE];
6993
7118
  }
7119
+ harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
6994
7120
  return [4 /*yield*/, this.getEndpointMetadataFromNetwork()];
6995
7121
  case 1:
6996
- metadata = _b.sent();
7122
+ metadata = _c.sent();
6997
7123
  if (!metadata) return [3 /*break*/, 4];
6998
7124
  if (!((_a = this.authorityOptions.azureRegionConfiguration) === null || _a === void 0 ? void 0 : _a.azureRegion)) return [3 /*break*/, 3];
6999
- return [4 /*yield*/, this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration.environmentRegion, this.regionDiscoveryMetadata, this.proxyUrl)];
7125
+ return [4 /*yield*/, this.updateMetadataWithRegionalInformation(metadata)];
7000
7126
  case 2:
7001
- autodetectedRegionName = _b.sent();
7002
- azureRegion = this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
7003
- ? autodetectedRegionName
7004
- : this.authorityOptions.azureRegionConfiguration.azureRegion;
7005
- if (this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
7006
- this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName ?
7007
- RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL :
7008
- RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
7009
- }
7010
- else {
7011
- if (autodetectedRegionName) {
7012
- this.regionDiscoveryMetadata.region_outcome = (this.authorityOptions.azureRegionConfiguration.azureRegion === autodetectedRegionName) ?
7013
- RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED :
7014
- RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;
7015
- }
7016
- else {
7017
- this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7018
- }
7019
- }
7020
- if (azureRegion) {
7021
- this.regionDiscoveryMetadata.region_used = azureRegion;
7022
- metadata = Authority.replaceWithRegionalInformation(metadata, azureRegion);
7023
- }
7024
- _b.label = 3;
7127
+ metadata = _c.sent();
7128
+ _c.label = 3;
7025
7129
  case 3:
7026
7130
  metadataEntity.updateEndpointMetadata(metadata, true);
7027
7131
  return [2 /*return*/, AuthorityMetadataSource.NETWORK];
7028
- case 4: throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
7132
+ case 4:
7133
+ if (!(harcodedMetadata && !this.authorityOptions.skipAuthorityMetadataCache)) return [3 /*break*/, 7];
7134
+ if (!((_b = this.authorityOptions.azureRegionConfiguration) === null || _b === void 0 ? void 0 : _b.azureRegion)) return [3 /*break*/, 6];
7135
+ return [4 /*yield*/, this.updateMetadataWithRegionalInformation(harcodedMetadata)];
7136
+ case 5:
7137
+ harcodedMetadata = _c.sent();
7138
+ _c.label = 6;
7139
+ case 6:
7140
+ metadataEntity.updateEndpointMetadata(harcodedMetadata, false);
7141
+ return [2 /*return*/, AuthorityMetadataSource.HARDCODED_VALUES];
7142
+ case 7: throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
7029
7143
  }
7030
7144
  });
7031
7145
  });
@@ -7056,6 +7170,8 @@ var Authority = /** @class */ (function () {
7056
7170
  };
7057
7171
  /**
7058
7172
  * Gets OAuth endpoints from the given OpenID configuration endpoint.
7173
+ *
7174
+ * @param hasHardcodedMetadata boolean
7059
7175
  */
7060
7176
  Authority.prototype.getEndpointMetadataFromNetwork = function () {
7061
7177
  return __awaiter(this, void 0, void 0, function () {
@@ -7082,6 +7198,54 @@ var Authority = /** @class */ (function () {
7082
7198
  });
7083
7199
  });
7084
7200
  };
7201
+ /**
7202
+ * Get OAuth endpoints for common authorities.
7203
+ */
7204
+ Authority.prototype.getEndpointMetadataFromHardcodedValues = function () {
7205
+ if (this.canonicalAuthority in EndpointMetadata) {
7206
+ return EndpointMetadata[this.canonicalAuthority];
7207
+ }
7208
+ return null;
7209
+ };
7210
+ /**
7211
+ * Update the retrieved metadata with regional information.
7212
+ */
7213
+ Authority.prototype.updateMetadataWithRegionalInformation = function (metadata) {
7214
+ var _a, _b, _c, _d, _e;
7215
+ return __awaiter(this, void 0, void 0, function () {
7216
+ var autodetectedRegionName, azureRegion;
7217
+ return __generator(this, function (_f) {
7218
+ switch (_f.label) {
7219
+ case 0: return [4 /*yield*/, this.regionDiscovery.detectRegion((_a = this.authorityOptions.azureRegionConfiguration) === null || _a === void 0 ? void 0 : _a.environmentRegion, this.regionDiscoveryMetadata, this.proxyUrl)];
7220
+ case 1:
7221
+ autodetectedRegionName = _f.sent();
7222
+ azureRegion = ((_b = this.authorityOptions.azureRegionConfiguration) === null || _b === void 0 ? void 0 : _b.azureRegion) === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
7223
+ ? autodetectedRegionName
7224
+ : (_c = this.authorityOptions.azureRegionConfiguration) === null || _c === void 0 ? void 0 : _c.azureRegion;
7225
+ if (((_d = this.authorityOptions.azureRegionConfiguration) === null || _d === void 0 ? void 0 : _d.azureRegion) === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
7226
+ this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName ?
7227
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL :
7228
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
7229
+ }
7230
+ else {
7231
+ if (autodetectedRegionName) {
7232
+ this.regionDiscoveryMetadata.region_outcome = (((_e = this.authorityOptions.azureRegionConfiguration) === null || _e === void 0 ? void 0 : _e.azureRegion) === autodetectedRegionName) ?
7233
+ RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED :
7234
+ RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;
7235
+ }
7236
+ else {
7237
+ this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7238
+ }
7239
+ }
7240
+ if (azureRegion) {
7241
+ this.regionDiscoveryMetadata.region_used = azureRegion;
7242
+ return [2 /*return*/, Authority.replaceWithRegionalInformation(metadata, azureRegion)];
7243
+ }
7244
+ return [2 /*return*/, metadata];
7245
+ }
7246
+ });
7247
+ });
7248
+ };
7085
7249
  /**
7086
7250
  * Updates the AuthorityMetadataEntity with new aliases, preferred_network and preferred_cache and returns where the information was retrived from
7087
7251
  * @param cachedMetadata
@@ -7089,7 +7253,7 @@ var Authority = /** @class */ (function () {
7089
7253
  */
7090
7254
  Authority.prototype.updateCloudDiscoveryMetadata = function (metadataEntity) {
7091
7255
  return __awaiter(this, void 0, void 0, function () {
7092
- var metadata;
7256
+ var metadata, harcodedMetadata;
7093
7257
  return __generator(this, function (_a) {
7094
7258
  switch (_a.label) {
7095
7259
  case 0:
@@ -7103,6 +7267,7 @@ var Authority = /** @class */ (function () {
7103
7267
  // No need to update
7104
7268
  return [2 /*return*/, AuthorityMetadataSource.CACHE];
7105
7269
  }
7270
+ harcodedMetadata = this.getCloudDiscoveryMetadataFromHarcodedValues();
7106
7271
  return [4 /*yield*/, this.getCloudDiscoveryMetadataFromNetwork()];
7107
7272
  case 1:
7108
7273
  metadata = _a.sent();
@@ -7110,6 +7275,10 @@ var Authority = /** @class */ (function () {
7110
7275
  metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
7111
7276
  return [2 /*return*/, AuthorityMetadataSource.NETWORK];
7112
7277
  }
7278
+ if (harcodedMetadata && !this.options.skipAuthorityMetadataCache) {
7279
+ metadataEntity.updateCloudDiscoveryMetadata(harcodedMetadata, false);
7280
+ return [2 /*return*/, AuthorityMetadataSource.HARDCODED_VALUES];
7281
+ }
7113
7282
  else {
7114
7283
  // Metadata could not be obtained from config, cache or network
7115
7284
  throw ClientConfigurationError.createUntrustedAuthorityError();
@@ -7143,7 +7312,8 @@ var Authority = /** @class */ (function () {
7143
7312
  };
7144
7313
  /**
7145
7314
  * Called to get metadata from network if CloudDiscoveryMetadata was not populated by config
7146
- * @param networkInterface
7315
+ *
7316
+ * @param hasHardcodedMetadata boolean
7147
7317
  */
7148
7318
  Authority.prototype.getCloudDiscoveryMetadataFromNetwork = function () {
7149
7319
  return __awaiter(this, void 0, void 0, function () {
@@ -7163,7 +7333,9 @@ var Authority = /** @class */ (function () {
7163
7333
  return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint, options)];
7164
7334
  case 2:
7165
7335
  response = _a.sent();
7166
- metadata = isCloudInstanceDiscoveryResponse(response.body) ? response.body.metadata : [];
7336
+ metadata = isCloudInstanceDiscoveryResponse(response.body)
7337
+ ? response.body.metadata
7338
+ : [];
7167
7339
  if (metadata.length === 0) {
7168
7340
  // If no metadata is returned, authority is untrusted
7169
7341
  return [2 /*return*/, null];
@@ -7183,6 +7355,15 @@ var Authority = /** @class */ (function () {
7183
7355
  });
7184
7356
  });
7185
7357
  };
7358
+ /**
7359
+ * Get cloud discovery metadata for common authorities
7360
+ */
7361
+ Authority.prototype.getCloudDiscoveryMetadataFromHarcodedValues = function () {
7362
+ if (this.canonicalAuthority in InstanceDiscoveryMetadata) {
7363
+ return InstanceDiscoveryMetadata[this.canonicalAuthority];
7364
+ }
7365
+ return null;
7366
+ };
7186
7367
  /**
7187
7368
  * Helper function to determine if this host is included in the knownAuthorities config option
7188
7369
  */
@@ -7807,6 +7988,19 @@ exports.PerformanceEvents = void 0;
7807
7988
  * Used to acquire a token from Native component when native brokering is enabled.
7808
7989
  */
7809
7990
  PerformanceEvents["NativeInteractionClientAcquireToken"] = "nativeInteractionClientAcquireToken";
7991
+ /**
7992
+ * Used to measure the time taken for completing embedded-broker handshake (PW-Broker).
7993
+ */
7994
+ PerformanceEvents["BrokerHandhshake"] = "brokerHandshake";
7995
+ /**
7996
+ * acquireTokenByRefreshToken API in BrokerClientApplication (PW-Broker) .
7997
+ */
7998
+ PerformanceEvents["AcquireTokenByRefreshTokenInBroker"] = "acquireTokenByRefreshTokenInBroker";
7999
+ /**
8000
+ * acquireToken API in BrokerClientApplication.
8001
+ * Used to acquire a token on behalf of the embedded application (PW-Broker).
8002
+ */
8003
+ PerformanceEvents["AcquireTokenByBroker"] = "acquireTokenByBroker";
7810
8004
  })(exports.PerformanceEvents || (exports.PerformanceEvents = {}));
7811
8005
  /**
7812
8006
  * State of the performance event.
@@ -7877,7 +8071,7 @@ var PerformanceClient = /** @class */ (function () {
7877
8071
  clientId: this.clientId,
7878
8072
  name: measureName,
7879
8073
  startTimeMs: Date.now(),
7880
- correlationId: eventCorrelationId
8074
+ correlationId: eventCorrelationId,
7881
8075
  };
7882
8076
  // Store in progress events so they can be discarded if not ended properly
7883
8077
  this.cacheEventByCorrelationId(inProgressEvent);
@@ -8022,6 +8216,12 @@ var PerformanceClient = /** @class */ (function () {
8022
8216
  else {
8023
8217
  _this.logger.verbose("PerformanceClient: Submeasurement for " + measureName + " already exists for " + current.name + ", ignoring", correlationId);
8024
8218
  }
8219
+ if (current.accessTokenSize) {
8220
+ previous.accessTokenSize = current.accessTokenSize;
8221
+ }
8222
+ if (current.idTokenSize) {
8223
+ previous.idTokenSize = current.idTokenSize;
8224
+ }
8025
8225
  }
8026
8226
  return previous;
8027
8227
  }, topLevelEvent);