@azure/msal-browser 3.28.0 → 4.0.0-alpha.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 (174) hide show
  1. package/dist/app/IPublicClientApplication.mjs +1 -1
  2. package/dist/app/PublicClientApplication.mjs +1 -1
  3. package/dist/app/PublicClientNext.mjs +1 -1
  4. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
  5. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
  6. package/dist/cache/AccountManager.mjs +1 -1
  7. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  8. package/dist/cache/BrowserCacheManager.d.ts +7 -47
  9. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  10. package/dist/cache/BrowserCacheManager.mjs +36 -285
  11. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  12. package/dist/cache/CacheHelpers.d.ts +16 -0
  13. package/dist/cache/CacheHelpers.d.ts.map +1 -0
  14. package/dist/cache/CacheHelpers.mjs +46 -0
  15. package/dist/cache/CacheHelpers.mjs.map +1 -0
  16. package/dist/cache/CookieStorage.d.ts +3 -0
  17. package/dist/cache/CookieStorage.d.ts.map +1 -1
  18. package/dist/cache/CookieStorage.mjs +12 -1
  19. package/dist/cache/CookieStorage.mjs.map +1 -1
  20. package/dist/cache/DatabaseStorage.mjs +1 -1
  21. package/dist/cache/ITokenCache.d.ts +1 -1
  22. package/dist/cache/ITokenCache.d.ts.map +1 -1
  23. package/dist/cache/IWindowStorage.d.ts +12 -0
  24. package/dist/cache/IWindowStorage.d.ts.map +1 -1
  25. package/dist/cache/LocalStorage.d.ts +34 -1
  26. package/dist/cache/LocalStorage.d.ts.map +1 -1
  27. package/dist/cache/LocalStorage.mjs +169 -2
  28. package/dist/cache/LocalStorage.mjs.map +1 -1
  29. package/dist/cache/MemoryStorage.d.ts +3 -0
  30. package/dist/cache/MemoryStorage.d.ts.map +1 -1
  31. package/dist/cache/MemoryStorage.mjs +10 -1
  32. package/dist/cache/MemoryStorage.mjs.map +1 -1
  33. package/dist/cache/SessionStorage.d.ts +3 -0
  34. package/dist/cache/SessionStorage.d.ts.map +1 -1
  35. package/dist/cache/SessionStorage.mjs +10 -1
  36. package/dist/cache/SessionStorage.mjs.map +1 -1
  37. package/dist/cache/TokenCache.d.ts +1 -1
  38. package/dist/cache/TokenCache.d.ts.map +1 -1
  39. package/dist/cache/TokenCache.mjs +15 -15
  40. package/dist/cache/TokenCache.mjs.map +1 -1
  41. package/dist/config/Configuration.mjs +1 -1
  42. package/dist/controllers/ControllerFactory.mjs +1 -1
  43. package/dist/controllers/NestedAppAuthController.d.ts.map +1 -1
  44. package/dist/controllers/NestedAppAuthController.mjs +4 -4
  45. package/dist/controllers/NestedAppAuthController.mjs.map +1 -1
  46. package/dist/controllers/StandardController.d.ts.map +1 -1
  47. package/dist/controllers/StandardController.mjs +3 -2
  48. package/dist/controllers/StandardController.mjs.map +1 -1
  49. package/dist/controllers/UnknownOperatingContextController.mjs +1 -1
  50. package/dist/crypto/BrowserCrypto.d.ts +27 -0
  51. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  52. package/dist/crypto/BrowserCrypto.mjs +83 -3
  53. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  54. package/dist/crypto/CryptoOps.mjs +1 -1
  55. package/dist/crypto/PkceGenerator.mjs +1 -1
  56. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  57. package/dist/encode/Base64Decode.d.ts +5 -0
  58. package/dist/encode/Base64Decode.d.ts.map +1 -1
  59. package/dist/encode/Base64Decode.mjs +2 -2
  60. package/dist/encode/Base64Decode.mjs.map +1 -1
  61. package/dist/encode/Base64Encode.mjs +1 -1
  62. package/dist/error/BrowserAuthError.mjs +1 -1
  63. package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
  64. package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
  65. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
  66. package/dist/error/NativeAuthError.mjs +1 -1
  67. package/dist/error/NativeAuthErrorCodes.mjs +1 -1
  68. package/dist/error/NestedAppAuthError.mjs +1 -1
  69. package/dist/event/EventHandler.mjs +1 -1
  70. package/dist/event/EventMessage.mjs +1 -1
  71. package/dist/event/EventType.mjs +1 -1
  72. package/dist/index.d.ts +0 -1
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.mjs +1 -2
  75. package/dist/index.mjs.map +1 -1
  76. package/dist/interaction_client/BaseInteractionClient.mjs +1 -1
  77. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  78. package/dist/interaction_client/NativeInteractionClient.d.ts +1 -1
  79. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  80. package/dist/interaction_client/NativeInteractionClient.mjs +4 -4
  81. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  82. package/dist/interaction_client/PopupClient.mjs +1 -1
  83. package/dist/interaction_client/RedirectClient.mjs +1 -1
  84. package/dist/interaction_client/SilentAuthCodeClient.mjs +1 -1
  85. package/dist/interaction_client/SilentCacheClient.mjs +1 -1
  86. package/dist/interaction_client/SilentIframeClient.mjs +1 -1
  87. package/dist/interaction_client/SilentRefreshClient.mjs +1 -1
  88. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  89. package/dist/interaction_client/StandardInteractionClient.mjs +1 -8
  90. package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
  91. package/dist/interaction_handler/InteractionHandler.mjs +1 -1
  92. package/dist/interaction_handler/RedirectHandler.mjs +1 -1
  93. package/dist/interaction_handler/SilentHandler.mjs +1 -1
  94. package/dist/naa/BridgeError.mjs +1 -1
  95. package/dist/naa/BridgeProxy.mjs +1 -1
  96. package/dist/naa/BridgeStatusCode.mjs +1 -1
  97. package/dist/naa/mapping/NestedAppAuthAdapter.mjs +1 -1
  98. package/dist/navigation/NavigationClient.mjs +1 -1
  99. package/dist/network/FetchClient.mjs +1 -1
  100. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  101. package/dist/operatingcontext/NestedAppOperatingContext.mjs +1 -1
  102. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  103. package/dist/operatingcontext/UnknownOperatingContext.mjs +1 -1
  104. package/dist/packageMetadata.d.ts +1 -1
  105. package/dist/packageMetadata.d.ts.map +1 -1
  106. package/dist/packageMetadata.mjs +2 -2
  107. package/dist/request/RequestHelpers.mjs +1 -1
  108. package/dist/response/ResponseHandler.mjs +1 -1
  109. package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
  110. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  111. package/dist/utils/BrowserConstants.mjs +1 -1
  112. package/dist/utils/BrowserProtocolUtils.mjs +1 -1
  113. package/dist/utils/BrowserUtils.mjs +1 -1
  114. package/lib/msal-browser.cjs +532 -591
  115. package/lib/msal-browser.cjs.map +1 -1
  116. package/lib/msal-browser.js +532 -591
  117. package/lib/msal-browser.js.map +1 -1
  118. package/lib/msal-browser.min.js +65 -66
  119. package/lib/types/cache/BrowserCacheManager.d.ts +7 -47
  120. package/lib/types/cache/BrowserCacheManager.d.ts.map +1 -1
  121. package/lib/types/cache/CacheHelpers.d.ts +16 -0
  122. package/lib/types/cache/CacheHelpers.d.ts.map +1 -0
  123. package/lib/types/cache/CookieStorage.d.ts +3 -0
  124. package/lib/types/cache/CookieStorage.d.ts.map +1 -1
  125. package/lib/types/cache/ITokenCache.d.ts +1 -1
  126. package/lib/types/cache/ITokenCache.d.ts.map +1 -1
  127. package/lib/types/cache/IWindowStorage.d.ts +12 -0
  128. package/lib/types/cache/IWindowStorage.d.ts.map +1 -1
  129. package/lib/types/cache/LocalStorage.d.ts +34 -1
  130. package/lib/types/cache/LocalStorage.d.ts.map +1 -1
  131. package/lib/types/cache/MemoryStorage.d.ts +3 -0
  132. package/lib/types/cache/MemoryStorage.d.ts.map +1 -1
  133. package/lib/types/cache/SessionStorage.d.ts +3 -0
  134. package/lib/types/cache/SessionStorage.d.ts.map +1 -1
  135. package/lib/types/cache/TokenCache.d.ts +1 -1
  136. package/lib/types/cache/TokenCache.d.ts.map +1 -1
  137. package/lib/types/controllers/NestedAppAuthController.d.ts.map +1 -1
  138. package/lib/types/controllers/StandardController.d.ts.map +1 -1
  139. package/lib/types/crypto/BrowserCrypto.d.ts +27 -0
  140. package/lib/types/crypto/BrowserCrypto.d.ts.map +1 -1
  141. package/lib/types/encode/Base64Decode.d.ts +5 -0
  142. package/lib/types/encode/Base64Decode.d.ts.map +1 -1
  143. package/lib/types/index.d.ts +0 -1
  144. package/lib/types/index.d.ts.map +1 -1
  145. package/lib/types/interaction_client/NativeInteractionClient.d.ts +1 -1
  146. package/lib/types/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  147. package/lib/types/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  148. package/lib/types/packageMetadata.d.ts +1 -1
  149. package/lib/types/packageMetadata.d.ts.map +1 -1
  150. package/package.json +2 -2
  151. package/src/cache/BrowserCacheManager.ts +59 -412
  152. package/src/cache/CacheHelpers.ts +52 -0
  153. package/src/cache/CookieStorage.ts +18 -0
  154. package/src/cache/ITokenCache.ts +1 -1
  155. package/src/cache/IWindowStorage.ts +14 -0
  156. package/src/cache/LocalStorage.ts +231 -1
  157. package/src/cache/MemoryStorage.ts +12 -0
  158. package/src/cache/SessionStorage.ts +12 -0
  159. package/src/cache/TokenCache.ts +19 -19
  160. package/src/controllers/NestedAppAuthController.ts +3 -3
  161. package/src/controllers/StandardController.ts +3 -1
  162. package/src/crypto/BrowserCrypto.ts +120 -1
  163. package/src/encode/Base64Decode.ts +1 -1
  164. package/src/index.ts +0 -1
  165. package/src/interaction_client/NativeInteractionClient.ts +3 -3
  166. package/src/interaction_client/StandardInteractionClient.ts +0 -8
  167. package/src/packageMetadata.ts +1 -1
  168. package/dist/cache/BrowserStorage.d.ts +0 -14
  169. package/dist/cache/BrowserStorage.d.ts.map +0 -1
  170. package/dist/cache/BrowserStorage.mjs +0 -46
  171. package/dist/cache/BrowserStorage.mjs.map +0 -1
  172. package/lib/types/cache/BrowserStorage.d.ts +0 -14
  173. package/lib/types/cache/BrowserStorage.d.ts.map +0 -1
  174. package/src/cache/BrowserStorage.ts +0 -52
@@ -1,6 +1,6 @@
1
- /*! @azure/msal-browser v3.28.0 2024-12-12 */
1
+ /*! @azure/msal-browser v4.0.0-alpha.0 2024-12-18 */
2
2
  'use strict';
3
- import { CacheManager, CredentialType, CacheHelpers, AccountEntity, createClientAuthError, ClientAuthErrorCodes, Constants, PersistentCacheKeys, PerformanceEvents, StringUtils, ProtocolUtils, AuthToken, CacheError, DEFAULT_CRYPTO_IMPLEMENTATION, CcsCredentialType } from '@azure/msal-common/browser';
3
+ import { CacheManager, AccountEntity, CredentialType, createClientAuthError, ClientAuthErrorCodes, CacheHelpers, Constants, PersistentCacheKeys, PerformanceEvents, StringUtils, ProtocolUtils, CacheError, DEFAULT_CRYPTO_IMPLEMENTATION, CcsCredentialType } from '@azure/msal-common/browser';
4
4
  import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
5
5
  import { BrowserCacheLocation, StaticCacheKeys, InMemoryCacheKeys, TemporaryCacheKeys } from '../utils/BrowserConstants.mjs';
6
6
  import { LocalStorage } from './LocalStorage.mjs';
@@ -10,6 +10,7 @@ import { extractBrowserRequestState } from '../utils/BrowserProtocolUtils.mjs';
10
10
  import { base64Decode } from '../encode/Base64Decode.mjs';
11
11
  import { base64Encode } from '../encode/Base64Encode.mjs';
12
12
  import { CookieStorage } from './CookieStorage.mjs';
13
+ import { getAccountKeys, getTokenKeys } from './CacheHelpers.mjs';
13
14
  import { noTokenRequestCacheError, unableToParseTokenRequestCacheError, noCachedAuthorityError, interactionInProgress } from '../error/BrowserAuthErrorCodes.mjs';
14
15
 
15
16
  /*
@@ -30,13 +31,11 @@ class BrowserCacheManager extends CacheManager {
30
31
  this.browserStorage = this.setupBrowserStorage(this.cacheConfig.cacheLocation);
31
32
  this.temporaryCacheStorage = this.setupBrowserStorage(this.cacheConfig.temporaryCacheLocation);
32
33
  this.cookieStorage = new CookieStorage();
33
- // Migrate cache entries from older versions of MSAL.
34
- if (cacheConfig.cacheMigrationEnabled) {
35
- this.migrateCacheEntries();
36
- this.createKeyMaps();
37
- }
38
34
  this.performanceClient = performanceClient;
39
35
  }
36
+ async initialize() {
37
+ await this.browserStorage.initialize();
38
+ }
40
39
  /**
41
40
  * Returns a window storage class implementing the IWindowStorage interface that corresponds to the configured cacheLocation.
42
41
  * @param cacheLocation
@@ -45,7 +44,7 @@ class BrowserCacheManager extends CacheManager {
45
44
  try {
46
45
  switch (cacheLocation) {
47
46
  case BrowserCacheLocation.LocalStorage:
48
- return new LocalStorage();
47
+ return new LocalStorage(this.clientId);
49
48
  case BrowserCacheLocation.SessionStorage:
50
49
  return new SessionStorage();
51
50
  case BrowserCacheLocation.MemoryStorage:
@@ -59,123 +58,6 @@ class BrowserCacheManager extends CacheManager {
59
58
  this.cacheConfig.cacheLocation = BrowserCacheLocation.MemoryStorage;
60
59
  return new MemoryStorage();
61
60
  }
62
- /**
63
- * Migrate all old cache entries to new schema. No rollback supported.
64
- * @param storeAuthStateInCookie
65
- */
66
- migrateCacheEntries() {
67
- const idTokenKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ID_TOKEN}`;
68
- const clientInfoKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.CLIENT_INFO}`;
69
- const errorKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ERROR}`;
70
- const errorDescKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ERROR_DESC}`;
71
- const idTokenValue = this.browserStorage.getItem(idTokenKey);
72
- const clientInfoValue = this.browserStorage.getItem(clientInfoKey);
73
- const errorValue = this.browserStorage.getItem(errorKey);
74
- const errorDescValue = this.browserStorage.getItem(errorDescKey);
75
- const values = [
76
- idTokenValue,
77
- clientInfoValue,
78
- errorValue,
79
- errorDescValue,
80
- ];
81
- const keysToMigrate = [
82
- PersistentCacheKeys.ID_TOKEN,
83
- PersistentCacheKeys.CLIENT_INFO,
84
- PersistentCacheKeys.ERROR,
85
- PersistentCacheKeys.ERROR_DESC,
86
- ];
87
- keysToMigrate.forEach((cacheKey, index) => {
88
- const value = values[index];
89
- if (value) {
90
- this.setTemporaryCache(cacheKey, value, true);
91
- }
92
- });
93
- }
94
- /**
95
- * Searches all cache entries for MSAL accounts and creates the account key map
96
- * This is used to migrate users from older versions of MSAL which did not create the map.
97
- * @returns
98
- */
99
- createKeyMaps() {
100
- this.logger.trace("BrowserCacheManager - createKeyMaps called.");
101
- const accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
102
- const tokenKeys = this.getItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`);
103
- if (accountKeys && tokenKeys) {
104
- this.logger.verbose("BrowserCacheManager:createKeyMaps - account and token key maps already exist, skipping migration.");
105
- // Key maps already exist, no need to iterate through cache
106
- return;
107
- }
108
- const allKeys = this.browserStorage.getKeys();
109
- allKeys.forEach((key) => {
110
- if (this.isCredentialKey(key)) {
111
- // Get item, parse, validate and write key to map
112
- const value = this.getItem(key);
113
- if (value) {
114
- const credObj = this.validateAndParseJson(value);
115
- if (credObj && credObj.hasOwnProperty("credentialType")) {
116
- switch (credObj["credentialType"]) {
117
- case CredentialType.ID_TOKEN:
118
- if (CacheHelpers.isIdTokenEntity(credObj)) {
119
- this.logger.trace("BrowserCacheManager:createKeyMaps - idToken found, saving key to token key map");
120
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - idToken with key: ${key} found, saving key to token key map`);
121
- const idTokenEntity = credObj;
122
- const newKey = this.updateCredentialCacheKey(key, idTokenEntity);
123
- this.addTokenKey(newKey, CredentialType.ID_TOKEN);
124
- return;
125
- }
126
- else {
127
- this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching idToken schema with value containing idToken credentialType field but value failed IdTokenEntity validation, skipping.");
128
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - failed idToken validation on key: ${key}`);
129
- }
130
- break;
131
- case CredentialType.ACCESS_TOKEN:
132
- case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
133
- if (CacheHelpers.isAccessTokenEntity(credObj)) {
134
- this.logger.trace("BrowserCacheManager:createKeyMaps - accessToken found, saving key to token key map");
135
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - accessToken with key: ${key} found, saving key to token key map`);
136
- const accessTokenEntity = credObj;
137
- const newKey = this.updateCredentialCacheKey(key, accessTokenEntity);
138
- this.addTokenKey(newKey, CredentialType.ACCESS_TOKEN);
139
- return;
140
- }
141
- else {
142
- this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching accessToken schema with value containing accessToken credentialType field but value failed AccessTokenEntity validation, skipping.");
143
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - failed accessToken validation on key: ${key}`);
144
- }
145
- break;
146
- case CredentialType.REFRESH_TOKEN:
147
- if (CacheHelpers.isRefreshTokenEntity(credObj)) {
148
- this.logger.trace("BrowserCacheManager:createKeyMaps - refreshToken found, saving key to token key map");
149
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - refreshToken with key: ${key} found, saving key to token key map`);
150
- const refreshTokenEntity = credObj;
151
- const newKey = this.updateCredentialCacheKey(key, refreshTokenEntity);
152
- this.addTokenKey(newKey, CredentialType.REFRESH_TOKEN);
153
- return;
154
- }
155
- else {
156
- this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching refreshToken schema with value containing refreshToken credentialType field but value failed RefreshTokenEntity validation, skipping.");
157
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - failed refreshToken validation on key: ${key}`);
158
- }
159
- break;
160
- // If credentialType isn't one of our predefined ones, it may not be an MSAL cache value. Ignore.
161
- }
162
- }
163
- }
164
- }
165
- if (this.isAccountKey(key)) {
166
- const value = this.getItem(key);
167
- if (value) {
168
- const accountObj = this.validateAndParseJson(value);
169
- if (accountObj &&
170
- AccountEntity.isAccountEntity(accountObj)) {
171
- this.logger.trace("BrowserCacheManager:createKeyMaps - account found, saving key to account key map");
172
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - account with key: ${key} found, saving key to account key map`);
173
- this.addAccountKeyToMap(key);
174
- }
175
- }
176
- }
177
- });
178
- }
179
61
  /**
180
62
  * Parses passed value as JSON object, JSON.parse() will throw an error.
181
63
  * @param input
@@ -197,38 +79,15 @@ class BrowserCacheManager extends CacheManager {
197
79
  return null;
198
80
  }
199
81
  }
200
- /**
201
- * fetches the entry from the browser storage based off the key
202
- * @param key
203
- */
204
- getItem(key) {
205
- return this.browserStorage.getItem(key);
206
- }
207
- /**
208
- * sets the entry in the browser storage
209
- * @param key
210
- * @param value
211
- */
212
- setItem(key, value) {
213
- this.browserStorage.setItem(key, value);
214
- }
215
- /**
216
- * fetch the account entity from the platform cache
217
- * @param accountKey
218
- */
219
- getAccount(accountKey, logger) {
220
- this.logger.trace("BrowserCacheManager.getAccount called");
221
- const accountEntity = this.getCachedAccountEntity(accountKey);
222
- return this.updateOutdatedCachedAccount(accountKey, accountEntity, logger);
223
- }
224
82
  /**
225
83
  * Reads account from cache, deserializes it into an account entity and returns it.
226
84
  * If account is not found from the key, returns null and removes key from map.
227
85
  * @param accountKey
228
86
  * @returns
229
87
  */
230
- getCachedAccountEntity(accountKey) {
231
- const serializedAccount = this.getItem(accountKey);
88
+ getAccount(accountKey) {
89
+ this.logger.trace("BrowserCacheManager.getAccount called");
90
+ const serializedAccount = this.browserStorage.getUserData(accountKey);
232
91
  if (!serializedAccount) {
233
92
  this.removeAccountKeyFromMap(accountKey);
234
93
  return null;
@@ -244,10 +103,10 @@ class BrowserCacheManager extends CacheManager {
244
103
  * set account entity in the platform cache
245
104
  * @param account
246
105
  */
247
- setAccount(account) {
106
+ async setAccount(account) {
248
107
  this.logger.trace("BrowserCacheManager.setAccount called");
249
108
  const key = account.generateAccountKey();
250
- this.setItem(key, JSON.stringify(account));
109
+ await this.browserStorage.setUserData(key, JSON.stringify(account));
251
110
  this.addAccountKeyToMap(key);
252
111
  }
253
112
  /**
@@ -255,13 +114,7 @@ class BrowserCacheManager extends CacheManager {
255
114
  * @returns
256
115
  */
257
116
  getAccountKeys() {
258
- this.logger.trace("BrowserCacheManager.getAccountKeys called");
259
- const accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
260
- if (accountKeys) {
261
- return JSON.parse(accountKeys);
262
- }
263
- this.logger.verbose("BrowserCacheManager.getAccountKeys - No account keys found");
264
- return [];
117
+ return getAccountKeys(this.browserStorage);
265
118
  }
266
119
  /**
267
120
  * Add a new account to the key map
@@ -274,7 +127,7 @@ class BrowserCacheManager extends CacheManager {
274
127
  if (accountKeys.indexOf(key) === -1) {
275
128
  // Only add key if it does not already exist in the map
276
129
  accountKeys.push(key);
277
- this.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
130
+ this.browserStorage.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
278
131
  this.logger.verbose("BrowserCacheManager.addAccountKeyToMap account key added");
279
132
  }
280
133
  else {
@@ -292,7 +145,7 @@ class BrowserCacheManager extends CacheManager {
292
145
  const removalIndex = accountKeys.indexOf(key);
293
146
  if (removalIndex > -1) {
294
147
  accountKeys.splice(removalIndex, 1);
295
- this.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
148
+ this.browserStorage.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
296
149
  this.logger.trace("BrowserCacheManager.removeAccountKeyFromMap account key removed");
297
150
  }
298
151
  else {
@@ -307,14 +160,6 @@ class BrowserCacheManager extends CacheManager {
307
160
  void super.removeAccount(key);
308
161
  this.removeAccountKeyFromMap(key);
309
162
  }
310
- /**
311
- * Remove account entity from the platform cache if it's outdated
312
- * @param accountKey
313
- */
314
- removeOutdatedAccount(accountKey) {
315
- this.removeItem(accountKey);
316
- this.removeAccountKeyFromMap(accountKey);
317
- }
318
163
  /**
319
164
  * Removes given idToken from the cache and from the key map
320
165
  * @param key
@@ -344,28 +189,7 @@ class BrowserCacheManager extends CacheManager {
344
189
  * @returns
345
190
  */
346
191
  getTokenKeys() {
347
- this.logger.trace("BrowserCacheManager.getTokenKeys called");
348
- const item = this.getItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`);
349
- if (item) {
350
- const tokenKeys = this.validateAndParseJson(item);
351
- if (tokenKeys &&
352
- tokenKeys.hasOwnProperty("idToken") &&
353
- tokenKeys.hasOwnProperty("accessToken") &&
354
- tokenKeys.hasOwnProperty("refreshToken")) {
355
- return tokenKeys;
356
- }
357
- else {
358
- this.logger.error("BrowserCacheManager.getTokenKeys - Token keys found but in an unknown format. Returning empty key map.");
359
- }
360
- }
361
- else {
362
- this.logger.verbose("BrowserCacheManager.getTokenKeys - No token keys found");
363
- }
364
- return {
365
- idToken: [],
366
- accessToken: [],
367
- refreshToken: [],
368
- };
192
+ return getTokenKeys(this.clientId, this.browserStorage);
369
193
  }
370
194
  /**
371
195
  * Adds the given key to the token key map
@@ -398,7 +222,7 @@ class BrowserCacheManager extends CacheManager {
398
222
  this.logger.error(`BrowserCacheManager:addTokenKey - CredentialType provided invalid. CredentialType: ${type}`);
399
223
  throw createClientAuthError(ClientAuthErrorCodes.unexpectedCredentialType);
400
224
  }
401
- this.setItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`, JSON.stringify(tokenKeys));
225
+ this.browserStorage.setItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`, JSON.stringify(tokenKeys));
402
226
  }
403
227
  /**
404
228
  * Removes the given key from the token key map
@@ -446,14 +270,14 @@ class BrowserCacheManager extends CacheManager {
446
270
  this.logger.error(`BrowserCacheManager:removeTokenKey - CredentialType provided invalid. CredentialType: ${type}`);
447
271
  throw createClientAuthError(ClientAuthErrorCodes.unexpectedCredentialType);
448
272
  }
449
- this.setItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`, JSON.stringify(tokenKeys));
273
+ this.browserStorage.setItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`, JSON.stringify(tokenKeys));
450
274
  }
451
275
  /**
452
276
  * generates idToken entity from a string
453
277
  * @param idTokenKey
454
278
  */
455
279
  getIdTokenCredential(idTokenKey) {
456
- const value = this.getItem(idTokenKey);
280
+ const value = this.browserStorage.getUserData(idTokenKey);
457
281
  if (!value) {
458
282
  this.logger.trace("BrowserCacheManager.getIdTokenCredential: called, no cache hit");
459
283
  this.removeTokenKey(idTokenKey, CredentialType.ID_TOKEN);
@@ -472,10 +296,10 @@ class BrowserCacheManager extends CacheManager {
472
296
  * set IdToken credential to the platform cache
473
297
  * @param idToken
474
298
  */
475
- setIdTokenCredential(idToken) {
299
+ async setIdTokenCredential(idToken) {
476
300
  this.logger.trace("BrowserCacheManager.setIdTokenCredential called");
477
301
  const idTokenKey = CacheHelpers.generateCredentialKey(idToken);
478
- this.setItem(idTokenKey, JSON.stringify(idToken));
302
+ await this.browserStorage.setUserData(idTokenKey, JSON.stringify(idToken));
479
303
  this.addTokenKey(idTokenKey, CredentialType.ID_TOKEN);
480
304
  }
481
305
  /**
@@ -483,7 +307,7 @@ class BrowserCacheManager extends CacheManager {
483
307
  * @param key
484
308
  */
485
309
  getAccessTokenCredential(accessTokenKey) {
486
- const value = this.getItem(accessTokenKey);
310
+ const value = this.browserStorage.getUserData(accessTokenKey);
487
311
  if (!value) {
488
312
  this.logger.trace("BrowserCacheManager.getAccessTokenCredential: called, no cache hit");
489
313
  this.removeTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
@@ -503,10 +327,10 @@ class BrowserCacheManager extends CacheManager {
503
327
  * set accessToken credential to the platform cache
504
328
  * @param accessToken
505
329
  */
506
- setAccessTokenCredential(accessToken) {
330
+ async setAccessTokenCredential(accessToken) {
507
331
  this.logger.trace("BrowserCacheManager.setAccessTokenCredential called");
508
332
  const accessTokenKey = CacheHelpers.generateCredentialKey(accessToken);
509
- this.setItem(accessTokenKey, JSON.stringify(accessToken));
333
+ await this.browserStorage.setUserData(accessTokenKey, JSON.stringify(accessToken));
510
334
  this.addTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
511
335
  }
512
336
  /**
@@ -514,7 +338,7 @@ class BrowserCacheManager extends CacheManager {
514
338
  * @param refreshTokenKey
515
339
  */
516
340
  getRefreshTokenCredential(refreshTokenKey) {
517
- const value = this.getItem(refreshTokenKey);
341
+ const value = this.browserStorage.getUserData(refreshTokenKey);
518
342
  if (!value) {
519
343
  this.logger.trace("BrowserCacheManager.getRefreshTokenCredential: called, no cache hit");
520
344
  this.removeTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
@@ -534,10 +358,10 @@ class BrowserCacheManager extends CacheManager {
534
358
  * set refreshToken credential to the platform cache
535
359
  * @param refreshToken
536
360
  */
537
- setRefreshTokenCredential(refreshToken) {
361
+ async setRefreshTokenCredential(refreshToken) {
538
362
  this.logger.trace("BrowserCacheManager.setRefreshTokenCredential called");
539
363
  const refreshTokenKey = CacheHelpers.generateCredentialKey(refreshToken);
540
- this.setItem(refreshTokenKey, JSON.stringify(refreshToken));
364
+ await this.browserStorage.setUserData(refreshTokenKey, JSON.stringify(refreshToken));
541
365
  this.addTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
542
366
  }
543
367
  /**
@@ -545,7 +369,7 @@ class BrowserCacheManager extends CacheManager {
545
369
  * @param appMetadataKey
546
370
  */
547
371
  getAppMetadata(appMetadataKey) {
548
- const value = this.getItem(appMetadataKey);
372
+ const value = this.browserStorage.getItem(appMetadataKey);
549
373
  if (!value) {
550
374
  this.logger.trace("BrowserCacheManager.getAppMetadata: called, no cache hit");
551
375
  return null;
@@ -566,14 +390,14 @@ class BrowserCacheManager extends CacheManager {
566
390
  setAppMetadata(appMetadata) {
567
391
  this.logger.trace("BrowserCacheManager.setAppMetadata called");
568
392
  const appMetadataKey = CacheHelpers.generateAppMetadataKey(appMetadata);
569
- this.setItem(appMetadataKey, JSON.stringify(appMetadata));
393
+ this.browserStorage.setItem(appMetadataKey, JSON.stringify(appMetadata));
570
394
  }
571
395
  /**
572
396
  * fetch server telemetry entity from the platform cache
573
397
  * @param serverTelemetryKey
574
398
  */
575
399
  getServerTelemetry(serverTelemetryKey) {
576
- const value = this.getItem(serverTelemetryKey);
400
+ const value = this.browserStorage.getItem(serverTelemetryKey);
577
401
  if (!value) {
578
402
  this.logger.trace("BrowserCacheManager.getServerTelemetry: called, no cache hit");
579
403
  return null;
@@ -594,7 +418,7 @@ class BrowserCacheManager extends CacheManager {
594
418
  */
595
419
  setServerTelemetry(serverTelemetryKey, serverTelemetry) {
596
420
  this.logger.trace("BrowserCacheManager.setServerTelemetry called");
597
- this.setItem(serverTelemetryKey, JSON.stringify(serverTelemetry));
421
+ this.browserStorage.setItem(serverTelemetryKey, JSON.stringify(serverTelemetry));
598
422
  }
599
423
  /**
600
424
  *
@@ -654,25 +478,9 @@ class BrowserCacheManager extends CacheManager {
654
478
  */
655
479
  getActiveAccount() {
656
480
  const activeAccountKeyFilters = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT_FILTERS);
657
- const activeAccountValueFilters = this.getItem(activeAccountKeyFilters);
481
+ const activeAccountValueFilters = this.browserStorage.getItem(activeAccountKeyFilters);
658
482
  if (!activeAccountValueFilters) {
659
- // if new active account cache type isn't found, it's an old version, so look for that instead
660
- this.logger.trace("BrowserCacheManager.getActiveAccount: No active account filters cache schema found, looking for legacy schema");
661
- const activeAccountKeyLocal = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT);
662
- const activeAccountValueLocal = this.getItem(activeAccountKeyLocal);
663
- if (!activeAccountValueLocal) {
664
- this.logger.trace("BrowserCacheManager.getActiveAccount: No active account found");
665
- return null;
666
- }
667
- const activeAccount = this.getAccountInfoFilteredBy({
668
- localAccountId: activeAccountValueLocal,
669
- });
670
- if (activeAccount) {
671
- this.logger.trace("BrowserCacheManager.getActiveAccount: Legacy active account cache schema found");
672
- this.logger.trace("BrowserCacheManager.getActiveAccount: Adding active account filters cache schema");
673
- this.setActiveAccount(activeAccount);
674
- return activeAccount;
675
- }
483
+ this.logger.trace("BrowserCacheManager.getActiveAccount: No active account filters found");
676
484
  return null;
677
485
  }
678
486
  const activeAccountValueObj = this.validateAndParseJson(activeAccountValueFilters);
@@ -693,7 +501,6 @@ class BrowserCacheManager extends CacheManager {
693
501
  */
694
502
  setActiveAccount(account) {
695
503
  const activeAccountKey = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT_FILTERS);
696
- const activeAccountKeyLocal = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT);
697
504
  if (account) {
698
505
  this.logger.verbose("setActiveAccount: Active account set");
699
506
  const activeAccountValue = {
@@ -702,12 +509,10 @@ class BrowserCacheManager extends CacheManager {
702
509
  tenantId: account.tenantId,
703
510
  };
704
511
  this.browserStorage.setItem(activeAccountKey, JSON.stringify(activeAccountValue));
705
- this.browserStorage.setItem(activeAccountKeyLocal, account.localAccountId);
706
512
  }
707
513
  else {
708
514
  this.logger.verbose("setActiveAccount: No account passed, active account not set");
709
515
  this.browserStorage.removeItem(activeAccountKey);
710
- this.browserStorage.removeItem(activeAccountKeyLocal);
711
516
  }
712
517
  }
713
518
  /**
@@ -715,7 +520,7 @@ class BrowserCacheManager extends CacheManager {
715
520
  * @param throttlingCacheKey
716
521
  */
717
522
  getThrottlingCache(throttlingCacheKey) {
718
- const value = this.getItem(throttlingCacheKey);
523
+ const value = this.browserStorage.getItem(throttlingCacheKey);
719
524
  if (!value) {
720
525
  this.logger.trace("BrowserCacheManager.getThrottlingCache: called, no cache hit");
721
526
  return null;
@@ -736,7 +541,7 @@ class BrowserCacheManager extends CacheManager {
736
541
  */
737
542
  setThrottlingCache(throttlingCacheKey, throttlingCache) {
738
543
  this.logger.trace("BrowserCacheManager.setThrottlingCache called");
739
- this.setItem(throttlingCacheKey, JSON.stringify(throttlingCache));
544
+ this.browserStorage.setItem(throttlingCacheKey, JSON.stringify(throttlingCache));
740
545
  }
741
546
  /**
742
547
  * Gets cache item with given key.
@@ -864,8 +669,7 @@ class BrowserCacheManager extends CacheManager {
864
669
  generateCacheKey(key) {
865
670
  const generatedKey = this.validateAndParseJson(key);
866
671
  if (!generatedKey) {
867
- if (StringUtils.startsWith(key, Constants.CACHE_PREFIX) ||
868
- StringUtils.startsWith(key, PersistentCacheKeys.ADAL_ID_TOKEN)) {
672
+ if (StringUtils.startsWith(key, Constants.CACHE_PREFIX)) {
869
673
  return key;
870
674
  }
871
675
  return `${Constants.CACHE_PREFIX}.${this.clientId}.${key}`;
@@ -1091,59 +895,6 @@ class BrowserCacheManager extends CacheManager {
1091
895
  this.removeTemporaryItem(key);
1092
896
  }
1093
897
  }
1094
- /**
1095
- * Returns username retrieved from ADAL or MSAL v1 idToken
1096
- * @deprecated
1097
- */
1098
- getLegacyLoginHint() {
1099
- // Only check for adal/msal token if no SSO params are being used
1100
- const adalIdTokenString = this.getTemporaryCache(PersistentCacheKeys.ADAL_ID_TOKEN);
1101
- if (adalIdTokenString) {
1102
- this.browserStorage.removeItem(PersistentCacheKeys.ADAL_ID_TOKEN);
1103
- this.logger.verbose("Cached ADAL id token retrieved.");
1104
- }
1105
- // Check for cached MSAL v1 id token
1106
- const msalIdTokenString = this.getTemporaryCache(PersistentCacheKeys.ID_TOKEN, true);
1107
- if (msalIdTokenString) {
1108
- this.browserStorage.removeItem(this.generateCacheKey(PersistentCacheKeys.ID_TOKEN));
1109
- this.logger.verbose("Cached MSAL.js v1 id token retrieved");
1110
- }
1111
- const cachedIdTokenString = msalIdTokenString || adalIdTokenString;
1112
- if (cachedIdTokenString) {
1113
- const idTokenClaims = AuthToken.extractTokenClaims(cachedIdTokenString, base64Decode);
1114
- if (idTokenClaims.preferred_username) {
1115
- this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 preferred_username as loginHint");
1116
- return idTokenClaims.preferred_username;
1117
- }
1118
- else if (idTokenClaims.upn) {
1119
- this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 upn as loginHint");
1120
- return idTokenClaims.upn;
1121
- }
1122
- else {
1123
- this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, however, no account hint claim found. Enable preferred_username or upn id token claim to get SSO.");
1124
- }
1125
- }
1126
- return null;
1127
- }
1128
- /**
1129
- * Updates a credential's cache key if the current cache key is outdated
1130
- */
1131
- updateCredentialCacheKey(currentCacheKey, credential) {
1132
- const updatedCacheKey = CacheHelpers.generateCredentialKey(credential);
1133
- if (currentCacheKey !== updatedCacheKey) {
1134
- const cacheItem = this.getItem(currentCacheKey);
1135
- if (cacheItem) {
1136
- this.browserStorage.removeItem(currentCacheKey);
1137
- this.setItem(updatedCacheKey, cacheItem);
1138
- this.logger.verbose(`Updated an outdated ${credential.credentialType} cache key`);
1139
- return updatedCacheKey;
1140
- }
1141
- else {
1142
- this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
1143
- }
1144
- }
1145
- return currentCacheKey;
1146
- }
1147
898
  /**
1148
899
  * Builds credential entities from AuthenticationResult object and saves the resulting credentials to the cache
1149
900
  * @param result