@azure/msal-common 5.0.1 → 5.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 (162) hide show
  1. package/CHANGELOG.json +1228 -1187
  2. package/CHANGELOG.md +467 -452
  3. package/LICENSE +21 -21
  4. package/README.md +62 -62
  5. package/dist/_virtual/_tslib.js +1 -1
  6. package/dist/account/AuthToken.js +1 -1
  7. package/dist/account/AuthToken.js.map +1 -1
  8. package/dist/account/CcsCredential.js +1 -1
  9. package/dist/account/CcsCredential.js.map +1 -1
  10. package/dist/account/ClientInfo.js +1 -1
  11. package/dist/account/ClientInfo.js.map +1 -1
  12. package/dist/authority/Authority.d.ts.map +1 -1
  13. package/dist/authority/Authority.js +8 -2
  14. package/dist/authority/Authority.js.map +1 -1
  15. package/dist/authority/AuthorityFactory.js +1 -1
  16. package/dist/authority/AuthorityFactory.js.map +1 -1
  17. package/dist/authority/AuthorityType.js +1 -1
  18. package/dist/authority/AuthorityType.js.map +1 -1
  19. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  20. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -1
  21. package/dist/authority/OpenIdConfigResponse.d.ts +1 -1
  22. package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -1
  23. package/dist/authority/OpenIdConfigResponse.js +1 -2
  24. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  25. package/dist/authority/ProtocolMode.js +1 -1
  26. package/dist/authority/ProtocolMode.js.map +1 -1
  27. package/dist/authority/RegionDiscovery.js +1 -1
  28. package/dist/authority/RegionDiscovery.js.map +1 -1
  29. package/dist/cache/CacheManager.d.ts +8 -2
  30. package/dist/cache/CacheManager.d.ts.map +1 -1
  31. package/dist/cache/CacheManager.js +35 -14
  32. package/dist/cache/CacheManager.js.map +1 -1
  33. package/dist/cache/entities/AccessTokenEntity.d.ts +1 -1
  34. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  35. package/dist/cache/entities/AccessTokenEntity.js +15 -9
  36. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  37. package/dist/cache/entities/AccountEntity.js +1 -1
  38. package/dist/cache/entities/AccountEntity.js.map +1 -1
  39. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  40. package/dist/cache/entities/AppMetadataEntity.js.map +1 -1
  41. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -1
  42. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  43. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -2
  44. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  45. package/dist/cache/entities/CacheRecord.js +1 -1
  46. package/dist/cache/entities/CacheRecord.js.map +1 -1
  47. package/dist/cache/entities/CredentialEntity.d.ts +1 -0
  48. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  49. package/dist/cache/entities/CredentialEntity.js +3 -3
  50. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  51. package/dist/cache/entities/IdTokenEntity.js +1 -1
  52. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  53. package/dist/cache/entities/RefreshTokenEntity.js +1 -1
  54. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  55. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  56. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -1
  57. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  58. package/dist/cache/entities/ThrottlingEntity.js.map +1 -1
  59. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  60. package/dist/cache/persistence/TokenCacheContext.js.map +1 -1
  61. package/dist/cache/utils/CacheTypes.d.ts +1 -0
  62. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  63. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  64. package/dist/client/AuthorizationCodeClient.js +16 -4
  65. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  66. package/dist/client/BaseClient.js +1 -1
  67. package/dist/client/BaseClient.js.map +1 -1
  68. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  69. package/dist/client/ClientCredentialClient.js +4 -2
  70. package/dist/client/ClientCredentialClient.js.map +1 -1
  71. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  72. package/dist/client/DeviceCodeClient.js +7 -3
  73. package/dist/client/DeviceCodeClient.js.map +1 -1
  74. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  75. package/dist/client/OnBehalfOfClient.js +4 -2
  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 +20 -8
  79. package/dist/client/RefreshTokenClient.js.map +1 -1
  80. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  81. package/dist/client/SilentFlowClient.js +17 -12
  82. package/dist/client/SilentFlowClient.js.map +1 -1
  83. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  84. package/dist/client/UsernamePasswordClient.js +4 -2
  85. package/dist/client/UsernamePasswordClient.js.map +1 -1
  86. package/dist/config/ClientConfiguration.js +1 -1
  87. package/dist/config/ClientConfiguration.js.map +1 -1
  88. package/dist/crypto/ICrypto.d.ts +1 -1
  89. package/dist/crypto/ICrypto.d.ts.map +1 -1
  90. package/dist/crypto/ICrypto.js +1 -1
  91. package/dist/crypto/ICrypto.js.map +1 -1
  92. package/dist/crypto/PopTokenGenerator.js +4 -4
  93. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  94. package/dist/error/AuthError.js +1 -1
  95. package/dist/error/AuthError.js.map +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.d.ts +29 -0
  101. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  102. package/dist/error/ClientConfigurationError.js +43 -3
  103. package/dist/error/ClientConfigurationError.js.map +1 -1
  104. package/dist/error/InteractionRequiredAuthError.js +1 -1
  105. package/dist/error/InteractionRequiredAuthError.js.map +1 -1
  106. package/dist/error/ServerError.js +1 -1
  107. package/dist/error/ServerError.js.map +1 -1
  108. package/dist/index.cjs.js +255 -61
  109. package/dist/index.cjs.js.map +1 -1
  110. package/dist/index.d.ts +1 -0
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +2 -1
  113. package/dist/index.js.map +1 -1
  114. package/dist/logger/Logger.js +1 -1
  115. package/dist/logger/Logger.js.map +1 -1
  116. package/dist/network/INetworkModule.js +1 -1
  117. package/dist/network/INetworkModule.js.map +1 -1
  118. package/dist/network/NetworkManager.js +1 -1
  119. package/dist/network/NetworkManager.js.map +1 -1
  120. package/dist/network/RequestThumbprint.d.ts +2 -0
  121. package/dist/network/RequestThumbprint.d.ts.map +1 -1
  122. package/dist/network/ThrottlingUtils.d.ts.map +1 -1
  123. package/dist/network/ThrottlingUtils.js +4 -2
  124. package/dist/network/ThrottlingUtils.js.map +1 -1
  125. package/dist/packageMetadata.d.ts +1 -1
  126. package/dist/packageMetadata.js +2 -2
  127. package/dist/packageMetadata.js.map +1 -1
  128. package/dist/request/AuthenticationHeaderParser.d.ts +20 -0
  129. package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -0
  130. package/dist/request/AuthenticationHeaderParser.js +64 -0
  131. package/dist/request/AuthenticationHeaderParser.js.map +1 -0
  132. package/dist/request/BaseAuthRequest.d.ts +7 -1
  133. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  134. package/dist/request/RequestParameterBuilder.d.ts +4 -0
  135. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  136. package/dist/request/RequestParameterBuilder.js +10 -1
  137. package/dist/request/RequestParameterBuilder.js.map +1 -1
  138. package/dist/request/RequestValidator.js +1 -1
  139. package/dist/request/RequestValidator.js.map +1 -1
  140. package/dist/request/ScopeSet.js +1 -1
  141. package/dist/request/ScopeSet.js.map +1 -1
  142. package/dist/response/AuthenticationResult.d.ts +1 -1
  143. package/dist/response/ResponseHandler.d.ts.map +1 -1
  144. package/dist/response/ResponseHandler.js +4 -2
  145. package/dist/response/ResponseHandler.js.map +1 -1
  146. package/dist/response/ServerAuthorizationTokenResponse.d.ts +2 -0
  147. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  148. package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
  149. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  150. package/dist/url/UrlString.js +1 -1
  151. package/dist/url/UrlString.js.map +1 -1
  152. package/dist/utils/Constants.d.ts +5 -2
  153. package/dist/utils/Constants.d.ts.map +1 -1
  154. package/dist/utils/Constants.js +5 -2
  155. package/dist/utils/Constants.js.map +1 -1
  156. package/dist/utils/ProtocolUtils.js +1 -1
  157. package/dist/utils/ProtocolUtils.js.map +1 -1
  158. package/dist/utils/StringUtils.js +1 -1
  159. package/dist/utils/StringUtils.js.map +1 -1
  160. package/dist/utils/TimeUtils.js +1 -1
  161. package/dist/utils/TimeUtils.js.map +1 -1
  162. package/package.json +76 -76
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v5.0.1 2021-10-05 */
1
+ /*! @azure/msal-common v5.1.0 2021-11-02 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -153,6 +153,8 @@ var HeaderNames;
153
153
  HeaderNames["CONTENT_TYPE"] = "Content-Type";
154
154
  HeaderNames["RETRY_AFTER"] = "Retry-After";
155
155
  HeaderNames["CCS_HEADER"] = "X-AnchorMailbox";
156
+ HeaderNames["WWWAuthenticate"] = "WWW-Authenticate";
157
+ HeaderNames["AuthenticationInfo"] = "Authentication-Info";
156
158
  })(HeaderNames || (HeaderNames = {}));
157
159
  /**
158
160
  * Persistent cache keys MSAL which stay while user is logged in.
@@ -387,8 +389,9 @@ var SERVER_TELEM_CONSTANTS = {
387
389
  */
388
390
  exports.AuthenticationScheme = void 0;
389
391
  (function (AuthenticationScheme) {
390
- AuthenticationScheme["POP"] = "pop";
391
392
  AuthenticationScheme["BEARER"] = "Bearer";
393
+ AuthenticationScheme["POP"] = "pop";
394
+ AuthenticationScheme["SSH"] = "ssh-cert";
392
395
  })(exports.AuthenticationScheme || (exports.AuthenticationScheme = {}));
393
396
  /**
394
397
  * Constants related to throttling
@@ -743,6 +746,10 @@ var ClientAuthErrorMessage = {
743
746
  bindingKeyNotRemovedError: {
744
747
  code: "binding_key_not_removed",
745
748
  desc: "Could not remove the credential's binding key from storage."
749
+ },
750
+ logoutNotSupported: {
751
+ code: "end_session_endpoint_not_supported",
752
+ desc: "Provided authority does not support logout."
746
753
  }
747
754
  };
748
755
  /**
@@ -1006,6 +1013,12 @@ var ClientAuthError = /** @class */ (function (_super) {
1006
1013
  ClientAuthError.createBindingKeyNotRemovedError = function () {
1007
1014
  return new ClientAuthError(ClientAuthErrorMessage.bindingKeyNotRemovedError.code, ClientAuthErrorMessage.bindingKeyNotRemovedError.desc);
1008
1015
  };
1016
+ /**
1017
+ * Thrown when logout is attempted for an authority that doesnt have an end_session_endpoint
1018
+ */
1019
+ ClientAuthError.createLogoutNotSupportedError = function () {
1020
+ return new ClientAuthError(ClientAuthErrorMessage.logoutNotSupported.code, ClientAuthErrorMessage.logoutNotSupported.desc);
1021
+ };
1009
1022
  return ClientAuthError;
1010
1023
  }(AuthError));
1011
1024
 
@@ -1312,7 +1325,7 @@ var Logger = /** @class */ (function () {
1312
1325
 
1313
1326
  /* eslint-disable header/header */
1314
1327
  var name = "@azure/msal-common";
1315
- var version = "5.0.1";
1328
+ var version = "5.1.0";
1316
1329
 
1317
1330
  /*
1318
1331
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1414,8 +1427,8 @@ var CredentialEntity = /** @class */ (function () {
1414
1427
  this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),
1415
1428
  this.generateTargetForCacheKey(target)
1416
1429
  ];
1417
- // PoP Tokens include scheme in cache key
1418
- if (tokenType === exports.AuthenticationScheme.POP) {
1430
+ // PoP Tokens and SSH certs include scheme in cache key
1431
+ if (tokenType && tokenType !== exports.AuthenticationScheme.BEARER) {
1419
1432
  credentialKey.push(tokenType.toLowerCase());
1420
1433
  }
1421
1434
  return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
@@ -1526,15 +1539,31 @@ var ClientConfigurationErrorMessage = {
1526
1539
  },
1527
1540
  invalidCloudDiscoveryMetadata: {
1528
1541
  code: "invalid_cloud_discovery_metadata",
1529
- desc: "Invalid cloudDiscoveryMetadata provided. Must be a JSON object containing tenant_discovery_endpoint and metadata fields"
1542
+ desc: "Invalid cloudDiscoveryMetadata provided. Must be a stringified JSON object containing tenant_discovery_endpoint and metadata fields"
1530
1543
  },
1531
1544
  invalidAuthorityMetadata: {
1532
1545
  code: "invalid_authority_metadata",
1533
- desc: "Invalid authorityMetadata provided. Must by a JSON object containing authorization_endpoint, token_endpoint, end_session_endpoint, issuer fields."
1546
+ desc: "Invalid authorityMetadata provided. Must by a stringified JSON object containing authorization_endpoint, token_endpoint, issuer fields."
1534
1547
  },
1535
1548
  untrustedAuthority: {
1536
1549
  code: "untrusted_authority",
1537
1550
  desc: "The provided authority is not a trusted authority. Please include this authority in the knownAuthorities config parameter."
1551
+ },
1552
+ missingSshJwk: {
1553
+ code: "missing_ssh_jwk",
1554
+ desc: "Missing sshJwk in SSH certificate request. A stringified JSON Web Key is required when using the SSH authentication scheme."
1555
+ },
1556
+ missingSshKid: {
1557
+ code: "missing_ssh_kid",
1558
+ desc: "Missing sshKid in SSH certificate request. A string that uniquely identifies the public SSH key is required when using the SSH authentication scheme."
1559
+ },
1560
+ missingNonceAuthenticationHeader: {
1561
+ code: "missing_nonce_authentication_header",
1562
+ desc: "Unable to find an authentication header containing server nonce. Either the Authentication-Info or WWW-Authenticate headers must be present in order to obtain a server nonce."
1563
+ },
1564
+ invalidAuthenticationHeader: {
1565
+ code: "invalid_authentication_header",
1566
+ desc: "Invalid authentication header provided"
1538
1567
  }
1539
1568
  };
1540
1569
  /**
@@ -1656,6 +1685,30 @@ var ClientConfigurationError = /** @class */ (function (_super) {
1656
1685
  ClientConfigurationError.createUntrustedAuthorityError = function () {
1657
1686
  return new ClientConfigurationError(ClientConfigurationErrorMessage.untrustedAuthority.code, ClientConfigurationErrorMessage.untrustedAuthority.desc);
1658
1687
  };
1688
+ /*
1689
+ * Throws an error when the authentication scheme is set to SSH but the SSH public key is omitted from the request
1690
+ */
1691
+ ClientConfigurationError.createMissingSshJwkError = function () {
1692
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.missingSshJwk.code, ClientConfigurationErrorMessage.missingSshJwk.desc);
1693
+ };
1694
+ /**
1695
+ * Throws an error when the authentication scheme is set to SSH but the SSH public key ID is omitted from the request
1696
+ */
1697
+ ClientConfigurationError.createMissingSshKidError = function () {
1698
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.missingSshKid.code, ClientConfigurationErrorMessage.missingSshKid.desc);
1699
+ };
1700
+ /**
1701
+ * Throws error when provided headers don't contain a header that a server nonce can be extracted from
1702
+ */
1703
+ ClientConfigurationError.createMissingNonceAuthenticationHeadersError = function () {
1704
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.missingNonceAuthenticationHeader.code, ClientConfigurationErrorMessage.missingNonceAuthenticationHeader.desc);
1705
+ };
1706
+ /**
1707
+ * Throws error when a provided header is invalid in any way
1708
+ */
1709
+ ClientConfigurationError.createInvalidAuthenticationHeaderError = function (invalidHeaderName, details) {
1710
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAuthenticationHeader.code, ClientConfigurationErrorMessage.invalidAuthenticationHeader.desc + ". Invalid header: " + invalidHeaderName + ". Details: " + details);
1711
+ };
1659
1712
  return ClientConfigurationError;
1660
1713
  }(ClientAuthError));
1661
1714
 
@@ -2318,7 +2371,7 @@ var CacheManager = /** @class */ (function () {
2318
2371
  * @param target
2319
2372
  */
2320
2373
  CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
2321
- return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.oboAssertion, filter.tokenType);
2374
+ return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.oboAssertion, filter.tokenType, filter.keyId);
2322
2375
  };
2323
2376
  /**
2324
2377
  * Support function to help match credentials
@@ -2331,7 +2384,7 @@ var CacheManager = /** @class */ (function () {
2331
2384
  * @param oboAssertion
2332
2385
  * @param tokenType
2333
2386
  */
2334
- CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType) {
2387
+ CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType, keyId) {
2335
2388
  var _this = this;
2336
2389
  var allCacheKeys = this.getKeys();
2337
2390
  var matchingCredentials = {
@@ -2378,15 +2431,26 @@ var CacheManager = /** @class */ (function () {
2378
2431
  if (!!target && !_this.matchTarget(entity, target)) {
2379
2432
  return;
2380
2433
  }
2434
+ // Access Token with Auth Scheme specific matching
2381
2435
  if (credentialType === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
2382
2436
  if (!!tokenType && !_this.matchTokenType(entity, tokenType)) {
2383
2437
  return;
2384
2438
  }
2385
- // This check avoids matching outdated POP tokens that don't have the <-scheme> in the cache key
2386
- if (cacheKey.indexOf(exports.AuthenticationScheme.POP) === -1) {
2387
- // AccessToken_With_AuthScheme that doesn't have pop in the key is outdated
2388
- _this.removeItem(cacheKey, exports.CacheSchemaType.CREDENTIAL);
2389
- return;
2439
+ switch (tokenType) {
2440
+ case exports.AuthenticationScheme.POP:
2441
+ // This check avoids matching outdated POP tokens that don't have the <-scheme> in the cache key
2442
+ if (cacheKey.indexOf(exports.AuthenticationScheme.POP) === -1) {
2443
+ // AccessToken_With_AuthScheme that doesn't have "-pop" in the key is outdated and needs to be removed
2444
+ _this.removeItem(cacheKey, exports.CacheSchemaType.CREDENTIAL);
2445
+ return;
2446
+ }
2447
+ break;
2448
+ case exports.AuthenticationScheme.SSH:
2449
+ // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
2450
+ if (keyId && !_this.matchKeyId(entity, keyId)) {
2451
+ return;
2452
+ }
2453
+ break;
2390
2454
  }
2391
2455
  }
2392
2456
  switch (credType) {
@@ -2557,6 +2621,7 @@ var CacheManager = /** @class */ (function () {
2557
2621
  case 0:
2558
2622
  key = credential.generateCredentialKey();
2559
2623
  if (!(credential.credentialType.toLowerCase() === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase())) return [3 /*break*/, 4];
2624
+ if (!(credential.tokenType === exports.AuthenticationScheme.POP)) return [3 /*break*/, 4];
2560
2625
  accessTokenWithAuthSchemeEntity = credential;
2561
2626
  kid = accessTokenWithAuthSchemeEntity.keyId;
2562
2627
  if (!kid) return [3 /*break*/, 4];
@@ -2596,10 +2661,10 @@ var CacheManager = /** @class */ (function () {
2596
2661
  * @param environment
2597
2662
  * @param authScheme
2598
2663
  */
2599
- CacheManager.prototype.readCacheRecord = function (account, clientId, scopes, environment, authScheme) {
2664
+ CacheManager.prototype.readCacheRecord = function (account, clientId, scopes, environment, authScheme, keyId) {
2600
2665
  var cachedAccount = this.readAccountFromCache(account);
2601
2666
  var cachedIdToken = this.readIdTokenFromCache(clientId, account);
2602
- var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, scopes, authScheme);
2667
+ var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, scopes, authScheme, keyId);
2603
2668
  var cachedRefreshToken = this.readRefreshTokenFromCache(clientId, account, false);
2604
2669
  var cachedAppMetadata = this.readAppMetadataFromCache(environment, clientId);
2605
2670
  if (cachedAccount && cachedIdToken) {
@@ -2653,9 +2718,9 @@ var CacheManager = /** @class */ (function () {
2653
2718
  * @param scopes
2654
2719
  * @param authScheme
2655
2720
  */
2656
- CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, scopes, authScheme) {
2657
- // Distinguish between Bearer and PoP token cache types
2658
- var credentialType = (authScheme === exports.AuthenticationScheme.POP) ? exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : exports.CredentialType.ACCESS_TOKEN;
2721
+ CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, scopes, authScheme, keyId) {
2722
+ // Distinguish between Bearer and PoP/SSH token cache types
2723
+ var credentialType = (authScheme && authScheme !== exports.AuthenticationScheme.BEARER) ? exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : exports.CredentialType.ACCESS_TOKEN;
2659
2724
  var accessTokenFilter = {
2660
2725
  homeAccountId: account.homeAccountId,
2661
2726
  environment: account.environment,
@@ -2663,7 +2728,8 @@ var CacheManager = /** @class */ (function () {
2663
2728
  clientId: clientId,
2664
2729
  realm: account.tenantId,
2665
2730
  target: scopes.printScopesLowerCase(),
2666
- tokenType: authScheme
2731
+ tokenType: authScheme,
2732
+ keyId: keyId
2667
2733
  };
2668
2734
  var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
2669
2735
  var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
@@ -2816,6 +2882,14 @@ var CacheManager = /** @class */ (function () {
2816
2882
  CacheManager.prototype.matchTokenType = function (entity, tokenType) {
2817
2883
  return !!(entity.tokenType && entity.tokenType === tokenType);
2818
2884
  };
2885
+ /**
2886
+ * Returns true if the credential's keyId matches the one in the request, false otherwise
2887
+ * @param entity
2888
+ * @param tokenType
2889
+ */
2890
+ CacheManager.prototype.matchKeyId = function (entity, keyId) {
2891
+ return !!(entity.keyId && entity.keyId === keyId);
2892
+ };
2819
2893
  /**
2820
2894
  * returns if a given cache entity is of the type appmetadata
2821
2895
  * @param key
@@ -3149,7 +3223,9 @@ var ThrottlingUtils = /** @class */ (function () {
3149
3223
  authenticationScheme: request.authenticationScheme,
3150
3224
  resourceRequestMethod: request.resourceRequestMethod,
3151
3225
  resourceRequestUri: request.resourceRequestUri,
3152
- shrClaims: request.shrClaims
3226
+ shrClaims: request.shrClaims,
3227
+ sshJwk: request.sshJwk,
3228
+ sshKid: request.sshKid
3153
3229
  };
3154
3230
  var key = this.generateThrottlingStorageKey(thumbprint);
3155
3231
  return cacheManager.removeItem(key, exports.CacheSchemaType.THROTTLING);
@@ -3687,6 +3763,15 @@ var RequestParameterBuilder = /** @class */ (function () {
3687
3763
  this.parameters.set(AADServerParamKeys.REQ_CNF, encodeURIComponent(cnfString));
3688
3764
  }
3689
3765
  };
3766
+ /**
3767
+ * add SSH JWK and key ID to query params
3768
+ */
3769
+ RequestParameterBuilder.prototype.addSshJwk = function (sshJwkString) {
3770
+ if (!StringUtils.isEmpty(sshJwkString)) {
3771
+ this.parameters.set(AADServerParamKeys.TOKEN_TYPE, exports.AuthenticationScheme.SSH);
3772
+ this.parameters.set(AADServerParamKeys.REQ_CNF, encodeURIComponent(sshJwkString));
3773
+ }
3774
+ };
3690
3775
  /**
3691
3776
  * add server telemetry fields
3692
3777
  * @param serverTelemetryManager
@@ -3870,7 +3955,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
3870
3955
  * @param expiresOn
3871
3956
  * @param extExpiresOn
3872
3957
  */
3873
- AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion) {
3958
+ AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion, keyId) {
3874
3959
  var _a;
3875
3960
  var atEntity = new AccessTokenEntity();
3876
3961
  atEntity.homeAccountId = homeAccountId;
@@ -3893,15 +3978,21 @@ var AccessTokenEntity = /** @class */ (function (_super) {
3893
3978
  atEntity.target = scopes;
3894
3979
  atEntity.oboAssertion = oboAssertion;
3895
3980
  atEntity.tokenType = StringUtils.isEmpty(tokenType) ? exports.AuthenticationScheme.BEARER : tokenType;
3896
- // Create Access Token With AuthScheme instead of regular access token
3897
- if (atEntity.tokenType === exports.AuthenticationScheme.POP) {
3981
+ // Create Access Token With Auth Scheme instead of regular access token
3982
+ if (atEntity.tokenType !== exports.AuthenticationScheme.BEARER) {
3898
3983
  atEntity.credentialType = exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
3899
- // Make sure keyId is present and add it to credential
3900
- var tokenClaims = AuthToken.extractTokenClaims(accessToken, cryptoUtils);
3901
- if (!((_a = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _a === void 0 ? void 0 : _a.kid)) {
3902
- throw ClientAuthError.createTokenClaimsRequiredError();
3984
+ switch (atEntity.tokenType) {
3985
+ case exports.AuthenticationScheme.POP:
3986
+ // Make sure keyId is present and add it to credential
3987
+ var tokenClaims = AuthToken.extractTokenClaims(accessToken, cryptoUtils);
3988
+ if (!((_a = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _a === void 0 ? void 0 : _a.kid)) {
3989
+ throw ClientAuthError.createTokenClaimsRequiredError();
3990
+ }
3991
+ atEntity.keyId = tokenClaims.cnf.kid;
3992
+ break;
3993
+ case exports.AuthenticationScheme.SSH:
3994
+ atEntity.keyId = keyId;
3903
3995
  }
3904
- atEntity.keyId = tokenClaims.cnf.kid;
3905
3996
  }
3906
3997
  return atEntity;
3907
3998
  };
@@ -4392,14 +4483,14 @@ var PopTokenGenerator = /** @class */ (function () {
4392
4483
  };
4393
4484
  PopTokenGenerator.prototype.signPayload = function (payload, kid, request, claims) {
4394
4485
  return __awaiter(this, void 0, void 0, function () {
4395
- var resourceRequestMethod, resourceRequestUri, shrClaims, resourceUrlString, resourceUrlComponents;
4486
+ var resourceRequestMethod, resourceRequestUri, shrClaims, shrNonce, resourceUrlString, resourceUrlComponents;
4396
4487
  return __generator(this, function (_a) {
4397
4488
  switch (_a.label) {
4398
4489
  case 0:
4399
- resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims;
4490
+ resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
4400
4491
  resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
4401
4492
  resourceUrlComponents = resourceUrlString === null || resourceUrlString === void 0 ? void 0 : resourceUrlString.getUrlComponents();
4402
- 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: 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)];
4493
+ 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)];
4403
4494
  case 1: return [2 /*return*/, _a.sent()];
4404
4495
  }
4405
4496
  });
@@ -4590,6 +4681,8 @@ var ResponseHandler = /** @class */ (function () {
4590
4681
  if (!!authCodePayload && !!authCodePayload.state) {
4591
4682
  requestStateObj = ProtocolUtils.parseRequestState(this.cryptoObj, authCodePayload.state);
4592
4683
  }
4684
+ // Add keyId from request to serverTokenResponse if defined
4685
+ serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
4593
4686
  cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, idTokenObj, request.scopes, oboAssertion, authCodePayload);
4594
4687
  _a.label = 1;
4595
4688
  case 1:
@@ -4666,7 +4759,7 @@ var ResponseHandler = /** @class */ (function () {
4666
4759
  var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
4667
4760
  var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
4668
4761
  // non AAD scenarios can have empty realm
4669
- 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);
4762
+ 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);
4670
4763
  }
4671
4764
  // refreshToken
4672
4765
  var cachedRefreshToken = null;
@@ -4884,7 +4977,9 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
4884
4977
  authenticationScheme: request.authenticationScheme,
4885
4978
  resourceRequestMethod: request.resourceRequestMethod,
4886
4979
  resourceRequestUri: request.resourceRequestUri,
4887
- shrClaims: request.shrClaims
4980
+ shrClaims: request.shrClaims,
4981
+ sshJwk: request.sshJwk,
4982
+ sshKid: request.sshKid
4888
4983
  };
4889
4984
  return [4 /*yield*/, this.createTokenRequestBody(request)];
4890
4985
  case 1:
@@ -4965,8 +5060,18 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
4965
5060
  case 1:
4966
5061
  cnfString = _a.sent();
4967
5062
  parameterBuilder.addPopToken(cnfString);
4968
- _a.label = 2;
5063
+ return [3 /*break*/, 3];
4969
5064
  case 2:
5065
+ if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
5066
+ if (request.sshJwk) {
5067
+ parameterBuilder.addSshJwk(request.sshJwk);
5068
+ }
5069
+ else {
5070
+ throw ClientConfigurationError.createMissingSshJwkError();
5071
+ }
5072
+ }
5073
+ _a.label = 3;
5074
+ case 3:
4970
5075
  correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
4971
5076
  parameterBuilder.addCorrelationId(correlationId);
4972
5077
  if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
@@ -5198,7 +5303,9 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5198
5303
  authenticationScheme: request.authenticationScheme,
5199
5304
  resourceRequestMethod: request.resourceRequestMethod,
5200
5305
  resourceRequestUri: request.resourceRequestUri,
5201
- shrClaims: request.shrClaims
5306
+ shrClaims: request.shrClaims,
5307
+ sshJwk: request.sshJwk,
5308
+ sshKid: request.sshKid
5202
5309
  };
5203
5310
  return [2 /*return*/, this.executePostRequestToDeviceCodeEndpoint(this.authority.deviceCodeEndpoint, queryString, headers, thumbprint)];
5204
5311
  });
@@ -5295,7 +5402,9 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5295
5402
  authenticationScheme: request.authenticationScheme,
5296
5403
  resourceRequestMethod: request.resourceRequestMethod,
5297
5404
  resourceRequestUri: request.resourceRequestUri,
5298
- shrClaims: request.shrClaims
5405
+ shrClaims: request.shrClaims,
5406
+ sshJwk: request.sshJwk,
5407
+ sshKid: request.sshKid
5299
5408
  };
5300
5409
  return [4 /*yield*/, this.executePostToTokenEndpoint(this.authority.tokenEndpoint, requestBody, headers, thumbprint)];
5301
5410
  case 2:
@@ -5461,7 +5570,9 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5461
5570
  authenticationScheme: request.authenticationScheme,
5462
5571
  resourceRequestMethod: request.resourceRequestMethod,
5463
5572
  resourceRequestUri: request.resourceRequestUri,
5464
- shrClaims: request.shrClaims
5573
+ shrClaims: request.shrClaims,
5574
+ sshJwk: request.sshJwk,
5575
+ sshKid: request.sshKid
5465
5576
  };
5466
5577
  endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParameters);
5467
5578
  return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)];
@@ -5486,9 +5597,9 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5486
5597
  */
5487
5598
  RefreshTokenClient.prototype.createTokenRequestBody = function (request) {
5488
5599
  return __awaiter(this, void 0, void 0, function () {
5489
- var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, _a, _b, clientInfo;
5490
- return __generator(this, function (_c) {
5491
- switch (_c.label) {
5600
+ var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, cnfString, clientInfo;
5601
+ return __generator(this, function (_a) {
5602
+ switch (_a.label) {
5492
5603
  case 0:
5493
5604
  parameterBuilder = new RequestParameterBuilder();
5494
5605
  parameterBuilder.addClientId(this.config.authOptions.clientId);
@@ -5513,12 +5624,22 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5513
5624
  }
5514
5625
  if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 2];
5515
5626
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5516
- _b = (_a = parameterBuilder).addPopToken;
5517
5627
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5518
5628
  case 1:
5519
- _b.apply(_a, [_c.sent()]);
5520
- _c.label = 2;
5629
+ cnfString = _a.sent();
5630
+ parameterBuilder.addPopToken(cnfString);
5631
+ return [3 /*break*/, 3];
5521
5632
  case 2:
5633
+ if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
5634
+ if (request.sshJwk) {
5635
+ parameterBuilder.addSshJwk(request.sshJwk);
5636
+ }
5637
+ else {
5638
+ throw ClientConfigurationError.createMissingSshJwkError();
5639
+ }
5640
+ }
5641
+ _a.label = 3;
5642
+ case 3:
5522
5643
  if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
5523
5644
  parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
5524
5645
  }
@@ -5657,7 +5778,9 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5657
5778
  authenticationScheme: request.authenticationScheme,
5658
5779
  resourceRequestMethod: request.resourceRequestMethod,
5659
5780
  resourceRequestUri: request.resourceRequestUri,
5660
- shrClaims: request.shrClaims
5781
+ shrClaims: request.shrClaims,
5782
+ sshJwk: request.sshJwk,
5783
+ sshKid: request.sshKid
5661
5784
  };
5662
5785
  reqTimestamp = TimeUtils.nowSeconds();
5663
5786
  return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
@@ -5856,7 +5979,9 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
5856
5979
  authenticationScheme: request.authenticationScheme,
5857
5980
  resourceRequestMethod: request.resourceRequestMethod,
5858
5981
  resourceRequestUri: request.resourceRequestUri,
5859
- shrClaims: request.shrClaims
5982
+ shrClaims: request.shrClaims,
5983
+ sshJwk: request.sshJwk,
5984
+ sshKid: request.sshKid
5860
5985
  };
5861
5986
  reqTimestamp = TimeUtils.nowSeconds();
5862
5987
  return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
@@ -5956,6 +6081,17 @@ var SilentFlowClient = /** @class */ (function (_super) {
5956
6081
  if (!request) {
5957
6082
  throw ClientConfigurationError.createEmptyTokenRequestError();
5958
6083
  }
6084
+ if (request.forceRefresh) {
6085
+ // Must refresh due to present force_refresh flag.
6086
+ (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.FORCE_REFRESH);
6087
+ this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true.");
6088
+ throw ClientAuthError.createRefreshRequiredError();
6089
+ }
6090
+ else if (!StringUtils.isEmptyObj(request.claims)) {
6091
+ // Must refresh due to request parameters.
6092
+ this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because claims are requested.");
6093
+ throw ClientAuthError.createRefreshRequiredError();
6094
+ }
5959
6095
  // We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
5960
6096
  if (!request.account) {
5961
6097
  throw ClientAuthError.createNoAccountInSilentRequestError();
@@ -5963,30 +6099,24 @@ var SilentFlowClient = /** @class */ (function (_super) {
5963
6099
  requestScopes = new ScopeSet(request.scopes || []);
5964
6100
  environment = request.authority || this.authority.getPreferredCache();
5965
6101
  authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
5966
- cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, requestScopes, environment, authScheme);
5967
- if (request.forceRefresh) {
5968
- // Must refresh due to present force_refresh flag.
5969
- (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.FORCE_REFRESH);
5970
- throw ClientAuthError.createRefreshRequiredError();
5971
- }
5972
- else if (!cacheRecord.accessToken) {
6102
+ cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, requestScopes, environment, authScheme, request.sshKid);
6103
+ if (!cacheRecord.accessToken) {
5973
6104
  // Must refresh due to non-existent access_token.
5974
6105
  (_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
6106
+ this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
5975
6107
  throw ClientAuthError.createRefreshRequiredError();
5976
6108
  }
5977
6109
  else if (TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
5978
6110
  TimeUtils.isTokenExpired(cacheRecord.accessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
5979
6111
  // Must refresh due to expired access_token.
5980
6112
  (_c = this.serverTelemetryManager) === null || _c === void 0 ? void 0 : _c.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
6113
+ this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token is expired or will expire within " + this.config.systemOptions.tokenRenewalOffsetSeconds + " seconds.");
5981
6114
  throw ClientAuthError.createRefreshRequiredError();
5982
6115
  }
5983
6116
  else if (cacheRecord.accessToken.refreshOn && TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)) {
5984
6117
  // Must refresh due to the refresh_in value.
5985
6118
  (_d = this.serverTelemetryManager) === null || _d === void 0 ? void 0 : _d.setCacheOutcome(CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN);
5986
- throw ClientAuthError.createRefreshRequiredError();
5987
- }
5988
- else if (!StringUtils.isEmptyObj(request.claims)) {
5989
- // Must refresh due to request parameters.
6119
+ this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'.");
5990
6120
  throw ClientAuthError.createRefreshRequiredError();
5991
6121
  }
5992
6122
  if (this.config.serverTelemetryManager) {
@@ -6074,7 +6204,9 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6074
6204
  authenticationScheme: request.authenticationScheme,
6075
6205
  resourceRequestMethod: request.resourceRequestMethod,
6076
6206
  resourceRequestUri: request.resourceRequestUri,
6077
- shrClaims: request.shrClaims
6207
+ shrClaims: request.shrClaims,
6208
+ sshJwk: request.sshJwk,
6209
+ sshKid: request.sshKid
6078
6210
  };
6079
6211
  requestBody = this.createTokenRequestBody(request);
6080
6212
  headers = this.createTokenRequestHeaders({
@@ -6130,7 +6262,6 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6130
6262
  function isOpenIdConfigResponse(response) {
6131
6263
  return (response.hasOwnProperty("authorization_endpoint") &&
6132
6264
  response.hasOwnProperty("token_endpoint") &&
6133
- response.hasOwnProperty("end_session_endpoint") &&
6134
6265
  response.hasOwnProperty("issuer"));
6135
6266
  }
6136
6267
 
@@ -6212,7 +6343,6 @@ var AuthorityMetadataEntity = /** @class */ (function () {
6212
6343
  entity.hasOwnProperty("canonical_authority") &&
6213
6344
  entity.hasOwnProperty("authorization_endpoint") &&
6214
6345
  entity.hasOwnProperty("token_endpoint") &&
6215
- entity.hasOwnProperty("end_session_endpoint") &&
6216
6346
  entity.hasOwnProperty("issuer") &&
6217
6347
  entity.hasOwnProperty("aliasesFromNetwork") &&
6218
6348
  entity.hasOwnProperty("endpointsFromNetwork") &&
@@ -6494,6 +6624,10 @@ var Authority = /** @class */ (function () {
6494
6624
  */
6495
6625
  get: function () {
6496
6626
  if (this.discoveryComplete()) {
6627
+ // ROPC policies may not have end_session_endpoint set
6628
+ if (!this.metadata.end_session_endpoint) {
6629
+ throw ClientAuthError.createLogoutNotSupportedError();
6630
+ }
6497
6631
  var endpoint = this.replacePath(this.metadata.end_session_endpoint);
6498
6632
  return this.replaceTenant(endpoint);
6499
6633
  }
@@ -6894,7 +7028,9 @@ var Authority = /** @class */ (function () {
6894
7028
  metadata.authorization_endpoint = Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
6895
7029
  // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
6896
7030
  metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, "allowestsrnonmsi=true");
6897
- metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
7031
+ if (metadata.end_session_endpoint) {
7032
+ metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
7033
+ }
6898
7034
  return metadata;
6899
7035
  };
6900
7036
  return Authority;
@@ -7029,6 +7165,63 @@ var StubbedNetworkModule = {
7029
7165
  }
7030
7166
  };
7031
7167
 
7168
+ /*
7169
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7170
+ * Licensed under the MIT License.
7171
+ */
7172
+ /**
7173
+ * This is a helper class that parses supported HTTP response authentication headers to extract and return
7174
+ * header challenge values that can be used outside the basic authorization flows.
7175
+ */
7176
+ var AuthenticationHeaderParser = /** @class */ (function () {
7177
+ function AuthenticationHeaderParser(headers) {
7178
+ this.headers = headers;
7179
+ }
7180
+ /**
7181
+ * This method parses the SHR nonce value out of either the Authentication-Info or WWW-Authenticate authentication headers.
7182
+ * @returns
7183
+ */
7184
+ AuthenticationHeaderParser.prototype.getShrNonce = function () {
7185
+ // Attempt to parse nonce from Authentiacation-Info
7186
+ var authenticationInfo = this.headers[HeaderNames.AuthenticationInfo];
7187
+ if (authenticationInfo) {
7188
+ var authenticationInfoChallenges = this.parseChallenges(authenticationInfo);
7189
+ if (authenticationInfoChallenges.nextnonce) {
7190
+ return authenticationInfoChallenges.nextnonce;
7191
+ }
7192
+ throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.AuthenticationInfo, "nextnonce challenge is missing.");
7193
+ }
7194
+ // Attempt to parse nonce from WWW-Authenticate
7195
+ var wwwAuthenticate = this.headers[HeaderNames.WWWAuthenticate];
7196
+ if (wwwAuthenticate) {
7197
+ var wwwAuthenticateChallenges = this.parseChallenges(wwwAuthenticate);
7198
+ if (wwwAuthenticateChallenges.nonce) {
7199
+ return wwwAuthenticateChallenges.nonce;
7200
+ }
7201
+ throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.WWWAuthenticate, "nonce challenge is missing.");
7202
+ }
7203
+ // If neither header is present, throw missing headers error
7204
+ throw ClientConfigurationError.createMissingNonceAuthenticationHeadersError();
7205
+ };
7206
+ /**
7207
+ * Parses an HTTP header's challenge set into a key/value map.
7208
+ * @param header
7209
+ * @returns
7210
+ */
7211
+ AuthenticationHeaderParser.prototype.parseChallenges = function (header) {
7212
+ var schemeSeparator = header.indexOf(" ");
7213
+ var challenges = header.substr(schemeSeparator + 1).split(",");
7214
+ var challengeMap = {};
7215
+ challenges.forEach(function (challenge) {
7216
+ var _a = challenge.split("="), key = _a[0], value = _a[1];
7217
+ // Remove escaped quotation marks (', ") from challenge string to keep only the challenge value
7218
+ challengeMap[key] = unescape(value.replace(/['"]+/g, ""));
7219
+ });
7220
+ return challengeMap;
7221
+ };
7222
+ return AuthenticationHeaderParser;
7223
+ }());
7224
+
7032
7225
  /*
7033
7226
  * Copyright (c) Microsoft Corporation. All rights reserved.
7034
7227
  * Licensed under the MIT License.
@@ -7195,6 +7388,7 @@ exports.AppMetadataEntity = AppMetadataEntity;
7195
7388
  exports.AuthError = AuthError;
7196
7389
  exports.AuthErrorMessage = AuthErrorMessage;
7197
7390
  exports.AuthToken = AuthToken;
7391
+ exports.AuthenticationHeaderParser = AuthenticationHeaderParser;
7198
7392
  exports.Authority = Authority;
7199
7393
  exports.AuthorityFactory = AuthorityFactory;
7200
7394
  exports.AuthorityMetadataEntity = AuthorityMetadataEntity;