@azure/msal-browser 2.34.0 → 2.36.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 (79) hide show
  1. package/README.md +1 -1
  2. package/dist/_virtual/_tslib.js +1 -1
  3. package/dist/app/ClientApplication.d.ts +2 -2
  4. package/dist/app/ClientApplication.d.ts.map +1 -1
  5. package/dist/app/ClientApplication.js +37 -20
  6. package/dist/app/ClientApplication.js.map +1 -1
  7. package/dist/app/IPublicClientApplication.js +1 -1
  8. package/dist/app/PublicClientApplication.js +1 -1
  9. package/dist/broker/nativeBroker/NativeMessageHandler.js +1 -1
  10. package/dist/cache/AsyncMemoryStorage.js +1 -1
  11. package/dist/cache/BrowserCacheManager.d.ts +63 -4
  12. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  13. package/dist/cache/BrowserCacheManager.js +320 -15
  14. package/dist/cache/BrowserCacheManager.js.map +1 -1
  15. package/dist/cache/BrowserStorage.js +1 -1
  16. package/dist/cache/CryptoKeyStore.js +1 -1
  17. package/dist/cache/DatabaseStorage.js +1 -1
  18. package/dist/cache/MemoryStorage.js +1 -1
  19. package/dist/cache/TokenCache.js +1 -1
  20. package/dist/config/Configuration.d.ts +9 -1
  21. package/dist/config/Configuration.d.ts.map +1 -1
  22. package/dist/config/Configuration.js +5 -2
  23. package/dist/config/Configuration.js.map +1 -1
  24. package/dist/crypto/BrowserCrypto.js +1 -1
  25. package/dist/crypto/CryptoOps.js +1 -1
  26. package/dist/crypto/GuidGenerator.js +1 -1
  27. package/dist/crypto/ModernBrowserCrypto.js +1 -1
  28. package/dist/crypto/MsBrowserCrypto.js +1 -1
  29. package/dist/crypto/MsrBrowserCrypto.js +1 -1
  30. package/dist/crypto/PkceGenerator.js +1 -1
  31. package/dist/crypto/SignedHttpRequest.js +1 -1
  32. package/dist/encode/Base64Decode.js +1 -1
  33. package/dist/encode/Base64Encode.js +1 -1
  34. package/dist/error/BrowserAuthError.js +1 -1
  35. package/dist/error/BrowserConfigurationAuthError.js +1 -1
  36. package/dist/error/NativeAuthError.js +1 -1
  37. package/dist/event/EventHandler.js +1 -1
  38. package/dist/event/EventMessage.js +1 -1
  39. package/dist/event/EventType.js +1 -1
  40. package/dist/index.cjs.js +1036 -578
  41. package/dist/index.cjs.js.map +1 -1
  42. package/dist/index.js +1 -1
  43. package/dist/interaction_client/BaseInteractionClient.js +1 -1
  44. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +1 -1
  45. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  46. package/dist/interaction_client/NativeInteractionClient.js +8 -9
  47. package/dist/interaction_client/NativeInteractionClient.js.map +1 -1
  48. package/dist/interaction_client/PopupClient.js +1 -1
  49. package/dist/interaction_client/RedirectClient.js +1 -1
  50. package/dist/interaction_client/SilentAuthCodeClient.js +1 -1
  51. package/dist/interaction_client/SilentCacheClient.js +1 -1
  52. package/dist/interaction_client/SilentIframeClient.js +1 -1
  53. package/dist/interaction_client/SilentRefreshClient.js +1 -1
  54. package/dist/interaction_client/StandardInteractionClient.js +1 -1
  55. package/dist/interaction_handler/InteractionHandler.js +1 -1
  56. package/dist/interaction_handler/RedirectHandler.js +1 -1
  57. package/dist/interaction_handler/SilentHandler.js +1 -1
  58. package/dist/internals.js +1 -1
  59. package/dist/navigation/NavigationClient.js +1 -1
  60. package/dist/network/FetchClient.js +1 -1
  61. package/dist/network/XhrClient.js +1 -1
  62. package/dist/packageMetadata.d.ts +1 -1
  63. package/dist/packageMetadata.js +2 -2
  64. package/dist/packageMetadata.js.map +1 -1
  65. package/dist/telemetry/BrowserPerformanceClient.js +2 -2
  66. package/dist/telemetry/BrowserPerformanceClient.js.map +1 -1
  67. package/dist/telemetry/BrowserPerformanceMeasurement.js +1 -1
  68. package/dist/utils/BrowserConstants.d.ts +4 -0
  69. package/dist/utils/BrowserConstants.d.ts.map +1 -1
  70. package/dist/utils/BrowserConstants.js +7 -2
  71. package/dist/utils/BrowserConstants.js.map +1 -1
  72. package/dist/utils/BrowserProtocolUtils.js +1 -1
  73. package/dist/utils/BrowserStringUtils.js +1 -1
  74. package/dist/utils/BrowserUtils.js +1 -1
  75. package/dist/utils/MathUtils.js +1 -1
  76. package/lib/msal-browser.js +1036 -578
  77. package/lib/msal-browser.js.map +1 -1
  78. package/lib/msal-browser.min.js +38 -40
  79. package/package.json +2 -2
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v2.34.0 2023-03-07 */
1
+ /*! @azure/msal-browser v2.36.0 2023-04-18 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -117,7 +117,7 @@ function __spread() {
117
117
  return ar;
118
118
  }
119
119
 
120
- /*! @azure/msal-common v11.0.0 2023-03-07 */
120
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
121
121
  /*! *****************************************************************************
122
122
  Copyright (c) Microsoft Corporation.
123
123
 
@@ -204,7 +204,7 @@ function __spreadArrays() {
204
204
  return r;
205
205
  }
206
206
 
207
- /*! @azure/msal-common v11.0.0 2023-03-07 */
207
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
208
208
 
209
209
  /*
210
210
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -451,22 +451,6 @@ var CredentialType;
451
451
  CredentialType["ACCESS_TOKEN_WITH_AUTH_SCHEME"] = "AccessToken_With_AuthScheme";
452
452
  CredentialType["REFRESH_TOKEN"] = "RefreshToken";
453
453
  })(CredentialType || (CredentialType = {}));
454
- /**
455
- * Credential Type stored in the cache
456
- */
457
- var CacheSchemaType;
458
- (function (CacheSchemaType) {
459
- CacheSchemaType["ACCOUNT"] = "Account";
460
- CacheSchemaType["CREDENTIAL"] = "Credential";
461
- CacheSchemaType["ID_TOKEN"] = "IdToken";
462
- CacheSchemaType["ACCESS_TOKEN"] = "AccessToken";
463
- CacheSchemaType["REFRESH_TOKEN"] = "RefreshToken";
464
- CacheSchemaType["APP_METADATA"] = "AppMetadata";
465
- CacheSchemaType["TEMPORARY"] = "TempCache";
466
- CacheSchemaType["TELEMETRY"] = "Telemetry";
467
- CacheSchemaType["UNDEFINED"] = "Undefined";
468
- CacheSchemaType["THROTTLING"] = "Throttling";
469
- })(CacheSchemaType || (CacheSchemaType = {}));
470
454
  /**
471
455
  * Combine all cache types
472
456
  */
@@ -589,7 +573,7 @@ var JsonTypes;
589
573
  JsonTypes["Pop"] = "pop";
590
574
  })(JsonTypes || (JsonTypes = {}));
591
575
 
592
- /*! @azure/msal-common v11.0.0 2023-03-07 */
576
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
593
577
 
594
578
  /*
595
579
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -645,7 +629,7 @@ var AuthError = /** @class */ (function (_super) {
645
629
  return AuthError;
646
630
  }(Error));
647
631
 
648
- /*! @azure/msal-common v11.0.0 2023-03-07 */
632
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
649
633
 
650
634
  /*
651
635
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -720,7 +704,7 @@ var DEFAULT_CRYPTO_IMPLEMENTATION = {
720
704
  }
721
705
  };
722
706
 
723
- /*! @azure/msal-common v11.0.0 2023-03-07 */
707
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
724
708
 
725
709
  /*
726
710
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1235,7 +1219,7 @@ var ClientAuthError = /** @class */ (function (_super) {
1235
1219
  return ClientAuthError;
1236
1220
  }(AuthError));
1237
1221
 
1238
- /*! @azure/msal-common v11.0.0 2023-03-07 */
1222
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
1239
1223
 
1240
1224
  /*
1241
1225
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1360,7 +1344,7 @@ var StringUtils = /** @class */ (function () {
1360
1344
  return StringUtils;
1361
1345
  }());
1362
1346
 
1363
- /*! @azure/msal-common v11.0.0 2023-03-07 */
1347
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
1364
1348
 
1365
1349
  /*
1366
1350
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1550,12 +1534,12 @@ var Logger = /** @class */ (function () {
1550
1534
  return Logger;
1551
1535
  }());
1552
1536
 
1553
- /*! @azure/msal-common v11.0.0 2023-03-07 */
1537
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
1554
1538
  /* eslint-disable header/header */
1555
1539
  var name$1 = "@azure/msal-common";
1556
- var version$1 = "11.0.0";
1540
+ var version$1 = "12.0.0";
1557
1541
 
1558
- /*! @azure/msal-common v11.0.0 2023-03-07 */
1542
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
1559
1543
  /*
1560
1544
  * Copyright (c) Microsoft Corporation. All rights reserved.
1561
1545
  * Licensed under the MIT License.
@@ -1576,184 +1560,7 @@ exports.AzureCloudInstance = void 0;
1576
1560
  AzureCloudInstance["AzureUsGovernment"] = "https://login.microsoftonline.us";
1577
1561
  })(exports.AzureCloudInstance || (exports.AzureCloudInstance = {}));
1578
1562
 
1579
- /*! @azure/msal-common v11.0.0 2023-03-07 */
1580
-
1581
- /*
1582
- * Copyright (c) Microsoft Corporation. All rights reserved.
1583
- * Licensed under the MIT License.
1584
- */
1585
- /**
1586
- * Base type for credentials to be stored in the cache: eg: ACCESS_TOKEN, ID_TOKEN etc
1587
- *
1588
- * Key:Value Schema:
1589
- *
1590
- * Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<requestedClaims*>-<scheme*>
1591
- *
1592
- * Value Schema:
1593
- * {
1594
- * homeAccountId: home account identifier for the auth scheme,
1595
- * environment: entity that issued the token, represented as a full host
1596
- * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
1597
- * clientId: client ID of the application
1598
- * secret: Actual credential as a string
1599
- * familyId: Family ID identifier, usually only used for refresh tokens
1600
- * realm: Full tenant or organizational identifier that the account belongs to
1601
- * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
1602
- * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
1603
- * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
1604
- * userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
1605
- * }
1606
- */
1607
- var CredentialEntity = /** @class */ (function () {
1608
- function CredentialEntity() {
1609
- }
1610
- /**
1611
- * Initializes a map with credential {CredentialType} regular expressions.
1612
- */
1613
- CredentialEntity._initRegex = function () {
1614
- var separator = Separators.CACHE_KEY_SEPARATOR;
1615
- CredentialEntity.credentialRegexMap = new Map();
1616
- for (var _i = 0, _a = Object.keys(CredentialType); _i < _a.length; _i++) {
1617
- var credKey = _a[_i];
1618
- var credVal = CredentialType[credKey].toLowerCase();
1619
- try {
1620
- // Verify credential type is preceded by a valid host name (environment) using lookbehind
1621
- CredentialEntity.credentialRegexMap.set(CredentialType[credKey], new RegExp("(?<=" + separator + CredentialEntity.credentialDomainRegex + ")" + separator + credVal + separator));
1622
- }
1623
- catch (err) {
1624
- // Lookbehind is not supported (Safari or older versions of IE) - removing it
1625
- CredentialEntity.credentialRegexMap.set(CredentialType[credKey], new RegExp("" + separator + CredentialEntity.credentialDomainRegex + separator + credVal + separator));
1626
- }
1627
- }
1628
- };
1629
- /**
1630
- * Generate Account Id key component as per the schema: <home_account_id>-<environment>
1631
- */
1632
- CredentialEntity.prototype.generateAccountId = function () {
1633
- return CredentialEntity.generateAccountIdForCacheKey(this.homeAccountId, this.environment);
1634
- };
1635
- /**
1636
- * Generate Credential Id key component as per the schema: <credential_type>-<client_id>-<realm>
1637
- */
1638
- CredentialEntity.prototype.generateCredentialId = function () {
1639
- return CredentialEntity.generateCredentialIdForCacheKey(this.credentialType, this.clientId, this.realm, this.familyId);
1640
- };
1641
- /**
1642
- * Generate target key component as per schema: <target>
1643
- */
1644
- CredentialEntity.prototype.generateTarget = function () {
1645
- return CredentialEntity.generateTargetForCacheKey(this.target);
1646
- };
1647
- /**
1648
- * generates credential key
1649
- */
1650
- CredentialEntity.prototype.generateCredentialKey = function () {
1651
- return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType, this.requestedClaimsHash);
1652
- };
1653
- /**
1654
- * returns the type of the cache (in this case credential)
1655
- */
1656
- CredentialEntity.prototype.generateType = function () {
1657
- switch (this.credentialType) {
1658
- case CredentialType.ID_TOKEN:
1659
- return CacheType.ID_TOKEN;
1660
- case CredentialType.ACCESS_TOKEN:
1661
- case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
1662
- return CacheType.ACCESS_TOKEN;
1663
- case CredentialType.REFRESH_TOKEN:
1664
- return CacheType.REFRESH_TOKEN;
1665
- default: {
1666
- throw ClientAuthError.createUnexpectedCredentialTypeError();
1667
- }
1668
- }
1669
- };
1670
- /**
1671
- * helper function to return `CredentialType`
1672
- * @param key
1673
- */
1674
- CredentialEntity.getCredentialType = function (key) {
1675
- var _a;
1676
- for (var _i = 0, _b = Object.keys(CredentialType); _i < _b.length; _i++) {
1677
- var credKey = _b[_i];
1678
- if ((_a = this.credentialRegexMap.get(CredentialType[credKey])) === null || _a === void 0 ? void 0 : _a.test(key.toLowerCase())) {
1679
- return CredentialType[credKey];
1680
- }
1681
- }
1682
- return Constants.NOT_DEFINED;
1683
- };
1684
- /**
1685
- * generates credential key
1686
- * <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
1687
- */
1688
- CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType, requestedClaimsHash) {
1689
- var credentialKey = [
1690
- this.generateAccountIdForCacheKey(homeAccountId, environment),
1691
- this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),
1692
- this.generateTargetForCacheKey(target),
1693
- this.generateClaimsHashForCacheKey(requestedClaimsHash),
1694
- this.generateSchemeForCacheKey(tokenType)
1695
- ];
1696
- return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
1697
- };
1698
- /**
1699
- * generates Account Id for keys
1700
- * @param homeAccountId
1701
- * @param environment
1702
- */
1703
- CredentialEntity.generateAccountIdForCacheKey = function (homeAccountId, environment) {
1704
- var accountId = [homeAccountId, environment];
1705
- return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
1706
- };
1707
- /**
1708
- * Generates Credential Id for keys
1709
- * @param credentialType
1710
- * @param realm
1711
- * @param clientId
1712
- * @param familyId
1713
- */
1714
- CredentialEntity.generateCredentialIdForCacheKey = function (credentialType, clientId, realm, familyId) {
1715
- var clientOrFamilyId = credentialType === CredentialType.REFRESH_TOKEN
1716
- ? familyId || clientId
1717
- : clientId;
1718
- var credentialId = [
1719
- credentialType,
1720
- clientOrFamilyId,
1721
- realm || Constants.EMPTY_STRING,
1722
- ];
1723
- return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
1724
- };
1725
- /**
1726
- * Generate target key component as per schema: <target>
1727
- */
1728
- CredentialEntity.generateTargetForCacheKey = function (scopes) {
1729
- return (scopes || Constants.EMPTY_STRING).toLowerCase();
1730
- };
1731
- /**
1732
- * Generate requested claims key component as per schema: <requestedClaims>
1733
- */
1734
- CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
1735
- return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
1736
- };
1737
- /**
1738
- * Generate scheme key componenet as per schema: <scheme>
1739
- */
1740
- CredentialEntity.generateSchemeForCacheKey = function (tokenType) {
1741
- /*
1742
- * PoP Tokens and SSH certs include scheme in cache key
1743
- * Cast to lowercase to handle "bearer" from ADFS
1744
- */
1745
- return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
1746
- };
1747
- /*
1748
- * Match host names like "login.microsoftonline.com", "https://accounts.google.com:4000", https://localhost:5000,
1749
- * "login.microsoftonline.com/common", "login.microsoftonline.com:4000/common", etc
1750
- */
1751
- CredentialEntity.credentialDomainRegex = "(https?:\\/\\/)?((([\\w-]+\\.)*([\\w-]{1,63})(\\.(\\w{2,63})))|(localhost))(\\:[0-9]{4,5})?(\\/[\\w-]+)?";
1752
- return CredentialEntity;
1753
- }());
1754
- CredentialEntity._initRegex();
1755
-
1756
- /*! @azure/msal-common v11.0.0 2023-03-07 */
1563
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
1757
1564
 
1758
1565
  /*
1759
1566
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2008,7 +1815,7 @@ var ClientConfigurationError = /** @class */ (function (_super) {
2008
1815
  return ClientConfigurationError;
2009
1816
  }(ClientAuthError));
2010
1817
 
2011
- /*! @azure/msal-common v11.0.0 2023-03-07 */
1818
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
2012
1819
 
2013
1820
  /*
2014
1821
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2041,6 +1848,21 @@ var ScopeSet = /** @class */ (function () {
2041
1848
  var inputScopes = scopeString.split(" ");
2042
1849
  return new ScopeSet(inputScopes);
2043
1850
  };
1851
+ /**
1852
+ * Creates the set of scopes to search for in cache lookups
1853
+ * @param inputScopeString
1854
+ * @returns
1855
+ */
1856
+ ScopeSet.createSearchScopes = function (inputScopeString) {
1857
+ var scopeSet = new ScopeSet(inputScopeString);
1858
+ if (!scopeSet.containsOnlyOIDCScopes()) {
1859
+ scopeSet.removeOIDCScopes();
1860
+ }
1861
+ else {
1862
+ scopeSet.removeScope(Constants.OFFLINE_ACCESS_SCOPE);
1863
+ }
1864
+ return scopeSet;
1865
+ };
2044
1866
  /**
2045
1867
  * Used to validate the scopes input parameter requested by the developer.
2046
1868
  * @param {Array<string>} inputScopes - Developer requested permissions. Not all scopes are guaranteed to be included in the access token returned.
@@ -2192,7 +2014,7 @@ var ScopeSet = /** @class */ (function () {
2192
2014
  return ScopeSet;
2193
2015
  }());
2194
2016
 
2195
- /*! @azure/msal-common v11.0.0 2023-03-07 */
2017
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
2196
2018
 
2197
2019
  /*
2198
2020
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2230,7 +2052,7 @@ function buildClientInfoFromHomeAccountId(homeAccountId) {
2230
2052
  };
2231
2053
  }
2232
2054
 
2233
- /*! @azure/msal-common v11.0.0 2023-03-07 */
2055
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
2234
2056
  /*
2235
2057
  * Copyright (c) Microsoft Corporation. All rights reserved.
2236
2058
  * Licensed under the MIT License.
@@ -2245,7 +2067,7 @@ var AuthorityType;
2245
2067
  AuthorityType[AuthorityType["Dsts"] = 2] = "Dsts";
2246
2068
  })(AuthorityType || (AuthorityType = {}));
2247
2069
 
2248
- /*! @azure/msal-common v11.0.0 2023-03-07 */
2070
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
2249
2071
 
2250
2072
  /*
2251
2073
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2484,7 +2306,7 @@ var AccountEntity = /** @class */ (function () {
2484
2306
  return AccountEntity;
2485
2307
  }());
2486
2308
 
2487
- /*! @azure/msal-common v11.0.0 2023-03-07 */
2309
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
2488
2310
 
2489
2311
  /*
2490
2312
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2536,7 +2358,7 @@ var AuthToken = /** @class */ (function () {
2536
2358
  return AuthToken;
2537
2359
  }());
2538
2360
 
2539
- /*! @azure/msal-common v11.0.0 2023-03-07 */
2361
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
2540
2362
 
2541
2363
  /*
2542
2364
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2546,35 +2368,59 @@ var AuthToken = /** @class */ (function () {
2546
2368
  * Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
2547
2369
  */
2548
2370
  var CacheManager = /** @class */ (function () {
2549
- function CacheManager(clientId, cryptoImpl) {
2371
+ function CacheManager(clientId, cryptoImpl, logger) {
2550
2372
  this.clientId = clientId;
2551
2373
  this.cryptoImpl = cryptoImpl;
2374
+ this.commonLogger = logger.clone(name$1, version$1);
2552
2375
  }
2553
2376
  /**
2554
2377
  * Returns all accounts in cache
2555
2378
  */
2556
2379
  CacheManager.prototype.getAllAccounts = function () {
2557
2380
  var _this = this;
2558
- var currentAccounts = this.getAccountsFilteredBy();
2559
- var accountValues = Object.keys(currentAccounts).map(function (accountKey) { return currentAccounts[accountKey]; });
2560
- var numAccounts = accountValues.length;
2561
- if (numAccounts < 1) {
2381
+ var allAccountKeys = this.getAccountKeys();
2382
+ if (allAccountKeys.length < 1) {
2383
+ return [];
2384
+ }
2385
+ var accountEntities = allAccountKeys.reduce(function (accounts, key) {
2386
+ var entity = _this.getAccount(key);
2387
+ if (!entity) {
2388
+ return accounts;
2389
+ }
2390
+ accounts.push(entity);
2391
+ return accounts;
2392
+ }, []);
2393
+ if (accountEntities.length < 1) {
2562
2394
  return [];
2563
2395
  }
2564
2396
  else {
2565
- var allAccounts = accountValues.map(function (value) {
2566
- var accountEntity = CacheManager.toObject(new AccountEntity(), value);
2567
- var accountInfo = accountEntity.getAccountInfo();
2568
- var idToken = _this.readIdTokenFromCache(_this.clientId, accountInfo);
2569
- if (idToken && !accountInfo.idTokenClaims) {
2570
- accountInfo.idToken = idToken.secret;
2571
- accountInfo.idTokenClaims = new AuthToken(idToken.secret, _this.cryptoImpl).claims;
2572
- }
2573
- return accountInfo;
2397
+ var allAccounts = accountEntities.map(function (accountEntity) {
2398
+ return _this.getAccountInfoFromEntity(accountEntity);
2574
2399
  });
2575
2400
  return allAccounts;
2576
2401
  }
2577
2402
  };
2403
+ /**
2404
+ * Gets accountInfo object based on provided filters
2405
+ */
2406
+ CacheManager.prototype.getAccountInfoFilteredBy = function (accountFilter) {
2407
+ var allAccounts = this.getAccountsFilteredBy(accountFilter);
2408
+ if (allAccounts.length > 0) {
2409
+ return this.getAccountInfoFromEntity(allAccounts[0]);
2410
+ }
2411
+ else {
2412
+ return null;
2413
+ }
2414
+ };
2415
+ CacheManager.prototype.getAccountInfoFromEntity = function (accountEntity) {
2416
+ var accountInfo = accountEntity.getAccountInfo();
2417
+ var idToken = this.getIdToken(accountInfo);
2418
+ if (idToken) {
2419
+ accountInfo.idToken = idToken.secret;
2420
+ accountInfo.idTokenClaims = new AuthToken(idToken.secret, this.cryptoImpl).claims;
2421
+ }
2422
+ return accountInfo;
2423
+ };
2578
2424
  /**
2579
2425
  * saves a cache record
2580
2426
  * @param cacheRecord
@@ -2616,12 +2462,12 @@ var CacheManager = /** @class */ (function () {
2616
2462
  */
2617
2463
  CacheManager.prototype.saveAccessToken = function (credential) {
2618
2464
  return __awaiter(this, void 0, void 0, function () {
2619
- var currentTokenCache, currentScopes, currentAccessTokens, removedAccessTokens_1;
2465
+ var accessTokenFilter, tokenKeys, currentScopes, removedAccessTokens;
2620
2466
  var _this = this;
2621
2467
  return __generator(this, function (_a) {
2622
2468
  switch (_a.label) {
2623
2469
  case 0:
2624
- currentTokenCache = this.getCredentialsFilteredBy({
2470
+ accessTokenFilter = {
2625
2471
  clientId: credential.clientId,
2626
2472
  credentialType: credential.credentialType,
2627
2473
  environment: credential.environment,
@@ -2629,22 +2475,25 @@ var CacheManager = /** @class */ (function () {
2629
2475
  realm: credential.realm,
2630
2476
  tokenType: credential.tokenType,
2631
2477
  requestedClaimsHash: credential.requestedClaimsHash
2632
- });
2478
+ };
2479
+ tokenKeys = this.getTokenKeys();
2633
2480
  currentScopes = ScopeSet.fromString(credential.target);
2634
- currentAccessTokens = Object.keys(currentTokenCache.accessTokens).map(function (key) { return currentTokenCache.accessTokens[key]; });
2635
- if (!currentAccessTokens) return [3 /*break*/, 2];
2636
- removedAccessTokens_1 = [];
2637
- currentAccessTokens.forEach(function (tokenEntity) {
2638
- var tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
2639
- if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
2640
- removedAccessTokens_1.push(_this.removeCredential(tokenEntity));
2481
+ removedAccessTokens = [];
2482
+ tokenKeys.accessToken.forEach(function (key) {
2483
+ if (!_this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)) {
2484
+ return;
2485
+ }
2486
+ var tokenEntity = _this.getAccessTokenCredential(key);
2487
+ if (tokenEntity && _this.credentialMatchesFilter(tokenEntity, accessTokenFilter)) {
2488
+ var tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
2489
+ if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
2490
+ removedAccessTokens.push(_this.removeAccessToken(key));
2491
+ }
2641
2492
  }
2642
2493
  });
2643
- return [4 /*yield*/, Promise.all(removedAccessTokens_1)];
2494
+ return [4 /*yield*/, Promise.all(removedAccessTokens)];
2644
2495
  case 1:
2645
2496
  _a.sent();
2646
- _a.label = 2;
2647
- case 2:
2648
2497
  this.setAccessTokenCredential(credential);
2649
2498
  return [2 /*return*/];
2650
2499
  }
@@ -2659,149 +2508,151 @@ var CacheManager = /** @class */ (function () {
2659
2508
  * @param realm
2660
2509
  */
2661
2510
  CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
2662
- return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING, accountFilter ? accountFilter.nativeAccountId : Constants.EMPTY_STRING);
2663
- };
2664
- /**
2665
- * retrieve accounts matching all provided filters; if no filter is set, get all accounts
2666
- * not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
2667
- * @param homeAccountId
2668
- * @param environment
2669
- * @param realm
2670
- */
2671
- CacheManager.prototype.getAccountsFilteredByInternal = function (homeAccountId, environment, realm, nativeAccountId) {
2672
2511
  var _this = this;
2673
- var allCacheKeys = this.getKeys();
2674
- var matchingAccounts = {};
2675
- allCacheKeys.forEach(function (cacheKey) {
2512
+ var allAccountKeys = this.getAccountKeys();
2513
+ var matchingAccounts = [];
2514
+ allAccountKeys.forEach(function (cacheKey) {
2515
+ if (!_this.isAccountKey(cacheKey, accountFilter.homeAccountId, accountFilter.realm)) {
2516
+ // Don't parse value if the key doesn't match the account filters
2517
+ return;
2518
+ }
2676
2519
  var entity = _this.getAccount(cacheKey);
2677
2520
  if (!entity) {
2678
2521
  return;
2679
2522
  }
2680
- if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
2523
+ if (!!accountFilter.homeAccountId && !_this.matchHomeAccountId(entity, accountFilter.homeAccountId)) {
2681
2524
  return;
2682
2525
  }
2683
- if (!!environment && !_this.matchEnvironment(entity, environment)) {
2526
+ if (!!accountFilter.localAccountId && !_this.matchLocalAccountId(entity, accountFilter.localAccountId)) {
2527
+ return;
2528
+ }
2529
+ if (!!accountFilter.username && !_this.matchUsername(entity, accountFilter.username)) {
2530
+ return;
2531
+ }
2532
+ if (!!accountFilter.environment && !_this.matchEnvironment(entity, accountFilter.environment)) {
2684
2533
  return;
2685
2534
  }
2686
- if (!!realm && !_this.matchRealm(entity, realm)) {
2535
+ if (!!accountFilter.realm && !_this.matchRealm(entity, accountFilter.realm)) {
2687
2536
  return;
2688
2537
  }
2689
- if (!!nativeAccountId && !_this.matchNativeAccountId(entity, nativeAccountId)) {
2538
+ if (!!accountFilter.nativeAccountId && !_this.matchNativeAccountId(entity, accountFilter.nativeAccountId)) {
2690
2539
  return;
2691
2540
  }
2692
- matchingAccounts[cacheKey] = entity;
2541
+ matchingAccounts.push(entity);
2693
2542
  });
2694
2543
  return matchingAccounts;
2695
2544
  };
2696
2545
  /**
2697
- * retrieve credentails matching all provided filters; if no filter is set, get all credentials
2546
+ * Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided
2547
+ * @param key
2698
2548
  * @param homeAccountId
2699
- * @param environment
2700
- * @param credentialType
2701
- * @param clientId
2702
- * @param realm
2703
- * @param target
2549
+ * @param tenantId
2550
+ * @returns
2704
2551
  */
2705
- CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
2706
- return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.userAssertionHash, filter.tokenType, filter.keyId, filter.requestedClaimsHash);
2552
+ CacheManager.prototype.isAccountKey = function (key, homeAccountId, tenantId) {
2553
+ if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 3) {
2554
+ // Account cache keys contain 3 items separated by '-' (each item may also contain '-')
2555
+ return false;
2556
+ }
2557
+ if (homeAccountId && !key.toLowerCase().includes(homeAccountId.toLowerCase())) {
2558
+ return false;
2559
+ }
2560
+ if (tenantId && !key.toLowerCase().includes(tenantId.toLowerCase())) {
2561
+ return false;
2562
+ }
2563
+ // Do not check environment as aliasing can cause false negatives
2564
+ return true;
2707
2565
  };
2708
2566
  /**
2709
- * Support function to help match credentials
2710
- * @param homeAccountId
2711
- * @param environment
2712
- * @param credentialType
2713
- * @param clientId
2714
- * @param realm
2715
- * @param target
2716
- * @param userAssertionHash
2717
- * @param tokenType
2567
+ * Returns true if the given key matches our credential key schema.
2568
+ * @param key
2718
2569
  */
2719
- CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, userAssertionHash, tokenType, keyId, requestedClaimsHash) {
2720
- var _this = this;
2721
- var allCacheKeys = this.getKeys();
2722
- var matchingCredentials = {
2723
- idTokens: {},
2724
- accessTokens: {},
2725
- refreshTokens: {},
2726
- };
2727
- allCacheKeys.forEach(function (cacheKey) {
2728
- // don't parse any non-credential type cache entities
2729
- var credType = CredentialEntity.getCredentialType(cacheKey);
2730
- if (credType === Constants.NOT_DEFINED) {
2731
- return;
2732
- }
2733
- // Attempt retrieval
2734
- var entity = _this.getSpecificCredential(cacheKey, credType);
2735
- if (!entity) {
2736
- return;
2737
- }
2738
- if (!!userAssertionHash && !_this.matchUserAssertionHash(entity, userAssertionHash)) {
2739
- return;
2740
- }
2741
- /*
2742
- * homeAccountId can undefined, and we want to filter out cached items that have a homeAccountId of ""
2743
- * because we don't want a client_credential request to return a cached token that has a homeAccountId
2744
- */
2745
- if ((typeof homeAccountId === "string") && !_this.matchHomeAccountId(entity, homeAccountId)) {
2746
- return;
2747
- }
2748
- if (!!environment && !_this.matchEnvironment(entity, environment)) {
2749
- return;
2750
- }
2751
- if (!!realm && !_this.matchRealm(entity, realm)) {
2752
- return;
2753
- }
2754
- if (!!credentialType && !_this.matchCredentialType(entity, credentialType)) {
2755
- return;
2756
- }
2757
- if (!!clientId && !_this.matchClientId(entity, clientId)) {
2758
- return;
2570
+ CacheManager.prototype.isCredentialKey = function (key) {
2571
+ if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 6) {
2572
+ // Credential cache keys contain 6 items separated by '-' (each item may also contain '-')
2573
+ return false;
2574
+ }
2575
+ var lowerCaseKey = key.toLowerCase();
2576
+ // Credential keys must indicate what credential type they represent
2577
+ if (lowerCaseKey.indexOf(CredentialType.ID_TOKEN.toLowerCase()) === -1 &&
2578
+ lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN.toLowerCase()) === -1 &&
2579
+ lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) === -1 &&
2580
+ lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) === -1) {
2581
+ return false;
2582
+ }
2583
+ if (lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) > -1) {
2584
+ // Refresh tokens must contain the client id or family id
2585
+ var clientIdValidation = "" + CredentialType.REFRESH_TOKEN + Separators.CACHE_KEY_SEPARATOR + this.clientId + Separators.CACHE_KEY_SEPARATOR;
2586
+ var familyIdValidation = "" + CredentialType.REFRESH_TOKEN + Separators.CACHE_KEY_SEPARATOR + THE_FAMILY_ID + Separators.CACHE_KEY_SEPARATOR;
2587
+ if (lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 && lowerCaseKey.indexOf(familyIdValidation.toLowerCase()) === -1) {
2588
+ return false;
2759
2589
  }
2760
- if (!!familyId && !_this.matchFamilyId(entity, familyId)) {
2761
- return;
2762
- }
2763
- /*
2764
- * idTokens do not have "target", target specific refreshTokens do exist for some types of authentication
2765
- * Resource specific refresh tokens case will be added when the support is deemed necessary
2766
- */
2767
- if (!!target && !_this.matchTarget(entity, target)) {
2768
- return;
2590
+ }
2591
+ else if (lowerCaseKey.indexOf(this.clientId.toLowerCase()) === -1) {
2592
+ // Tokens must contain the clientId
2593
+ return false;
2594
+ }
2595
+ return true;
2596
+ };
2597
+ /**
2598
+ * Returns whether or not the given credential entity matches the filter
2599
+ * @param entity
2600
+ * @param filter
2601
+ * @returns
2602
+ */
2603
+ CacheManager.prototype.credentialMatchesFilter = function (entity, filter) {
2604
+ if (!!filter.clientId && !this.matchClientId(entity, filter.clientId)) {
2605
+ return false;
2606
+ }
2607
+ if (!!filter.userAssertionHash && !this.matchUserAssertionHash(entity, filter.userAssertionHash)) {
2608
+ return false;
2609
+ }
2610
+ /*
2611
+ * homeAccountId can be undefined, and we want to filter out cached items that have a homeAccountId of ""
2612
+ * because we don't want a client_credential request to return a cached token that has a homeAccountId
2613
+ */
2614
+ if ((typeof filter.homeAccountId === "string") && !this.matchHomeAccountId(entity, filter.homeAccountId)) {
2615
+ return false;
2616
+ }
2617
+ if (!!filter.environment && !this.matchEnvironment(entity, filter.environment)) {
2618
+ return false;
2619
+ }
2620
+ if (!!filter.realm && !this.matchRealm(entity, filter.realm)) {
2621
+ return false;
2622
+ }
2623
+ if (!!filter.credentialType && !this.matchCredentialType(entity, filter.credentialType)) {
2624
+ return false;
2625
+ }
2626
+ if (!!filter.familyId && !this.matchFamilyId(entity, filter.familyId)) {
2627
+ return false;
2628
+ }
2629
+ /*
2630
+ * idTokens do not have "target", target specific refreshTokens do exist for some types of authentication
2631
+ * Resource specific refresh tokens case will be added when the support is deemed necessary
2632
+ */
2633
+ if (!!filter.target && !this.matchTarget(entity, filter.target)) {
2634
+ return false;
2635
+ }
2636
+ // If request OR cached entity has requested Claims Hash, check if they match
2637
+ if (filter.requestedClaimsHash || entity.requestedClaimsHash) {
2638
+ // Don't match if either is undefined or they are different
2639
+ if (entity.requestedClaimsHash !== filter.requestedClaimsHash) {
2640
+ return false;
2769
2641
  }
2770
- // If request OR cached entity has requested Claims Hash, check if they match
2771
- if (requestedClaimsHash || entity.requestedClaimsHash) {
2772
- // Don't match if either is undefined or they are different
2773
- if (entity.requestedClaimsHash !== requestedClaimsHash) {
2774
- return;
2775
- }
2642
+ }
2643
+ // Access Token with Auth Scheme specific matching
2644
+ if (entity.credentialType === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
2645
+ if (!!filter.tokenType && !this.matchTokenType(entity, filter.tokenType)) {
2646
+ return false;
2776
2647
  }
2777
- // Access Token with Auth Scheme specific matching
2778
- if (credentialType === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
2779
- if (!!tokenType && !_this.matchTokenType(entity, tokenType)) {
2780
- return;
2781
- }
2782
- // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
2783
- if (tokenType === exports.AuthenticationScheme.SSH) {
2784
- if (keyId && !_this.matchKeyId(entity, keyId)) {
2785
- return;
2786
- }
2648
+ // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
2649
+ if (filter.tokenType === exports.AuthenticationScheme.SSH) {
2650
+ if (filter.keyId && !this.matchKeyId(entity, filter.keyId)) {
2651
+ return false;
2787
2652
  }
2788
2653
  }
2789
- // At this point, the entity matches the request, update cache key if key schema has changed
2790
- var updatedCacheKey = _this.updateCredentialCacheKey(cacheKey, entity);
2791
- switch (credType) {
2792
- case CredentialType.ID_TOKEN:
2793
- matchingCredentials.idTokens[updatedCacheKey] = entity;
2794
- break;
2795
- case CredentialType.ACCESS_TOKEN:
2796
- case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
2797
- matchingCredentials.accessTokens[updatedCacheKey] = entity;
2798
- break;
2799
- case CredentialType.REFRESH_TOKEN:
2800
- matchingCredentials.refreshTokens[updatedCacheKey] = entity;
2801
- break;
2802
- }
2803
- });
2804
- return matchingCredentials;
2654
+ }
2655
+ return true;
2805
2656
  };
2806
2657
  /**
2807
2658
  * retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata
@@ -2869,30 +2720,26 @@ var CacheManager = /** @class */ (function () {
2869
2720
  */
2870
2721
  CacheManager.prototype.removeAllAccounts = function () {
2871
2722
  return __awaiter(this, void 0, void 0, function () {
2872
- var allCacheKeys, removedAccounts;
2723
+ var allAccountKeys, removedAccounts;
2873
2724
  var _this = this;
2874
2725
  return __generator(this, function (_a) {
2875
2726
  switch (_a.label) {
2876
2727
  case 0:
2877
- allCacheKeys = this.getKeys();
2728
+ allAccountKeys = this.getAccountKeys();
2878
2729
  removedAccounts = [];
2879
- allCacheKeys.forEach(function (cacheKey) {
2880
- var entity = _this.getAccount(cacheKey);
2881
- if (!entity) {
2882
- return;
2883
- }
2730
+ allAccountKeys.forEach(function (cacheKey) {
2884
2731
  removedAccounts.push(_this.removeAccount(cacheKey));
2885
2732
  });
2886
2733
  return [4 /*yield*/, Promise.all(removedAccounts)];
2887
2734
  case 1:
2888
2735
  _a.sent();
2889
- return [2 /*return*/, true];
2736
+ return [2 /*return*/];
2890
2737
  }
2891
2738
  });
2892
2739
  });
2893
2740
  };
2894
2741
  /**
2895
- * returns a boolean if the given account is removed
2742
+ * Removes the account and related tokens for a given account key
2896
2743
  * @param account
2897
2744
  */
2898
2745
  CacheManager.prototype.removeAccount = function (accountKey) {
@@ -2906,7 +2753,10 @@ var CacheManager = /** @class */ (function () {
2906
2753
  throw ClientAuthError.createNoAccountFoundError();
2907
2754
  }
2908
2755
  return [4 /*yield*/, this.removeAccountContext(account)];
2909
- case 1: return [2 /*return*/, ((_a.sent()) && this.removeItem(accountKey, CacheSchemaType.ACCOUNT))];
2756
+ case 1:
2757
+ _a.sent();
2758
+ this.removeItem(accountKey);
2759
+ return [2 /*return*/];
2910
2760
  }
2911
2761
  });
2912
2762
  });
@@ -2917,29 +2767,33 @@ var CacheManager = /** @class */ (function () {
2917
2767
  */
2918
2768
  CacheManager.prototype.removeAccountContext = function (account) {
2919
2769
  return __awaiter(this, void 0, void 0, function () {
2920
- var allCacheKeys, accountId, removedCredentials;
2770
+ var allTokenKeys, accountId, removedCredentials;
2921
2771
  var _this = this;
2922
2772
  return __generator(this, function (_a) {
2923
2773
  switch (_a.label) {
2924
2774
  case 0:
2925
- allCacheKeys = this.getKeys();
2775
+ allTokenKeys = this.getTokenKeys();
2926
2776
  accountId = account.generateAccountId();
2927
2777
  removedCredentials = [];
2928
- allCacheKeys.forEach(function (cacheKey) {
2929
- // don't parse any non-credential type cache entities
2930
- var credType = CredentialEntity.getCredentialType(cacheKey);
2931
- if (credType === Constants.NOT_DEFINED) {
2932
- return;
2778
+ allTokenKeys.idToken.forEach(function (key) {
2779
+ if (key.indexOf(accountId) === 0) {
2780
+ _this.removeIdToken(key);
2933
2781
  }
2934
- var cacheEntity = _this.getSpecificCredential(cacheKey, credType);
2935
- if (!!cacheEntity && accountId === cacheEntity.generateAccountId()) {
2936
- removedCredentials.push(_this.removeCredential(cacheEntity));
2782
+ });
2783
+ allTokenKeys.accessToken.forEach(function (key) {
2784
+ if (key.indexOf(accountId) === 0) {
2785
+ removedCredentials.push(_this.removeAccessToken(key));
2786
+ }
2787
+ });
2788
+ allTokenKeys.refreshToken.forEach(function (key) {
2789
+ if (key.indexOf(accountId) === 0) {
2790
+ _this.removeRefreshToken(key);
2937
2791
  }
2938
2792
  });
2939
2793
  return [4 /*yield*/, Promise.all(removedCredentials)];
2940
2794
  case 1:
2941
2795
  _a.sent();
2942
- return [2 /*return*/, true];
2796
+ return [2 /*return*/];
2943
2797
  }
2944
2798
  });
2945
2799
  });
@@ -2948,13 +2802,16 @@ var CacheManager = /** @class */ (function () {
2948
2802
  * returns a boolean if the given credential is removed
2949
2803
  * @param credential
2950
2804
  */
2951
- CacheManager.prototype.removeCredential = function (credential) {
2805
+ CacheManager.prototype.removeAccessToken = function (key) {
2952
2806
  return __awaiter(this, void 0, void 0, function () {
2953
- var key, accessTokenWithAuthSchemeEntity, kid;
2807
+ var credential, accessTokenWithAuthSchemeEntity, kid;
2954
2808
  return __generator(this, function (_a) {
2955
2809
  switch (_a.label) {
2956
2810
  case 0:
2957
- key = credential.generateCredentialKey();
2811
+ credential = this.getAccessTokenCredential(key);
2812
+ if (!credential) {
2813
+ return [2 /*return*/];
2814
+ }
2958
2815
  if (!(credential.credentialType.toLowerCase() === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase())) return [3 /*break*/, 4];
2959
2816
  if (!(credential.tokenType === exports.AuthenticationScheme.POP)) return [3 /*break*/, 4];
2960
2817
  accessTokenWithAuthSchemeEntity = credential;
@@ -2970,7 +2827,7 @@ var CacheManager = /** @class */ (function () {
2970
2827
  case 3:
2971
2828
  _a.sent();
2972
2829
  throw ClientAuthError.createBindingKeyNotRemovedError();
2973
- case 4: return [2 /*return*/, this.removeItem(key, CacheSchemaType.CREDENTIAL)];
2830
+ case 4: return [2 /*return*/, this.removeItem(key)];
2974
2831
  }
2975
2832
  });
2976
2833
  });
@@ -2983,7 +2840,7 @@ var CacheManager = /** @class */ (function () {
2983
2840
  var allCacheKeys = this.getKeys();
2984
2841
  allCacheKeys.forEach(function (cacheKey) {
2985
2842
  if (_this.isAppMetadata(cacheKey)) {
2986
- _this.removeItem(cacheKey, CacheSchemaType.APP_METADATA);
2843
+ _this.removeItem(cacheKey);
2987
2844
  }
2988
2845
  });
2989
2846
  return true;
@@ -2996,12 +2853,13 @@ var CacheManager = /** @class */ (function () {
2996
2853
  * @param environment
2997
2854
  * @param authScheme
2998
2855
  */
2999
- CacheManager.prototype.readCacheRecord = function (account, clientId, request, environment) {
2856
+ CacheManager.prototype.readCacheRecord = function (account, request, environment) {
2857
+ var tokenKeys = this.getTokenKeys();
3000
2858
  var cachedAccount = this.readAccountFromCache(account);
3001
- var cachedIdToken = this.readIdTokenFromCache(clientId, account);
3002
- var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, request);
3003
- var cachedRefreshToken = this.readRefreshTokenFromCache(clientId, account, false);
3004
- var cachedAppMetadata = this.readAppMetadataFromCache(environment, clientId);
2859
+ var cachedIdToken = this.getIdToken(account, tokenKeys);
2860
+ var cachedAccessToken = this.getAccessToken(account, request, tokenKeys);
2861
+ var cachedRefreshToken = this.getRefreshToken(account, false, tokenKeys);
2862
+ var cachedAppMetadata = this.readAppMetadataFromCache(environment);
3005
2863
  if (cachedAccount && cachedIdToken) {
3006
2864
  cachedAccount.idTokenClaims = new AuthToken(cachedIdToken.secret, this.cryptoImpl).claims;
3007
2865
  }
@@ -3021,51 +2879,83 @@ var CacheManager = /** @class */ (function () {
3021
2879
  var accountKey = AccountEntity.generateAccountCacheKey(account);
3022
2880
  return this.getAccount(accountKey);
3023
2881
  };
3024
- /**
3025
- * Retrieve AccountEntity from cache
3026
- * @param nativeAccountId
3027
- * @returns AccountEntity or Null
3028
- */
3029
- CacheManager.prototype.readAccountFromCacheWithNativeAccountId = function (nativeAccountId) {
3030
- // fetch account from memory
3031
- var accountFilter = {
3032
- nativeAccountId: nativeAccountId
3033
- };
3034
- var accountCache = this.getAccountsFilteredBy(accountFilter);
3035
- var accounts = Object.keys(accountCache).map(function (key) { return accountCache[key]; });
3036
- if (accounts.length < 1) {
3037
- return null;
3038
- }
3039
- else if (accounts.length > 1) {
3040
- throw ClientAuthError.createMultipleMatchingAccountsInCacheError();
3041
- }
3042
- return accounts[0];
3043
- };
3044
2882
  /**
3045
2883
  * Retrieve IdTokenEntity from cache
3046
2884
  * @param clientId
3047
2885
  * @param account
3048
2886
  * @param inputRealm
3049
2887
  */
3050
- CacheManager.prototype.readIdTokenFromCache = function (clientId, account) {
2888
+ CacheManager.prototype.getIdToken = function (account, tokenKeys) {
2889
+ this.commonLogger.trace("CacheManager - getIdToken called");
3051
2890
  var idTokenFilter = {
3052
2891
  homeAccountId: account.homeAccountId,
3053
2892
  environment: account.environment,
3054
2893
  credentialType: CredentialType.ID_TOKEN,
3055
- clientId: clientId,
2894
+ clientId: this.clientId,
3056
2895
  realm: account.tenantId,
3057
2896
  };
3058
- var credentialCache = this.getCredentialsFilteredBy(idTokenFilter);
3059
- var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
2897
+ var idTokens = this.getIdTokensByFilter(idTokenFilter, tokenKeys);
3060
2898
  var numIdTokens = idTokens.length;
3061
2899
  if (numIdTokens < 1) {
2900
+ this.commonLogger.info("CacheManager:getIdToken - No token found");
3062
2901
  return null;
3063
2902
  }
3064
2903
  else if (numIdTokens > 1) {
3065
2904
  throw ClientAuthError.createMultipleMatchingTokensInCacheError();
3066
2905
  }
2906
+ this.commonLogger.info("CacheManager:getIdToken - Returning id token");
3067
2907
  return idTokens[0];
3068
2908
  };
2909
+ /**
2910
+ * Gets all idTokens matching the given filter
2911
+ * @param filter
2912
+ * @returns
2913
+ */
2914
+ CacheManager.prototype.getIdTokensByFilter = function (filter, tokenKeys) {
2915
+ var _this = this;
2916
+ var idTokenKeys = tokenKeys && tokenKeys.idToken || this.getTokenKeys().idToken;
2917
+ var idTokens = [];
2918
+ idTokenKeys.forEach(function (key) {
2919
+ if (!_this.idTokenKeyMatchesFilter(key, __assign({ clientId: _this.clientId }, filter))) {
2920
+ return;
2921
+ }
2922
+ var idToken = _this.getIdTokenCredential(key);
2923
+ if (idToken && _this.credentialMatchesFilter(idToken, filter)) {
2924
+ idTokens.push(idToken);
2925
+ }
2926
+ });
2927
+ return idTokens;
2928
+ };
2929
+ /**
2930
+ * Validate the cache key against filter before retrieving and parsing cache value
2931
+ * @param key
2932
+ * @param filter
2933
+ * @returns
2934
+ */
2935
+ CacheManager.prototype.idTokenKeyMatchesFilter = function (inputKey, filter) {
2936
+ var key = inputKey.toLowerCase();
2937
+ if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
2938
+ return false;
2939
+ }
2940
+ if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
2941
+ return false;
2942
+ }
2943
+ return true;
2944
+ };
2945
+ /**
2946
+ * Removes idToken from the cache
2947
+ * @param key
2948
+ */
2949
+ CacheManager.prototype.removeIdToken = function (key) {
2950
+ this.removeItem(key);
2951
+ };
2952
+ /**
2953
+ * Removes refresh token from the cache
2954
+ * @param key
2955
+ */
2956
+ CacheManager.prototype.removeRefreshToken = function (key) {
2957
+ this.removeItem(key);
2958
+ };
3069
2959
  /**
3070
2960
  * Retrieve AccessTokenEntity from cache
3071
2961
  * @param clientId
@@ -3073,8 +2963,10 @@ var CacheManager = /** @class */ (function () {
3073
2963
  * @param scopes
3074
2964
  * @param authScheme
3075
2965
  */
3076
- CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, request) {
3077
- var scopes = new ScopeSet(request.scopes || []);
2966
+ CacheManager.prototype.getAccessToken = function (account, request, tokenKeys) {
2967
+ var _this = this;
2968
+ this.commonLogger.trace("CacheManager - getAccessToken called");
2969
+ var scopes = ScopeSet.createSearchScopes(request.scopes);
3078
2970
  var authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
3079
2971
  /*
3080
2972
  * Distinguish between Bearer and PoP/SSH token cache types
@@ -3085,55 +2977,156 @@ var CacheManager = /** @class */ (function () {
3085
2977
  homeAccountId: account.homeAccountId,
3086
2978
  environment: account.environment,
3087
2979
  credentialType: credentialType,
3088
- clientId: clientId,
2980
+ clientId: this.clientId,
3089
2981
  realm: account.tenantId,
3090
- target: scopes.printScopesLowerCase(),
2982
+ target: scopes,
3091
2983
  tokenType: authScheme,
3092
2984
  keyId: request.sshKid,
3093
2985
  requestedClaimsHash: request.requestedClaimsHash,
3094
2986
  };
3095
- var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
3096
- var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
2987
+ var accessTokenKeys = tokenKeys && tokenKeys.accessToken || this.getTokenKeys().accessToken;
2988
+ var accessTokens = [];
2989
+ accessTokenKeys.forEach(function (key) {
2990
+ // Validate key
2991
+ if (_this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)) {
2992
+ var accessToken = _this.getAccessTokenCredential(key);
2993
+ // Validate value
2994
+ if (accessToken && _this.credentialMatchesFilter(accessToken, accessTokenFilter)) {
2995
+ accessTokens.push(accessToken);
2996
+ }
2997
+ }
2998
+ });
3097
2999
  var numAccessTokens = accessTokens.length;
3098
3000
  if (numAccessTokens < 1) {
3001
+ this.commonLogger.info("CacheManager:getAccessToken - No token found");
3099
3002
  return null;
3100
3003
  }
3101
3004
  else if (numAccessTokens > 1) {
3102
3005
  throw ClientAuthError.createMultipleMatchingTokensInCacheError();
3103
3006
  }
3007
+ this.commonLogger.info("CacheManager:getAccessToken - Returning access token");
3104
3008
  return accessTokens[0];
3105
3009
  };
3010
+ /**
3011
+ * Validate the cache key against filter before retrieving and parsing cache value
3012
+ * @param key
3013
+ * @param filter
3014
+ * @param keyMustContainAllScopes
3015
+ * @returns
3016
+ */
3017
+ CacheManager.prototype.accessTokenKeyMatchesFilter = function (inputKey, filter, keyMustContainAllScopes) {
3018
+ var key = inputKey.toLowerCase();
3019
+ if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
3020
+ return false;
3021
+ }
3022
+ if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
3023
+ return false;
3024
+ }
3025
+ if (filter.realm && key.indexOf(filter.realm.toLowerCase()) === -1) {
3026
+ return false;
3027
+ }
3028
+ if (filter.requestedClaimsHash && key.indexOf(filter.requestedClaimsHash.toLowerCase()) === -1) {
3029
+ return false;
3030
+ }
3031
+ if (filter.target) {
3032
+ var scopes = filter.target.asArray();
3033
+ for (var i = 0; i < scopes.length; i++) {
3034
+ if (keyMustContainAllScopes && !key.includes(scopes[i].toLowerCase())) {
3035
+ // When performing a cache lookup a missing scope would be a cache miss
3036
+ return false;
3037
+ }
3038
+ else if (!keyMustContainAllScopes && key.includes(scopes[i].toLowerCase())) {
3039
+ // When performing a cache write, any token with a subset of requested scopes should be replaced
3040
+ return true;
3041
+ }
3042
+ }
3043
+ }
3044
+ return true;
3045
+ };
3046
+ /**
3047
+ * Gets all access tokens matching the filter
3048
+ * @param filter
3049
+ * @returns
3050
+ */
3051
+ CacheManager.prototype.getAccessTokensByFilter = function (filter) {
3052
+ var _this = this;
3053
+ var tokenKeys = this.getTokenKeys();
3054
+ var accessTokens = [];
3055
+ tokenKeys.accessToken.forEach(function (key) {
3056
+ if (!_this.accessTokenKeyMatchesFilter(key, filter, true)) {
3057
+ return;
3058
+ }
3059
+ var accessToken = _this.getAccessTokenCredential(key);
3060
+ if (accessToken && _this.credentialMatchesFilter(accessToken, filter)) {
3061
+ accessTokens.push(accessToken);
3062
+ }
3063
+ });
3064
+ return accessTokens;
3065
+ };
3106
3066
  /**
3107
3067
  * Helper to retrieve the appropriate refresh token from cache
3108
3068
  * @param clientId
3109
3069
  * @param account
3110
3070
  * @param familyRT
3111
3071
  */
3112
- CacheManager.prototype.readRefreshTokenFromCache = function (clientId, account, familyRT) {
3072
+ CacheManager.prototype.getRefreshToken = function (account, familyRT, tokenKeys) {
3073
+ var _this = this;
3074
+ this.commonLogger.trace("CacheManager - getRefreshToken called");
3113
3075
  var id = familyRT ? THE_FAMILY_ID : undefined;
3114
3076
  var refreshTokenFilter = {
3115
3077
  homeAccountId: account.homeAccountId,
3116
3078
  environment: account.environment,
3117
3079
  credentialType: CredentialType.REFRESH_TOKEN,
3118
- clientId: clientId,
3080
+ clientId: this.clientId,
3119
3081
  familyId: id,
3120
3082
  };
3121
- var credentialCache = this.getCredentialsFilteredBy(refreshTokenFilter);
3122
- var refreshTokens = Object.keys(credentialCache.refreshTokens).map(function (key) { return credentialCache.refreshTokens[key]; });
3083
+ var refreshTokenKeys = tokenKeys && tokenKeys.refreshToken || this.getTokenKeys().refreshToken;
3084
+ var refreshTokens = [];
3085
+ refreshTokenKeys.forEach(function (key) {
3086
+ // Validate key
3087
+ if (_this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {
3088
+ var refreshToken = _this.getRefreshTokenCredential(key);
3089
+ // Validate value
3090
+ if (refreshToken && _this.credentialMatchesFilter(refreshToken, refreshTokenFilter)) {
3091
+ refreshTokens.push(refreshToken);
3092
+ }
3093
+ }
3094
+ });
3123
3095
  var numRefreshTokens = refreshTokens.length;
3124
3096
  if (numRefreshTokens < 1) {
3097
+ this.commonLogger.info("CacheManager:getRefreshToken - No refresh token found.");
3125
3098
  return null;
3126
3099
  }
3127
3100
  // address the else case after remove functions address environment aliases
3101
+ this.commonLogger.info("CacheManager:getRefreshToken - returning refresh token");
3128
3102
  return refreshTokens[0];
3129
3103
  };
3104
+ /**
3105
+ * Validate the cache key against filter before retrieving and parsing cache value
3106
+ * @param key
3107
+ * @param filter
3108
+ */
3109
+ CacheManager.prototype.refreshTokenKeyMatchesFilter = function (inputKey, filter) {
3110
+ var key = inputKey.toLowerCase();
3111
+ if (filter.familyId && key.indexOf(filter.familyId.toLowerCase()) === -1) {
3112
+ return false;
3113
+ }
3114
+ // If familyId is used, clientId is not in the key
3115
+ if (!filter.familyId && filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
3116
+ return false;
3117
+ }
3118
+ if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
3119
+ return false;
3120
+ }
3121
+ return true;
3122
+ };
3130
3123
  /**
3131
3124
  * Retrieve AppMetadataEntity from cache
3132
3125
  */
3133
- CacheManager.prototype.readAppMetadataFromCache = function (environment, clientId) {
3126
+ CacheManager.prototype.readAppMetadataFromCache = function (environment) {
3134
3127
  var appMetadataFilter = {
3135
3128
  environment: environment,
3136
- clientId: clientId,
3129
+ clientId: this.clientId,
3137
3130
  };
3138
3131
  var appMetadata = this.getAppMetadataFilteredBy(appMetadataFilter);
3139
3132
  var appMetadataEntries = Object.keys(appMetadata).map(function (key) { return appMetadata[key]; });
@@ -3151,8 +3144,8 @@ var CacheManager = /** @class */ (function () {
3151
3144
  * @param environment
3152
3145
  * @param clientId
3153
3146
  */
3154
- CacheManager.prototype.isAppMetadataFOCI = function (environment, clientId) {
3155
- var appMetadata = this.readAppMetadataFromCache(environment, clientId);
3147
+ CacheManager.prototype.isAppMetadataFOCI = function (environment) {
3148
+ var appMetadata = this.readAppMetadataFromCache(environment);
3156
3149
  return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);
3157
3150
  };
3158
3151
  /**
@@ -3163,6 +3156,24 @@ var CacheManager = /** @class */ (function () {
3163
3156
  CacheManager.prototype.matchHomeAccountId = function (entity, homeAccountId) {
3164
3157
  return !!((typeof entity.homeAccountId === "string") && (homeAccountId === entity.homeAccountId));
3165
3158
  };
3159
+ /**
3160
+ * helper to match account ids
3161
+ * @param entity
3162
+ * @param localAccountId
3163
+ * @returns
3164
+ */
3165
+ CacheManager.prototype.matchLocalAccountId = function (entity, localAccountId) {
3166
+ return !!((typeof entity.localAccountId === "string") && (localAccountId === entity.localAccountId));
3167
+ };
3168
+ /**
3169
+ * helper to match usernames
3170
+ * @param entity
3171
+ * @param username
3172
+ * @returns
3173
+ */
3174
+ CacheManager.prototype.matchUsername = function (entity, username) {
3175
+ return !!((typeof entity.username === "string") && (username.toLowerCase() === entity.username.toLowerCase()));
3176
+ };
3166
3177
  /**
3167
3178
  * helper to match assertion
3168
3179
  * @param value
@@ -3235,14 +3246,7 @@ var CacheManager = /** @class */ (function () {
3235
3246
  return false;
3236
3247
  }
3237
3248
  var entityScopeSet = ScopeSet.fromString(entity.target);
3238
- var requestTargetScopeSet = ScopeSet.fromString(target);
3239
- if (!requestTargetScopeSet.containsOnlyOIDCScopes()) {
3240
- requestTargetScopeSet.removeOIDCScopes(); // ignore OIDC scopes
3241
- }
3242
- else {
3243
- requestTargetScopeSet.removeScope(Constants.OFFLINE_ACCESS_SCOPE);
3244
- }
3245
- return entityScopeSet.containsScopeSet(requestTargetScopeSet);
3249
+ return entityScopeSet.containsScopeSet(target);
3246
3250
  };
3247
3251
  /**
3248
3252
  * Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
@@ -3280,27 +3284,6 @@ var CacheManager = /** @class */ (function () {
3280
3284
  CacheManager.prototype.generateAuthorityMetadataCacheKey = function (authority) {
3281
3285
  return AUTHORITY_METADATA_CONSTANTS.CACHE_KEY + "-" + this.clientId + "-" + authority;
3282
3286
  };
3283
- /**
3284
- * Returns the specific credential (IdToken/AccessToken/RefreshToken) from the cache
3285
- * @param key
3286
- * @param credType
3287
- */
3288
- CacheManager.prototype.getSpecificCredential = function (key, credType) {
3289
- switch (credType) {
3290
- case CredentialType.ID_TOKEN: {
3291
- return this.getIdTokenCredential(key);
3292
- }
3293
- case CredentialType.ACCESS_TOKEN:
3294
- case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME: {
3295
- return this.getAccessTokenCredential(key);
3296
- }
3297
- case CredentialType.REFRESH_TOKEN: {
3298
- return this.getRefreshTokenCredential(key);
3299
- }
3300
- default:
3301
- return null;
3302
- }
3303
- };
3304
3287
  /**
3305
3288
  * Helper to convert serialized data to object
3306
3289
  * @param obj
@@ -3399,6 +3382,14 @@ var DefaultStorageClass = /** @class */ (function (_super) {
3399
3382
  var notImplErr = "Storage interface - getKeys() has not been implemented for the cacheStorage interface.";
3400
3383
  throw AuthError.createUnexpectedError(notImplErr);
3401
3384
  };
3385
+ DefaultStorageClass.prototype.getAccountKeys = function () {
3386
+ var notImplErr = "Storage interface - getAccountKeys() has not been implemented for the cacheStorage interface.";
3387
+ throw AuthError.createUnexpectedError(notImplErr);
3388
+ };
3389
+ DefaultStorageClass.prototype.getTokenKeys = function () {
3390
+ var notImplErr = "Storage interface - getTokenKeys() has not been implemented for the cacheStorage interface.";
3391
+ throw AuthError.createUnexpectedError(notImplErr);
3392
+ };
3402
3393
  DefaultStorageClass.prototype.clear = function () {
3403
3394
  return __awaiter(this, void 0, void 0, function () {
3404
3395
  var notImplErr;
@@ -3415,7 +3406,7 @@ var DefaultStorageClass = /** @class */ (function (_super) {
3415
3406
  return DefaultStorageClass;
3416
3407
  }(CacheManager));
3417
3408
 
3418
- /*! @azure/msal-common v11.0.0 2023-03-07 */
3409
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
3419
3410
 
3420
3411
  /*
3421
3412
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3489,7 +3480,7 @@ function buildClientConfiguration(_a) {
3489
3480
  authOptions: buildAuthOptions(userAuthOptions),
3490
3481
  systemOptions: __assign(__assign({}, DEFAULT_SYSTEM_OPTIONS), userSystemOptions),
3491
3482
  loggerOptions: loggerOptions,
3492
- storageInterface: storageImplementation || new DefaultStorageClass(userAuthOptions.clientId, DEFAULT_CRYPTO_IMPLEMENTATION),
3483
+ storageInterface: storageImplementation || new DefaultStorageClass(userAuthOptions.clientId, DEFAULT_CRYPTO_IMPLEMENTATION, new Logger(loggerOptions)),
3493
3484
  networkInterface: networkImplementation || DEFAULT_NETWORK_IMPLEMENTATION,
3494
3485
  cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,
3495
3486
  clientCredentials: clientCredentials || DEFAULT_CLIENT_CREDENTIALS,
@@ -3508,7 +3499,7 @@ function buildAuthOptions(authOptions) {
3508
3499
  return __assign({ clientCapabilities: [], azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS, skipAuthorityMetadataCache: false }, authOptions);
3509
3500
  }
3510
3501
 
3511
- /*! @azure/msal-common v11.0.0 2023-03-07 */
3502
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
3512
3503
 
3513
3504
  /*
3514
3505
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3528,7 +3519,7 @@ var ServerError = /** @class */ (function (_super) {
3528
3519
  return ServerError;
3529
3520
  }(AuthError));
3530
3521
 
3531
- /*! @azure/msal-common v11.0.0 2023-03-07 */
3522
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
3532
3523
 
3533
3524
  /*
3534
3525
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3555,7 +3546,7 @@ var ThrottlingUtils = /** @class */ (function () {
3555
3546
  var value = cacheManager.getThrottlingCache(key);
3556
3547
  if (value) {
3557
3548
  if (value.throttleTime < Date.now()) {
3558
- cacheManager.removeItem(key, CacheSchemaType.THROTTLING);
3549
+ cacheManager.removeItem(key);
3559
3550
  return;
3560
3551
  }
3561
3552
  throw new ServerError(((_a = value.errorCodes) === null || _a === void 0 ? void 0 : _a.join(" ")) || Constants.EMPTY_STRING, value.errorMessage, value.subError);
@@ -3619,12 +3610,12 @@ var ThrottlingUtils = /** @class */ (function () {
3619
3610
  sshKid: request.sshKid
3620
3611
  };
3621
3612
  var key = this.generateThrottlingStorageKey(thumbprint);
3622
- return cacheManager.removeItem(key, CacheSchemaType.THROTTLING);
3613
+ cacheManager.removeItem(key);
3623
3614
  };
3624
3615
  return ThrottlingUtils;
3625
3616
  }());
3626
3617
 
3627
- /*! @azure/msal-common v11.0.0 2023-03-07 */
3618
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
3628
3619
 
3629
3620
  /*
3630
3621
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3673,7 +3664,7 @@ var NetworkManager = /** @class */ (function () {
3673
3664
  return NetworkManager;
3674
3665
  }());
3675
3666
 
3676
- /*! @azure/msal-common v11.0.0 2023-03-07 */
3667
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
3677
3668
  /*
3678
3669
  * Copyright (c) Microsoft Corporation. All rights reserved.
3679
3670
  * Licensed under the MIT License.
@@ -3684,7 +3675,7 @@ var CcsCredentialType;
3684
3675
  CcsCredentialType["UPN"] = "UPN";
3685
3676
  })(CcsCredentialType || (CcsCredentialType = {}));
3686
3677
 
3687
- /*! @azure/msal-common v11.0.0 2023-03-07 */
3678
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
3688
3679
 
3689
3680
  /*
3690
3681
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3775,7 +3766,7 @@ var RequestValidator = /** @class */ (function () {
3775
3766
  return RequestValidator;
3776
3767
  }());
3777
3768
 
3778
- /*! @azure/msal-common v11.0.0 2023-03-07 */
3769
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
3779
3770
 
3780
3771
  /*
3781
3772
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4153,7 +4144,7 @@ var RequestParameterBuilder = /** @class */ (function () {
4153
4144
  return RequestParameterBuilder;
4154
4145
  }());
4155
4146
 
4156
- /*! @azure/msal-common v11.0.0 2023-03-07 */
4147
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4157
4148
 
4158
4149
  /*
4159
4150
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4205,57 +4196,195 @@ var BaseClient = /** @class */ (function () {
4205
4196
  break;
4206
4197
  }
4207
4198
  }
4208
- return headers;
4199
+ return headers;
4200
+ };
4201
+ /**
4202
+ * Http post to token endpoint
4203
+ * @param tokenEndpoint
4204
+ * @param queryString
4205
+ * @param headers
4206
+ * @param thumbprint
4207
+ */
4208
+ BaseClient.prototype.executePostToTokenEndpoint = function (tokenEndpoint, queryString, headers, thumbprint) {
4209
+ return __awaiter(this, void 0, void 0, function () {
4210
+ var response;
4211
+ return __generator(this, function (_a) {
4212
+ switch (_a.label) {
4213
+ case 0: return [4 /*yield*/, this.networkManager.sendPostRequest(thumbprint, tokenEndpoint, { body: queryString, headers: headers })];
4214
+ case 1:
4215
+ response = _a.sent();
4216
+ if (this.config.serverTelemetryManager && response.status < 500 && response.status !== 429) {
4217
+ // Telemetry data successfully logged by server, clear Telemetry cache
4218
+ this.config.serverTelemetryManager.clearTelemetryCache();
4219
+ }
4220
+ return [2 /*return*/, response];
4221
+ }
4222
+ });
4223
+ });
4224
+ };
4225
+ /**
4226
+ * Updates the authority object of the client. Endpoint discovery must be completed.
4227
+ * @param updatedAuthority
4228
+ */
4229
+ BaseClient.prototype.updateAuthority = function (updatedAuthority) {
4230
+ if (!updatedAuthority.discoveryComplete()) {
4231
+ throw ClientAuthError.createEndpointDiscoveryIncompleteError("Updated authority has not completed endpoint discovery.");
4232
+ }
4233
+ this.authority = updatedAuthority;
4234
+ };
4235
+ /**
4236
+ * Creates query string for the /token request
4237
+ * @param request
4238
+ */
4239
+ BaseClient.prototype.createTokenQueryParameters = function (request) {
4240
+ var parameterBuilder = new RequestParameterBuilder();
4241
+ if (request.tokenQueryParameters) {
4242
+ parameterBuilder.addExtraQueryParameters(request.tokenQueryParameters);
4243
+ }
4244
+ return parameterBuilder.createQueryString();
4245
+ };
4246
+ return BaseClient;
4247
+ }());
4248
+
4249
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4250
+
4251
+ /*
4252
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4253
+ * Licensed under the MIT License.
4254
+ */
4255
+ /**
4256
+ * Base type for credentials to be stored in the cache: eg: ACCESS_TOKEN, ID_TOKEN etc
4257
+ *
4258
+ * Key:Value Schema:
4259
+ *
4260
+ * Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<requestedClaims*>-<scheme*>
4261
+ *
4262
+ * Value Schema:
4263
+ * {
4264
+ * homeAccountId: home account identifier for the auth scheme,
4265
+ * environment: entity that issued the token, represented as a full host
4266
+ * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
4267
+ * clientId: client ID of the application
4268
+ * secret: Actual credential as a string
4269
+ * familyId: Family ID identifier, usually only used for refresh tokens
4270
+ * realm: Full tenant or organizational identifier that the account belongs to
4271
+ * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
4272
+ * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
4273
+ * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
4274
+ * userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
4275
+ * }
4276
+ */
4277
+ var CredentialEntity = /** @class */ (function () {
4278
+ function CredentialEntity() {
4279
+ }
4280
+ /**
4281
+ * Generate Account Id key component as per the schema: <home_account_id>-<environment>
4282
+ */
4283
+ CredentialEntity.prototype.generateAccountId = function () {
4284
+ return CredentialEntity.generateAccountIdForCacheKey(this.homeAccountId, this.environment);
4285
+ };
4286
+ /**
4287
+ * Generate Credential Id key component as per the schema: <credential_type>-<client_id>-<realm>
4288
+ */
4289
+ CredentialEntity.prototype.generateCredentialId = function () {
4290
+ return CredentialEntity.generateCredentialIdForCacheKey(this.credentialType, this.clientId, this.realm, this.familyId);
4291
+ };
4292
+ /**
4293
+ * Generate target key component as per schema: <target>
4294
+ */
4295
+ CredentialEntity.prototype.generateTarget = function () {
4296
+ return CredentialEntity.generateTargetForCacheKey(this.target);
4297
+ };
4298
+ /**
4299
+ * generates credential key
4300
+ */
4301
+ CredentialEntity.prototype.generateCredentialKey = function () {
4302
+ return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType, this.requestedClaimsHash);
4303
+ };
4304
+ /**
4305
+ * returns the type of the cache (in this case credential)
4306
+ */
4307
+ CredentialEntity.prototype.generateType = function () {
4308
+ switch (this.credentialType) {
4309
+ case CredentialType.ID_TOKEN:
4310
+ return CacheType.ID_TOKEN;
4311
+ case CredentialType.ACCESS_TOKEN:
4312
+ case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
4313
+ return CacheType.ACCESS_TOKEN;
4314
+ case CredentialType.REFRESH_TOKEN:
4315
+ return CacheType.REFRESH_TOKEN;
4316
+ default: {
4317
+ throw ClientAuthError.createUnexpectedCredentialTypeError();
4318
+ }
4319
+ }
4209
4320
  };
4210
4321
  /**
4211
- * Http post to token endpoint
4212
- * @param tokenEndpoint
4213
- * @param queryString
4214
- * @param headers
4215
- * @param thumbprint
4322
+ * generates credential key
4323
+ * <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
4216
4324
  */
4217
- BaseClient.prototype.executePostToTokenEndpoint = function (tokenEndpoint, queryString, headers, thumbprint) {
4218
- return __awaiter(this, void 0, void 0, function () {
4219
- var response;
4220
- return __generator(this, function (_a) {
4221
- switch (_a.label) {
4222
- case 0: return [4 /*yield*/, this.networkManager.sendPostRequest(thumbprint, tokenEndpoint, { body: queryString, headers: headers })];
4223
- case 1:
4224
- response = _a.sent();
4225
- if (this.config.serverTelemetryManager && response.status < 500 && response.status !== 429) {
4226
- // Telemetry data successfully logged by server, clear Telemetry cache
4227
- this.config.serverTelemetryManager.clearTelemetryCache();
4228
- }
4229
- return [2 /*return*/, response];
4230
- }
4231
- });
4232
- });
4325
+ CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType, requestedClaimsHash) {
4326
+ var credentialKey = [
4327
+ this.generateAccountIdForCacheKey(homeAccountId, environment),
4328
+ this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),
4329
+ this.generateTargetForCacheKey(target),
4330
+ this.generateClaimsHashForCacheKey(requestedClaimsHash),
4331
+ this.generateSchemeForCacheKey(tokenType)
4332
+ ];
4333
+ return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
4233
4334
  };
4234
4335
  /**
4235
- * Updates the authority object of the client. Endpoint discovery must be completed.
4236
- * @param updatedAuthority
4336
+ * generates Account Id for keys
4337
+ * @param homeAccountId
4338
+ * @param environment
4237
4339
  */
4238
- BaseClient.prototype.updateAuthority = function (updatedAuthority) {
4239
- if (!updatedAuthority.discoveryComplete()) {
4240
- throw ClientAuthError.createEndpointDiscoveryIncompleteError("Updated authority has not completed endpoint discovery.");
4241
- }
4242
- this.authority = updatedAuthority;
4340
+ CredentialEntity.generateAccountIdForCacheKey = function (homeAccountId, environment) {
4341
+ var accountId = [homeAccountId, environment];
4342
+ return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
4243
4343
  };
4244
4344
  /**
4245
- * Creates query string for the /token request
4246
- * @param request
4345
+ * Generates Credential Id for keys
4346
+ * @param credentialType
4347
+ * @param realm
4348
+ * @param clientId
4349
+ * @param familyId
4247
4350
  */
4248
- BaseClient.prototype.createTokenQueryParameters = function (request) {
4249
- var parameterBuilder = new RequestParameterBuilder();
4250
- if (request.tokenQueryParameters) {
4251
- parameterBuilder.addExtraQueryParameters(request.tokenQueryParameters);
4252
- }
4253
- return parameterBuilder.createQueryString();
4351
+ CredentialEntity.generateCredentialIdForCacheKey = function (credentialType, clientId, realm, familyId) {
4352
+ var clientOrFamilyId = credentialType === CredentialType.REFRESH_TOKEN
4353
+ ? familyId || clientId
4354
+ : clientId;
4355
+ var credentialId = [
4356
+ credentialType,
4357
+ clientOrFamilyId,
4358
+ realm || Constants.EMPTY_STRING,
4359
+ ];
4360
+ return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
4254
4361
  };
4255
- return BaseClient;
4362
+ /**
4363
+ * Generate target key component as per schema: <target>
4364
+ */
4365
+ CredentialEntity.generateTargetForCacheKey = function (scopes) {
4366
+ return (scopes || Constants.EMPTY_STRING).toLowerCase();
4367
+ };
4368
+ /**
4369
+ * Generate requested claims key component as per schema: <requestedClaims>
4370
+ */
4371
+ CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
4372
+ return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
4373
+ };
4374
+ /**
4375
+ * Generate scheme key componenet as per schema: <scheme>
4376
+ */
4377
+ CredentialEntity.generateSchemeForCacheKey = function (tokenType) {
4378
+ /*
4379
+ * PoP Tokens and SSH certs include scheme in cache key
4380
+ * Cast to lowercase to handle "bearer" from ADFS
4381
+ */
4382
+ return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
4383
+ };
4384
+ return CredentialEntity;
4256
4385
  }());
4257
4386
 
4258
- /*! @azure/msal-common v11.0.0 2023-03-07 */
4387
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4259
4388
 
4260
4389
  /*
4261
4390
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4319,7 +4448,7 @@ var IdTokenEntity = /** @class */ (function (_super) {
4319
4448
  return IdTokenEntity;
4320
4449
  }(CredentialEntity));
4321
4450
 
4322
- /*! @azure/msal-common v11.0.0 2023-03-07 */
4451
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4323
4452
  /*
4324
4453
  * Copyright (c) Microsoft Corporation. All rights reserved.
4325
4454
  * Licensed under the MIT License.
@@ -4369,7 +4498,7 @@ var TimeUtils = /** @class */ (function () {
4369
4498
  return TimeUtils;
4370
4499
  }());
4371
4500
 
4372
- /*! @azure/msal-common v11.0.0 2023-03-07 */
4501
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4373
4502
 
4374
4503
  /*
4375
4504
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4483,7 +4612,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
4483
4612
  return AccessTokenEntity;
4484
4613
  }(CredentialEntity));
4485
4614
 
4486
- /*! @azure/msal-common v11.0.0 2023-03-07 */
4615
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4487
4616
 
4488
4617
  /*
4489
4618
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4550,7 +4679,7 @@ var RefreshTokenEntity = /** @class */ (function (_super) {
4550
4679
  return RefreshTokenEntity;
4551
4680
  }(CredentialEntity));
4552
4681
 
4553
- /*! @azure/msal-common v11.0.0 2023-03-07 */
4682
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4554
4683
 
4555
4684
  /*
4556
4685
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4629,7 +4758,7 @@ var InteractionRequiredAuthError = /** @class */ (function (_super) {
4629
4758
  return InteractionRequiredAuthError;
4630
4759
  }(AuthError));
4631
4760
 
4632
- /*! @azure/msal-common v11.0.0 2023-03-07 */
4761
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4633
4762
  /*
4634
4763
  * Copyright (c) Microsoft Corporation. All rights reserved.
4635
4764
  * Licensed under the MIT License.
@@ -4645,7 +4774,7 @@ var CacheRecord = /** @class */ (function () {
4645
4774
  return CacheRecord;
4646
4775
  }());
4647
4776
 
4648
- /*! @azure/msal-common v11.0.0 2023-03-07 */
4777
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4649
4778
 
4650
4779
  /*
4651
4780
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4716,7 +4845,7 @@ var ProtocolUtils = /** @class */ (function () {
4716
4845
  return ProtocolUtils;
4717
4846
  }());
4718
4847
 
4719
- /*! @azure/msal-common v11.0.0 2023-03-07 */
4848
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4720
4849
 
4721
4850
  /*
4722
4851
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4950,7 +5079,7 @@ var UrlString = /** @class */ (function () {
4950
5079
  return UrlString;
4951
5080
  }());
4952
5081
 
4953
- /*! @azure/msal-common v11.0.0 2023-03-07 */
5082
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
4954
5083
  /*
4955
5084
  * Copyright (c) Microsoft Corporation. All rights reserved.
4956
5085
  * Licensed under the MIT License.
@@ -5179,7 +5308,7 @@ var IntFields = new Set([
5179
5308
  "status",
5180
5309
  ]);
5181
5310
 
5182
- /*! @azure/msal-common v11.0.0 2023-03-07 */
5311
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
5183
5312
 
5184
5313
  /*
5185
5314
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5288,7 +5417,7 @@ var PopTokenGenerator = /** @class */ (function () {
5288
5417
  return PopTokenGenerator;
5289
5418
  }());
5290
5419
 
5291
- /*! @azure/msal-common v11.0.0 2023-03-07 */
5420
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
5292
5421
 
5293
5422
  /*
5294
5423
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5358,7 +5487,7 @@ var AppMetadataEntity = /** @class */ (function () {
5358
5487
  return AppMetadataEntity;
5359
5488
  }());
5360
5489
 
5361
- /*! @azure/msal-common v11.0.0 2023-03-07 */
5490
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
5362
5491
  /*
5363
5492
  * Copyright (c) Microsoft Corporation. All rights reserved.
5364
5493
  * Licensed under the MIT License.
@@ -5394,7 +5523,7 @@ var AppMetadataEntity = /** @class */ (function () {
5394
5523
  return TokenCacheContext;
5395
5524
  }());
5396
5525
 
5397
- /*! @azure/msal-common v11.0.0 2023-03-07 */
5526
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
5398
5527
 
5399
5528
  /*
5400
5529
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5681,7 +5810,7 @@ var ResponseHandler = /** @class */ (function () {
5681
5810
  return ResponseHandler;
5682
5811
  }());
5683
5812
 
5684
- /*! @azure/msal-common v11.0.0 2023-03-07 */
5813
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
5685
5814
 
5686
5815
  /*
5687
5816
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6159,7 +6288,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
6159
6288
  return AuthorizationCodeClient;
6160
6289
  }(BaseClient));
6161
6290
 
6162
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6291
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6163
6292
 
6164
6293
  /*
6165
6294
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6239,7 +6368,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
6239
6368
  if (!request.account) {
6240
6369
  throw ClientAuthError.createNoAccountInSilentRequestError();
6241
6370
  }
6242
- isFOCI = this.cacheManager.isAppMetadataFOCI(request.account.environment, this.config.authOptions.clientId);
6371
+ isFOCI = this.cacheManager.isAppMetadataFOCI(request.account.environment);
6243
6372
  // if the app is part of the family, retrive a Family refresh token if present and make a refreshTokenRequest
6244
6373
  if (isFOCI) {
6245
6374
  try {
@@ -6278,7 +6407,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
6278
6407
  (_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(exports.PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken, request.correlationId);
6279
6408
  atsMeasurement = (_b = this.performanceClient) === null || _b === void 0 ? void 0 : _b.startMeasurement(exports.PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken, request.correlationId);
6280
6409
  this.logger.verbose("RefreshTokenClientAcquireTokenWithCachedRefreshToken called", request.correlationId);
6281
- refreshToken = this.cacheManager.readRefreshTokenFromCache(this.config.authOptions.clientId, request.account, foci);
6410
+ refreshToken = this.cacheManager.getRefreshToken(request.account, foci);
6282
6411
  if (!refreshToken) {
6283
6412
  atsMeasurement === null || atsMeasurement === void 0 ? void 0 : atsMeasurement.discardMeasurement();
6284
6413
  throw InteractionRequiredAuthError.createNoTokensFoundError();
@@ -6433,7 +6562,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
6433
6562
  return RefreshTokenClient;
6434
6563
  }(BaseClient));
6435
6564
 
6436
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6565
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6437
6566
 
6438
6567
  /*
6439
6568
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6498,7 +6627,7 @@ var SilentFlowClient = /** @class */ (function (_super) {
6498
6627
  throw ClientAuthError.createNoAccountInSilentRequestError();
6499
6628
  }
6500
6629
  environment = request.authority || this.authority.getPreferredCache();
6501
- cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, request, environment);
6630
+ cacheRecord = this.cacheManager.readCacheRecord(request.account, request, environment);
6502
6631
  if (!cacheRecord.accessToken) {
6503
6632
  // Must refresh due to non-existent access_token.
6504
6633
  (_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
@@ -6557,7 +6686,7 @@ var SilentFlowClient = /** @class */ (function (_super) {
6557
6686
  return SilentFlowClient;
6558
6687
  }(BaseClient));
6559
6688
 
6560
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6689
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6561
6690
  /*
6562
6691
  * Copyright (c) Microsoft Corporation. All rights reserved.
6563
6692
  * Licensed under the MIT License.
@@ -6569,7 +6698,7 @@ function isOpenIdConfigResponse(response) {
6569
6698
  response.hasOwnProperty("jwks_uri"));
6570
6699
  }
6571
6700
 
6572
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6701
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6573
6702
  /*
6574
6703
  * Copyright (c) Microsoft Corporation. All rights reserved.
6575
6704
  * Licensed under the MIT License.
@@ -6578,7 +6707,7 @@ var rawMetdataJSON = { "endpointMetadata": { "https://login.microsoftonline.com/
6578
6707
  var EndpointMetadata = rawMetdataJSON.endpointMetadata;
6579
6708
  var InstanceDiscoveryMetadata = rawMetdataJSON.instanceDiscoveryMetadata;
6580
6709
 
6581
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6710
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6582
6711
  /*
6583
6712
  * Copyright (c) Microsoft Corporation. All rights reserved.
6584
6713
  * Licensed under the MIT License.
@@ -6592,7 +6721,7 @@ exports.ProtocolMode = void 0;
6592
6721
  ProtocolMode["OIDC"] = "OIDC";
6593
6722
  })(exports.ProtocolMode || (exports.ProtocolMode = {}));
6594
6723
 
6595
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6724
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6596
6725
 
6597
6726
  /*
6598
6727
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6669,7 +6798,7 @@ var AuthorityMetadataEntity = /** @class */ (function () {
6669
6798
  return AuthorityMetadataEntity;
6670
6799
  }());
6671
6800
 
6672
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6801
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6673
6802
  /*
6674
6803
  * Copyright (c) Microsoft Corporation. All rights reserved.
6675
6804
  * Licensed under the MIT License.
@@ -6679,7 +6808,7 @@ function isCloudInstanceDiscoveryResponse(response) {
6679
6808
  response.hasOwnProperty("metadata"));
6680
6809
  }
6681
6810
 
6682
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6811
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6683
6812
  /*
6684
6813
  * Copyright (c) Microsoft Corporation. All rights reserved.
6685
6814
  * Licensed under the MIT License.
@@ -6689,7 +6818,7 @@ function isCloudInstanceDiscoveryErrorResponse(response) {
6689
6818
  response.hasOwnProperty("error_description"));
6690
6819
  }
6691
6820
 
6692
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6821
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6693
6822
 
6694
6823
  /*
6695
6824
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6821,7 +6950,7 @@ var RegionDiscovery = /** @class */ (function () {
6821
6950
  return RegionDiscovery;
6822
6951
  }());
6823
6952
 
6824
- /*! @azure/msal-common v11.0.0 2023-03-07 */
6953
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
6825
6954
 
6826
6955
  /*
6827
6956
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7556,7 +7685,7 @@ var Authority = /** @class */ (function () {
7556
7685
  return Authority;
7557
7686
  }());
7558
7687
 
7559
- /*! @azure/msal-common v11.0.0 2023-03-07 */
7688
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
7560
7689
 
7561
7690
  /*
7562
7691
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7619,7 +7748,7 @@ var AuthorityFactory = /** @class */ (function () {
7619
7748
  return AuthorityFactory;
7620
7749
  }());
7621
7750
 
7622
- /*! @azure/msal-common v11.0.0 2023-03-07 */
7751
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
7623
7752
 
7624
7753
  /*
7625
7754
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7650,7 +7779,7 @@ var ServerTelemetryEntity = /** @class */ (function () {
7650
7779
  return ServerTelemetryEntity;
7651
7780
  }());
7652
7781
 
7653
- /*! @azure/msal-common v11.0.0 2023-03-07 */
7782
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
7654
7783
 
7655
7784
  /*
7656
7785
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7678,7 +7807,7 @@ var ThrottlingEntity = /** @class */ (function () {
7678
7807
  return ThrottlingEntity;
7679
7808
  }());
7680
7809
 
7681
- /*! @azure/msal-common v11.0.0 2023-03-07 */
7810
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
7682
7811
 
7683
7812
  /*
7684
7813
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7695,7 +7824,7 @@ var StubbedNetworkModule = {
7695
7824
  }
7696
7825
  };
7697
7826
 
7698
- /*! @azure/msal-common v11.0.0 2023-03-07 */
7827
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
7699
7828
 
7700
7829
  /*
7701
7830
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7740,7 +7869,7 @@ var JoseHeaderError = /** @class */ (function (_super) {
7740
7869
  return JoseHeaderError;
7741
7870
  }(AuthError));
7742
7871
 
7743
- /*! @azure/msal-common v11.0.0 2023-03-07 */
7872
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
7744
7873
 
7745
7874
  /*
7746
7875
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7780,7 +7909,7 @@ var JoseHeader = /** @class */ (function () {
7780
7909
  return JoseHeader;
7781
7910
  }());
7782
7911
 
7783
- /*! @azure/msal-common v11.0.0 2023-03-07 */
7912
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
7784
7913
 
7785
7914
  /*
7786
7915
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7839,7 +7968,7 @@ var AuthenticationHeaderParser = /** @class */ (function () {
7839
7968
  return AuthenticationHeaderParser;
7840
7969
  }());
7841
7970
 
7842
- /*! @azure/msal-common v11.0.0 2023-03-07 */
7971
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
7843
7972
 
7844
7973
  /*
7845
7974
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8001,7 +8130,7 @@ var ServerTelemetryManager = /** @class */ (function () {
8001
8130
  return ServerTelemetryManager;
8002
8131
  }());
8003
8132
 
8004
- /*! @azure/msal-common v11.0.0 2023-03-07 */
8133
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
8005
8134
 
8006
8135
  /*
8007
8136
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -8404,7 +8533,7 @@ var PerformanceClient = /** @class */ (function () {
8404
8533
  return PerformanceClient;
8405
8534
  }());
8406
8535
 
8407
- /*! @azure/msal-common v11.0.0 2023-03-07 */
8536
+ /*! @azure/msal-common v12.0.0 2023-04-03 */
8408
8537
 
8409
8538
  /*
8410
8539
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -9020,6 +9149,11 @@ var TemporaryCacheKeys;
9020
9149
  TemporaryCacheKeys["NATIVE_REQUEST"] = "request.native";
9021
9150
  TemporaryCacheKeys["REDIRECT_CONTEXT"] = "request.redirect.context";
9022
9151
  })(TemporaryCacheKeys || (TemporaryCacheKeys = {}));
9152
+ var StaticCacheKeys;
9153
+ (function (StaticCacheKeys) {
9154
+ StaticCacheKeys["ACCOUNT_KEYS"] = "msal.account.keys";
9155
+ StaticCacheKeys["TOKEN_KEYS"] = "msal.token.keys";
9156
+ })(StaticCacheKeys || (StaticCacheKeys = {}));
9023
9157
  /**
9024
9158
  * Cache keys stored in-memory
9025
9159
  */
@@ -9365,16 +9499,19 @@ var BrowserProtocolUtils = /** @class */ (function () {
9365
9499
  var BrowserCacheManager = /** @class */ (function (_super) {
9366
9500
  __extends$1(BrowserCacheManager, _super);
9367
9501
  function BrowserCacheManager(clientId, cacheConfig, cryptoImpl, logger) {
9368
- var _this = _super.call(this, clientId, cryptoImpl) || this;
9502
+ var _this = _super.call(this, clientId, cryptoImpl, logger) || this;
9369
9503
  // Cookie life calculation (hours * minutes * seconds * ms)
9370
9504
  _this.COOKIE_LIFE_MULTIPLIER = 24 * 60 * 60 * 1000;
9371
9505
  _this.cacheConfig = cacheConfig;
9372
9506
  _this.logger = logger;
9373
9507
  _this.internalStorage = new MemoryStorage();
9374
9508
  _this.browserStorage = _this.setupBrowserStorage(_this.cacheConfig.cacheLocation);
9375
- _this.temporaryCacheStorage = _this.setupTemporaryCacheStorage(_this.cacheConfig.cacheLocation);
9376
- // Migrate any cache entries from older versions of MSAL.
9377
- _this.migrateCacheEntries();
9509
+ _this.temporaryCacheStorage = _this.setupTemporaryCacheStorage(_this.cacheConfig.temporaryCacheLocation, _this.cacheConfig.cacheLocation);
9510
+ // Migrate cache entries from older versions of MSAL.
9511
+ if (cacheConfig.cacheMigrationEnabled) {
9512
+ _this.migrateCacheEntries();
9513
+ _this.createKeyMaps();
9514
+ }
9378
9515
  return _this;
9379
9516
  }
9380
9517
  /**
@@ -9386,7 +9523,6 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9386
9523
  case exports.BrowserCacheLocation.LocalStorage:
9387
9524
  case exports.BrowserCacheLocation.SessionStorage:
9388
9525
  try {
9389
- // Temporary cache items will always be stored in session storage to mitigate problems caused by multiple tabs
9390
9526
  return new BrowserStorage(cacheLocation);
9391
9527
  }
9392
9528
  catch (e) {
@@ -9399,16 +9535,20 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9399
9535
  return new MemoryStorage();
9400
9536
  };
9401
9537
  /**
9402
- *
9538
+ * Returns a window storage class implementing the IWindowStorage interface that corresponds to the configured temporaryCacheLocation.
9539
+ * @param temporaryCacheLocation
9403
9540
  * @param cacheLocation
9404
9541
  */
9405
- BrowserCacheManager.prototype.setupTemporaryCacheStorage = function (cacheLocation) {
9542
+ BrowserCacheManager.prototype.setupTemporaryCacheStorage = function (temporaryCacheLocation, cacheLocation) {
9406
9543
  switch (cacheLocation) {
9407
9544
  case exports.BrowserCacheLocation.LocalStorage:
9408
9545
  case exports.BrowserCacheLocation.SessionStorage:
9409
9546
  try {
9410
- // Temporary cache items will always be stored in session storage to mitigate problems caused by multiple tabs
9411
- return new BrowserStorage(exports.BrowserCacheLocation.SessionStorage);
9547
+ /*
9548
+ * When users do not explicitly choose their own temporaryCacheLocation,
9549
+ * temporary cache items will always be stored in session storage to mitigate problems caused by multiple tabs
9550
+ */
9551
+ return new BrowserStorage(temporaryCacheLocation || exports.BrowserCacheLocation.SessionStorage);
9412
9552
  }
9413
9553
  catch (e) {
9414
9554
  this.logger.verbose(e);
@@ -9448,6 +9588,91 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9448
9588
  this.setTemporaryCache(newKey, value, true);
9449
9589
  }
9450
9590
  };
9591
+ /**
9592
+ * Searches all cache entries for MSAL accounts and creates the account key map
9593
+ * This is used to migrate users from older versions of MSAL which did not create the map.
9594
+ * @returns
9595
+ */
9596
+ BrowserCacheManager.prototype.createKeyMaps = function () {
9597
+ var _this = this;
9598
+ this.logger.trace("BrowserCacheManager - createKeyMaps called.");
9599
+ var accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
9600
+ var tokenKeys = this.getItem(StaticCacheKeys.TOKEN_KEYS + "." + this.clientId);
9601
+ if (accountKeys && tokenKeys) {
9602
+ this.logger.verbose("BrowserCacheManager:createKeyMaps - account and token key maps already exist, skipping migration.");
9603
+ // Key maps already exist, no need to iterate through cache
9604
+ return;
9605
+ }
9606
+ var allKeys = this.browserStorage.getKeys();
9607
+ allKeys.forEach(function (key) {
9608
+ if (_this.isCredentialKey(key)) {
9609
+ // Get item, parse, validate and write key to map
9610
+ var value = _this.getItem(key);
9611
+ if (value) {
9612
+ var credObj = _this.validateAndParseJson(value);
9613
+ if (credObj && credObj.hasOwnProperty("credentialType")) {
9614
+ switch (credObj["credentialType"]) {
9615
+ case CredentialType.ID_TOKEN:
9616
+ if (IdTokenEntity.isIdTokenEntity(credObj)) {
9617
+ _this.logger.trace("BrowserCacheManager:createKeyMaps - idToken found, saving key to token key map");
9618
+ _this.logger.tracePii("BrowserCacheManager:createKeyMaps - idToken with key: " + key + " found, saving key to token key map");
9619
+ var idTokenEntity = CacheManager.toObject(new IdTokenEntity(), credObj);
9620
+ var newKey = _this.updateCredentialCacheKey(key, idTokenEntity);
9621
+ _this.addTokenKey(newKey, CredentialType.ID_TOKEN);
9622
+ return;
9623
+ }
9624
+ else {
9625
+ _this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching idToken schema with value containing idToken credentialType field but value failed IdTokenEntity validation, skipping.");
9626
+ _this.logger.tracePii("BrowserCacheManager:createKeyMaps - failed idToken validation on key: " + key);
9627
+ }
9628
+ break;
9629
+ case CredentialType.ACCESS_TOKEN:
9630
+ case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
9631
+ if (AccessTokenEntity.isAccessTokenEntity(credObj)) {
9632
+ _this.logger.trace("BrowserCacheManager:createKeyMaps - accessToken found, saving key to token key map");
9633
+ _this.logger.tracePii("BrowserCacheManager:createKeyMaps - accessToken with key: " + key + " found, saving key to token key map");
9634
+ var accessTokenEntity = CacheManager.toObject(new AccessTokenEntity(), credObj);
9635
+ var newKey = _this.updateCredentialCacheKey(key, accessTokenEntity);
9636
+ _this.addTokenKey(newKey, CredentialType.ACCESS_TOKEN);
9637
+ return;
9638
+ }
9639
+ else {
9640
+ _this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching accessToken schema with value containing accessToken credentialType field but value failed AccessTokenEntity validation, skipping.");
9641
+ _this.logger.tracePii("BrowserCacheManager:createKeyMaps - failed accessToken validation on key: " + key);
9642
+ }
9643
+ break;
9644
+ case CredentialType.REFRESH_TOKEN:
9645
+ if (RefreshTokenEntity.isRefreshTokenEntity(credObj)) {
9646
+ _this.logger.trace("BrowserCacheManager:createKeyMaps - refreshToken found, saving key to token key map");
9647
+ _this.logger.tracePii("BrowserCacheManager:createKeyMaps - refreshToken with key: " + key + " found, saving key to token key map");
9648
+ var refreshTokenEntity = CacheManager.toObject(new RefreshTokenEntity(), credObj);
9649
+ var newKey = _this.updateCredentialCacheKey(key, refreshTokenEntity);
9650
+ _this.addTokenKey(newKey, CredentialType.REFRESH_TOKEN);
9651
+ return;
9652
+ }
9653
+ else {
9654
+ _this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching refreshToken schema with value containing refreshToken credentialType field but value failed RefreshTokenEntity validation, skipping.");
9655
+ _this.logger.tracePii("BrowserCacheManager:createKeyMaps - failed refreshToken validation on key: " + key);
9656
+ }
9657
+ break;
9658
+ // If credentialType isn't one of our predefined ones, it may not be an MSAL cache value. Ignore.
9659
+ }
9660
+ }
9661
+ }
9662
+ }
9663
+ if (_this.isAccountKey(key)) {
9664
+ var value = _this.getItem(key);
9665
+ if (value) {
9666
+ var accountObj = _this.validateAndParseJson(value);
9667
+ if (accountObj && AccountEntity.isAccountEntity(accountObj)) {
9668
+ _this.logger.trace("BrowserCacheManager:createKeyMaps - account found, saving key to account key map");
9669
+ _this.logger.tracePii("BrowserCacheManager:createKeyMaps - account with key: " + key + " found, saving key to account key map");
9670
+ _this.addAccountKeyToMap(key);
9671
+ }
9672
+ }
9673
+ }
9674
+ });
9675
+ };
9451
9676
  /**
9452
9677
  * Parses passed value as JSON object, JSON.parse() will throw an error.
9453
9678
  * @param input
@@ -9487,12 +9712,15 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9487
9712
  * @param accountKey
9488
9713
  */
9489
9714
  BrowserCacheManager.prototype.getAccount = function (accountKey) {
9715
+ this.logger.trace("BrowserCacheManager.getAccount called");
9490
9716
  var account = this.getItem(accountKey);
9491
9717
  if (!account) {
9718
+ this.removeAccountKeyFromMap(accountKey);
9492
9719
  return null;
9493
9720
  }
9494
9721
  var parsedAccount = this.validateAndParseJson(account);
9495
9722
  if (!parsedAccount || !AccountEntity.isAccountEntity(parsedAccount)) {
9723
+ this.removeAccountKeyFromMap(accountKey);
9496
9724
  return null;
9497
9725
  }
9498
9726
  return CacheManager.toObject(new AccountEntity(), parsedAccount);
@@ -9506,6 +9734,207 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9506
9734
  this.logger.trace("BrowserCacheManager.setAccount called");
9507
9735
  var key = account.generateAccountKey();
9508
9736
  this.setItem(key, JSON.stringify(account));
9737
+ this.addAccountKeyToMap(key);
9738
+ };
9739
+ /**
9740
+ * Returns the array of account keys currently cached
9741
+ * @returns
9742
+ */
9743
+ BrowserCacheManager.prototype.getAccountKeys = function () {
9744
+ this.logger.trace("BrowserCacheManager.getAccountKeys called");
9745
+ var accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
9746
+ if (accountKeys) {
9747
+ return JSON.parse(accountKeys);
9748
+ }
9749
+ this.logger.verbose("BrowserCacheManager.getAccountKeys - No account keys found");
9750
+ return [];
9751
+ };
9752
+ /**
9753
+ * Add a new account to the key map
9754
+ * @param key
9755
+ */
9756
+ BrowserCacheManager.prototype.addAccountKeyToMap = function (key) {
9757
+ this.logger.trace("BrowserCacheManager.addAccountKeyToMap called");
9758
+ this.logger.tracePii("BrowserCacheManager.addAccountKeyToMap called with key: " + key);
9759
+ var accountKeys = this.getAccountKeys();
9760
+ if (accountKeys.indexOf(key) === -1) {
9761
+ // Only add key if it does not already exist in the map
9762
+ accountKeys.push(key);
9763
+ this.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
9764
+ this.logger.verbose("BrowserCacheManager.addAccountKeyToMap account key added");
9765
+ }
9766
+ else {
9767
+ this.logger.verbose("BrowserCacheManager.addAccountKeyToMap account key already exists in map");
9768
+ }
9769
+ };
9770
+ /**
9771
+ * Remove an account from the key map
9772
+ * @param key
9773
+ */
9774
+ BrowserCacheManager.prototype.removeAccountKeyFromMap = function (key) {
9775
+ this.logger.trace("BrowserCacheManager.removeAccountKeyFromMap called");
9776
+ this.logger.tracePii("BrowserCacheManager.removeAccountKeyFromMap called with key: " + key);
9777
+ var accountKeys = this.getAccountKeys();
9778
+ var removalIndex = accountKeys.indexOf(key);
9779
+ if (removalIndex > -1) {
9780
+ accountKeys.splice(removalIndex, 1);
9781
+ this.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
9782
+ this.logger.trace("BrowserCacheManager.removeAccountKeyFromMap account key removed");
9783
+ }
9784
+ else {
9785
+ this.logger.trace("BrowserCacheManager.removeAccountKeyFromMap key not found in existing map");
9786
+ }
9787
+ };
9788
+ /**
9789
+ * Extends inherited removeAccount function to include removal of the account key from the map
9790
+ * @param key
9791
+ */
9792
+ BrowserCacheManager.prototype.removeAccount = function (key) {
9793
+ return __awaiter$1(this, void 0, void 0, function () {
9794
+ return __generator$1(this, function (_a) {
9795
+ _super.prototype.removeAccount.call(this, key);
9796
+ this.removeAccountKeyFromMap(key);
9797
+ return [2 /*return*/];
9798
+ });
9799
+ });
9800
+ };
9801
+ /**
9802
+ * Removes given idToken from the cache and from the key map
9803
+ * @param key
9804
+ */
9805
+ BrowserCacheManager.prototype.removeIdToken = function (key) {
9806
+ _super.prototype.removeIdToken.call(this, key);
9807
+ this.removeTokenKey(key, CredentialType.ID_TOKEN);
9808
+ };
9809
+ /**
9810
+ * Removes given accessToken from the cache and from the key map
9811
+ * @param key
9812
+ */
9813
+ BrowserCacheManager.prototype.removeAccessToken = function (key) {
9814
+ return __awaiter$1(this, void 0, void 0, function () {
9815
+ return __generator$1(this, function (_a) {
9816
+ _super.prototype.removeAccessToken.call(this, key);
9817
+ this.removeTokenKey(key, CredentialType.ACCESS_TOKEN);
9818
+ return [2 /*return*/];
9819
+ });
9820
+ });
9821
+ };
9822
+ /**
9823
+ * Removes given refreshToken from the cache and from the key map
9824
+ * @param key
9825
+ */
9826
+ BrowserCacheManager.prototype.removeRefreshToken = function (key) {
9827
+ _super.prototype.removeRefreshToken.call(this, key);
9828
+ this.removeTokenKey(key, CredentialType.REFRESH_TOKEN);
9829
+ };
9830
+ /**
9831
+ * Gets the keys for the cached tokens associated with this clientId
9832
+ * @returns
9833
+ */
9834
+ BrowserCacheManager.prototype.getTokenKeys = function () {
9835
+ this.logger.trace("BrowserCacheManager.getTokenKeys called");
9836
+ var item = this.getItem(StaticCacheKeys.TOKEN_KEYS + "." + this.clientId);
9837
+ if (item) {
9838
+ var tokenKeys = this.validateAndParseJson(item);
9839
+ if (tokenKeys &&
9840
+ tokenKeys.hasOwnProperty("idToken") &&
9841
+ tokenKeys.hasOwnProperty("accessToken") &&
9842
+ tokenKeys.hasOwnProperty("refreshToken")) {
9843
+ return tokenKeys;
9844
+ }
9845
+ else {
9846
+ this.logger.error("BrowserCacheManager.getTokenKeys - Token keys found but in an unknown format. Returning empty key map.");
9847
+ }
9848
+ }
9849
+ else {
9850
+ this.logger.verbose("BrowserCacheManager.getTokenKeys - No token keys found");
9851
+ }
9852
+ return {
9853
+ idToken: [],
9854
+ accessToken: [],
9855
+ refreshToken: []
9856
+ };
9857
+ };
9858
+ /**
9859
+ * Adds the given key to the token key map
9860
+ * @param key
9861
+ * @param type
9862
+ */
9863
+ BrowserCacheManager.prototype.addTokenKey = function (key, type) {
9864
+ this.logger.trace("BrowserCacheManager addTokenKey called");
9865
+ var tokenKeys = this.getTokenKeys();
9866
+ switch (type) {
9867
+ case CredentialType.ID_TOKEN:
9868
+ if (tokenKeys.idToken.indexOf(key) === -1) {
9869
+ this.logger.info("BrowserCacheManager: addTokenKey - idToken added to map");
9870
+ tokenKeys.idToken.push(key);
9871
+ }
9872
+ break;
9873
+ case CredentialType.ACCESS_TOKEN:
9874
+ if (tokenKeys.accessToken.indexOf(key) === -1) {
9875
+ this.logger.info("BrowserCacheManager: addTokenKey - accessToken added to map");
9876
+ tokenKeys.accessToken.push(key);
9877
+ }
9878
+ break;
9879
+ case CredentialType.REFRESH_TOKEN:
9880
+ if (tokenKeys.refreshToken.indexOf(key) === -1) {
9881
+ this.logger.info("BrowserCacheManager: addTokenKey - refreshToken added to map");
9882
+ tokenKeys.refreshToken.push(key);
9883
+ }
9884
+ break;
9885
+ default:
9886
+ this.logger.error("BrowserCacheManager:addTokenKey - CredentialType provided invalid. CredentialType: " + type);
9887
+ ClientAuthError.createUnexpectedCredentialTypeError();
9888
+ }
9889
+ this.setItem(StaticCacheKeys.TOKEN_KEYS + "." + this.clientId, JSON.stringify(tokenKeys));
9890
+ };
9891
+ /**
9892
+ * Removes the given key from the token key map
9893
+ * @param key
9894
+ * @param type
9895
+ */
9896
+ BrowserCacheManager.prototype.removeTokenKey = function (key, type) {
9897
+ this.logger.trace("BrowserCacheManager removeTokenKey called");
9898
+ var tokenKeys = this.getTokenKeys();
9899
+ switch (type) {
9900
+ case CredentialType.ID_TOKEN:
9901
+ this.logger.infoPii("BrowserCacheManager: removeTokenKey - attempting to remove idToken with key: " + key + " from map");
9902
+ var idRemoval = tokenKeys.idToken.indexOf(key);
9903
+ if (idRemoval > -1) {
9904
+ this.logger.info("BrowserCacheManager: removeTokenKey - idToken removed from map");
9905
+ tokenKeys.idToken.splice(idRemoval, 1);
9906
+ }
9907
+ else {
9908
+ this.logger.info("BrowserCacheManager: removeTokenKey - idToken does not exist in map. Either it was previously removed or it was never added.");
9909
+ }
9910
+ break;
9911
+ case CredentialType.ACCESS_TOKEN:
9912
+ this.logger.infoPii("BrowserCacheManager: removeTokenKey - attempting to remove accessToken with key: " + key + " from map");
9913
+ var accessRemoval = tokenKeys.accessToken.indexOf(key);
9914
+ if (accessRemoval > -1) {
9915
+ this.logger.info("BrowserCacheManager: removeTokenKey - accessToken removed from map");
9916
+ tokenKeys.accessToken.splice(accessRemoval, 1);
9917
+ }
9918
+ else {
9919
+ this.logger.info("BrowserCacheManager: removeTokenKey - accessToken does not exist in map. Either it was previously removed or it was never added.");
9920
+ }
9921
+ break;
9922
+ case CredentialType.REFRESH_TOKEN:
9923
+ this.logger.infoPii("BrowserCacheManager: removeTokenKey - attempting to remove refreshToken with key: " + key + " from map");
9924
+ var refreshRemoval = tokenKeys.refreshToken.indexOf(key);
9925
+ if (refreshRemoval > -1) {
9926
+ this.logger.info("BrowserCacheManager: removeTokenKey - refreshToken removed from map");
9927
+ tokenKeys.refreshToken.splice(refreshRemoval, 1);
9928
+ }
9929
+ else {
9930
+ this.logger.info("BrowserCacheManager: removeTokenKey - refreshToken does not exist in map. Either it was previously removed or it was never added.");
9931
+ }
9932
+ break;
9933
+ default:
9934
+ this.logger.error("BrowserCacheManager:removeTokenKey - CredentialType provided invalid. CredentialType: " + type);
9935
+ ClientAuthError.createUnexpectedCredentialTypeError();
9936
+ }
9937
+ this.setItem(StaticCacheKeys.TOKEN_KEYS + "." + this.clientId, JSON.stringify(tokenKeys));
9509
9938
  };
9510
9939
  /**
9511
9940
  * generates idToken entity from a string
@@ -9515,11 +9944,13 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9515
9944
  var value = this.getItem(idTokenKey);
9516
9945
  if (!value) {
9517
9946
  this.logger.trace("BrowserCacheManager.getIdTokenCredential: called, no cache hit");
9947
+ this.removeTokenKey(idTokenKey, CredentialType.ID_TOKEN);
9518
9948
  return null;
9519
9949
  }
9520
9950
  var parsedIdToken = this.validateAndParseJson(value);
9521
9951
  if (!parsedIdToken || !IdTokenEntity.isIdTokenEntity(parsedIdToken)) {
9522
9952
  this.logger.trace("BrowserCacheManager.getIdTokenCredential: called, no cache hit");
9953
+ this.removeTokenKey(idTokenKey, CredentialType.ID_TOKEN);
9523
9954
  return null;
9524
9955
  }
9525
9956
  this.logger.trace("BrowserCacheManager.getIdTokenCredential: cache hit");
@@ -9533,6 +9964,7 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9533
9964
  this.logger.trace("BrowserCacheManager.setIdTokenCredential called");
9534
9965
  var idTokenKey = idToken.generateCredentialKey();
9535
9966
  this.setItem(idTokenKey, JSON.stringify(idToken));
9967
+ this.addTokenKey(idTokenKey, CredentialType.ID_TOKEN);
9536
9968
  };
9537
9969
  /**
9538
9970
  * generates accessToken entity from a string
@@ -9542,11 +9974,13 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9542
9974
  var value = this.getItem(accessTokenKey);
9543
9975
  if (!value) {
9544
9976
  this.logger.trace("BrowserCacheManager.getAccessTokenCredential: called, no cache hit");
9977
+ this.removeTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
9545
9978
  return null;
9546
9979
  }
9547
9980
  var parsedAccessToken = this.validateAndParseJson(value);
9548
9981
  if (!parsedAccessToken || !AccessTokenEntity.isAccessTokenEntity(parsedAccessToken)) {
9549
9982
  this.logger.trace("BrowserCacheManager.getAccessTokenCredential: called, no cache hit");
9983
+ this.removeTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
9550
9984
  return null;
9551
9985
  }
9552
9986
  this.logger.trace("BrowserCacheManager.getAccessTokenCredential: cache hit");
@@ -9560,6 +9994,7 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9560
9994
  this.logger.trace("BrowserCacheManager.setAccessTokenCredential called");
9561
9995
  var accessTokenKey = accessToken.generateCredentialKey();
9562
9996
  this.setItem(accessTokenKey, JSON.stringify(accessToken));
9997
+ this.addTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
9563
9998
  };
9564
9999
  /**
9565
10000
  * generates refreshToken entity from a string
@@ -9569,11 +10004,13 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9569
10004
  var value = this.getItem(refreshTokenKey);
9570
10005
  if (!value) {
9571
10006
  this.logger.trace("BrowserCacheManager.getRefreshTokenCredential: called, no cache hit");
10007
+ this.removeTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
9572
10008
  return null;
9573
10009
  }
9574
10010
  var parsedRefreshToken = this.validateAndParseJson(value);
9575
10011
  if (!parsedRefreshToken || !RefreshTokenEntity.isRefreshTokenEntity(parsedRefreshToken)) {
9576
10012
  this.logger.trace("BrowserCacheManager.getRefreshTokenCredential: called, no cache hit");
10013
+ this.removeTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
9577
10014
  return null;
9578
10015
  }
9579
10016
  this.logger.trace("BrowserCacheManager.getRefreshTokenCredential: cache hit");
@@ -9587,6 +10024,7 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9587
10024
  this.logger.trace("BrowserCacheManager.setRefreshTokenCredential called");
9588
10025
  var refreshTokenKey = refreshToken.generateCredentialKey();
9589
10026
  this.setItem(refreshTokenKey, JSON.stringify(refreshToken));
10027
+ this.addTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
9590
10028
  };
9591
10029
  /**
9592
10030
  * fetch appMetadata entity from the platform cache
@@ -9884,7 +10322,6 @@ var BrowserCacheManager = /** @class */ (function (_super) {
9884
10322
  this.logger.trace("BrowserCacheManager.removeItem: storeAuthStateInCookie is true, clearing item cookie");
9885
10323
  this.clearItemCookie(key);
9886
10324
  }
9887
- return true;
9888
10325
  };
9889
10326
  /**
9890
10327
  * Checks whether key is in cache.
@@ -10311,15 +10748,17 @@ var BrowserCacheManager = /** @class */ (function (_super) {
10311
10748
  var DEFAULT_BROWSER_CACHE_MANAGER = function (clientId, logger) {
10312
10749
  var cacheOptions = {
10313
10750
  cacheLocation: exports.BrowserCacheLocation.MemoryStorage,
10751
+ temporaryCacheLocation: exports.BrowserCacheLocation.MemoryStorage,
10314
10752
  storeAuthStateInCookie: false,
10315
- secureCookies: false
10753
+ secureCookies: false,
10754
+ cacheMigrationEnabled: false
10316
10755
  };
10317
10756
  return new BrowserCacheManager(clientId, cacheOptions, DEFAULT_CRYPTO_IMPLEMENTATION, logger);
10318
10757
  };
10319
10758
 
10320
10759
  /* eslint-disable header/header */
10321
10760
  var name = "@azure/msal-browser";
10322
- var version = "2.34.0";
10761
+ var version = "2.36.0";
10323
10762
 
10324
10763
  /*
10325
10764
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -11790,15 +12229,18 @@ var NativeInteractionClient = /** @class */ (function (_super) {
11790
12229
  */
11791
12230
  NativeInteractionClient.prototype.acquireTokensFromCache = function (nativeAccountId, request) {
11792
12231
  return __awaiter$1(this, void 0, void 0, function () {
11793
- var accountEntity, account, silentRequest, result, e_2;
12232
+ var account, silentRequest, result, e_2;
11794
12233
  return __generator$1(this, function (_a) {
11795
12234
  switch (_a.label) {
11796
12235
  case 0:
11797
- accountEntity = this.browserStorage.readAccountFromCacheWithNativeAccountId(nativeAccountId);
11798
- if (!accountEntity) {
12236
+ if (!nativeAccountId) {
12237
+ this.logger.warning("NativeInteractionClient:acquireTokensFromCache - No nativeAccountId provided");
12238
+ throw ClientAuthError.createNoAccountFoundError();
12239
+ }
12240
+ account = this.browserStorage.getAccountInfoFilteredBy({ nativeAccountId: nativeAccountId });
12241
+ if (!account) {
11799
12242
  throw ClientAuthError.createNoAccountFoundError();
11800
12243
  }
11801
- account = accountEntity.getAccountInfo();
11802
12244
  _a.label = 1;
11803
12245
  case 1:
11804
12246
  _a.trys.push([1, 3, , 4]);
@@ -11938,10 +12380,6 @@ var NativeInteractionClient = /** @class */ (function (_super) {
11938
12380
  // User switch in native broker prompt is not supported. All users must first sign in through web flow to ensure server state is in sync
11939
12381
  throw NativeAuthError.createUserSwitchError();
11940
12382
  }
11941
- if (response.account.id !== request.accountId) {
11942
- // User switch in native broker prompt is not supported. All users must first sign in through web flow to ensure server state is in sync
11943
- throw NativeAuthError.createUserSwitchError();
11944
- }
11945
12383
  return [4 /*yield*/, this.getDiscoveredAuthority(request.authority)];
11946
12384
  case 1:
11947
12385
  authority = _a.sent();
@@ -13444,8 +13882,11 @@ function buildConfiguration(_a, isBrowserEnvironment) {
13444
13882
  // Default cache options for browser
13445
13883
  var DEFAULT_CACHE_OPTIONS = {
13446
13884
  cacheLocation: exports.BrowserCacheLocation.SessionStorage,
13885
+ temporaryCacheLocation: exports.BrowserCacheLocation.SessionStorage,
13447
13886
  storeAuthStateInCookie: false,
13448
- secureCookies: false
13887
+ secureCookies: false,
13888
+ // Default cache migration to true if cache location is localStorage since entries are preserved across tabs/windows. Migration has little to no benefit in sessionStorage and memoryStorage
13889
+ cacheMigrationEnabled: userInputCache && userInputCache.cacheLocation === exports.BrowserCacheLocation.LocalStorage ? true : false
13449
13890
  };
13450
13891
  // Default logger options for browser
13451
13892
  var DEFAULT_LOGGER_OPTIONS = {
@@ -15701,7 +16142,7 @@ var BrowserPerformanceClient = /** @class */ (function (_super) {
15701
16142
  this.logger.trace("BrowserPerformanceClient: Incomplete pre-queue " + preQueueEvent.name + " found", correlationId);
15702
16143
  this.addQueueMeasurement(preQueueEvent.name, correlationId, undefined, true);
15703
16144
  }
15704
- this.preQueueTimeByCorrelationId.set(eventName, { name: eventName, time: window.performance.now() });
16145
+ this.preQueueTimeByCorrelationId.set(correlationId, { name: eventName, time: window.performance.now() });
15705
16146
  };
15706
16147
  /**
15707
16148
  * Calculates and adds queue time measurement for given performance event.
@@ -16127,8 +16568,10 @@ var ClientApplication = /** @class */ (function () {
16127
16568
  // initialize in memory storage for native flows
16128
16569
  var nativeCacheOptions = {
16129
16570
  cacheLocation: exports.BrowserCacheLocation.MemoryStorage,
16571
+ temporaryCacheLocation: exports.BrowserCacheLocation.MemoryStorage,
16130
16572
  storeAuthStateInCookie: false,
16131
- secureCookies: false
16573
+ secureCookies: false,
16574
+ cacheMigrationEnabled: false
16132
16575
  };
16133
16576
  this.nativeInternalStorage = new BrowserCacheManager(this.config.auth.clientId, nativeCacheOptions, this.browserCrypto, this.logger);
16134
16577
  // Initialize the token cache
@@ -16761,15 +17204,20 @@ var ClientApplication = /** @class */ (function () {
16761
17204
  * (the account object is created at the time of successful login)
16762
17205
  * or null when no matching account is found.
16763
17206
  * This API is provided for convenience but getAccountById should be used for best reliability
16764
- * @param userName
17207
+ * @param username
16765
17208
  * @returns The account object stored in MSAL
16766
17209
  */
16767
- ClientApplication.prototype.getAccountByUsername = function (userName) {
16768
- var allAccounts = this.getAllAccounts();
16769
- if (!StringUtils.isEmpty(userName) && allAccounts && allAccounts.length) {
16770
- this.logger.verbose("Account matching username found, returning");
16771
- this.logger.verbosePii("Returning signed-in accounts matching username: " + userName);
16772
- return allAccounts.filter(function (accountObj) { return accountObj.username.toLowerCase() === userName.toLowerCase(); })[0] || null;
17210
+ ClientApplication.prototype.getAccountByUsername = function (username) {
17211
+ this.logger.trace("getAccountByUsername called");
17212
+ if (!username) {
17213
+ this.logger.warning("getAccountByUsername: No username provided");
17214
+ return null;
17215
+ }
17216
+ var account = this.browserStorage.getAccountInfoFilteredBy({ username: username });
17217
+ if (account) {
17218
+ this.logger.verbose("getAccountByUsername: Account matching username found, returning");
17219
+ this.logger.verbosePii("getAccountByUsername: Returning signed-in accounts matching username: " + username);
17220
+ return account;
16773
17221
  }
16774
17222
  else {
16775
17223
  this.logger.verbose("getAccountByUsername: No matching account found, returning null");
@@ -16784,11 +17232,16 @@ var ClientApplication = /** @class */ (function () {
16784
17232
  * @returns The account object stored in MSAL
16785
17233
  */
16786
17234
  ClientApplication.prototype.getAccountByHomeId = function (homeAccountId) {
16787
- var allAccounts = this.getAllAccounts();
16788
- if (!StringUtils.isEmpty(homeAccountId) && allAccounts && allAccounts.length) {
16789
- this.logger.verbose("Account matching homeAccountId found, returning");
16790
- this.logger.verbosePii("Returning signed-in accounts matching homeAccountId: " + homeAccountId);
16791
- return allAccounts.filter(function (accountObj) { return accountObj.homeAccountId === homeAccountId; })[0] || null;
17235
+ this.logger.trace("getAccountByHomeId called");
17236
+ if (!homeAccountId) {
17237
+ this.logger.warning("getAccountByHomeId: No homeAccountId provided");
17238
+ return null;
17239
+ }
17240
+ var account = this.browserStorage.getAccountInfoFilteredBy({ homeAccountId: homeAccountId });
17241
+ if (account) {
17242
+ this.logger.verbose("getAccountByHomeId: Account matching homeAccountId found, returning");
17243
+ this.logger.verbosePii("getAccountByHomeId: Returning signed-in accounts matching homeAccountId: " + homeAccountId);
17244
+ return account;
16792
17245
  }
16793
17246
  else {
16794
17247
  this.logger.verbose("getAccountByHomeId: No matching account found, returning null");
@@ -16803,11 +17256,16 @@ var ClientApplication = /** @class */ (function () {
16803
17256
  * @returns The account object stored in MSAL
16804
17257
  */
16805
17258
  ClientApplication.prototype.getAccountByLocalId = function (localAccountId) {
16806
- var allAccounts = this.getAllAccounts();
16807
- if (!StringUtils.isEmpty(localAccountId) && allAccounts && allAccounts.length) {
16808
- this.logger.verbose("Account matching localAccountId found, returning");
16809
- this.logger.verbosePii("Returning signed-in accounts matching localAccountId: " + localAccountId);
16810
- return allAccounts.filter(function (accountObj) { return accountObj.localAccountId === localAccountId; })[0] || null;
17259
+ this.logger.trace("getAccountByLocalId called");
17260
+ if (!localAccountId) {
17261
+ this.logger.warning("getAccountByLocalId: No localAccountId provided");
17262
+ return null;
17263
+ }
17264
+ var account = this.browserStorage.getAccountInfoFilteredBy({ localAccountId: localAccountId });
17265
+ if (account) {
17266
+ this.logger.verbose("getAccountByLocalId: Account matching localAccountId found, returning");
17267
+ this.logger.verbosePii("getAccountByLocalId: Returning signed-in accounts matching localAccountId: " + localAccountId);
17268
+ return account;
16811
17269
  }
16812
17270
  else {
16813
17271
  this.logger.verbose("getAccountByLocalId: No matching account found, returning null");