@azure/msal-common 5.0.1 → 5.1.2

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 (132) 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/ClientInfo.js +1 -1
  5. package/dist/authority/Authority.d.ts.map +1 -1
  6. package/dist/authority/Authority.js +8 -2
  7. package/dist/authority/Authority.js.map +1 -1
  8. package/dist/authority/AuthorityFactory.js +1 -1
  9. package/dist/authority/AuthorityType.js +1 -1
  10. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  11. package/dist/authority/OpenIdConfigResponse.d.ts +1 -1
  12. package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -1
  13. package/dist/authority/OpenIdConfigResponse.js +1 -2
  14. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  15. package/dist/authority/ProtocolMode.js +1 -1
  16. package/dist/authority/RegionDiscovery.js +1 -1
  17. package/dist/cache/CacheManager.d.ts +14 -3
  18. package/dist/cache/CacheManager.d.ts.map +1 -1
  19. package/dist/cache/CacheManager.js +47 -17
  20. package/dist/cache/CacheManager.js.map +1 -1
  21. package/dist/cache/entities/AccessTokenEntity.d.ts +1 -1
  22. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  23. package/dist/cache/entities/AccessTokenEntity.js +15 -9
  24. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  25. package/dist/cache/entities/AccountEntity.js +1 -1
  26. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  27. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -1
  28. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  29. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -2
  30. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  31. package/dist/cache/entities/CacheRecord.js +1 -1
  32. package/dist/cache/entities/CredentialEntity.d.ts +1 -0
  33. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  34. package/dist/cache/entities/CredentialEntity.js +3 -3
  35. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  36. package/dist/cache/entities/IdTokenEntity.js +1 -1
  37. package/dist/cache/entities/RefreshTokenEntity.js +1 -1
  38. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  39. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  40. package/dist/cache/interface/ICacheManager.d.ts +5 -1
  41. package/dist/cache/interface/ICacheManager.d.ts.map +1 -1
  42. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  43. package/dist/cache/utils/CacheTypes.d.ts +1 -0
  44. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  45. package/dist/client/AuthorizationCodeClient.d.ts +1 -0
  46. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  47. package/dist/client/AuthorizationCodeClient.js +43 -15
  48. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  49. package/dist/client/BaseClient.js +1 -1
  50. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  51. package/dist/client/ClientCredentialClient.js +4 -2
  52. package/dist/client/ClientCredentialClient.js.map +1 -1
  53. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  54. package/dist/client/DeviceCodeClient.js +7 -3
  55. package/dist/client/DeviceCodeClient.js.map +1 -1
  56. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  57. package/dist/client/OnBehalfOfClient.js +4 -2
  58. package/dist/client/OnBehalfOfClient.js.map +1 -1
  59. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  60. package/dist/client/RefreshTokenClient.js +20 -8
  61. package/dist/client/RefreshTokenClient.js.map +1 -1
  62. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  63. package/dist/client/SilentFlowClient.js +17 -12
  64. package/dist/client/SilentFlowClient.js.map +1 -1
  65. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  66. package/dist/client/UsernamePasswordClient.js +4 -2
  67. package/dist/client/UsernamePasswordClient.js.map +1 -1
  68. package/dist/config/ClientConfiguration.js +1 -1
  69. package/dist/crypto/ICrypto.d.ts +1 -1
  70. package/dist/crypto/ICrypto.d.ts.map +1 -1
  71. package/dist/crypto/ICrypto.js +1 -1
  72. package/dist/crypto/ICrypto.js.map +1 -1
  73. package/dist/crypto/PopTokenGenerator.js +4 -4
  74. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  75. package/dist/error/AuthError.js +1 -1
  76. package/dist/error/ClientAuthError.d.ts +8 -0
  77. package/dist/error/ClientAuthError.d.ts.map +1 -1
  78. package/dist/error/ClientAuthError.js +11 -1
  79. package/dist/error/ClientAuthError.js.map +1 -1
  80. package/dist/error/ClientConfigurationError.d.ts +29 -0
  81. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  82. package/dist/error/ClientConfigurationError.js +43 -3
  83. package/dist/error/ClientConfigurationError.js.map +1 -1
  84. package/dist/error/InteractionRequiredAuthError.js +1 -1
  85. package/dist/error/ServerError.js +1 -1
  86. package/dist/index.cjs.js +294 -75
  87. package/dist/index.cjs.js.map +1 -1
  88. package/dist/index.d.ts +1 -0
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.js +2 -1
  91. package/dist/index.js.map +1 -1
  92. package/dist/logger/Logger.js +1 -1
  93. package/dist/network/INetworkModule.js +1 -1
  94. package/dist/network/NetworkManager.js +1 -1
  95. package/dist/network/RequestThumbprint.d.ts +2 -0
  96. package/dist/network/RequestThumbprint.d.ts.map +1 -1
  97. package/dist/network/ThrottlingUtils.d.ts.map +1 -1
  98. package/dist/network/ThrottlingUtils.js +4 -2
  99. package/dist/network/ThrottlingUtils.js.map +1 -1
  100. package/dist/packageMetadata.d.ts +1 -1
  101. package/dist/packageMetadata.js +2 -2
  102. package/dist/packageMetadata.js.map +1 -1
  103. package/dist/request/AuthenticationHeaderParser.d.ts +20 -0
  104. package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -0
  105. package/dist/request/AuthenticationHeaderParser.js +64 -0
  106. package/dist/request/AuthenticationHeaderParser.js.map +1 -0
  107. package/dist/request/BaseAuthRequest.d.ts +7 -1
  108. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  109. package/dist/request/RequestParameterBuilder.d.ts +4 -0
  110. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  111. package/dist/request/RequestParameterBuilder.js +10 -1
  112. package/dist/request/RequestParameterBuilder.js.map +1 -1
  113. package/dist/request/RequestValidator.js +1 -1
  114. package/dist/request/ScopeSet.js +1 -1
  115. package/dist/response/AuthenticationResult.d.ts +1 -1
  116. package/dist/response/ResponseHandler.d.ts.map +1 -1
  117. package/dist/response/ResponseHandler.js +4 -2
  118. package/dist/response/ResponseHandler.js.map +1 -1
  119. package/dist/response/ServerAuthorizationTokenResponse.d.ts +2 -0
  120. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  121. package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
  122. package/dist/url/UrlString.js +1 -1
  123. package/dist/utils/Constants.d.ts +5 -2
  124. package/dist/utils/Constants.d.ts.map +1 -1
  125. package/dist/utils/Constants.js +5 -2
  126. package/dist/utils/Constants.js.map +1 -1
  127. package/dist/utils/ProtocolUtils.js +1 -1
  128. package/dist/utils/StringUtils.js +1 -1
  129. package/dist/utils/TimeUtils.js +1 -1
  130. package/package.json +1 -1
  131. package/CHANGELOG.json +0 -1187
  132. package/CHANGELOG.md +0 -452
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.2 2022-08-03 */
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.2";
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,27 +2431,43 @@ 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
  }
2456
+ /*
2457
+ * At this point, the entity matches the request, update cache key if key schema has changed
2458
+ * Migration code for forwards compatibility with new versions of the library in case of rollback.
2459
+ */
2460
+ var updatedCacheKey = _this.updateCredentialCacheKey(cacheKey, entity);
2392
2461
  switch (credType) {
2393
2462
  case exports.CredentialType.ID_TOKEN:
2394
- matchingCredentials.idTokens[cacheKey] = entity;
2463
+ matchingCredentials.idTokens[updatedCacheKey] = entity;
2395
2464
  break;
2396
2465
  case exports.CredentialType.ACCESS_TOKEN:
2397
2466
  case exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
2398
- matchingCredentials.accessTokens[cacheKey] = entity;
2467
+ matchingCredentials.accessTokens[updatedCacheKey] = entity;
2399
2468
  break;
2400
2469
  case exports.CredentialType.REFRESH_TOKEN:
2401
- matchingCredentials.refreshTokens[cacheKey] = entity;
2470
+ matchingCredentials.refreshTokens[updatedCacheKey] = entity;
2402
2471
  break;
2403
2472
  }
2404
2473
  });
@@ -2557,6 +2626,7 @@ var CacheManager = /** @class */ (function () {
2557
2626
  case 0:
2558
2627
  key = credential.generateCredentialKey();
2559
2628
  if (!(credential.credentialType.toLowerCase() === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase())) return [3 /*break*/, 4];
2629
+ if (!(credential.tokenType === exports.AuthenticationScheme.POP)) return [3 /*break*/, 4];
2560
2630
  accessTokenWithAuthSchemeEntity = credential;
2561
2631
  kid = accessTokenWithAuthSchemeEntity.keyId;
2562
2632
  if (!kid) return [3 /*break*/, 4];
@@ -2596,10 +2666,10 @@ var CacheManager = /** @class */ (function () {
2596
2666
  * @param environment
2597
2667
  * @param authScheme
2598
2668
  */
2599
- CacheManager.prototype.readCacheRecord = function (account, clientId, scopes, environment, authScheme) {
2669
+ CacheManager.prototype.readCacheRecord = function (account, clientId, scopes, environment, authScheme, keyId) {
2600
2670
  var cachedAccount = this.readAccountFromCache(account);
2601
2671
  var cachedIdToken = this.readIdTokenFromCache(clientId, account);
2602
- var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, scopes, authScheme);
2672
+ var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, scopes, authScheme, keyId);
2603
2673
  var cachedRefreshToken = this.readRefreshTokenFromCache(clientId, account, false);
2604
2674
  var cachedAppMetadata = this.readAppMetadataFromCache(environment, clientId);
2605
2675
  if (cachedAccount && cachedIdToken) {
@@ -2653,9 +2723,9 @@ var CacheManager = /** @class */ (function () {
2653
2723
  * @param scopes
2654
2724
  * @param authScheme
2655
2725
  */
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;
2726
+ CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, scopes, authScheme, keyId) {
2727
+ // Distinguish between Bearer and PoP/SSH token cache types
2728
+ var credentialType = (authScheme && authScheme !== exports.AuthenticationScheme.BEARER) ? exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : exports.CredentialType.ACCESS_TOKEN;
2659
2729
  var accessTokenFilter = {
2660
2730
  homeAccountId: account.homeAccountId,
2661
2731
  environment: account.environment,
@@ -2663,7 +2733,8 @@ var CacheManager = /** @class */ (function () {
2663
2733
  clientId: clientId,
2664
2734
  realm: account.tenantId,
2665
2735
  target: scopes.printScopesLowerCase(),
2666
- tokenType: authScheme
2736
+ tokenType: authScheme,
2737
+ keyId: keyId
2667
2738
  };
2668
2739
  var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
2669
2740
  var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
@@ -2816,6 +2887,14 @@ var CacheManager = /** @class */ (function () {
2816
2887
  CacheManager.prototype.matchTokenType = function (entity, tokenType) {
2817
2888
  return !!(entity.tokenType && entity.tokenType === tokenType);
2818
2889
  };
2890
+ /**
2891
+ * Returns true if the credential's keyId matches the one in the request, false otherwise
2892
+ * @param entity
2893
+ * @param tokenType
2894
+ */
2895
+ CacheManager.prototype.matchKeyId = function (entity, keyId) {
2896
+ return !!(entity.keyId && entity.keyId === keyId);
2897
+ };
2819
2898
  /**
2820
2899
  * returns if a given cache entity is of the type appmetadata
2821
2900
  * @param key
@@ -2964,6 +3043,10 @@ var DefaultStorageClass = /** @class */ (function (_super) {
2964
3043
  });
2965
3044
  });
2966
3045
  };
3046
+ DefaultStorageClass.prototype.updateCredentialCacheKey = function () {
3047
+ var notImplErr = "Storage interface - updateCredentialCacheKey() has not been implemented for the cacheStorage interface.";
3048
+ throw AuthError.createUnexpectedError(notImplErr);
3049
+ };
2967
3050
  return DefaultStorageClass;
2968
3051
  }(CacheManager));
2969
3052
 
@@ -3149,7 +3232,9 @@ var ThrottlingUtils = /** @class */ (function () {
3149
3232
  authenticationScheme: request.authenticationScheme,
3150
3233
  resourceRequestMethod: request.resourceRequestMethod,
3151
3234
  resourceRequestUri: request.resourceRequestUri,
3152
- shrClaims: request.shrClaims
3235
+ shrClaims: request.shrClaims,
3236
+ sshJwk: request.sshJwk,
3237
+ sshKid: request.sshKid
3153
3238
  };
3154
3239
  var key = this.generateThrottlingStorageKey(thumbprint);
3155
3240
  return cacheManager.removeItem(key, exports.CacheSchemaType.THROTTLING);
@@ -3687,6 +3772,15 @@ var RequestParameterBuilder = /** @class */ (function () {
3687
3772
  this.parameters.set(AADServerParamKeys.REQ_CNF, encodeURIComponent(cnfString));
3688
3773
  }
3689
3774
  };
3775
+ /**
3776
+ * add SSH JWK and key ID to query params
3777
+ */
3778
+ RequestParameterBuilder.prototype.addSshJwk = function (sshJwkString) {
3779
+ if (!StringUtils.isEmpty(sshJwkString)) {
3780
+ this.parameters.set(AADServerParamKeys.TOKEN_TYPE, exports.AuthenticationScheme.SSH);
3781
+ this.parameters.set(AADServerParamKeys.REQ_CNF, encodeURIComponent(sshJwkString));
3782
+ }
3783
+ };
3690
3784
  /**
3691
3785
  * add server telemetry fields
3692
3786
  * @param serverTelemetryManager
@@ -3870,7 +3964,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
3870
3964
  * @param expiresOn
3871
3965
  * @param extExpiresOn
3872
3966
  */
3873
- AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion) {
3967
+ AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion, keyId) {
3874
3968
  var _a;
3875
3969
  var atEntity = new AccessTokenEntity();
3876
3970
  atEntity.homeAccountId = homeAccountId;
@@ -3893,15 +3987,21 @@ var AccessTokenEntity = /** @class */ (function (_super) {
3893
3987
  atEntity.target = scopes;
3894
3988
  atEntity.oboAssertion = oboAssertion;
3895
3989
  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) {
3990
+ // Create Access Token With Auth Scheme instead of regular access token
3991
+ if (atEntity.tokenType !== exports.AuthenticationScheme.BEARER) {
3898
3992
  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();
3993
+ switch (atEntity.tokenType) {
3994
+ case exports.AuthenticationScheme.POP:
3995
+ // Make sure keyId is present and add it to credential
3996
+ var tokenClaims = AuthToken.extractTokenClaims(accessToken, cryptoUtils);
3997
+ if (!((_a = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _a === void 0 ? void 0 : _a.kid)) {
3998
+ throw ClientAuthError.createTokenClaimsRequiredError();
3999
+ }
4000
+ atEntity.keyId = tokenClaims.cnf.kid;
4001
+ break;
4002
+ case exports.AuthenticationScheme.SSH:
4003
+ atEntity.keyId = keyId;
3903
4004
  }
3904
- atEntity.keyId = tokenClaims.cnf.kid;
3905
4005
  }
3906
4006
  return atEntity;
3907
4007
  };
@@ -4392,14 +4492,14 @@ var PopTokenGenerator = /** @class */ (function () {
4392
4492
  };
4393
4493
  PopTokenGenerator.prototype.signPayload = function (payload, kid, request, claims) {
4394
4494
  return __awaiter(this, void 0, void 0, function () {
4395
- var resourceRequestMethod, resourceRequestUri, shrClaims, resourceUrlString, resourceUrlComponents;
4495
+ var resourceRequestMethod, resourceRequestUri, shrClaims, shrNonce, resourceUrlString, resourceUrlComponents;
4396
4496
  return __generator(this, function (_a) {
4397
4497
  switch (_a.label) {
4398
4498
  case 0:
4399
- resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims;
4499
+ resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
4400
4500
  resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
4401
4501
  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)];
4502
+ 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
4503
  case 1: return [2 /*return*/, _a.sent()];
4404
4504
  }
4405
4505
  });
@@ -4590,6 +4690,8 @@ var ResponseHandler = /** @class */ (function () {
4590
4690
  if (!!authCodePayload && !!authCodePayload.state) {
4591
4691
  requestStateObj = ProtocolUtils.parseRequestState(this.cryptoObj, authCodePayload.state);
4592
4692
  }
4693
+ // Add keyId from request to serverTokenResponse if defined
4694
+ serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
4593
4695
  cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, idTokenObj, request.scopes, oboAssertion, authCodePayload);
4594
4696
  _a.label = 1;
4595
4697
  case 1:
@@ -4666,7 +4768,7 @@ var ResponseHandler = /** @class */ (function () {
4666
4768
  var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
4667
4769
  var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
4668
4770
  // 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);
4771
+ 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
4772
  }
4671
4773
  // refreshToken
4672
4774
  var cachedRefreshToken = null;
@@ -4884,7 +4986,9 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
4884
4986
  authenticationScheme: request.authenticationScheme,
4885
4987
  resourceRequestMethod: request.resourceRequestMethod,
4886
4988
  resourceRequestUri: request.resourceRequestUri,
4887
- shrClaims: request.shrClaims
4989
+ shrClaims: request.shrClaims,
4990
+ sshJwk: request.sshJwk,
4991
+ sshKid: request.sshKid
4888
4992
  };
4889
4993
  return [4 /*yield*/, this.createTokenRequestBody(request)];
4890
4994
  case 1:
@@ -4965,8 +5069,18 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
4965
5069
  case 1:
4966
5070
  cnfString = _a.sent();
4967
5071
  parameterBuilder.addPopToken(cnfString);
4968
- _a.label = 2;
5072
+ return [3 /*break*/, 3];
4969
5073
  case 2:
5074
+ if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
5075
+ if (request.sshJwk) {
5076
+ parameterBuilder.addSshJwk(request.sshJwk);
5077
+ }
5078
+ else {
5079
+ throw ClientConfigurationError.createMissingSshJwkError();
5080
+ }
5081
+ }
5082
+ _a.label = 3;
5083
+ case 3:
4970
5084
  correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
4971
5085
  parameterBuilder.addCorrelationId(correlationId);
4972
5086
  if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
@@ -5041,7 +5155,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5041
5155
  if (request.domainHint) {
5042
5156
  parameterBuilder.addDomainHint(request.domainHint);
5043
5157
  }
5044
- // Add sid or loginHint with preference for sid -> loginHint -> username of AccountInfo object
5158
+ // Add sid or loginHint with preference for login_hint claim (in request) -> sid -> loginHint (upn/email) -> username of AccountInfo object
5045
5159
  if (request.prompt !== PromptValue.SELECT_ACCOUNT) {
5046
5160
  // AAD will throw if prompt=select_account is passed with an account hint
5047
5161
  if (request.sid && request.prompt === PromptValue.NONE) {
@@ -5051,9 +5165,24 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5051
5165
  }
5052
5166
  else if (request.account) {
5053
5167
  var accountSid = this.extractAccountSid(request.account);
5054
- // If account and loginHint are provided, we will check account first for sid before adding loginHint
5055
- if (accountSid && request.prompt === PromptValue.NONE) {
5056
- // SessionId is only used in silent calls
5168
+ var accountLoginHintClaim = this.extractLoginHint(request.account);
5169
+ // If login_hint claim is present, use it over sid/username
5170
+ if (accountLoginHintClaim) {
5171
+ this.logger.verbose("createAuthCodeUrlQueryString: login_hint claim present on account");
5172
+ parameterBuilder.addLoginHint(accountLoginHintClaim);
5173
+ try {
5174
+ var clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5175
+ parameterBuilder.addCcsOid(clientInfo);
5176
+ }
5177
+ catch (e) {
5178
+ this.logger.verbose("createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header");
5179
+ }
5180
+ }
5181
+ else if (accountSid && request.prompt === PromptValue.NONE) {
5182
+ /*
5183
+ * If account and loginHint are provided, we will check account first for sid before adding loginHint
5184
+ * SessionId is only used in silent calls
5185
+ */
5057
5186
  this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from account");
5058
5187
  parameterBuilder.addSid(accountSid);
5059
5188
  try {
@@ -5061,7 +5190,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5061
5190
  parameterBuilder.addCcsOid(clientInfo);
5062
5191
  }
5063
5192
  catch (e) {
5064
- this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5193
+ this.logger.verbose("createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header");
5065
5194
  }
5066
5195
  }
5067
5196
  else if (request.loginHint) {
@@ -5078,7 +5207,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5078
5207
  parameterBuilder.addCcsOid(clientInfo);
5079
5208
  }
5080
5209
  catch (e) {
5081
- this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5210
+ this.logger.verbose("createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header");
5082
5211
  }
5083
5212
  }
5084
5213
  }
@@ -5133,11 +5262,12 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5133
5262
  * @param account
5134
5263
  */
5135
5264
  AuthorizationCodeClient.prototype.extractAccountSid = function (account) {
5136
- if (account.idTokenClaims) {
5137
- var tokenClaims = account.idTokenClaims;
5138
- return tokenClaims.sid || null;
5139
- }
5140
- return null;
5265
+ var _a;
5266
+ return ((_a = account.idTokenClaims) === null || _a === void 0 ? void 0 : _a["sid"]) || null;
5267
+ };
5268
+ AuthorizationCodeClient.prototype.extractLoginHint = function (account) {
5269
+ var _a;
5270
+ return ((_a = account.idTokenClaims) === null || _a === void 0 ? void 0 : _a["login_hint"]) || null;
5141
5271
  };
5142
5272
  return AuthorizationCodeClient;
5143
5273
  }(BaseClient));
@@ -5198,7 +5328,9 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5198
5328
  authenticationScheme: request.authenticationScheme,
5199
5329
  resourceRequestMethod: request.resourceRequestMethod,
5200
5330
  resourceRequestUri: request.resourceRequestUri,
5201
- shrClaims: request.shrClaims
5331
+ shrClaims: request.shrClaims,
5332
+ sshJwk: request.sshJwk,
5333
+ sshKid: request.sshKid
5202
5334
  };
5203
5335
  return [2 /*return*/, this.executePostRequestToDeviceCodeEndpoint(this.authority.deviceCodeEndpoint, queryString, headers, thumbprint)];
5204
5336
  });
@@ -5295,7 +5427,9 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5295
5427
  authenticationScheme: request.authenticationScheme,
5296
5428
  resourceRequestMethod: request.resourceRequestMethod,
5297
5429
  resourceRequestUri: request.resourceRequestUri,
5298
- shrClaims: request.shrClaims
5430
+ shrClaims: request.shrClaims,
5431
+ sshJwk: request.sshJwk,
5432
+ sshKid: request.sshKid
5299
5433
  };
5300
5434
  return [4 /*yield*/, this.executePostToTokenEndpoint(this.authority.tokenEndpoint, requestBody, headers, thumbprint)];
5301
5435
  case 2:
@@ -5461,7 +5595,9 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5461
5595
  authenticationScheme: request.authenticationScheme,
5462
5596
  resourceRequestMethod: request.resourceRequestMethod,
5463
5597
  resourceRequestUri: request.resourceRequestUri,
5464
- shrClaims: request.shrClaims
5598
+ shrClaims: request.shrClaims,
5599
+ sshJwk: request.sshJwk,
5600
+ sshKid: request.sshKid
5465
5601
  };
5466
5602
  endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParameters);
5467
5603
  return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)];
@@ -5486,9 +5622,9 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5486
5622
  */
5487
5623
  RefreshTokenClient.prototype.createTokenRequestBody = function (request) {
5488
5624
  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) {
5625
+ var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, cnfString, clientInfo;
5626
+ return __generator(this, function (_a) {
5627
+ switch (_a.label) {
5492
5628
  case 0:
5493
5629
  parameterBuilder = new RequestParameterBuilder();
5494
5630
  parameterBuilder.addClientId(this.config.authOptions.clientId);
@@ -5513,12 +5649,22 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5513
5649
  }
5514
5650
  if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 2];
5515
5651
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5516
- _b = (_a = parameterBuilder).addPopToken;
5517
5652
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5518
5653
  case 1:
5519
- _b.apply(_a, [_c.sent()]);
5520
- _c.label = 2;
5654
+ cnfString = _a.sent();
5655
+ parameterBuilder.addPopToken(cnfString);
5656
+ return [3 /*break*/, 3];
5521
5657
  case 2:
5658
+ if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
5659
+ if (request.sshJwk) {
5660
+ parameterBuilder.addSshJwk(request.sshJwk);
5661
+ }
5662
+ else {
5663
+ throw ClientConfigurationError.createMissingSshJwkError();
5664
+ }
5665
+ }
5666
+ _a.label = 3;
5667
+ case 3:
5522
5668
  if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
5523
5669
  parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
5524
5670
  }
@@ -5657,7 +5803,9 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5657
5803
  authenticationScheme: request.authenticationScheme,
5658
5804
  resourceRequestMethod: request.resourceRequestMethod,
5659
5805
  resourceRequestUri: request.resourceRequestUri,
5660
- shrClaims: request.shrClaims
5806
+ shrClaims: request.shrClaims,
5807
+ sshJwk: request.sshJwk,
5808
+ sshKid: request.sshKid
5661
5809
  };
5662
5810
  reqTimestamp = TimeUtils.nowSeconds();
5663
5811
  return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
@@ -5856,7 +6004,9 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
5856
6004
  authenticationScheme: request.authenticationScheme,
5857
6005
  resourceRequestMethod: request.resourceRequestMethod,
5858
6006
  resourceRequestUri: request.resourceRequestUri,
5859
- shrClaims: request.shrClaims
6007
+ shrClaims: request.shrClaims,
6008
+ sshJwk: request.sshJwk,
6009
+ sshKid: request.sshKid
5860
6010
  };
5861
6011
  reqTimestamp = TimeUtils.nowSeconds();
5862
6012
  return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
@@ -5956,6 +6106,17 @@ var SilentFlowClient = /** @class */ (function (_super) {
5956
6106
  if (!request) {
5957
6107
  throw ClientConfigurationError.createEmptyTokenRequestError();
5958
6108
  }
6109
+ if (request.forceRefresh) {
6110
+ // Must refresh due to present force_refresh flag.
6111
+ (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.FORCE_REFRESH);
6112
+ this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true.");
6113
+ throw ClientAuthError.createRefreshRequiredError();
6114
+ }
6115
+ else if (!StringUtils.isEmptyObj(request.claims)) {
6116
+ // Must refresh due to request parameters.
6117
+ this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because claims are requested.");
6118
+ throw ClientAuthError.createRefreshRequiredError();
6119
+ }
5959
6120
  // We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
5960
6121
  if (!request.account) {
5961
6122
  throw ClientAuthError.createNoAccountInSilentRequestError();
@@ -5963,30 +6124,24 @@ var SilentFlowClient = /** @class */ (function (_super) {
5963
6124
  requestScopes = new ScopeSet(request.scopes || []);
5964
6125
  environment = request.authority || this.authority.getPreferredCache();
5965
6126
  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) {
6127
+ cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, requestScopes, environment, authScheme, request.sshKid);
6128
+ if (!cacheRecord.accessToken) {
5973
6129
  // Must refresh due to non-existent access_token.
5974
6130
  (_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
6131
+ this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
5975
6132
  throw ClientAuthError.createRefreshRequiredError();
5976
6133
  }
5977
6134
  else if (TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
5978
6135
  TimeUtils.isTokenExpired(cacheRecord.accessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
5979
6136
  // Must refresh due to expired access_token.
5980
6137
  (_c = this.serverTelemetryManager) === null || _c === void 0 ? void 0 : _c.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
6138
+ this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token is expired or will expire within " + this.config.systemOptions.tokenRenewalOffsetSeconds + " seconds.");
5981
6139
  throw ClientAuthError.createRefreshRequiredError();
5982
6140
  }
5983
6141
  else if (cacheRecord.accessToken.refreshOn && TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)) {
5984
6142
  // Must refresh due to the refresh_in value.
5985
6143
  (_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.
6144
+ this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'.");
5990
6145
  throw ClientAuthError.createRefreshRequiredError();
5991
6146
  }
5992
6147
  if (this.config.serverTelemetryManager) {
@@ -6074,7 +6229,9 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6074
6229
  authenticationScheme: request.authenticationScheme,
6075
6230
  resourceRequestMethod: request.resourceRequestMethod,
6076
6231
  resourceRequestUri: request.resourceRequestUri,
6077
- shrClaims: request.shrClaims
6232
+ shrClaims: request.shrClaims,
6233
+ sshJwk: request.sshJwk,
6234
+ sshKid: request.sshKid
6078
6235
  };
6079
6236
  requestBody = this.createTokenRequestBody(request);
6080
6237
  headers = this.createTokenRequestHeaders({
@@ -6130,7 +6287,6 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6130
6287
  function isOpenIdConfigResponse(response) {
6131
6288
  return (response.hasOwnProperty("authorization_endpoint") &&
6132
6289
  response.hasOwnProperty("token_endpoint") &&
6133
- response.hasOwnProperty("end_session_endpoint") &&
6134
6290
  response.hasOwnProperty("issuer"));
6135
6291
  }
6136
6292
 
@@ -6212,7 +6368,6 @@ var AuthorityMetadataEntity = /** @class */ (function () {
6212
6368
  entity.hasOwnProperty("canonical_authority") &&
6213
6369
  entity.hasOwnProperty("authorization_endpoint") &&
6214
6370
  entity.hasOwnProperty("token_endpoint") &&
6215
- entity.hasOwnProperty("end_session_endpoint") &&
6216
6371
  entity.hasOwnProperty("issuer") &&
6217
6372
  entity.hasOwnProperty("aliasesFromNetwork") &&
6218
6373
  entity.hasOwnProperty("endpointsFromNetwork") &&
@@ -6494,6 +6649,10 @@ var Authority = /** @class */ (function () {
6494
6649
  */
6495
6650
  get: function () {
6496
6651
  if (this.discoveryComplete()) {
6652
+ // ROPC policies may not have end_session_endpoint set
6653
+ if (!this.metadata.end_session_endpoint) {
6654
+ throw ClientAuthError.createLogoutNotSupportedError();
6655
+ }
6497
6656
  var endpoint = this.replacePath(this.metadata.end_session_endpoint);
6498
6657
  return this.replaceTenant(endpoint);
6499
6658
  }
@@ -6894,7 +7053,9 @@ var Authority = /** @class */ (function () {
6894
7053
  metadata.authorization_endpoint = Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
6895
7054
  // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
6896
7055
  metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, "allowestsrnonmsi=true");
6897
- metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
7056
+ if (metadata.end_session_endpoint) {
7057
+ metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
7058
+ }
6898
7059
  return metadata;
6899
7060
  };
6900
7061
  return Authority;
@@ -7189,12 +7350,70 @@ var ServerTelemetryManager = /** @class */ (function () {
7189
7350
  return ServerTelemetryManager;
7190
7351
  }());
7191
7352
 
7353
+ /*
7354
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7355
+ * Licensed under the MIT License.
7356
+ */
7357
+ /**
7358
+ * This is a helper class that parses supported HTTP response authentication headers to extract and return
7359
+ * header challenge values that can be used outside the basic authorization flows.
7360
+ */
7361
+ var AuthenticationHeaderParser = /** @class */ (function () {
7362
+ function AuthenticationHeaderParser(headers) {
7363
+ this.headers = headers;
7364
+ }
7365
+ /**
7366
+ * This method parses the SHR nonce value out of either the Authentication-Info or WWW-Authenticate authentication headers.
7367
+ * @returns
7368
+ */
7369
+ AuthenticationHeaderParser.prototype.getShrNonce = function () {
7370
+ // Attempt to parse nonce from Authentiacation-Info
7371
+ var authenticationInfo = this.headers[HeaderNames.AuthenticationInfo];
7372
+ if (authenticationInfo) {
7373
+ var authenticationInfoChallenges = this.parseChallenges(authenticationInfo);
7374
+ if (authenticationInfoChallenges.nextnonce) {
7375
+ return authenticationInfoChallenges.nextnonce;
7376
+ }
7377
+ throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.AuthenticationInfo, "nextnonce challenge is missing.");
7378
+ }
7379
+ // Attempt to parse nonce from WWW-Authenticate
7380
+ var wwwAuthenticate = this.headers[HeaderNames.WWWAuthenticate];
7381
+ if (wwwAuthenticate) {
7382
+ var wwwAuthenticateChallenges = this.parseChallenges(wwwAuthenticate);
7383
+ if (wwwAuthenticateChallenges.nonce) {
7384
+ return wwwAuthenticateChallenges.nonce;
7385
+ }
7386
+ throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.WWWAuthenticate, "nonce challenge is missing.");
7387
+ }
7388
+ // If neither header is present, throw missing headers error
7389
+ throw ClientConfigurationError.createMissingNonceAuthenticationHeadersError();
7390
+ };
7391
+ /**
7392
+ * Parses an HTTP header's challenge set into a key/value map.
7393
+ * @param header
7394
+ * @returns
7395
+ */
7396
+ AuthenticationHeaderParser.prototype.parseChallenges = function (header) {
7397
+ var schemeSeparator = header.indexOf(" ");
7398
+ var challenges = header.substr(schemeSeparator + 1).split(",");
7399
+ var challengeMap = {};
7400
+ challenges.forEach(function (challenge) {
7401
+ var _a = challenge.split("="), key = _a[0], value = _a[1];
7402
+ // Remove escaped quotation marks (', ") from challenge string to keep only the challenge value
7403
+ challengeMap[key] = unescape(value.replace(/['"]+/g, ""));
7404
+ });
7405
+ return challengeMap;
7406
+ };
7407
+ return AuthenticationHeaderParser;
7408
+ }());
7409
+
7192
7410
  exports.AccessTokenEntity = AccessTokenEntity;
7193
7411
  exports.AccountEntity = AccountEntity;
7194
7412
  exports.AppMetadataEntity = AppMetadataEntity;
7195
7413
  exports.AuthError = AuthError;
7196
7414
  exports.AuthErrorMessage = AuthErrorMessage;
7197
7415
  exports.AuthToken = AuthToken;
7416
+ exports.AuthenticationHeaderParser = AuthenticationHeaderParser;
7198
7417
  exports.Authority = Authority;
7199
7418
  exports.AuthorityFactory = AuthorityFactory;
7200
7419
  exports.AuthorityMetadataEntity = AuthorityMetadataEntity;