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