@azure/msal-common 6.3.0 → 7.1.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 (151) hide show
  1. package/dist/_virtual/_tslib.js +1 -1
  2. package/dist/account/AuthToken.js +1 -1
  3. package/dist/account/CcsCredential.js +1 -1
  4. package/dist/account/ClientCredentials.d.ts +15 -0
  5. package/dist/account/ClientCredentials.d.ts.map +1 -0
  6. package/dist/account/ClientInfo.js +1 -1
  7. package/dist/account/TokenClaims.d.ts +1 -1
  8. package/dist/account/TokenClaims.d.ts.map +1 -1
  9. package/dist/authority/Authority.d.ts +20 -1
  10. package/dist/authority/Authority.d.ts.map +1 -1
  11. package/dist/authority/Authority.js +108 -35
  12. package/dist/authority/Authority.js.map +1 -1
  13. package/dist/authority/AuthorityFactory.js +1 -1
  14. package/dist/authority/AuthorityMetadata.d.ts +623 -0
  15. package/dist/authority/AuthorityMetadata.d.ts.map +1 -0
  16. package/dist/authority/AuthorityMetadata.js +12 -0
  17. package/dist/authority/AuthorityMetadata.js.map +1 -0
  18. package/dist/authority/AuthorityOptions.d.ts +1 -0
  19. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  20. package/dist/authority/AuthorityOptions.js +1 -1
  21. package/dist/authority/AuthorityOptions.js.map +1 -1
  22. package/dist/authority/AuthorityType.js +1 -1
  23. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  24. package/dist/authority/OpenIdConfigResponse.d.ts +1 -0
  25. package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -1
  26. package/dist/authority/OpenIdConfigResponse.js +3 -2
  27. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  28. package/dist/authority/ProtocolMode.js +1 -1
  29. package/dist/authority/RegionDiscovery.js +1 -1
  30. package/dist/cache/CacheManager.d.ts +2 -2
  31. package/dist/cache/CacheManager.d.ts.map +1 -1
  32. package/dist/cache/CacheManager.js +9 -9
  33. package/dist/cache/CacheManager.js.map +1 -1
  34. package/dist/cache/entities/AccessTokenEntity.d.ts +1 -1
  35. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  36. package/dist/cache/entities/AccessTokenEntity.js +3 -3
  37. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  38. package/dist/cache/entities/AccountEntity.d.ts +2 -4
  39. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  40. package/dist/cache/entities/AccountEntity.js +3 -6
  41. package/dist/cache/entities/AccountEntity.js.map +1 -1
  42. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  43. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -0
  44. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  45. package/dist/cache/entities/AuthorityMetadataEntity.js +4 -2
  46. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  47. package/dist/cache/entities/CacheRecord.js +1 -1
  48. package/dist/cache/entities/CredentialEntity.d.ts +2 -2
  49. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  50. package/dist/cache/entities/CredentialEntity.js +2 -2
  51. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  52. package/dist/cache/entities/IdTokenEntity.d.ts +1 -1
  53. package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
  54. package/dist/cache/entities/IdTokenEntity.js +2 -3
  55. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  56. package/dist/cache/entities/RefreshTokenEntity.d.ts +1 -1
  57. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  58. package/dist/cache/entities/RefreshTokenEntity.js +3 -3
  59. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  60. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  61. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  62. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  63. package/dist/cache/utils/CacheTypes.d.ts +1 -1
  64. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  65. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  66. package/dist/client/AuthorizationCodeClient.js +12 -14
  67. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  68. package/dist/client/BaseClient.js +1 -1
  69. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  70. package/dist/client/ClientCredentialClient.js +4 -3
  71. package/dist/client/ClientCredentialClient.js.map +1 -1
  72. package/dist/client/DeviceCodeClient.js +1 -1
  73. package/dist/client/OnBehalfOfClient.d.ts +12 -9
  74. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  75. package/dist/client/OnBehalfOfClient.js +87 -59
  76. package/dist/client/OnBehalfOfClient.js.map +1 -1
  77. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  78. package/dist/client/RefreshTokenClient.js +5 -4
  79. package/dist/client/RefreshTokenClient.js.map +1 -1
  80. package/dist/client/SilentFlowClient.js +1 -1
  81. package/dist/client/UsernamePasswordClient.js +1 -1
  82. package/dist/config/ClientConfiguration.d.ts +3 -10
  83. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  84. package/dist/config/ClientConfiguration.js +2 -2
  85. package/dist/config/ClientConfiguration.js.map +1 -1
  86. package/dist/crypto/ICrypto.js +1 -1
  87. package/dist/crypto/JoseHeader.d.ts +22 -0
  88. package/dist/crypto/JoseHeader.d.ts.map +1 -0
  89. package/dist/crypto/JoseHeader.js +45 -0
  90. package/dist/crypto/JoseHeader.js.map +1 -0
  91. package/dist/crypto/PopTokenGenerator.d.ts +9 -9
  92. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  93. package/dist/crypto/PopTokenGenerator.js +19 -31
  94. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  95. package/dist/error/AuthError.js +1 -1
  96. package/dist/error/ClientAuthError.d.ts +8 -0
  97. package/dist/error/ClientAuthError.d.ts.map +1 -1
  98. package/dist/error/ClientAuthError.js +11 -1
  99. package/dist/error/ClientAuthError.js.map +1 -1
  100. package/dist/error/ClientConfigurationError.js +1 -1
  101. package/dist/error/InteractionRequiredAuthError.d.ts +9 -0
  102. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  103. package/dist/error/InteractionRequiredAuthError.js +12 -1
  104. package/dist/error/InteractionRequiredAuthError.js.map +1 -1
  105. package/dist/error/JoseHeaderError.d.ts +29 -0
  106. package/dist/error/JoseHeaderError.d.ts.map +1 -0
  107. package/dist/error/JoseHeaderError.js +50 -0
  108. package/dist/error/JoseHeaderError.js.map +1 -0
  109. package/dist/error/ServerError.js +1 -1
  110. package/dist/index.cjs.js +399 -185
  111. package/dist/index.cjs.js.map +1 -1
  112. package/dist/index.d.ts +1 -0
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +2 -1
  115. package/dist/index.js.map +1 -1
  116. package/dist/logger/Logger.js +1 -1
  117. package/dist/network/INetworkModule.js +1 -1
  118. package/dist/network/NetworkManager.js +1 -1
  119. package/dist/network/ThrottlingUtils.js +1 -1
  120. package/dist/packageMetadata.d.ts +1 -1
  121. package/dist/packageMetadata.js +2 -2
  122. package/dist/packageMetadata.js.map +1 -1
  123. package/dist/request/AuthenticationHeaderParser.js +1 -1
  124. package/dist/request/BaseAuthRequest.d.ts +2 -2
  125. package/dist/request/CommonClientCredentialRequest.d.ts +2 -0
  126. package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
  127. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  128. package/dist/request/RequestParameterBuilder.js +9 -5
  129. package/dist/request/RequestParameterBuilder.js.map +1 -1
  130. package/dist/request/RequestValidator.js +1 -1
  131. package/dist/request/ScopeSet.js +1 -1
  132. package/dist/response/ResponseHandler.d.ts +1 -1
  133. package/dist/response/ResponseHandler.d.ts.map +1 -1
  134. package/dist/response/ResponseHandler.js +23 -19
  135. package/dist/response/ResponseHandler.js.map +1 -1
  136. package/dist/telemetry/performance/PerformanceClient.js +1 -1
  137. package/dist/telemetry/performance/PerformanceEvent.d.ts +12 -0
  138. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  139. package/dist/telemetry/performance/PerformanceEvent.js +1 -1
  140. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -1
  141. package/dist/telemetry/performance/StubPerformanceClient.js +1 -1
  142. package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
  143. package/dist/url/UrlString.js +1 -1
  144. package/dist/utils/Constants.d.ts +6 -1
  145. package/dist/utils/Constants.d.ts.map +1 -1
  146. package/dist/utils/Constants.js +9 -3
  147. package/dist/utils/Constants.js.map +1 -1
  148. package/dist/utils/ProtocolUtils.js +1 -1
  149. package/dist/utils/StringUtils.js +1 -1
  150. package/dist/utils/TimeUtils.js +1 -1
  151. package/package.json +7 -3
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v6.3.0 2022-05-02 */
1
+ /*! @azure/msal-common v7.1.0 2022-07-05 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -379,6 +379,7 @@ var AuthorityMetadataSource;
379
379
  AuthorityMetadataSource["CONFIG"] = "config";
380
380
  AuthorityMetadataSource["CACHE"] = "cache";
381
381
  AuthorityMetadataSource["NETWORK"] = "network";
382
+ AuthorityMetadataSource["HARDCODED_VALUES"] = "hardcoded_values";
382
383
  })(AuthorityMetadataSource || (AuthorityMetadataSource = {}));
383
384
  var SERVER_TELEM_CONSTANTS = {
384
385
  SCHEMA_VERSION: 5,
@@ -462,7 +463,12 @@ var CacheOutcome;
462
463
  CacheOutcome["NO_CACHED_ACCESS_TOKEN"] = "2";
463
464
  CacheOutcome["CACHED_ACCESS_TOKEN_EXPIRED"] = "3";
464
465
  CacheOutcome["REFRESH_CACHED_ACCESS_TOKEN"] = "4";
465
- })(CacheOutcome || (CacheOutcome = {}));
466
+ })(CacheOutcome || (CacheOutcome = {}));
467
+ var JsonTypes;
468
+ (function (JsonTypes) {
469
+ JsonTypes["Jwt"] = "JWT";
470
+ JsonTypes["Jwk"] = "JWK";
471
+ })(JsonTypes || (JsonTypes = {}));
466
472
 
467
473
  /*
468
474
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -767,6 +773,10 @@ var ClientAuthErrorMessage = {
767
773
  logoutNotSupported: {
768
774
  code: "end_session_endpoint_not_supported",
769
775
  desc: "Provided authority does not support logout."
776
+ },
777
+ keyIdMissing: {
778
+ code: "key_id_missing",
779
+ desc: "A keyId value is missing from the requested bound token's cache record and is required to match the token to it's stored binding key."
770
780
  }
771
781
  };
772
782
  /**
@@ -1036,6 +1046,12 @@ var ClientAuthError = /** @class */ (function (_super) {
1036
1046
  ClientAuthError.createLogoutNotSupportedError = function () {
1037
1047
  return new ClientAuthError(ClientAuthErrorMessage.logoutNotSupported.code, ClientAuthErrorMessage.logoutNotSupported.desc);
1038
1048
  };
1049
+ /**
1050
+ * Create an error when kid attribute is missing from a PoP token's cache record
1051
+ */
1052
+ ClientAuthError.createKeyIdMissingError = function () {
1053
+ return new ClientAuthError(ClientAuthErrorMessage.keyIdMissing.code, ClientAuthErrorMessage.keyIdMissing.desc);
1054
+ };
1039
1055
  return ClientAuthError;
1040
1056
  }(AuthError));
1041
1057
 
@@ -1342,7 +1358,7 @@ var Logger = /** @class */ (function () {
1342
1358
 
1343
1359
  /* eslint-disable header/header */
1344
1360
  var name = "@azure/msal-common";
1345
- var version = "6.3.0";
1361
+ var version = "7.1.0";
1346
1362
 
1347
1363
  /*
1348
1364
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1385,9 +1401,9 @@ exports.AzureCloudInstance = void 0;
1385
1401
  * familyId: Family ID identifier, usually only used for refresh tokens
1386
1402
  * realm: Full tenant or organizational identifier that the account belongs to
1387
1403
  * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
1388
- * oboAssertion: access token passed in as part of OBO request
1389
1404
  * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
1390
1405
  * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
1406
+ * userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
1391
1407
  * }
1392
1408
  */
1393
1409
  var CredentialEntity = /** @class */ (function () {
@@ -2028,7 +2044,6 @@ exports.AuthorityType = void 0;
2028
2044
  * clientInfo: Full base64 encoded client info received from ESTS
2029
2045
  * lastModificationTime: last time this entity was modified in the cache
2030
2046
  * lastModificationApp:
2031
- * oboAssertion: access token passed in as part of OBO request
2032
2047
  * idTokenClaims: Object containing claims parsed from ID token
2033
2048
  * nativeAccountId: Account identifier on the native device
2034
2049
  * }
@@ -2107,7 +2122,7 @@ var AccountEntity = /** @class */ (function () {
2107
2122
  * @param idToken
2108
2123
  * @param policy
2109
2124
  */
2110
- AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2125
+ AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2111
2126
  var _a, _b, _c, _d, _e, _f;
2112
2127
  var account = new AccountEntity();
2113
2128
  account.authorityType = exports.CacheAccountType.MSSTS_ACCOUNT_TYPE;
@@ -2121,7 +2136,6 @@ var AccountEntity = /** @class */ (function () {
2121
2136
  account.environment = env;
2122
2137
  // non AAD scenarios can have empty realm
2123
2138
  account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || Constants.EMPTY_STRING;
2124
- account.oboAssertion = oboAssertion;
2125
2139
  if (idToken) {
2126
2140
  account.idTokenClaims = idToken.claims;
2127
2141
  // How do you account for MSA CID here?
@@ -2142,14 +2156,13 @@ var AccountEntity = /** @class */ (function () {
2142
2156
  * @param authority
2143
2157
  * @param idToken
2144
2158
  */
2145
- AccountEntity.createGenericAccount = function (homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment) {
2159
+ AccountEntity.createGenericAccount = function (homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment) {
2146
2160
  var _a, _b, _c, _d;
2147
2161
  var account = new AccountEntity();
2148
2162
  account.authorityType = (authority && authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
2149
2163
  account.homeAccountId = homeAccountId;
2150
2164
  // non AAD scenarios can have empty realm
2151
2165
  account.realm = Constants.EMPTY_STRING;
2152
- account.oboAssertion = oboAssertion;
2153
2166
  var env = environment || authority && authority.getPreferredCache();
2154
2167
  if (!env) {
2155
2168
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -2438,7 +2451,7 @@ var CacheManager = /** @class */ (function () {
2438
2451
  * @param target
2439
2452
  */
2440
2453
  CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
2441
- 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);
2454
+ 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);
2442
2455
  };
2443
2456
  /**
2444
2457
  * Support function to help match credentials
@@ -2448,10 +2461,10 @@ var CacheManager = /** @class */ (function () {
2448
2461
  * @param clientId
2449
2462
  * @param realm
2450
2463
  * @param target
2451
- * @param oboAssertion
2464
+ * @param userAssertionHash
2452
2465
  * @param tokenType
2453
2466
  */
2454
- CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType, keyId, requestedClaimsHash) {
2467
+ CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, userAssertionHash, tokenType, keyId, requestedClaimsHash) {
2455
2468
  var _this = this;
2456
2469
  var allCacheKeys = this.getKeys();
2457
2470
  var matchingCredentials = {
@@ -2470,7 +2483,7 @@ var CacheManager = /** @class */ (function () {
2470
2483
  if (!entity) {
2471
2484
  return;
2472
2485
  }
2473
- if (!!oboAssertion && !_this.matchOboAssertion(entity, oboAssertion)) {
2486
+ if (!!userAssertionHash && !_this.matchUserAssertionHash(entity, userAssertionHash)) {
2474
2487
  return;
2475
2488
  }
2476
2489
  if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
@@ -2801,7 +2814,7 @@ var CacheManager = /** @class */ (function () {
2801
2814
  target: scopes.printScopesLowerCase(),
2802
2815
  tokenType: authScheme,
2803
2816
  keyId: request.sshKid,
2804
- requestedClaimsHash: request.requestedClaimsHash
2817
+ requestedClaimsHash: request.requestedClaimsHash,
2805
2818
  };
2806
2819
  var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
2807
2820
  var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
@@ -2827,7 +2840,7 @@ var CacheManager = /** @class */ (function () {
2827
2840
  environment: account.environment,
2828
2841
  credentialType: exports.CredentialType.REFRESH_TOKEN,
2829
2842
  clientId: clientId,
2830
- familyId: id
2843
+ familyId: id,
2831
2844
  };
2832
2845
  var credentialCache = this.getCredentialsFilteredBy(refreshTokenFilter);
2833
2846
  var refreshTokens = Object.keys(credentialCache.refreshTokens).map(function (key) { return credentialCache.refreshTokens[key]; });
@@ -2879,8 +2892,8 @@ var CacheManager = /** @class */ (function () {
2879
2892
  * @param value
2880
2893
  * @param oboAssertion
2881
2894
  */
2882
- CacheManager.prototype.matchOboAssertion = function (entity, oboAssertion) {
2883
- return !!(entity.oboAssertion && oboAssertion === entity.oboAssertion);
2895
+ CacheManager.prototype.matchUserAssertionHash = function (entity, userAssertionHash) {
2896
+ return !!(entity.userAssertionHash && userAssertionHash === entity.userAssertionHash);
2884
2897
  };
2885
2898
  /**
2886
2899
  * helper to match environment
@@ -3206,7 +3219,7 @@ function buildClientConfiguration(_a) {
3206
3219
  * @param authOptions
3207
3220
  */
3208
3221
  function buildAuthOptions(authOptions) {
3209
- return __assign({ clientCapabilities: [], azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS }, authOptions);
3222
+ return __assign({ clientCapabilities: [], azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS, skipAuthorityMetadataCache: false }, authOptions);
3210
3223
  }
3211
3224
 
3212
3225
  /*
@@ -3781,14 +3794,18 @@ var RequestParameterBuilder = /** @class */ (function () {
3781
3794
  * @param clientAssertion
3782
3795
  */
3783
3796
  RequestParameterBuilder.prototype.addClientAssertion = function (clientAssertion) {
3784
- this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION, encodeURIComponent(clientAssertion));
3797
+ if (!StringUtils.isEmpty(clientAssertion)) {
3798
+ this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION, encodeURIComponent(clientAssertion));
3799
+ }
3785
3800
  };
3786
3801
  /**
3787
3802
  * add clientAssertionType for confidential client flows
3788
3803
  * @param clientAssertionType
3789
3804
  */
3790
3805
  RequestParameterBuilder.prototype.addClientAssertionType = function (clientAssertionType) {
3791
- this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION_TYPE, encodeURIComponent(clientAssertionType));
3806
+ if (!StringUtils.isEmpty(clientAssertionType)) {
3807
+ this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION_TYPE, encodeURIComponent(clientAssertionType));
3808
+ }
3792
3809
  };
3793
3810
  /**
3794
3811
  * add OBO assertion for confidential client flows
@@ -3860,14 +3877,14 @@ var RequestParameterBuilder = /** @class */ (function () {
3860
3877
  * @param username
3861
3878
  */
3862
3879
  RequestParameterBuilder.prototype.addUsername = function (username) {
3863
- this.parameters.set(PasswordGrantConstants.username, username);
3880
+ this.parameters.set(PasswordGrantConstants.username, encodeURIComponent(username));
3864
3881
  };
3865
3882
  /**
3866
3883
  * adds `password` for Password Grant flow
3867
3884
  * @param password
3868
3885
  */
3869
3886
  RequestParameterBuilder.prototype.addPassword = function (password) {
3870
- this.parameters.set(PasswordGrantConstants.password, password);
3887
+ this.parameters.set(PasswordGrantConstants.password, encodeURIComponent(password));
3871
3888
  };
3872
3889
  /**
3873
3890
  * add pop_jwk to query params
@@ -3954,7 +3971,7 @@ var IdTokenEntity = /** @class */ (function (_super) {
3954
3971
  * @param clientId
3955
3972
  * @param authority
3956
3973
  */
3957
- IdTokenEntity.createIdTokenEntity = function (homeAccountId, environment, idToken, clientId, tenantId, oboAssertion) {
3974
+ IdTokenEntity.createIdTokenEntity = function (homeAccountId, environment, idToken, clientId, tenantId) {
3958
3975
  var idTokenEntity = new IdTokenEntity();
3959
3976
  idTokenEntity.credentialType = exports.CredentialType.ID_TOKEN;
3960
3977
  idTokenEntity.homeAccountId = homeAccountId;
@@ -3962,7 +3979,6 @@ var IdTokenEntity = /** @class */ (function (_super) {
3962
3979
  idTokenEntity.clientId = clientId;
3963
3980
  idTokenEntity.secret = idToken;
3964
3981
  idTokenEntity.realm = tenantId;
3965
- idTokenEntity.oboAssertion = oboAssertion;
3966
3982
  return idTokenEntity;
3967
3983
  };
3968
3984
  /**
@@ -4077,7 +4093,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
4077
4093
  * @param expiresOn
4078
4094
  * @param extExpiresOn
4079
4095
  */
4080
- AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion, keyId, requestedClaims, requestedClaimsHash) {
4096
+ AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, userAssertionHash, keyId, requestedClaims, requestedClaimsHash) {
4081
4097
  var _a, _b;
4082
4098
  var atEntity = new AccessTokenEntity();
4083
4099
  atEntity.homeAccountId = homeAccountId;
@@ -4098,7 +4114,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
4098
4114
  atEntity.clientId = clientId;
4099
4115
  atEntity.realm = tenantId;
4100
4116
  atEntity.target = scopes;
4101
- atEntity.oboAssertion = oboAssertion;
4117
+ atEntity.userAssertionHash = userAssertionHash;
4102
4118
  atEntity.tokenType = StringUtils.isEmpty(tokenType) ? exports.AuthenticationScheme.BEARER : tokenType;
4103
4119
  if (requestedClaims) {
4104
4120
  atEntity.requestedClaims = requestedClaims;
@@ -4180,14 +4196,14 @@ var RefreshTokenEntity = /** @class */ (function (_super) {
4180
4196
  * @param clientId
4181
4197
  * @param authority
4182
4198
  */
4183
- RefreshTokenEntity.createRefreshTokenEntity = function (homeAccountId, environment, refreshToken, clientId, familyId, oboAssertion) {
4199
+ RefreshTokenEntity.createRefreshTokenEntity = function (homeAccountId, environment, refreshToken, clientId, familyId, userAssertionHash) {
4184
4200
  var rtEntity = new RefreshTokenEntity();
4185
4201
  rtEntity.clientId = clientId;
4186
4202
  rtEntity.credentialType = exports.CredentialType.REFRESH_TOKEN;
4187
4203
  rtEntity.environment = environment;
4188
4204
  rtEntity.homeAccountId = homeAccountId;
4189
4205
  rtEntity.secret = refreshToken;
4190
- rtEntity.oboAssertion = oboAssertion;
4206
+ rtEntity.userAssertionHash = userAssertionHash;
4191
4207
  if (familyId)
4192
4208
  rtEntity.familyId = familyId;
4193
4209
  return rtEntity;
@@ -4236,6 +4252,10 @@ var InteractionRequiredAuthErrorMessage = {
4236
4252
  noTokensFoundError: {
4237
4253
  code: "no_tokens_found",
4238
4254
  desc: "No refresh token found in the cache. Please sign-in."
4255
+ },
4256
+ native_account_unavailable: {
4257
+ code: "native_account_unavailable",
4258
+ 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."
4239
4259
  }
4240
4260
  };
4241
4261
  /**
@@ -4269,6 +4289,13 @@ var InteractionRequiredAuthError = /** @class */ (function (_super) {
4269
4289
  InteractionRequiredAuthError.createNoTokensFoundError = function () {
4270
4290
  return new InteractionRequiredAuthError(InteractionRequiredAuthErrorMessage.noTokensFoundError.code, InteractionRequiredAuthErrorMessage.noTokensFoundError.desc);
4271
4291
  };
4292
+ /**
4293
+ * Creates an error thrown when the native broker returns ACCOUNT_UNAVAILABLE status, indicating that the account was removed and interactive sign-in is required
4294
+ * @returns
4295
+ */
4296
+ InteractionRequiredAuthError.createNativeAccountUnavailableError = function () {
4297
+ return new InteractionRequiredAuthError(InteractionRequiredAuthErrorMessage.native_account_unavailable.code, InteractionRequiredAuthErrorMessage.native_account_unavailable.desc);
4298
+ };
4272
4299
  return InteractionRequiredAuthError;
4273
4300
  }(AuthError));
4274
4301
 
@@ -4570,34 +4597,30 @@ var PopTokenGenerator = /** @class */ (function () {
4570
4597
  }
4571
4598
  /**
4572
4599
  * Generates the req_cnf validated at the RP in the POP protocol for SHR parameters
4600
+ * and returns an object containing the keyid, the full req_cnf string and the req_cnf string hash
4573
4601
  * @param request
4574
4602
  * @returns
4575
4603
  */
4576
4604
  PopTokenGenerator.prototype.generateCnf = function (request) {
4577
4605
  return __awaiter(this, void 0, void 0, function () {
4578
- var reqCnf;
4579
- return __generator(this, function (_a) {
4580
- switch (_a.label) {
4606
+ var reqCnf, reqCnfString, _a;
4607
+ return __generator(this, function (_b) {
4608
+ switch (_b.label) {
4581
4609
  case 0: return [4 /*yield*/, this.generateKid(request)];
4582
4610
  case 1:
4583
- reqCnf = _a.sent();
4584
- return [2 /*return*/, this.cryptoUtils.base64Encode(JSON.stringify(reqCnf))];
4611
+ reqCnf = _b.sent();
4612
+ reqCnfString = this.cryptoUtils.base64Encode(JSON.stringify(reqCnf));
4613
+ _a = {
4614
+ kid: reqCnf.kid,
4615
+ reqCnfString: reqCnfString
4616
+ };
4617
+ return [4 /*yield*/, this.cryptoUtils.hashString(reqCnfString)];
4618
+ case 2: return [2 /*return*/, (_a.reqCnfHash = _b.sent(),
4619
+ _a)];
4585
4620
  }
4586
4621
  });
4587
4622
  });
4588
4623
  };
4589
- /**
4590
- * Generates the hash of the req_cnf
4591
- * @param cnf
4592
- * @returns
4593
- */
4594
- PopTokenGenerator.prototype.generateCnfHash = function (cnf) {
4595
- return __awaiter(this, void 0, void 0, function () {
4596
- return __generator(this, function (_a) {
4597
- return [2 /*return*/, this.cryptoUtils.hashString(cnf)];
4598
- });
4599
- });
4600
- };
4601
4624
  /**
4602
4625
  * Generates key_id for a SHR token request
4603
4626
  * @param request
@@ -4625,16 +4648,10 @@ var PopTokenGenerator = /** @class */ (function () {
4625
4648
  * @param request
4626
4649
  * @returns
4627
4650
  */
4628
- PopTokenGenerator.prototype.signPopToken = function (accessToken, request) {
4629
- var _a;
4651
+ PopTokenGenerator.prototype.signPopToken = function (accessToken, keyId, request) {
4630
4652
  return __awaiter(this, void 0, void 0, function () {
4631
- var tokenClaims;
4632
- return __generator(this, function (_b) {
4633
- tokenClaims = AuthToken.extractTokenClaims(accessToken, this.cryptoUtils);
4634
- if (!((_a = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _a === void 0 ? void 0 : _a.kid)) {
4635
- throw ClientAuthError.createTokenClaimsRequiredError();
4636
- }
4637
- return [2 /*return*/, this.signPayload(accessToken, tokenClaims.cnf.kid, request)];
4653
+ return __generator(this, function (_a) {
4654
+ return [2 /*return*/, this.signPayload(accessToken, keyId, request)];
4638
4655
  });
4639
4656
  });
4640
4657
  };
@@ -4646,7 +4663,7 @@ var PopTokenGenerator = /** @class */ (function () {
4646
4663
  * @param claims
4647
4664
  * @returns
4648
4665
  */
4649
- PopTokenGenerator.prototype.signPayload = function (payload, kid, request, claims) {
4666
+ PopTokenGenerator.prototype.signPayload = function (payload, keyId, request, claims) {
4650
4667
  return __awaiter(this, void 0, void 0, function () {
4651
4668
  var resourceRequestMethod, resourceRequestUri, shrClaims, shrNonce, resourceUrlString, resourceUrlComponents;
4652
4669
  return __generator(this, function (_a) {
@@ -4655,7 +4672,7 @@ var PopTokenGenerator = /** @class */ (function () {
4655
4672
  resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
4656
4673
  resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
4657
4674
  resourceUrlComponents = resourceUrlString === null || resourceUrlString === void 0 ? void 0 : resourceUrlString.getUrlComponents();
4658
- return [4 /*yield*/, this.cryptoUtils.signJwt(__assign({ at: payload, ts: TimeUtils.nowSeconds(), m: resourceRequestMethod === null || resourceRequestMethod === void 0 ? void 0 : resourceRequestMethod.toUpperCase(), u: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.HostNameAndPort, nonce: shrNonce || this.cryptoUtils.createNewGuid(), p: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.AbsolutePath, q: (resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.QueryString) ? [[], resourceUrlComponents.QueryString] : undefined, client_claims: shrClaims || undefined }, claims), kid, request.correlationId)];
4675
+ return [4 /*yield*/, this.cryptoUtils.signJwt(__assign({ at: payload, ts: TimeUtils.nowSeconds(), m: resourceRequestMethod === null || resourceRequestMethod === void 0 ? void 0 : resourceRequestMethod.toUpperCase(), u: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.HostNameAndPort, nonce: shrNonce || this.cryptoUtils.createNewGuid(), p: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.AbsolutePath, q: (resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.QueryString) ? [[], resourceUrlComponents.QueryString] : undefined, client_claims: shrClaims || undefined }, claims), keyId, request.correlationId)];
4659
4676
  case 1: return [2 /*return*/, _a.sent()];
4660
4677
  }
4661
4678
  });
@@ -4826,7 +4843,7 @@ var ResponseHandler = /** @class */ (function () {
4826
4843
  * @param serverTokenResponse
4827
4844
  * @param authority
4828
4845
  */
4829
- ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, oboAssertion, handlingRefreshTokenResponse) {
4846
+ ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, userAssertionHash, handlingRefreshTokenResponse) {
4830
4847
  return __awaiter(this, void 0, void 0, function () {
4831
4848
  var idTokenObj, requestStateObj, cacheRecord, cacheContext, key, account;
4832
4849
  return __generator(this, function (_a) {
@@ -4848,7 +4865,7 @@ var ResponseHandler = /** @class */ (function () {
4848
4865
  }
4849
4866
  // Add keyId from request to serverTokenResponse if defined
4850
4867
  serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
4851
- cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload);
4868
+ cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, userAssertionHash, authCodePayload);
4852
4869
  _a.label = 1;
4853
4870
  case 1:
4854
4871
  _a.trys.push([1, , 5, 8]);
@@ -4896,7 +4913,7 @@ var ResponseHandler = /** @class */ (function () {
4896
4913
  * @param idTokenObj
4897
4914
  * @param authority
4898
4915
  */
4899
- ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload) {
4916
+ ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, userAssertionHash, authCodePayload) {
4900
4917
  var env = authority.getPreferredCache();
4901
4918
  if (StringUtils.isEmpty(env)) {
4902
4919
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -4905,8 +4922,8 @@ var ResponseHandler = /** @class */ (function () {
4905
4922
  var cachedIdToken;
4906
4923
  var cachedAccount;
4907
4924
  if (!StringUtils.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {
4908
- cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING, oboAssertion);
4909
- cachedAccount = this.generateAccountEntity(serverTokenResponse, idTokenObj, authority, oboAssertion, authCodePayload);
4925
+ cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING);
4926
+ cachedAccount = this.generateAccountEntity(serverTokenResponse, idTokenObj, authority, authCodePayload);
4910
4927
  }
4911
4928
  // AccessToken
4912
4929
  var cachedAccessToken = null;
@@ -4924,12 +4941,12 @@ var ResponseHandler = /** @class */ (function () {
4924
4941
  var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
4925
4942
  var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
4926
4943
  // non AAD scenarios can have empty realm
4927
- 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);
4944
+ 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);
4928
4945
  }
4929
4946
  // refreshToken
4930
4947
  var cachedRefreshToken = null;
4931
4948
  if (!StringUtils.isEmpty(serverTokenResponse.refresh_token)) {
4932
- cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.refresh_token || Constants.EMPTY_STRING, this.clientId, serverTokenResponse.foci, oboAssertion);
4949
+ cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.refresh_token || Constants.EMPTY_STRING, this.clientId, serverTokenResponse.foci, userAssertionHash);
4933
4950
  }
4934
4951
  // appMetadata
4935
4952
  var cachedAppMetadata = null;
@@ -4944,22 +4961,22 @@ var ResponseHandler = /** @class */ (function () {
4944
4961
  * @param idToken
4945
4962
  * @param authority
4946
4963
  */
4947
- ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, oboAssertion, authCodePayload) {
4964
+ ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, authCodePayload) {
4948
4965
  var authorityType = authority.authorityType;
4949
4966
  var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;
4950
4967
  var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;
4951
4968
  // ADFS does not require client_info in the response
4952
4969
  if (authorityType === exports.AuthorityType.Adfs) {
4953
4970
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
4954
- return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
4971
+ return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
4955
4972
  }
4956
4973
  // This fallback applies to B2C as well as they fall under an AAD account type.
4957
4974
  if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === "AAD") {
4958
4975
  throw ClientAuthError.createClientInfoEmptyError();
4959
4976
  }
4960
4977
  return serverTokenResponse.client_info ?
4961
- AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost) :
4962
- AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
4978
+ AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost) :
4979
+ AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
4963
4980
  };
4964
4981
  /**
4965
4982
  * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
@@ -4974,9 +4991,9 @@ var ResponseHandler = /** @class */ (function () {
4974
4991
  ResponseHandler.generateAuthenticationResult = function (cryptoObj, authority, cacheRecord, fromTokenCache, request, idTokenObj, requestState, code) {
4975
4992
  var _a, _b, _c;
4976
4993
  return __awaiter(this, void 0, void 0, function () {
4977
- var accessToken, responseScopes, expiresOn, extExpiresOn, familyId, popTokenGenerator, uid, tid;
4978
- return __generator(this, function (_d) {
4979
- switch (_d.label) {
4994
+ var accessToken, responseScopes, expiresOn, extExpiresOn, familyId, popTokenGenerator, _d, secret, keyId, uid, tid;
4995
+ return __generator(this, function (_e) {
4996
+ switch (_e.label) {
4980
4997
  case 0:
4981
4998
  accessToken = Constants.EMPTY_STRING;
4982
4999
  responseScopes = [];
@@ -4985,18 +5002,22 @@ var ResponseHandler = /** @class */ (function () {
4985
5002
  if (!cacheRecord.accessToken) return [3 /*break*/, 4];
4986
5003
  if (!(cacheRecord.accessToken.tokenType === exports.AuthenticationScheme.POP)) return [3 /*break*/, 2];
4987
5004
  popTokenGenerator = new PopTokenGenerator(cryptoObj);
4988
- return [4 /*yield*/, popTokenGenerator.signPopToken(cacheRecord.accessToken.secret, request)];
5005
+ _d = cacheRecord.accessToken, secret = _d.secret, keyId = _d.keyId;
5006
+ if (!keyId) {
5007
+ throw ClientAuthError.createKeyIdMissingError();
5008
+ }
5009
+ return [4 /*yield*/, popTokenGenerator.signPopToken(secret, keyId, request)];
4989
5010
  case 1:
4990
- accessToken = _d.sent();
5011
+ accessToken = _e.sent();
4991
5012
  return [3 /*break*/, 3];
4992
5013
  case 2:
4993
5014
  accessToken = cacheRecord.accessToken.secret;
4994
- _d.label = 3;
5015
+ _e.label = 3;
4995
5016
  case 3:
4996
5017
  responseScopes = ScopeSet.fromString(cacheRecord.accessToken.target).asArray();
4997
5018
  expiresOn = new Date(Number(cacheRecord.accessToken.expiresOn) * 1000);
4998
5019
  extExpiresOn = new Date(Number(cacheRecord.accessToken.extendedExpiresOn) * 1000);
4999
- _d.label = 4;
5020
+ _e.label = 4;
5000
5021
  case 4:
5001
5022
  if (cacheRecord.appMetadata) {
5002
5023
  familyId = cacheRecord.appMetadata.familyId === THE_FAMILY_ID ? THE_FAMILY_ID : Constants.EMPTY_STRING;
@@ -5196,7 +5217,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5196
5217
  */
5197
5218
  AuthorizationCodeClient.prototype.createTokenRequestBody = function (request) {
5198
5219
  return __awaiter(this, void 0, void 0, function () {
5199
- var parameterBuilder, clientAssertion, popTokenGenerator, cnfString, correlationId, ccsCred, clientInfo, clientInfo;
5220
+ var parameterBuilder, clientAssertion, popTokenGenerator, reqCnfData, correlationId, ccsCred, clientInfo, clientInfo;
5200
5221
  var _a;
5201
5222
  return __generator(this, function (_b) {
5202
5223
  switch (_b.label) {
@@ -5244,8 +5265,9 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5244
5265
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5245
5266
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5246
5267
  case 1:
5247
- cnfString = _b.sent();
5248
- parameterBuilder.addPopToken(cnfString);
5268
+ reqCnfData = _b.sent();
5269
+ // SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
5270
+ parameterBuilder.addPopToken(reqCnfData.reqCnfString);
5249
5271
  return [3 /*break*/, 3];
5250
5272
  case 2:
5251
5273
  if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
@@ -5316,7 +5338,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5316
5338
  */
5317
5339
  AuthorizationCodeClient.prototype.createAuthCodeUrlQueryString = function (request) {
5318
5340
  return __awaiter(this, void 0, void 0, function () {
5319
- var parameterBuilder, requestScopes, correlationId, accountSid, clientInfo, clientInfo, popTokenGenerator, cnf, cnfHash;
5341
+ var parameterBuilder, requestScopes, correlationId, accountSid, clientInfo, clientInfo, popTokenGenerator, reqCnfData;
5320
5342
  return __generator(this, function (_a) {
5321
5343
  switch (_a.label) {
5322
5344
  case 0:
@@ -5408,20 +5430,17 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5408
5430
  if (request.extraQueryParameters) {
5409
5431
  parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
5410
5432
  }
5411
- if (!request.nativeBroker) return [3 /*break*/, 3];
5433
+ if (!request.nativeBroker) return [3 /*break*/, 2];
5412
5434
  // signal ests that this is a WAM call
5413
5435
  parameterBuilder.addNativeBroker();
5414
- if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 3];
5436
+ if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 2];
5415
5437
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5416
5438
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5417
5439
  case 1:
5418
- cnf = _a.sent();
5419
- return [4 /*yield*/, popTokenGenerator.generateCnfHash(cnf)];
5420
- case 2:
5421
- cnfHash = _a.sent();
5422
- parameterBuilder.addPopToken(cnfHash);
5423
- _a.label = 3;
5424
- case 3: return [2 /*return*/, parameterBuilder.createQueryString()];
5440
+ reqCnfData = _a.sent();
5441
+ parameterBuilder.addPopToken(reqCnfData.reqCnfHash);
5442
+ _a.label = 2;
5443
+ case 2: return [2 /*return*/, parameterBuilder.createQueryString()];
5425
5444
  }
5426
5445
  });
5427
5446
  });
@@ -5818,7 +5837,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5818
5837
  */
5819
5838
  RefreshTokenClient.prototype.createTokenRequestBody = function (request) {
5820
5839
  return __awaiter(this, void 0, void 0, function () {
5821
- var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, cnfString, clientInfo;
5840
+ var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, reqCnfData, clientInfo;
5822
5841
  return __generator(this, function (_a) {
5823
5842
  switch (_a.label) {
5824
5843
  case 0:
@@ -5848,8 +5867,9 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5848
5867
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5849
5868
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5850
5869
  case 1:
5851
- cnfString = _a.sent();
5852
- parameterBuilder.addPopToken(cnfString);
5870
+ reqCnfData = _a.sent();
5871
+ // SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
5872
+ parameterBuilder.addPopToken(reqCnfData.reqCnfString);
5853
5873
  return [3 /*break*/, 3];
5854
5874
  case 2:
5855
5875
  if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
@@ -6038,8 +6058,9 @@ var ClientCredentialClient = /** @class */ (function (_super) {
6038
6058
  if (this.config.clientCredentials.clientSecret) {
6039
6059
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
6040
6060
  }
6041
- if (this.config.clientCredentials.clientAssertion) {
6042
- var clientAssertion = this.config.clientCredentials.clientAssertion;
6061
+ // Use clientAssertion from request, fallback to client assertion in base configuration
6062
+ var clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
6063
+ if (clientAssertion) {
6043
6064
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
6044
6065
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
6045
6066
  }
@@ -6069,44 +6090,64 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6069
6090
  */
6070
6091
  OnBehalfOfClient.prototype.acquireToken = function (request) {
6071
6092
  return __awaiter(this, void 0, void 0, function () {
6072
- var cachedAuthenticationResult;
6073
- return __generator(this, function (_a) {
6074
- switch (_a.label) {
6093
+ var _a;
6094
+ return __generator(this, function (_b) {
6095
+ switch (_b.label) {
6075
6096
  case 0:
6076
6097
  this.scopeSet = new ScopeSet(request.scopes || []);
6077
- if (!request.skipCache) return [3 /*break*/, 2];
6078
- return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
6079
- case 1: return [2 /*return*/, _a.sent()];
6080
- case 2: return [4 /*yield*/, this.getCachedAuthenticationResult(request)];
6098
+ // generate the user_assertion_hash for OBOAssertion
6099
+ _a = this;
6100
+ return [4 /*yield*/, this.cryptoUtils.hashString(request.oboAssertion)];
6101
+ case 1:
6102
+ // generate the user_assertion_hash for OBOAssertion
6103
+ _a.userAssertionHash = _b.sent();
6104
+ if (!request.skipCache) return [3 /*break*/, 3];
6105
+ return [4 /*yield*/, this.executeTokenRequest(request, this.authority, this.userAssertionHash)];
6106
+ case 2: return [2 /*return*/, _b.sent()];
6081
6107
  case 3:
6082
- cachedAuthenticationResult = _a.sent();
6083
- if (!cachedAuthenticationResult) return [3 /*break*/, 4];
6084
- return [2 /*return*/, cachedAuthenticationResult];
6085
- case 4: return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
6086
- case 5: return [2 /*return*/, _a.sent()];
6108
+ _b.trys.push([3, 5, , 7]);
6109
+ return [4 /*yield*/, this.getCachedAuthenticationResult(request)];
6110
+ case 4: return [2 /*return*/, _b.sent()];
6111
+ case 5:
6112
+ _b.sent();
6113
+ return [4 /*yield*/, this.executeTokenRequest(request, this.authority, this.userAssertionHash)];
6114
+ case 6:
6115
+ // Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT
6116
+ return [2 /*return*/, _b.sent()];
6117
+ case 7: return [2 /*return*/];
6087
6118
  }
6088
6119
  });
6089
6120
  });
6090
6121
  };
6091
6122
  /**
6092
6123
  * look up cache for tokens
6124
+ * Find idtoken in the cache
6125
+ * Find accessToken based on user assertion and account info in the cache
6126
+ * 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
6127
+ * This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
6093
6128
  * @param request
6094
6129
  */
6095
6130
  OnBehalfOfClient.prototype.getCachedAuthenticationResult = function (request) {
6096
- var _a;
6131
+ var _a, _b;
6097
6132
  return __awaiter(this, void 0, void 0, function () {
6098
6133
  var cachedAccessToken, cachedIdToken, idTokenObject, cachedAccount, localAccountId, accountInfo;
6099
- return __generator(this, function (_b) {
6100
- switch (_b.label) {
6134
+ return __generator(this, function (_c) {
6135
+ switch (_c.label) {
6101
6136
  case 0:
6102
- cachedAccessToken = this.readAccessTokenFromCache();
6103
- if (!cachedAccessToken ||
6104
- TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
6105
- // Update the server telemetry outcome
6106
- (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(!cachedAccessToken ? CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED : CacheOutcome.NO_CACHED_ACCESS_TOKEN);
6107
- return [2 /*return*/, null];
6137
+ cachedAccessToken = this.readAccessTokenFromCacheForOBO(this.config.authOptions.clientId, request);
6138
+ if (!cachedAccessToken) {
6139
+ // Must refresh due to non-existent access_token.
6140
+ (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
6141
+ this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
6142
+ throw ClientAuthError.createRefreshRequiredError();
6143
+ }
6144
+ else if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
6145
+ // Access token expired, will need to renewed
6146
+ (_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
6147
+ this.logger.info("OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within " + this.config.systemOptions.tokenRenewalOffsetSeconds + " seconds.");
6148
+ throw ClientAuthError.createRefreshRequiredError();
6108
6149
  }
6109
- cachedIdToken = this.readIdTokenFromCache(request);
6150
+ cachedIdToken = this.readIdTokenFromCacheForOBO(request, cachedAccessToken.homeAccountId);
6110
6151
  cachedAccount = null;
6111
6152
  if (cachedIdToken) {
6112
6153
  idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);
@@ -6118,7 +6159,11 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6118
6159
  username: Constants.EMPTY_STRING,
6119
6160
  localAccountId: localAccountId || Constants.EMPTY_STRING
6120
6161
  };
6121
- cachedAccount = this.readAccountFromCache(accountInfo);
6162
+ cachedAccount = this.cacheManager.readAccountFromCache(accountInfo);
6163
+ }
6164
+ // increment telemetry cache hit counter
6165
+ if (this.config.serverTelemetryManager) {
6166
+ this.config.serverTelemetryManager.incrementCacheHits();
6122
6167
  }
6123
6168
  return [4 /*yield*/, ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
6124
6169
  account: cachedAccount,
@@ -6127,45 +6172,23 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6127
6172
  refreshToken: null,
6128
6173
  appMetadata: null
6129
6174
  }, true, request, idTokenObject)];
6130
- case 1: return [2 /*return*/, _b.sent()];
6175
+ case 1: return [2 /*return*/, _c.sent()];
6131
6176
  }
6132
6177
  });
6133
6178
  });
6134
6179
  };
6135
6180
  /**
6136
- * read access token from cache TODO: CacheManager API should be used here
6181
+ * read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
6182
+ * Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
6137
6183
  * @param request
6138
6184
  */
6139
- OnBehalfOfClient.prototype.readAccessTokenFromCache = function () {
6140
- var accessTokenFilter = {
6141
- environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
6142
- credentialType: exports.CredentialType.ACCESS_TOKEN,
6143
- clientId: this.config.authOptions.clientId,
6144
- realm: this.authority.tenant,
6145
- target: this.scopeSet.printScopesLowerCase(),
6146
- };
6147
- var credentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);
6148
- var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
6149
- var numAccessTokens = accessTokens.length;
6150
- if (numAccessTokens < 1) {
6151
- return null;
6152
- }
6153
- else if (numAccessTokens > 1) {
6154
- throw ClientAuthError.createMultipleMatchingTokensInCacheError();
6155
- }
6156
- return accessTokens[0];
6157
- };
6158
- /**
6159
- * read idtoken from cache TODO: CacheManager API should be used here instead
6160
- * @param request
6161
- */
6162
- OnBehalfOfClient.prototype.readIdTokenFromCache = function (request) {
6185
+ OnBehalfOfClient.prototype.readIdTokenFromCacheForOBO = function (request, atHomeAccountId) {
6163
6186
  var idTokenFilter = {
6187
+ homeAccountId: atHomeAccountId,
6164
6188
  environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
6165
6189
  credentialType: exports.CredentialType.ID_TOKEN,
6166
6190
  clientId: this.config.authOptions.clientId,
6167
- realm: this.authority.tenant,
6168
- oboAssertion: request.oboAssertion
6191
+ realm: this.authority.tenant
6169
6192
  };
6170
6193
  var credentialCache = this.cacheManager.getCredentialsFilteredBy(idTokenFilter);
6171
6194
  var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
@@ -6176,18 +6199,44 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6176
6199
  return idTokens[0];
6177
6200
  };
6178
6201
  /**
6179
- * read account from cache, TODO: CacheManager API should be used here instead
6180
- * @param account
6202
+ * Fetches the cached access token based on incoming assertion
6203
+ * @param clientId
6204
+ * @param request
6205
+ * @param userAssertionHash
6181
6206
  */
6182
- OnBehalfOfClient.prototype.readAccountFromCache = function (account) {
6183
- return this.cacheManager.readAccountFromCache(account);
6207
+ OnBehalfOfClient.prototype.readAccessTokenFromCacheForOBO = function (clientId, request) {
6208
+ var authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
6209
+ /*
6210
+ * Distinguish between Bearer and PoP/SSH token cache types
6211
+ * Cast to lowercase to handle "bearer" from ADFS
6212
+ */
6213
+ var credentialType = (authScheme && authScheme.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : exports.CredentialType.ACCESS_TOKEN;
6214
+ var accessTokenFilter = {
6215
+ credentialType: credentialType,
6216
+ clientId: clientId,
6217
+ target: this.scopeSet.printScopesLowerCase(),
6218
+ tokenType: authScheme,
6219
+ keyId: request.sshKid,
6220
+ requestedClaimsHash: request.requestedClaimsHash,
6221
+ userAssertionHash: this.userAssertionHash
6222
+ };
6223
+ var credentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);
6224
+ var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
6225
+ var numAccessTokens = accessTokens.length;
6226
+ if (numAccessTokens < 1) {
6227
+ return null;
6228
+ }
6229
+ else if (numAccessTokens > 1) {
6230
+ throw ClientAuthError.createMultipleMatchingTokensInCacheError();
6231
+ }
6232
+ return accessTokens[0];
6184
6233
  };
6185
6234
  /**
6186
6235
  * Make a network call to the server requesting credentials
6187
6236
  * @param request
6188
6237
  * @param authority
6189
6238
  */
6190
- OnBehalfOfClient.prototype.executeTokenRequest = function (request, authority) {
6239
+ OnBehalfOfClient.prototype.executeTokenRequest = function (request, authority, userAssertionHash) {
6191
6240
  return __awaiter(this, void 0, void 0, function () {
6192
6241
  var requestBody, headers, thumbprint, reqTimestamp, response, responseHandler, tokenResponse;
6193
6242
  return __generator(this, function (_a) {
@@ -6212,7 +6261,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6212
6261
  response = _a.sent();
6213
6262
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
6214
6263
  responseHandler.validateTokenResponse(response.body);
6215
- return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request)];
6264
+ return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, userAssertionHash)];
6216
6265
  case 2:
6217
6266
  tokenResponse = _a.sent();
6218
6267
  return [2 /*return*/, tokenResponse];
@@ -6481,9 +6530,18 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6481
6530
  function isOpenIdConfigResponse(response) {
6482
6531
  return (response.hasOwnProperty("authorization_endpoint") &&
6483
6532
  response.hasOwnProperty("token_endpoint") &&
6484
- response.hasOwnProperty("issuer"));
6533
+ response.hasOwnProperty("issuer") &&
6534
+ response.hasOwnProperty("jwks_uri"));
6485
6535
  }
6486
6536
 
6537
+ /*
6538
+ * Copyright (c) Microsoft Corporation. All rights reserved.
6539
+ * Licensed under the MIT License.
6540
+ */
6541
+ 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"] }] } } };
6542
+ var EndpointMetadata = rawMetdataJSON.endpointMetadata;
6543
+ var InstanceDiscoveryMetadata = rawMetdataJSON.instanceDiscoveryMetadata;
6544
+
6487
6545
  /*
6488
6546
  * Copyright (c) Microsoft Corporation. All rights reserved.
6489
6547
  * Licensed under the MIT License.
@@ -6527,6 +6585,7 @@ var AuthorityMetadataEntity = /** @class */ (function () {
6527
6585
  this.end_session_endpoint = metadata.end_session_endpoint;
6528
6586
  this.issuer = metadata.issuer;
6529
6587
  this.endpointsFromNetwork = fromNetwork;
6588
+ this.jwks_uri = metadata.jwks_uri;
6530
6589
  };
6531
6590
  /**
6532
6591
  * Save the authority that was used to create this cache entry
@@ -6565,7 +6624,8 @@ var AuthorityMetadataEntity = /** @class */ (function () {
6565
6624
  entity.hasOwnProperty("issuer") &&
6566
6625
  entity.hasOwnProperty("aliasesFromNetwork") &&
6567
6626
  entity.hasOwnProperty("endpointsFromNetwork") &&
6568
- entity.hasOwnProperty("expiresAt"));
6627
+ entity.hasOwnProperty("expiresAt") &&
6628
+ entity.hasOwnProperty("jwks_uri"));
6569
6629
  };
6570
6630
  return AuthorityMetadataEntity;
6571
6631
  }());
@@ -6882,6 +6942,22 @@ var Authority = /** @class */ (function () {
6882
6942
  enumerable: false,
6883
6943
  configurable: true
6884
6944
  });
6945
+ Object.defineProperty(Authority.prototype, "jwksUri", {
6946
+ /**
6947
+ * Jwks_uri for token signing keys
6948
+ */
6949
+ get: function () {
6950
+ if (this.discoveryComplete()) {
6951
+ var endpoint = this.replacePath(this.metadata.jwks_uri);
6952
+ return this.replaceTenant(endpoint);
6953
+ }
6954
+ else {
6955
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Discovery incomplete.");
6956
+ }
6957
+ },
6958
+ enumerable: false,
6959
+ configurable: true
6960
+ });
6885
6961
  /**
6886
6962
  * Replaces tenant in url path with current tenant. Defaults to common.
6887
6963
  * @param urlString
@@ -6965,11 +7041,11 @@ var Authority = /** @class */ (function () {
6965
7041
  * @param metadataEntity
6966
7042
  */
6967
7043
  Authority.prototype.updateEndpointMetadata = function (metadataEntity) {
6968
- var _a;
7044
+ var _a, _b;
6969
7045
  return __awaiter(this, void 0, void 0, function () {
6970
- var metadata, autodetectedRegionName, azureRegion;
6971
- return __generator(this, function (_b) {
6972
- switch (_b.label) {
7046
+ var metadata, harcodedMetadata;
7047
+ return __generator(this, function (_c) {
7048
+ switch (_c.label) {
6973
7049
  case 0:
6974
7050
  metadata = this.getEndpointMetadataFromConfig();
6975
7051
  if (metadata) {
@@ -6980,41 +7056,30 @@ var Authority = /** @class */ (function () {
6980
7056
  // No need to update
6981
7057
  return [2 /*return*/, AuthorityMetadataSource.CACHE];
6982
7058
  }
7059
+ harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
6983
7060
  return [4 /*yield*/, this.getEndpointMetadataFromNetwork()];
6984
7061
  case 1:
6985
- metadata = _b.sent();
7062
+ metadata = _c.sent();
6986
7063
  if (!metadata) return [3 /*break*/, 4];
6987
7064
  if (!((_a = this.authorityOptions.azureRegionConfiguration) === null || _a === void 0 ? void 0 : _a.azureRegion)) return [3 /*break*/, 3];
6988
- return [4 /*yield*/, this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration.environmentRegion, this.regionDiscoveryMetadata, this.proxyUrl)];
7065
+ return [4 /*yield*/, this.updateMetadataWithRegionalInformation(metadata)];
6989
7066
  case 2:
6990
- autodetectedRegionName = _b.sent();
6991
- azureRegion = this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
6992
- ? autodetectedRegionName
6993
- : this.authorityOptions.azureRegionConfiguration.azureRegion;
6994
- if (this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
6995
- this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName ?
6996
- RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL :
6997
- RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
6998
- }
6999
- else {
7000
- if (autodetectedRegionName) {
7001
- this.regionDiscoveryMetadata.region_outcome = (this.authorityOptions.azureRegionConfiguration.azureRegion === autodetectedRegionName) ?
7002
- RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED :
7003
- RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;
7004
- }
7005
- else {
7006
- this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7007
- }
7008
- }
7009
- if (azureRegion) {
7010
- this.regionDiscoveryMetadata.region_used = azureRegion;
7011
- metadata = Authority.replaceWithRegionalInformation(metadata, azureRegion);
7012
- }
7013
- _b.label = 3;
7067
+ metadata = _c.sent();
7068
+ _c.label = 3;
7014
7069
  case 3:
7015
7070
  metadataEntity.updateEndpointMetadata(metadata, true);
7016
7071
  return [2 /*return*/, AuthorityMetadataSource.NETWORK];
7017
- case 4: throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
7072
+ case 4:
7073
+ if (!(harcodedMetadata && !this.authorityOptions.skipAuthorityMetadataCache)) return [3 /*break*/, 7];
7074
+ if (!((_b = this.authorityOptions.azureRegionConfiguration) === null || _b === void 0 ? void 0 : _b.azureRegion)) return [3 /*break*/, 6];
7075
+ return [4 /*yield*/, this.updateMetadataWithRegionalInformation(harcodedMetadata)];
7076
+ case 5:
7077
+ harcodedMetadata = _c.sent();
7078
+ _c.label = 6;
7079
+ case 6:
7080
+ metadataEntity.updateEndpointMetadata(harcodedMetadata, false);
7081
+ return [2 /*return*/, AuthorityMetadataSource.HARDCODED_VALUES];
7082
+ case 7: throw ClientAuthError.createUnableToGetOpenidConfigError(this.defaultOpenIdConfigurationEndpoint);
7018
7083
  }
7019
7084
  });
7020
7085
  });
@@ -7045,6 +7110,8 @@ var Authority = /** @class */ (function () {
7045
7110
  };
7046
7111
  /**
7047
7112
  * Gets OAuth endpoints from the given OpenID configuration endpoint.
7113
+ *
7114
+ * @param hasHardcodedMetadata boolean
7048
7115
  */
7049
7116
  Authority.prototype.getEndpointMetadataFromNetwork = function () {
7050
7117
  return __awaiter(this, void 0, void 0, function () {
@@ -7071,6 +7138,54 @@ var Authority = /** @class */ (function () {
7071
7138
  });
7072
7139
  });
7073
7140
  };
7141
+ /**
7142
+ * Get OAuth endpoints for common authorities.
7143
+ */
7144
+ Authority.prototype.getEndpointMetadataFromHardcodedValues = function () {
7145
+ if (this.canonicalAuthority in EndpointMetadata) {
7146
+ return EndpointMetadata[this.canonicalAuthority];
7147
+ }
7148
+ return null;
7149
+ };
7150
+ /**
7151
+ * Update the retrieved metadata with regional information.
7152
+ */
7153
+ Authority.prototype.updateMetadataWithRegionalInformation = function (metadata) {
7154
+ var _a, _b, _c, _d, _e;
7155
+ return __awaiter(this, void 0, void 0, function () {
7156
+ var autodetectedRegionName, azureRegion;
7157
+ return __generator(this, function (_f) {
7158
+ switch (_f.label) {
7159
+ case 0: return [4 /*yield*/, this.regionDiscovery.detectRegion((_a = this.authorityOptions.azureRegionConfiguration) === null || _a === void 0 ? void 0 : _a.environmentRegion, this.regionDiscoveryMetadata, this.proxyUrl)];
7160
+ case 1:
7161
+ autodetectedRegionName = _f.sent();
7162
+ azureRegion = ((_b = this.authorityOptions.azureRegionConfiguration) === null || _b === void 0 ? void 0 : _b.azureRegion) === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
7163
+ ? autodetectedRegionName
7164
+ : (_c = this.authorityOptions.azureRegionConfiguration) === null || _c === void 0 ? void 0 : _c.azureRegion;
7165
+ if (((_d = this.authorityOptions.azureRegionConfiguration) === null || _d === void 0 ? void 0 : _d.azureRegion) === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG) {
7166
+ this.regionDiscoveryMetadata.region_outcome = autodetectedRegionName ?
7167
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_SUCCESSFUL :
7168
+ RegionDiscoveryOutcomes.AUTO_DETECTION_REQUESTED_FAILED;
7169
+ }
7170
+ else {
7171
+ if (autodetectedRegionName) {
7172
+ this.regionDiscoveryMetadata.region_outcome = (((_e = this.authorityOptions.azureRegionConfiguration) === null || _e === void 0 ? void 0 : _e.azureRegion) === autodetectedRegionName) ?
7173
+ RegionDiscoveryOutcomes.CONFIGURED_MATCHES_DETECTED :
7174
+ RegionDiscoveryOutcomes.CONFIGURED_NOT_DETECTED;
7175
+ }
7176
+ else {
7177
+ this.regionDiscoveryMetadata.region_outcome = RegionDiscoveryOutcomes.CONFIGURED_NO_AUTO_DETECTION;
7178
+ }
7179
+ }
7180
+ if (azureRegion) {
7181
+ this.regionDiscoveryMetadata.region_used = azureRegion;
7182
+ return [2 /*return*/, Authority.replaceWithRegionalInformation(metadata, azureRegion)];
7183
+ }
7184
+ return [2 /*return*/, metadata];
7185
+ }
7186
+ });
7187
+ });
7188
+ };
7074
7189
  /**
7075
7190
  * Updates the AuthorityMetadataEntity with new aliases, preferred_network and preferred_cache and returns where the information was retrived from
7076
7191
  * @param cachedMetadata
@@ -7078,7 +7193,7 @@ var Authority = /** @class */ (function () {
7078
7193
  */
7079
7194
  Authority.prototype.updateCloudDiscoveryMetadata = function (metadataEntity) {
7080
7195
  return __awaiter(this, void 0, void 0, function () {
7081
- var metadata;
7196
+ var metadata, harcodedMetadata;
7082
7197
  return __generator(this, function (_a) {
7083
7198
  switch (_a.label) {
7084
7199
  case 0:
@@ -7092,6 +7207,7 @@ var Authority = /** @class */ (function () {
7092
7207
  // No need to update
7093
7208
  return [2 /*return*/, AuthorityMetadataSource.CACHE];
7094
7209
  }
7210
+ harcodedMetadata = this.getCloudDiscoveryMetadataFromHarcodedValues();
7095
7211
  return [4 /*yield*/, this.getCloudDiscoveryMetadataFromNetwork()];
7096
7212
  case 1:
7097
7213
  metadata = _a.sent();
@@ -7099,6 +7215,10 @@ var Authority = /** @class */ (function () {
7099
7215
  metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
7100
7216
  return [2 /*return*/, AuthorityMetadataSource.NETWORK];
7101
7217
  }
7218
+ if (harcodedMetadata && !this.options.skipAuthorityMetadataCache) {
7219
+ metadataEntity.updateCloudDiscoveryMetadata(harcodedMetadata, false);
7220
+ return [2 /*return*/, AuthorityMetadataSource.HARDCODED_VALUES];
7221
+ }
7102
7222
  else {
7103
7223
  // Metadata could not be obtained from config, cache or network
7104
7224
  throw ClientConfigurationError.createUntrustedAuthorityError();
@@ -7132,7 +7252,8 @@ var Authority = /** @class */ (function () {
7132
7252
  };
7133
7253
  /**
7134
7254
  * Called to get metadata from network if CloudDiscoveryMetadata was not populated by config
7135
- * @param networkInterface
7255
+ *
7256
+ * @param hasHardcodedMetadata boolean
7136
7257
  */
7137
7258
  Authority.prototype.getCloudDiscoveryMetadataFromNetwork = function () {
7138
7259
  return __awaiter(this, void 0, void 0, function () {
@@ -7152,7 +7273,9 @@ var Authority = /** @class */ (function () {
7152
7273
  return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint, options)];
7153
7274
  case 2:
7154
7275
  response = _a.sent();
7155
- metadata = isCloudInstanceDiscoveryResponse(response.body) ? response.body.metadata : [];
7276
+ metadata = isCloudInstanceDiscoveryResponse(response.body)
7277
+ ? response.body.metadata
7278
+ : [];
7156
7279
  if (metadata.length === 0) {
7157
7280
  // If no metadata is returned, authority is untrusted
7158
7281
  return [2 /*return*/, null];
@@ -7172,6 +7295,15 @@ var Authority = /** @class */ (function () {
7172
7295
  });
7173
7296
  });
7174
7297
  };
7298
+ /**
7299
+ * Get cloud discovery metadata for common authorities
7300
+ */
7301
+ Authority.prototype.getCloudDiscoveryMetadataFromHarcodedValues = function () {
7302
+ if (this.canonicalAuthority in InstanceDiscoveryMetadata) {
7303
+ return InstanceDiscoveryMetadata[this.canonicalAuthority];
7304
+ }
7305
+ return null;
7306
+ };
7175
7307
  /**
7176
7308
  * Helper function to determine if this host is included in the knownAuthorities config option
7177
7309
  */
@@ -7416,6 +7548,87 @@ var StubbedNetworkModule = {
7416
7548
  }
7417
7549
  };
7418
7550
 
7551
+ /*
7552
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7553
+ * Licensed under the MIT License.
7554
+ */
7555
+ /**
7556
+ * ClientAuthErrorMessage class containing string constants used by error codes and messages.
7557
+ */
7558
+ var JoseHeaderErrorMessage = {
7559
+ missingKidError: {
7560
+ code: "missing_kid_error",
7561
+ desc: "The JOSE Header for the requested JWT, JWS or JWK object requires a keyId to be configured as the 'kid' header claim. No 'kid' value was provided."
7562
+ },
7563
+ missingAlgError: {
7564
+ code: "missing_alg_error",
7565
+ desc: "The JOSE Header for the requested JWT, JWS or JWK object requires an algorithm to be specified as the 'alg' header claim. No 'alg' value was provided."
7566
+ },
7567
+ };
7568
+ /**
7569
+ * Error thrown when there is an error in the client code running on the browser.
7570
+ */
7571
+ var JoseHeaderError = /** @class */ (function (_super) {
7572
+ __extends(JoseHeaderError, _super);
7573
+ function JoseHeaderError(errorCode, errorMessage) {
7574
+ var _this = _super.call(this, errorCode, errorMessage) || this;
7575
+ _this.name = "JoseHeaderError";
7576
+ Object.setPrototypeOf(_this, JoseHeaderError.prototype);
7577
+ return _this;
7578
+ }
7579
+ /**
7580
+ * Creates an error thrown when keyId isn't set on JOSE header.
7581
+ */
7582
+ JoseHeaderError.createMissingKidError = function () {
7583
+ return new JoseHeaderError(JoseHeaderErrorMessage.missingKidError.code, JoseHeaderErrorMessage.missingKidError.desc);
7584
+ };
7585
+ /**
7586
+ * Creates an error thrown when algorithm isn't set on JOSE header.
7587
+ */
7588
+ JoseHeaderError.createMissingAlgError = function () {
7589
+ return new JoseHeaderError(JoseHeaderErrorMessage.missingAlgError.code, JoseHeaderErrorMessage.missingAlgError.desc);
7590
+ };
7591
+ return JoseHeaderError;
7592
+ }(AuthError));
7593
+
7594
+ /*
7595
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7596
+ * Licensed under the MIT License.
7597
+ */
7598
+ var JoseHeader = /** @class */ (function () {
7599
+ function JoseHeader(options) {
7600
+ this.typ = options.typ;
7601
+ this.alg = options.alg;
7602
+ this.kid = options.kid;
7603
+ }
7604
+ /**
7605
+ * Builds SignedHttpRequest formatted JOSE Header from the
7606
+ * JOSE Header options provided or previously set on the object and returns
7607
+ * the stringified header object.
7608
+ * Throws if keyId or algorithm aren't provided since they are required for Access Token Binding.
7609
+ * @param shrHeaderOptions
7610
+ * @returns
7611
+ */
7612
+ JoseHeader.getShrHeaderString = function (shrHeaderOptions) {
7613
+ // KeyID is required on the SHR header
7614
+ if (!shrHeaderOptions.kid) {
7615
+ throw JoseHeaderError.createMissingKidError();
7616
+ }
7617
+ // Alg is required on the SHR header
7618
+ if (!shrHeaderOptions.alg) {
7619
+ throw JoseHeaderError.createMissingAlgError();
7620
+ }
7621
+ var shrHeader = new JoseHeader({
7622
+ // Access Token PoP headers must have type JWT, but the type header can be overriden for special cases
7623
+ typ: shrHeaderOptions.typ || JsonTypes.Jwt,
7624
+ kid: shrHeaderOptions.kid,
7625
+ alg: shrHeaderOptions.alg
7626
+ });
7627
+ return JSON.stringify(shrHeader);
7628
+ };
7629
+ return JoseHeader;
7630
+ }());
7631
+
7419
7632
  /*
7420
7633
  * Copyright (c) Microsoft Corporation. All rights reserved.
7421
7634
  * Licensed under the MIT License.
@@ -8054,6 +8267,7 @@ exports.IdToken = AuthToken;
8054
8267
  exports.IdTokenEntity = IdTokenEntity;
8055
8268
  exports.InteractionRequiredAuthError = InteractionRequiredAuthError;
8056
8269
  exports.InteractionRequiredAuthErrorMessage = InteractionRequiredAuthErrorMessage;
8270
+ exports.JoseHeader = JoseHeader;
8057
8271
  exports.Logger = Logger;
8058
8272
  exports.NetworkManager = NetworkManager;
8059
8273
  exports.OIDC_DEFAULT_SCOPES = OIDC_DEFAULT_SCOPES;