@azure/msal-browser 3.27.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 +9 -85
  9. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  10. package/dist/cache/BrowserCacheManager.mjs +55 -398
  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 +17 -0
  17. package/dist/cache/CookieStorage.d.ts.map +1 -0
  18. package/dist/cache/CookieStorage.mjs +73 -0
  19. package/dist/cache/CookieStorage.mjs.map +1 -0
  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 +43 -0
  26. package/dist/cache/LocalStorage.d.ts.map +1 -0
  27. package/dist/cache/LocalStorage.mjs +201 -0
  28. package/dist/cache/LocalStorage.mjs.map +1 -0
  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 +13 -0
  34. package/dist/cache/SessionStorage.d.ts.map +1 -0
  35. package/dist/cache/SessionStorage.mjs +43 -0
  36. package/dist/cache/SessionStorage.mjs.map +1 -0
  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 +3 -1
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.mjs +3 -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 +5 -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 +587 -622
  115. package/lib/msal-browser.cjs.map +1 -1
  116. package/lib/msal-browser.js +587 -622
  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 +9 -85
  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 +17 -0
  124. package/lib/types/cache/CookieStorage.d.ts.map +1 -0
  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 +43 -0
  130. package/lib/types/cache/LocalStorage.d.ts.map +1 -0
  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 +13 -0
  134. package/lib/types/cache/SessionStorage.d.ts.map +1 -0
  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 +3 -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 +85 -552
  152. package/src/cache/CacheHelpers.ts +52 -0
  153. package/src/cache/CookieStorage.ts +98 -0
  154. package/src/cache/ITokenCache.ts +1 -1
  155. package/src/cache/IWindowStorage.ts +14 -0
  156. package/src/cache/LocalStorage.ts +270 -0
  157. package/src/cache/MemoryStorage.ts +12 -0
  158. package/src/cache/SessionStorage.ts +52 -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 +3 -1
  165. package/src/interaction_client/NativeInteractionClient.ts +3 -3
  166. package/src/interaction_client/StandardInteractionClient.ts +5 -8
  167. package/src/packageMetadata.ts +1 -1
  168. package/dist/cache/BrowserStorage.d.ts +0 -12
  169. package/dist/cache/BrowserStorage.d.ts.map +0 -1
  170. package/dist/cache/BrowserStorage.mjs +0 -41
  171. package/dist/cache/BrowserStorage.mjs.map +0 -1
  172. package/lib/types/cache/BrowserStorage.d.ts +0 -12
  173. package/lib/types/cache/BrowserStorage.d.ts.map +0 -1
  174. package/src/cache/BrowserStorage.ts +0 -52
@@ -1,13 +1,16 @@
1
- /*! @azure/msal-browser v3.27.0 2024-11-05 */
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
- import { BrowserStorage } from './BrowserStorage.mjs';
6
+ import { LocalStorage } from './LocalStorage.mjs';
7
+ import { SessionStorage } from './SessionStorage.mjs';
7
8
  import { MemoryStorage } from './MemoryStorage.mjs';
8
9
  import { extractBrowserRequestState } from '../utils/BrowserProtocolUtils.mjs';
9
10
  import { base64Decode } from '../encode/Base64Decode.mjs';
10
11
  import { base64Encode } from '../encode/Base64Encode.mjs';
12
+ import { CookieStorage } from './CookieStorage.mjs';
13
+ import { getAccountKeys, getTokenKeys } from './CacheHelpers.mjs';
11
14
  import { noTokenRequestCacheError, unableToParseTokenRequestCacheError, noCachedAuthorityError, interactionInProgress } from '../error/BrowserAuthErrorCodes.mjs';
12
15
 
13
16
  /*
@@ -22,179 +25,39 @@ import { noTokenRequestCacheError, unableToParseTokenRequestCacheError, noCached
22
25
  class BrowserCacheManager extends CacheManager {
23
26
  constructor(clientId, cacheConfig, cryptoImpl, logger, staticAuthorityOptions, performanceClient) {
24
27
  super(clientId, cryptoImpl, logger, staticAuthorityOptions);
25
- // Cookie life calculation (hours * minutes * seconds * ms)
26
- this.COOKIE_LIFE_MULTIPLIER = 24 * 60 * 60 * 1000;
27
28
  this.cacheConfig = cacheConfig;
28
29
  this.logger = logger;
29
30
  this.internalStorage = new MemoryStorage();
30
31
  this.browserStorage = this.setupBrowserStorage(this.cacheConfig.cacheLocation);
31
- this.temporaryCacheStorage = this.setupTemporaryCacheStorage(this.cacheConfig.temporaryCacheLocation, this.cacheConfig.cacheLocation);
32
- // Migrate cache entries from older versions of MSAL.
33
- if (cacheConfig.cacheMigrationEnabled) {
34
- this.migrateCacheEntries();
35
- this.createKeyMaps();
36
- }
32
+ this.temporaryCacheStorage = this.setupBrowserStorage(this.cacheConfig.temporaryCacheLocation);
33
+ this.cookieStorage = new CookieStorage();
37
34
  this.performanceClient = performanceClient;
38
35
  }
36
+ async initialize() {
37
+ await this.browserStorage.initialize();
38
+ }
39
39
  /**
40
40
  * Returns a window storage class implementing the IWindowStorage interface that corresponds to the configured cacheLocation.
41
41
  * @param cacheLocation
42
42
  */
43
43
  setupBrowserStorage(cacheLocation) {
44
- switch (cacheLocation) {
45
- case BrowserCacheLocation.LocalStorage:
46
- case BrowserCacheLocation.SessionStorage:
47
- try {
48
- return new BrowserStorage(cacheLocation);
49
- }
50
- catch (e) {
51
- this.logger.verbose(e);
44
+ try {
45
+ switch (cacheLocation) {
46
+ case BrowserCacheLocation.LocalStorage:
47
+ return new LocalStorage(this.clientId);
48
+ case BrowserCacheLocation.SessionStorage:
49
+ return new SessionStorage();
50
+ case BrowserCacheLocation.MemoryStorage:
51
+ default:
52
52
  break;
53
- }
53
+ }
54
+ }
55
+ catch (e) {
56
+ this.logger.error(e);
54
57
  }
55
58
  this.cacheConfig.cacheLocation = BrowserCacheLocation.MemoryStorage;
56
59
  return new MemoryStorage();
57
60
  }
58
- /**
59
- * Returns a window storage class implementing the IWindowStorage interface that corresponds to the configured temporaryCacheLocation.
60
- * @param temporaryCacheLocation
61
- * @param cacheLocation
62
- */
63
- setupTemporaryCacheStorage(temporaryCacheLocation, cacheLocation) {
64
- switch (cacheLocation) {
65
- case BrowserCacheLocation.LocalStorage:
66
- case BrowserCacheLocation.SessionStorage:
67
- try {
68
- // Temporary cache items will always be stored in session storage to mitigate problems caused by multiple tabs
69
- return new BrowserStorage(temporaryCacheLocation ||
70
- BrowserCacheLocation.SessionStorage);
71
- }
72
- catch (e) {
73
- this.logger.verbose(e);
74
- return this.internalStorage;
75
- }
76
- case BrowserCacheLocation.MemoryStorage:
77
- default:
78
- return this.internalStorage;
79
- }
80
- }
81
- /**
82
- * Migrate all old cache entries to new schema. No rollback supported.
83
- * @param storeAuthStateInCookie
84
- */
85
- migrateCacheEntries() {
86
- const idTokenKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ID_TOKEN}`;
87
- const clientInfoKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.CLIENT_INFO}`;
88
- const errorKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ERROR}`;
89
- const errorDescKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ERROR_DESC}`;
90
- const idTokenValue = this.browserStorage.getItem(idTokenKey);
91
- const clientInfoValue = this.browserStorage.getItem(clientInfoKey);
92
- const errorValue = this.browserStorage.getItem(errorKey);
93
- const errorDescValue = this.browserStorage.getItem(errorDescKey);
94
- const values = [
95
- idTokenValue,
96
- clientInfoValue,
97
- errorValue,
98
- errorDescValue,
99
- ];
100
- const keysToMigrate = [
101
- PersistentCacheKeys.ID_TOKEN,
102
- PersistentCacheKeys.CLIENT_INFO,
103
- PersistentCacheKeys.ERROR,
104
- PersistentCacheKeys.ERROR_DESC,
105
- ];
106
- keysToMigrate.forEach((cacheKey, index) => {
107
- const value = values[index];
108
- if (value) {
109
- this.setTemporaryCache(cacheKey, value, true);
110
- }
111
- });
112
- }
113
- /**
114
- * Searches all cache entries for MSAL accounts and creates the account key map
115
- * This is used to migrate users from older versions of MSAL which did not create the map.
116
- * @returns
117
- */
118
- createKeyMaps() {
119
- this.logger.trace("BrowserCacheManager - createKeyMaps called.");
120
- const accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
121
- const tokenKeys = this.getItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`);
122
- if (accountKeys && tokenKeys) {
123
- this.logger.verbose("BrowserCacheManager:createKeyMaps - account and token key maps already exist, skipping migration.");
124
- // Key maps already exist, no need to iterate through cache
125
- return;
126
- }
127
- const allKeys = this.browserStorage.getKeys();
128
- allKeys.forEach((key) => {
129
- if (this.isCredentialKey(key)) {
130
- // Get item, parse, validate and write key to map
131
- const value = this.getItem(key);
132
- if (value) {
133
- const credObj = this.validateAndParseJson(value);
134
- if (credObj && credObj.hasOwnProperty("credentialType")) {
135
- switch (credObj["credentialType"]) {
136
- case CredentialType.ID_TOKEN:
137
- if (CacheHelpers.isIdTokenEntity(credObj)) {
138
- this.logger.trace("BrowserCacheManager:createKeyMaps - idToken found, saving key to token key map");
139
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - idToken with key: ${key} found, saving key to token key map`);
140
- const idTokenEntity = credObj;
141
- const newKey = this.updateCredentialCacheKey(key, idTokenEntity);
142
- this.addTokenKey(newKey, CredentialType.ID_TOKEN);
143
- return;
144
- }
145
- else {
146
- this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching idToken schema with value containing idToken credentialType field but value failed IdTokenEntity validation, skipping.");
147
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - failed idToken validation on key: ${key}`);
148
- }
149
- break;
150
- case CredentialType.ACCESS_TOKEN:
151
- case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
152
- if (CacheHelpers.isAccessTokenEntity(credObj)) {
153
- this.logger.trace("BrowserCacheManager:createKeyMaps - accessToken found, saving key to token key map");
154
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - accessToken with key: ${key} found, saving key to token key map`);
155
- const accessTokenEntity = credObj;
156
- const newKey = this.updateCredentialCacheKey(key, accessTokenEntity);
157
- this.addTokenKey(newKey, CredentialType.ACCESS_TOKEN);
158
- return;
159
- }
160
- else {
161
- this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching accessToken schema with value containing accessToken credentialType field but value failed AccessTokenEntity validation, skipping.");
162
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - failed accessToken validation on key: ${key}`);
163
- }
164
- break;
165
- case CredentialType.REFRESH_TOKEN:
166
- if (CacheHelpers.isRefreshTokenEntity(credObj)) {
167
- this.logger.trace("BrowserCacheManager:createKeyMaps - refreshToken found, saving key to token key map");
168
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - refreshToken with key: ${key} found, saving key to token key map`);
169
- const refreshTokenEntity = credObj;
170
- const newKey = this.updateCredentialCacheKey(key, refreshTokenEntity);
171
- this.addTokenKey(newKey, CredentialType.REFRESH_TOKEN);
172
- return;
173
- }
174
- else {
175
- this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching refreshToken schema with value containing refreshToken credentialType field but value failed RefreshTokenEntity validation, skipping.");
176
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - failed refreshToken validation on key: ${key}`);
177
- }
178
- break;
179
- // If credentialType isn't one of our predefined ones, it may not be an MSAL cache value. Ignore.
180
- }
181
- }
182
- }
183
- }
184
- if (this.isAccountKey(key)) {
185
- const value = this.getItem(key);
186
- if (value) {
187
- const accountObj = this.validateAndParseJson(value);
188
- if (accountObj &&
189
- AccountEntity.isAccountEntity(accountObj)) {
190
- this.logger.trace("BrowserCacheManager:createKeyMaps - account found, saving key to account key map");
191
- this.logger.tracePii(`BrowserCacheManager:createKeyMaps - account with key: ${key} found, saving key to account key map`);
192
- this.addAccountKeyToMap(key);
193
- }
194
- }
195
- }
196
- });
197
- }
198
61
  /**
199
62
  * Parses passed value as JSON object, JSON.parse() will throw an error.
200
63
  * @param input
@@ -216,38 +79,15 @@ class BrowserCacheManager extends CacheManager {
216
79
  return null;
217
80
  }
218
81
  }
219
- /**
220
- * fetches the entry from the browser storage based off the key
221
- * @param key
222
- */
223
- getItem(key) {
224
- return this.browserStorage.getItem(key);
225
- }
226
- /**
227
- * sets the entry in the browser storage
228
- * @param key
229
- * @param value
230
- */
231
- setItem(key, value) {
232
- this.browserStorage.setItem(key, value);
233
- }
234
- /**
235
- * fetch the account entity from the platform cache
236
- * @param accountKey
237
- */
238
- getAccount(accountKey, logger) {
239
- this.logger.trace("BrowserCacheManager.getAccount called");
240
- const accountEntity = this.getCachedAccountEntity(accountKey);
241
- return this.updateOutdatedCachedAccount(accountKey, accountEntity, logger);
242
- }
243
82
  /**
244
83
  * Reads account from cache, deserializes it into an account entity and returns it.
245
84
  * If account is not found from the key, returns null and removes key from map.
246
85
  * @param accountKey
247
86
  * @returns
248
87
  */
249
- getCachedAccountEntity(accountKey) {
250
- const serializedAccount = this.getItem(accountKey);
88
+ getAccount(accountKey) {
89
+ this.logger.trace("BrowserCacheManager.getAccount called");
90
+ const serializedAccount = this.browserStorage.getUserData(accountKey);
251
91
  if (!serializedAccount) {
252
92
  this.removeAccountKeyFromMap(accountKey);
253
93
  return null;
@@ -263,10 +103,10 @@ class BrowserCacheManager extends CacheManager {
263
103
  * set account entity in the platform cache
264
104
  * @param account
265
105
  */
266
- setAccount(account) {
106
+ async setAccount(account) {
267
107
  this.logger.trace("BrowserCacheManager.setAccount called");
268
108
  const key = account.generateAccountKey();
269
- this.setItem(key, JSON.stringify(account));
109
+ await this.browserStorage.setUserData(key, JSON.stringify(account));
270
110
  this.addAccountKeyToMap(key);
271
111
  }
272
112
  /**
@@ -274,13 +114,7 @@ class BrowserCacheManager extends CacheManager {
274
114
  * @returns
275
115
  */
276
116
  getAccountKeys() {
277
- this.logger.trace("BrowserCacheManager.getAccountKeys called");
278
- const accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
279
- if (accountKeys) {
280
- return JSON.parse(accountKeys);
281
- }
282
- this.logger.verbose("BrowserCacheManager.getAccountKeys - No account keys found");
283
- return [];
117
+ return getAccountKeys(this.browserStorage);
284
118
  }
285
119
  /**
286
120
  * Add a new account to the key map
@@ -293,7 +127,7 @@ class BrowserCacheManager extends CacheManager {
293
127
  if (accountKeys.indexOf(key) === -1) {
294
128
  // Only add key if it does not already exist in the map
295
129
  accountKeys.push(key);
296
- this.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
130
+ this.browserStorage.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
297
131
  this.logger.verbose("BrowserCacheManager.addAccountKeyToMap account key added");
298
132
  }
299
133
  else {
@@ -311,7 +145,7 @@ class BrowserCacheManager extends CacheManager {
311
145
  const removalIndex = accountKeys.indexOf(key);
312
146
  if (removalIndex > -1) {
313
147
  accountKeys.splice(removalIndex, 1);
314
- this.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
148
+ this.browserStorage.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
315
149
  this.logger.trace("BrowserCacheManager.removeAccountKeyFromMap account key removed");
316
150
  }
317
151
  else {
@@ -326,14 +160,6 @@ class BrowserCacheManager extends CacheManager {
326
160
  void super.removeAccount(key);
327
161
  this.removeAccountKeyFromMap(key);
328
162
  }
329
- /**
330
- * Remove account entity from the platform cache if it's outdated
331
- * @param accountKey
332
- */
333
- removeOutdatedAccount(accountKey) {
334
- this.removeItem(accountKey);
335
- this.removeAccountKeyFromMap(accountKey);
336
- }
337
163
  /**
338
164
  * Removes given idToken from the cache and from the key map
339
165
  * @param key
@@ -363,28 +189,7 @@ class BrowserCacheManager extends CacheManager {
363
189
  * @returns
364
190
  */
365
191
  getTokenKeys() {
366
- this.logger.trace("BrowserCacheManager.getTokenKeys called");
367
- const item = this.getItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`);
368
- if (item) {
369
- const tokenKeys = this.validateAndParseJson(item);
370
- if (tokenKeys &&
371
- tokenKeys.hasOwnProperty("idToken") &&
372
- tokenKeys.hasOwnProperty("accessToken") &&
373
- tokenKeys.hasOwnProperty("refreshToken")) {
374
- return tokenKeys;
375
- }
376
- else {
377
- this.logger.error("BrowserCacheManager.getTokenKeys - Token keys found but in an unknown format. Returning empty key map.");
378
- }
379
- }
380
- else {
381
- this.logger.verbose("BrowserCacheManager.getTokenKeys - No token keys found");
382
- }
383
- return {
384
- idToken: [],
385
- accessToken: [],
386
- refreshToken: [],
387
- };
192
+ return getTokenKeys(this.clientId, this.browserStorage);
388
193
  }
389
194
  /**
390
195
  * Adds the given key to the token key map
@@ -417,7 +222,7 @@ class BrowserCacheManager extends CacheManager {
417
222
  this.logger.error(`BrowserCacheManager:addTokenKey - CredentialType provided invalid. CredentialType: ${type}`);
418
223
  throw createClientAuthError(ClientAuthErrorCodes.unexpectedCredentialType);
419
224
  }
420
- this.setItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`, JSON.stringify(tokenKeys));
225
+ this.browserStorage.setItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`, JSON.stringify(tokenKeys));
421
226
  }
422
227
  /**
423
228
  * Removes the given key from the token key map
@@ -465,14 +270,14 @@ class BrowserCacheManager extends CacheManager {
465
270
  this.logger.error(`BrowserCacheManager:removeTokenKey - CredentialType provided invalid. CredentialType: ${type}`);
466
271
  throw createClientAuthError(ClientAuthErrorCodes.unexpectedCredentialType);
467
272
  }
468
- this.setItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`, JSON.stringify(tokenKeys));
273
+ this.browserStorage.setItem(`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`, JSON.stringify(tokenKeys));
469
274
  }
470
275
  /**
471
276
  * generates idToken entity from a string
472
277
  * @param idTokenKey
473
278
  */
474
279
  getIdTokenCredential(idTokenKey) {
475
- const value = this.getItem(idTokenKey);
280
+ const value = this.browserStorage.getUserData(idTokenKey);
476
281
  if (!value) {
477
282
  this.logger.trace("BrowserCacheManager.getIdTokenCredential: called, no cache hit");
478
283
  this.removeTokenKey(idTokenKey, CredentialType.ID_TOKEN);
@@ -491,10 +296,10 @@ class BrowserCacheManager extends CacheManager {
491
296
  * set IdToken credential to the platform cache
492
297
  * @param idToken
493
298
  */
494
- setIdTokenCredential(idToken) {
299
+ async setIdTokenCredential(idToken) {
495
300
  this.logger.trace("BrowserCacheManager.setIdTokenCredential called");
496
301
  const idTokenKey = CacheHelpers.generateCredentialKey(idToken);
497
- this.setItem(idTokenKey, JSON.stringify(idToken));
302
+ await this.browserStorage.setUserData(idTokenKey, JSON.stringify(idToken));
498
303
  this.addTokenKey(idTokenKey, CredentialType.ID_TOKEN);
499
304
  }
500
305
  /**
@@ -502,7 +307,7 @@ class BrowserCacheManager extends CacheManager {
502
307
  * @param key
503
308
  */
504
309
  getAccessTokenCredential(accessTokenKey) {
505
- const value = this.getItem(accessTokenKey);
310
+ const value = this.browserStorage.getUserData(accessTokenKey);
506
311
  if (!value) {
507
312
  this.logger.trace("BrowserCacheManager.getAccessTokenCredential: called, no cache hit");
508
313
  this.removeTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
@@ -522,10 +327,10 @@ class BrowserCacheManager extends CacheManager {
522
327
  * set accessToken credential to the platform cache
523
328
  * @param accessToken
524
329
  */
525
- setAccessTokenCredential(accessToken) {
330
+ async setAccessTokenCredential(accessToken) {
526
331
  this.logger.trace("BrowserCacheManager.setAccessTokenCredential called");
527
332
  const accessTokenKey = CacheHelpers.generateCredentialKey(accessToken);
528
- this.setItem(accessTokenKey, JSON.stringify(accessToken));
333
+ await this.browserStorage.setUserData(accessTokenKey, JSON.stringify(accessToken));
529
334
  this.addTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
530
335
  }
531
336
  /**
@@ -533,7 +338,7 @@ class BrowserCacheManager extends CacheManager {
533
338
  * @param refreshTokenKey
534
339
  */
535
340
  getRefreshTokenCredential(refreshTokenKey) {
536
- const value = this.getItem(refreshTokenKey);
341
+ const value = this.browserStorage.getUserData(refreshTokenKey);
537
342
  if (!value) {
538
343
  this.logger.trace("BrowserCacheManager.getRefreshTokenCredential: called, no cache hit");
539
344
  this.removeTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
@@ -553,10 +358,10 @@ class BrowserCacheManager extends CacheManager {
553
358
  * set refreshToken credential to the platform cache
554
359
  * @param refreshToken
555
360
  */
556
- setRefreshTokenCredential(refreshToken) {
361
+ async setRefreshTokenCredential(refreshToken) {
557
362
  this.logger.trace("BrowserCacheManager.setRefreshTokenCredential called");
558
363
  const refreshTokenKey = CacheHelpers.generateCredentialKey(refreshToken);
559
- this.setItem(refreshTokenKey, JSON.stringify(refreshToken));
364
+ await this.browserStorage.setUserData(refreshTokenKey, JSON.stringify(refreshToken));
560
365
  this.addTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
561
366
  }
562
367
  /**
@@ -564,7 +369,7 @@ class BrowserCacheManager extends CacheManager {
564
369
  * @param appMetadataKey
565
370
  */
566
371
  getAppMetadata(appMetadataKey) {
567
- const value = this.getItem(appMetadataKey);
372
+ const value = this.browserStorage.getItem(appMetadataKey);
568
373
  if (!value) {
569
374
  this.logger.trace("BrowserCacheManager.getAppMetadata: called, no cache hit");
570
375
  return null;
@@ -585,14 +390,14 @@ class BrowserCacheManager extends CacheManager {
585
390
  setAppMetadata(appMetadata) {
586
391
  this.logger.trace("BrowserCacheManager.setAppMetadata called");
587
392
  const appMetadataKey = CacheHelpers.generateAppMetadataKey(appMetadata);
588
- this.setItem(appMetadataKey, JSON.stringify(appMetadata));
393
+ this.browserStorage.setItem(appMetadataKey, JSON.stringify(appMetadata));
589
394
  }
590
395
  /**
591
396
  * fetch server telemetry entity from the platform cache
592
397
  * @param serverTelemetryKey
593
398
  */
594
399
  getServerTelemetry(serverTelemetryKey) {
595
- const value = this.getItem(serverTelemetryKey);
400
+ const value = this.browserStorage.getItem(serverTelemetryKey);
596
401
  if (!value) {
597
402
  this.logger.trace("BrowserCacheManager.getServerTelemetry: called, no cache hit");
598
403
  return null;
@@ -613,7 +418,7 @@ class BrowserCacheManager extends CacheManager {
613
418
  */
614
419
  setServerTelemetry(serverTelemetryKey, serverTelemetry) {
615
420
  this.logger.trace("BrowserCacheManager.setServerTelemetry called");
616
- this.setItem(serverTelemetryKey, JSON.stringify(serverTelemetry));
421
+ this.browserStorage.setItem(serverTelemetryKey, JSON.stringify(serverTelemetry));
617
422
  }
618
423
  /**
619
424
  *
@@ -673,25 +478,9 @@ class BrowserCacheManager extends CacheManager {
673
478
  */
674
479
  getActiveAccount() {
675
480
  const activeAccountKeyFilters = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT_FILTERS);
676
- const activeAccountValueFilters = this.getItem(activeAccountKeyFilters);
481
+ const activeAccountValueFilters = this.browserStorage.getItem(activeAccountKeyFilters);
677
482
  if (!activeAccountValueFilters) {
678
- // if new active account cache type isn't found, it's an old version, so look for that instead
679
- this.logger.trace("BrowserCacheManager.getActiveAccount: No active account filters cache schema found, looking for legacy schema");
680
- const activeAccountKeyLocal = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT);
681
- const activeAccountValueLocal = this.getItem(activeAccountKeyLocal);
682
- if (!activeAccountValueLocal) {
683
- this.logger.trace("BrowserCacheManager.getActiveAccount: No active account found");
684
- return null;
685
- }
686
- const activeAccount = this.getAccountInfoFilteredBy({
687
- localAccountId: activeAccountValueLocal,
688
- });
689
- if (activeAccount) {
690
- this.logger.trace("BrowserCacheManager.getActiveAccount: Legacy active account cache schema found");
691
- this.logger.trace("BrowserCacheManager.getActiveAccount: Adding active account filters cache schema");
692
- this.setActiveAccount(activeAccount);
693
- return activeAccount;
694
- }
483
+ this.logger.trace("BrowserCacheManager.getActiveAccount: No active account filters found");
695
484
  return null;
696
485
  }
697
486
  const activeAccountValueObj = this.validateAndParseJson(activeAccountValueFilters);
@@ -712,7 +501,6 @@ class BrowserCacheManager extends CacheManager {
712
501
  */
713
502
  setActiveAccount(account) {
714
503
  const activeAccountKey = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT_FILTERS);
715
- const activeAccountKeyLocal = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT);
716
504
  if (account) {
717
505
  this.logger.verbose("setActiveAccount: Active account set");
718
506
  const activeAccountValue = {
@@ -721,12 +509,10 @@ class BrowserCacheManager extends CacheManager {
721
509
  tenantId: account.tenantId,
722
510
  };
723
511
  this.browserStorage.setItem(activeAccountKey, JSON.stringify(activeAccountValue));
724
- this.browserStorage.setItem(activeAccountKeyLocal, account.localAccountId);
725
512
  }
726
513
  else {
727
514
  this.logger.verbose("setActiveAccount: No account passed, active account not set");
728
515
  this.browserStorage.removeItem(activeAccountKey);
729
- this.browserStorage.removeItem(activeAccountKeyLocal);
730
516
  }
731
517
  }
732
518
  /**
@@ -734,7 +520,7 @@ class BrowserCacheManager extends CacheManager {
734
520
  * @param throttlingCacheKey
735
521
  */
736
522
  getThrottlingCache(throttlingCacheKey) {
737
- const value = this.getItem(throttlingCacheKey);
523
+ const value = this.browserStorage.getItem(throttlingCacheKey);
738
524
  if (!value) {
739
525
  this.logger.trace("BrowserCacheManager.getThrottlingCache: called, no cache hit");
740
526
  return null;
@@ -755,7 +541,7 @@ class BrowserCacheManager extends CacheManager {
755
541
  */
756
542
  setThrottlingCache(throttlingCacheKey, throttlingCache) {
757
543
  this.logger.trace("BrowserCacheManager.setThrottlingCache called");
758
- this.setItem(throttlingCacheKey, JSON.stringify(throttlingCache));
544
+ this.browserStorage.setItem(throttlingCacheKey, JSON.stringify(throttlingCache));
759
545
  }
760
546
  /**
761
547
  * Gets cache item with given key.
@@ -765,7 +551,7 @@ class BrowserCacheManager extends CacheManager {
765
551
  getTemporaryCache(cacheKey, generateKey) {
766
552
  const key = generateKey ? this.generateCacheKey(cacheKey) : cacheKey;
767
553
  if (this.cacheConfig.storeAuthStateInCookie) {
768
- const itemCookie = this.getItemCookie(key);
554
+ const itemCookie = this.cookieStorage.getItem(key);
769
555
  if (itemCookie) {
770
556
  this.logger.trace("BrowserCacheManager.getTemporaryCache: storeAuthStateInCookies set to true, retrieving from cookies");
771
557
  return itemCookie;
@@ -800,7 +586,7 @@ class BrowserCacheManager extends CacheManager {
800
586
  this.temporaryCacheStorage.setItem(key, value);
801
587
  if (this.cacheConfig.storeAuthStateInCookie) {
802
588
  this.logger.trace("BrowserCacheManager.setTemporaryCache: storeAuthStateInCookie set to true, setting item cookie");
803
- this.setItemCookie(key, value);
589
+ this.cookieStorage.setItem(key, value, undefined, this.cacheConfig.secureCookies);
804
590
  }
805
591
  }
806
592
  /**
@@ -819,7 +605,7 @@ class BrowserCacheManager extends CacheManager {
819
605
  this.temporaryCacheStorage.removeItem(key);
820
606
  if (this.cacheConfig.storeAuthStateInCookie) {
821
607
  this.logger.trace("BrowserCacheManager.removeItem: storeAuthStateInCookie is true, clearing item cookie");
822
- this.clearItemCookie(key);
608
+ this.cookieStorage.removeItem(key);
823
609
  }
824
610
  }
825
611
  /**
@@ -875,79 +661,6 @@ class BrowserCacheManager extends CacheManager {
875
661
  this.logger.warning(`${removedAccessTokens.length} access tokens with claims in the cache keys have been removed from the cache.`);
876
662
  }
877
663
  }
878
- /**
879
- * Add value to cookies
880
- * @param cookieName
881
- * @param cookieValue
882
- * @param expires
883
- * @deprecated
884
- */
885
- setItemCookie(cookieName, cookieValue, expires) {
886
- let cookieStr = `${encodeURIComponent(cookieName)}=${encodeURIComponent(cookieValue)};path=/;SameSite=Lax;`;
887
- if (expires) {
888
- const expireTime = this.getCookieExpirationTime(expires);
889
- cookieStr += `expires=${expireTime};`;
890
- }
891
- if (this.cacheConfig.secureCookies) {
892
- cookieStr += "Secure;";
893
- }
894
- document.cookie = cookieStr;
895
- }
896
- /**
897
- * Get one item by key from cookies
898
- * @param cookieName
899
- * @deprecated
900
- */
901
- getItemCookie(cookieName) {
902
- const name = `${encodeURIComponent(cookieName)}=`;
903
- const cookieList = document.cookie.split(";");
904
- for (let i = 0; i < cookieList.length; i++) {
905
- let cookie = cookieList[i];
906
- while (cookie.charAt(0) === " ") {
907
- cookie = cookie.substring(1);
908
- }
909
- if (cookie.indexOf(name) === 0) {
910
- return decodeURIComponent(cookie.substring(name.length, cookie.length));
911
- }
912
- }
913
- return Constants.EMPTY_STRING;
914
- }
915
- /**
916
- * Clear all msal-related cookies currently set in the browser. Should only be used to clear temporary cache items.
917
- * @deprecated
918
- */
919
- clearMsalCookies() {
920
- const cookiePrefix = `${Constants.CACHE_PREFIX}.${this.clientId}`;
921
- const cookieList = document.cookie.split(";");
922
- cookieList.forEach((cookie) => {
923
- while (cookie.charAt(0) === " ") {
924
- // eslint-disable-next-line no-param-reassign
925
- cookie = cookie.substring(1);
926
- }
927
- if (cookie.indexOf(cookiePrefix) === 0) {
928
- const cookieKey = cookie.split("=")[0];
929
- this.clearItemCookie(cookieKey);
930
- }
931
- });
932
- }
933
- /**
934
- * Clear an item in the cookies by key
935
- * @param cookieName
936
- * @deprecated
937
- */
938
- clearItemCookie(cookieName) {
939
- this.setItemCookie(cookieName, Constants.EMPTY_STRING, -1);
940
- }
941
- /**
942
- * Get cookie expiration time
943
- * @param cookieLifeDays
944
- * @deprecated
945
- */
946
- getCookieExpirationTime(cookieLifeDays) {
947
- const today = new Date();
948
- const expr = new Date(today.getTime() + cookieLifeDays * this.COOKIE_LIFE_MULTIPLIER);
949
- return expr.toUTCString();
950
- }
951
664
  /**
952
665
  * Prepend msal.<client-id> to each key; Skip for any JSON object as Key (defined schemas do not need the key appended: AccessToken Keys or the upcoming schema)
953
666
  * @param key
@@ -956,8 +669,7 @@ class BrowserCacheManager extends CacheManager {
956
669
  generateCacheKey(key) {
957
670
  const generatedKey = this.validateAndParseJson(key);
958
671
  if (!generatedKey) {
959
- if (StringUtils.startsWith(key, Constants.CACHE_PREFIX) ||
960
- StringUtils.startsWith(key, PersistentCacheKeys.ADAL_ID_TOKEN)) {
672
+ if (StringUtils.startsWith(key, Constants.CACHE_PREFIX)) {
961
673
  return key;
962
674
  }
963
675
  return `${Constants.CACHE_PREFIX}.${this.clientId}.${key}`;
@@ -1071,7 +783,6 @@ class BrowserCacheManager extends CacheManager {
1071
783
  this.logger.infoPii(`BrowserCacheManager.cleanRequestByState: Removing temporary cache items for state: ${cachedState}`);
1072
784
  this.resetRequestCache(cachedState || Constants.EMPTY_STRING);
1073
785
  }
1074
- this.clearMsalCookies();
1075
786
  }
1076
787
  /**
1077
788
  * Looks in temporary cache for any state values with the provided interactionType and removes all temporary cache items for that state
@@ -1099,7 +810,6 @@ class BrowserCacheManager extends CacheManager {
1099
810
  this.resetRequestCache(stateValue);
1100
811
  }
1101
812
  });
1102
- this.clearMsalCookies();
1103
813
  this.setInteractionInProgress(false);
1104
814
  }
1105
815
  cacheCodeRequest(authCodeRequest) {
@@ -1185,59 +895,6 @@ class BrowserCacheManager extends CacheManager {
1185
895
  this.removeTemporaryItem(key);
1186
896
  }
1187
897
  }
1188
- /**
1189
- * Returns username retrieved from ADAL or MSAL v1 idToken
1190
- * @deprecated
1191
- */
1192
- getLegacyLoginHint() {
1193
- // Only check for adal/msal token if no SSO params are being used
1194
- const adalIdTokenString = this.getTemporaryCache(PersistentCacheKeys.ADAL_ID_TOKEN);
1195
- if (adalIdTokenString) {
1196
- this.browserStorage.removeItem(PersistentCacheKeys.ADAL_ID_TOKEN);
1197
- this.logger.verbose("Cached ADAL id token retrieved.");
1198
- }
1199
- // Check for cached MSAL v1 id token
1200
- const msalIdTokenString = this.getTemporaryCache(PersistentCacheKeys.ID_TOKEN, true);
1201
- if (msalIdTokenString) {
1202
- this.browserStorage.removeItem(this.generateCacheKey(PersistentCacheKeys.ID_TOKEN));
1203
- this.logger.verbose("Cached MSAL.js v1 id token retrieved");
1204
- }
1205
- const cachedIdTokenString = msalIdTokenString || adalIdTokenString;
1206
- if (cachedIdTokenString) {
1207
- const idTokenClaims = AuthToken.extractTokenClaims(cachedIdTokenString, base64Decode);
1208
- if (idTokenClaims.preferred_username) {
1209
- this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 preferred_username as loginHint");
1210
- return idTokenClaims.preferred_username;
1211
- }
1212
- else if (idTokenClaims.upn) {
1213
- this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 upn as loginHint");
1214
- return idTokenClaims.upn;
1215
- }
1216
- else {
1217
- 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.");
1218
- }
1219
- }
1220
- return null;
1221
- }
1222
- /**
1223
- * Updates a credential's cache key if the current cache key is outdated
1224
- */
1225
- updateCredentialCacheKey(currentCacheKey, credential) {
1226
- const updatedCacheKey = CacheHelpers.generateCredentialKey(credential);
1227
- if (currentCacheKey !== updatedCacheKey) {
1228
- const cacheItem = this.getItem(currentCacheKey);
1229
- if (cacheItem) {
1230
- this.browserStorage.removeItem(currentCacheKey);
1231
- this.setItem(updatedCacheKey, cacheItem);
1232
- this.logger.verbose(`Updated an outdated ${credential.credentialType} cache key`);
1233
- return updatedCacheKey;
1234
- }
1235
- else {
1236
- this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
1237
- }
1238
- }
1239
- return currentCacheKey;
1240
- }
1241
898
  /**
1242
899
  * Builds credential entities from AuthenticationResult object and saves the resulting credentials to the cache
1243
900
  * @param result