@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.
- package/dist/app/IPublicClientApplication.mjs +1 -1
- package/dist/app/PublicClientApplication.mjs +1 -1
- package/dist/app/PublicClientNext.mjs +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
- package/dist/cache/AccountManager.mjs +1 -1
- package/dist/cache/AsyncMemoryStorage.mjs +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +9 -85
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +55 -398
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/CacheHelpers.d.ts +16 -0
- package/dist/cache/CacheHelpers.d.ts.map +1 -0
- package/dist/cache/CacheHelpers.mjs +46 -0
- package/dist/cache/CacheHelpers.mjs.map +1 -0
- package/dist/cache/CookieStorage.d.ts +17 -0
- package/dist/cache/CookieStorage.d.ts.map +1 -0
- package/dist/cache/CookieStorage.mjs +73 -0
- package/dist/cache/CookieStorage.mjs.map +1 -0
- package/dist/cache/DatabaseStorage.mjs +1 -1
- package/dist/cache/ITokenCache.d.ts +1 -1
- package/dist/cache/ITokenCache.d.ts.map +1 -1
- package/dist/cache/IWindowStorage.d.ts +12 -0
- package/dist/cache/IWindowStorage.d.ts.map +1 -1
- package/dist/cache/LocalStorage.d.ts +43 -0
- package/dist/cache/LocalStorage.d.ts.map +1 -0
- package/dist/cache/LocalStorage.mjs +201 -0
- package/dist/cache/LocalStorage.mjs.map +1 -0
- package/dist/cache/MemoryStorage.d.ts +3 -0
- package/dist/cache/MemoryStorage.d.ts.map +1 -1
- package/dist/cache/MemoryStorage.mjs +10 -1
- package/dist/cache/MemoryStorage.mjs.map +1 -1
- package/dist/cache/SessionStorage.d.ts +13 -0
- package/dist/cache/SessionStorage.d.ts.map +1 -0
- package/dist/cache/SessionStorage.mjs +43 -0
- package/dist/cache/SessionStorage.mjs.map +1 -0
- package/dist/cache/TokenCache.d.ts +1 -1
- package/dist/cache/TokenCache.d.ts.map +1 -1
- package/dist/cache/TokenCache.mjs +15 -15
- package/dist/cache/TokenCache.mjs.map +1 -1
- package/dist/config/Configuration.mjs +1 -1
- package/dist/controllers/ControllerFactory.mjs +1 -1
- package/dist/controllers/NestedAppAuthController.d.ts.map +1 -1
- package/dist/controllers/NestedAppAuthController.mjs +4 -4
- package/dist/controllers/NestedAppAuthController.mjs.map +1 -1
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +3 -2
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/controllers/UnknownOperatingContextController.mjs +1 -1
- package/dist/crypto/BrowserCrypto.d.ts +27 -0
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.mjs +83 -3
- package/dist/crypto/BrowserCrypto.mjs.map +1 -1
- package/dist/crypto/CryptoOps.mjs +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/crypto/SignedHttpRequest.mjs +1 -1
- package/dist/encode/Base64Decode.d.ts +5 -0
- package/dist/encode/Base64Decode.d.ts.map +1 -1
- package/dist/encode/Base64Decode.mjs +2 -2
- package/dist/encode/Base64Decode.mjs.map +1 -1
- package/dist/encode/Base64Encode.mjs +1 -1
- package/dist/error/BrowserAuthError.mjs +1 -1
- package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
- package/dist/error/NativeAuthError.mjs +1 -1
- package/dist/error/NativeAuthErrorCodes.mjs +1 -1
- package/dist/error/NestedAppAuthError.mjs +1 -1
- package/dist/event/EventHandler.mjs +1 -1
- package/dist/event/EventMessage.mjs +1 -1
- package/dist/event/EventType.mjs +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
- package/dist/interaction_client/NativeInteractionClient.d.ts +1 -1
- package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.mjs +4 -4
- package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +1 -1
- package/dist/interaction_client/RedirectClient.mjs +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +1 -1
- package/dist/interaction_client/SilentCacheClient.mjs +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +1 -1
- package/dist/interaction_client/SilentRefreshClient.mjs +1 -1
- package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.mjs +5 -8
- package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
- package/dist/interaction_handler/InteractionHandler.mjs +1 -1
- package/dist/interaction_handler/RedirectHandler.mjs +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +1 -1
- package/dist/naa/BridgeError.mjs +1 -1
- package/dist/naa/BridgeProxy.mjs +1 -1
- package/dist/naa/BridgeStatusCode.mjs +1 -1
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs +1 -1
- package/dist/navigation/NavigationClient.mjs +1 -1
- package/dist/network/FetchClient.mjs +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
- package/dist/operatingcontext/NestedAppOperatingContext.mjs +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
- package/dist/operatingcontext/UnknownOperatingContext.mjs +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/request/RequestHelpers.mjs +1 -1
- package/dist/response/ResponseHandler.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
- package/dist/utils/BrowserConstants.mjs +1 -1
- package/dist/utils/BrowserProtocolUtils.mjs +1 -1
- package/dist/utils/BrowserUtils.mjs +1 -1
- package/lib/msal-browser.cjs +587 -622
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +587 -622
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +65 -66
- package/lib/types/cache/BrowserCacheManager.d.ts +9 -85
- package/lib/types/cache/BrowserCacheManager.d.ts.map +1 -1
- package/lib/types/cache/CacheHelpers.d.ts +16 -0
- package/lib/types/cache/CacheHelpers.d.ts.map +1 -0
- package/lib/types/cache/CookieStorage.d.ts +17 -0
- package/lib/types/cache/CookieStorage.d.ts.map +1 -0
- package/lib/types/cache/ITokenCache.d.ts +1 -1
- package/lib/types/cache/ITokenCache.d.ts.map +1 -1
- package/lib/types/cache/IWindowStorage.d.ts +12 -0
- package/lib/types/cache/IWindowStorage.d.ts.map +1 -1
- package/lib/types/cache/LocalStorage.d.ts +43 -0
- package/lib/types/cache/LocalStorage.d.ts.map +1 -0
- package/lib/types/cache/MemoryStorage.d.ts +3 -0
- package/lib/types/cache/MemoryStorage.d.ts.map +1 -1
- package/lib/types/cache/SessionStorage.d.ts +13 -0
- package/lib/types/cache/SessionStorage.d.ts.map +1 -0
- package/lib/types/cache/TokenCache.d.ts +1 -1
- package/lib/types/cache/TokenCache.d.ts.map +1 -1
- package/lib/types/controllers/NestedAppAuthController.d.ts.map +1 -1
- package/lib/types/controllers/StandardController.d.ts.map +1 -1
- package/lib/types/crypto/BrowserCrypto.d.ts +27 -0
- package/lib/types/crypto/BrowserCrypto.d.ts.map +1 -1
- package/lib/types/encode/Base64Decode.d.ts +5 -0
- package/lib/types/encode/Base64Decode.d.ts.map +1 -1
- package/lib/types/index.d.ts +3 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/interaction_client/NativeInteractionClient.d.ts +1 -1
- package/lib/types/interaction_client/NativeInteractionClient.d.ts.map +1 -1
- package/lib/types/interaction_client/StandardInteractionClient.d.ts.map +1 -1
- package/lib/types/packageMetadata.d.ts +1 -1
- package/lib/types/packageMetadata.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/cache/BrowserCacheManager.ts +85 -552
- package/src/cache/CacheHelpers.ts +52 -0
- package/src/cache/CookieStorage.ts +98 -0
- package/src/cache/ITokenCache.ts +1 -1
- package/src/cache/IWindowStorage.ts +14 -0
- package/src/cache/LocalStorage.ts +270 -0
- package/src/cache/MemoryStorage.ts +12 -0
- package/src/cache/SessionStorage.ts +52 -0
- package/src/cache/TokenCache.ts +19 -19
- package/src/controllers/NestedAppAuthController.ts +3 -3
- package/src/controllers/StandardController.ts +3 -1
- package/src/crypto/BrowserCrypto.ts +120 -1
- package/src/encode/Base64Decode.ts +1 -1
- package/src/index.ts +3 -1
- package/src/interaction_client/NativeInteractionClient.ts +3 -3
- package/src/interaction_client/StandardInteractionClient.ts +5 -8
- package/src/packageMetadata.ts +1 -1
- package/dist/cache/BrowserStorage.d.ts +0 -12
- package/dist/cache/BrowserStorage.d.ts.map +0 -1
- package/dist/cache/BrowserStorage.mjs +0 -41
- package/dist/cache/BrowserStorage.mjs.map +0 -1
- package/lib/types/cache/BrowserStorage.d.ts +0 -12
- package/lib/types/cache/BrowserStorage.d.ts.map +0 -1
- package/src/cache/BrowserStorage.ts +0 -52
|
@@ -25,8 +25,6 @@ import {
|
|
|
25
25
|
ActiveAccountFilters,
|
|
26
26
|
CcsCredential,
|
|
27
27
|
CcsCredentialType,
|
|
28
|
-
AuthToken,
|
|
29
|
-
ValidCredentialType,
|
|
30
28
|
TokenKeys,
|
|
31
29
|
CredentialType,
|
|
32
30
|
CacheRecord,
|
|
@@ -52,7 +50,8 @@ import {
|
|
|
52
50
|
InMemoryCacheKeys,
|
|
53
51
|
StaticCacheKeys,
|
|
54
52
|
} from "../utils/BrowserConstants.js";
|
|
55
|
-
import {
|
|
53
|
+
import { LocalStorage } from "./LocalStorage.js";
|
|
54
|
+
import { SessionStorage } from "./SessionStorage.js";
|
|
56
55
|
import { MemoryStorage } from "./MemoryStorage.js";
|
|
57
56
|
import { IWindowStorage } from "./IWindowStorage.js";
|
|
58
57
|
import { extractBrowserRequestState } from "../utils/BrowserProtocolUtils.js";
|
|
@@ -64,6 +63,8 @@ import { RedirectRequest } from "../request/RedirectRequest.js";
|
|
|
64
63
|
import { PopupRequest } from "../request/PopupRequest.js";
|
|
65
64
|
import { base64Decode } from "../encode/Base64Decode.js";
|
|
66
65
|
import { base64Encode } from "../encode/Base64Encode.js";
|
|
66
|
+
import { CookieStorage } from "./CookieStorage.js";
|
|
67
|
+
import { getAccountKeys, getTokenKeys } from "./CacheHelpers.js";
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
70
|
* This class implements the cache storage interface for MSAL through browser local or session storage.
|
|
@@ -79,14 +80,13 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
79
80
|
protected internalStorage: MemoryStorage<string>;
|
|
80
81
|
// Temporary cache
|
|
81
82
|
protected temporaryCacheStorage: IWindowStorage<string>;
|
|
83
|
+
// Cookie storage
|
|
84
|
+
protected cookieStorage: CookieStorage;
|
|
82
85
|
// Logger instance
|
|
83
86
|
protected logger: Logger;
|
|
84
87
|
// Telemetry perf client
|
|
85
88
|
protected performanceClient?: IPerformanceClient;
|
|
86
89
|
|
|
87
|
-
// Cookie life calculation (hours * minutes * seconds * ms)
|
|
88
|
-
protected readonly COOKIE_LIFE_MULTIPLIER = 24 * 60 * 60 * 1000;
|
|
89
|
-
|
|
90
90
|
constructor(
|
|
91
91
|
clientId: string,
|
|
92
92
|
cacheConfig: Required<CacheOptions>,
|
|
@@ -102,20 +102,18 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
102
102
|
this.browserStorage = this.setupBrowserStorage(
|
|
103
103
|
this.cacheConfig.cacheLocation
|
|
104
104
|
);
|
|
105
|
-
this.temporaryCacheStorage = this.
|
|
106
|
-
this.cacheConfig.temporaryCacheLocation
|
|
107
|
-
this.cacheConfig.cacheLocation
|
|
105
|
+
this.temporaryCacheStorage = this.setupBrowserStorage(
|
|
106
|
+
this.cacheConfig.temporaryCacheLocation
|
|
108
107
|
);
|
|
109
|
-
|
|
110
|
-
// Migrate cache entries from older versions of MSAL.
|
|
111
|
-
if (cacheConfig.cacheMigrationEnabled) {
|
|
112
|
-
this.migrateCacheEntries();
|
|
113
|
-
this.createKeyMaps();
|
|
114
|
-
}
|
|
108
|
+
this.cookieStorage = new CookieStorage();
|
|
115
109
|
|
|
116
110
|
this.performanceClient = performanceClient;
|
|
117
111
|
}
|
|
118
112
|
|
|
113
|
+
async initialize(): Promise<void> {
|
|
114
|
+
await this.browserStorage.initialize();
|
|
115
|
+
}
|
|
116
|
+
|
|
119
117
|
/**
|
|
120
118
|
* Returns a window storage class implementing the IWindowStorage interface that corresponds to the configured cacheLocation.
|
|
121
119
|
* @param cacheLocation
|
|
@@ -123,233 +121,23 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
123
121
|
protected setupBrowserStorage(
|
|
124
122
|
cacheLocation: BrowserCacheLocation | string
|
|
125
123
|
): IWindowStorage<string> {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
try {
|
|
125
|
+
switch (cacheLocation) {
|
|
126
|
+
case BrowserCacheLocation.LocalStorage:
|
|
127
|
+
return new LocalStorage(this.clientId);
|
|
128
|
+
case BrowserCacheLocation.SessionStorage:
|
|
129
|
+
return new SessionStorage();
|
|
130
|
+
case BrowserCacheLocation.MemoryStorage:
|
|
131
|
+
default:
|
|
133
132
|
break;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
break;
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {
|
|
135
|
+
this.logger.error(e as string);
|
|
138
136
|
}
|
|
139
137
|
this.cacheConfig.cacheLocation = BrowserCacheLocation.MemoryStorage;
|
|
140
138
|
return new MemoryStorage();
|
|
141
139
|
}
|
|
142
140
|
|
|
143
|
-
/**
|
|
144
|
-
* Returns a window storage class implementing the IWindowStorage interface that corresponds to the configured temporaryCacheLocation.
|
|
145
|
-
* @param temporaryCacheLocation
|
|
146
|
-
* @param cacheLocation
|
|
147
|
-
*/
|
|
148
|
-
protected setupTemporaryCacheStorage(
|
|
149
|
-
temporaryCacheLocation: BrowserCacheLocation | string,
|
|
150
|
-
cacheLocation: BrowserCacheLocation | string
|
|
151
|
-
): IWindowStorage<string> {
|
|
152
|
-
switch (cacheLocation) {
|
|
153
|
-
case BrowserCacheLocation.LocalStorage:
|
|
154
|
-
case BrowserCacheLocation.SessionStorage:
|
|
155
|
-
try {
|
|
156
|
-
// Temporary cache items will always be stored in session storage to mitigate problems caused by multiple tabs
|
|
157
|
-
return new BrowserStorage(
|
|
158
|
-
temporaryCacheLocation ||
|
|
159
|
-
BrowserCacheLocation.SessionStorage
|
|
160
|
-
);
|
|
161
|
-
} catch (e) {
|
|
162
|
-
this.logger.verbose(e as string);
|
|
163
|
-
return this.internalStorage;
|
|
164
|
-
}
|
|
165
|
-
case BrowserCacheLocation.MemoryStorage:
|
|
166
|
-
default:
|
|
167
|
-
return this.internalStorage;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Migrate all old cache entries to new schema. No rollback supported.
|
|
173
|
-
* @param storeAuthStateInCookie
|
|
174
|
-
*/
|
|
175
|
-
protected migrateCacheEntries(): void {
|
|
176
|
-
const idTokenKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ID_TOKEN}`;
|
|
177
|
-
const clientInfoKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.CLIENT_INFO}`;
|
|
178
|
-
const errorKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ERROR}`;
|
|
179
|
-
const errorDescKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ERROR_DESC}`;
|
|
180
|
-
|
|
181
|
-
const idTokenValue = this.browserStorage.getItem(idTokenKey);
|
|
182
|
-
const clientInfoValue = this.browserStorage.getItem(clientInfoKey);
|
|
183
|
-
const errorValue = this.browserStorage.getItem(errorKey);
|
|
184
|
-
const errorDescValue = this.browserStorage.getItem(errorDescKey);
|
|
185
|
-
|
|
186
|
-
const values = [
|
|
187
|
-
idTokenValue,
|
|
188
|
-
clientInfoValue,
|
|
189
|
-
errorValue,
|
|
190
|
-
errorDescValue,
|
|
191
|
-
];
|
|
192
|
-
const keysToMigrate = [
|
|
193
|
-
PersistentCacheKeys.ID_TOKEN,
|
|
194
|
-
PersistentCacheKeys.CLIENT_INFO,
|
|
195
|
-
PersistentCacheKeys.ERROR,
|
|
196
|
-
PersistentCacheKeys.ERROR_DESC,
|
|
197
|
-
];
|
|
198
|
-
|
|
199
|
-
keysToMigrate.forEach((cacheKey: string, index: number) => {
|
|
200
|
-
const value = values[index];
|
|
201
|
-
if (value) {
|
|
202
|
-
this.setTemporaryCache(cacheKey, value, true);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Searches all cache entries for MSAL accounts and creates the account key map
|
|
209
|
-
* This is used to migrate users from older versions of MSAL which did not create the map.
|
|
210
|
-
* @returns
|
|
211
|
-
*/
|
|
212
|
-
private createKeyMaps(): void {
|
|
213
|
-
this.logger.trace("BrowserCacheManager - createKeyMaps called.");
|
|
214
|
-
const accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
|
|
215
|
-
const tokenKeys = this.getItem(
|
|
216
|
-
`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`
|
|
217
|
-
);
|
|
218
|
-
if (accountKeys && tokenKeys) {
|
|
219
|
-
this.logger.verbose(
|
|
220
|
-
"BrowserCacheManager:createKeyMaps - account and token key maps already exist, skipping migration."
|
|
221
|
-
);
|
|
222
|
-
// Key maps already exist, no need to iterate through cache
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const allKeys = this.browserStorage.getKeys();
|
|
227
|
-
allKeys.forEach((key) => {
|
|
228
|
-
if (this.isCredentialKey(key)) {
|
|
229
|
-
// Get item, parse, validate and write key to map
|
|
230
|
-
const value = this.getItem(key);
|
|
231
|
-
if (value) {
|
|
232
|
-
const credObj = this.validateAndParseJson(value);
|
|
233
|
-
if (credObj && credObj.hasOwnProperty("credentialType")) {
|
|
234
|
-
switch (credObj["credentialType"]) {
|
|
235
|
-
case CredentialType.ID_TOKEN:
|
|
236
|
-
if (CacheHelpers.isIdTokenEntity(credObj)) {
|
|
237
|
-
this.logger.trace(
|
|
238
|
-
"BrowserCacheManager:createKeyMaps - idToken found, saving key to token key map"
|
|
239
|
-
);
|
|
240
|
-
this.logger.tracePii(
|
|
241
|
-
`BrowserCacheManager:createKeyMaps - idToken with key: ${key} found, saving key to token key map`
|
|
242
|
-
);
|
|
243
|
-
const idTokenEntity =
|
|
244
|
-
credObj as IdTokenEntity;
|
|
245
|
-
const newKey =
|
|
246
|
-
this.updateCredentialCacheKey(
|
|
247
|
-
key,
|
|
248
|
-
idTokenEntity
|
|
249
|
-
);
|
|
250
|
-
this.addTokenKey(
|
|
251
|
-
newKey,
|
|
252
|
-
CredentialType.ID_TOKEN
|
|
253
|
-
);
|
|
254
|
-
return;
|
|
255
|
-
} else {
|
|
256
|
-
this.logger.trace(
|
|
257
|
-
"BrowserCacheManager:createKeyMaps - key found matching idToken schema with value containing idToken credentialType field but value failed IdTokenEntity validation, skipping."
|
|
258
|
-
);
|
|
259
|
-
this.logger.tracePii(
|
|
260
|
-
`BrowserCacheManager:createKeyMaps - failed idToken validation on key: ${key}`
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
break;
|
|
264
|
-
case CredentialType.ACCESS_TOKEN:
|
|
265
|
-
case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
|
|
266
|
-
if (CacheHelpers.isAccessTokenEntity(credObj)) {
|
|
267
|
-
this.logger.trace(
|
|
268
|
-
"BrowserCacheManager:createKeyMaps - accessToken found, saving key to token key map"
|
|
269
|
-
);
|
|
270
|
-
this.logger.tracePii(
|
|
271
|
-
`BrowserCacheManager:createKeyMaps - accessToken with key: ${key} found, saving key to token key map`
|
|
272
|
-
);
|
|
273
|
-
const accessTokenEntity =
|
|
274
|
-
credObj as AccessTokenEntity;
|
|
275
|
-
const newKey =
|
|
276
|
-
this.updateCredentialCacheKey(
|
|
277
|
-
key,
|
|
278
|
-
accessTokenEntity
|
|
279
|
-
);
|
|
280
|
-
this.addTokenKey(
|
|
281
|
-
newKey,
|
|
282
|
-
CredentialType.ACCESS_TOKEN
|
|
283
|
-
);
|
|
284
|
-
return;
|
|
285
|
-
} else {
|
|
286
|
-
this.logger.trace(
|
|
287
|
-
"BrowserCacheManager:createKeyMaps - key found matching accessToken schema with value containing accessToken credentialType field but value failed AccessTokenEntity validation, skipping."
|
|
288
|
-
);
|
|
289
|
-
this.logger.tracePii(
|
|
290
|
-
`BrowserCacheManager:createKeyMaps - failed accessToken validation on key: ${key}`
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
break;
|
|
294
|
-
case CredentialType.REFRESH_TOKEN:
|
|
295
|
-
if (
|
|
296
|
-
CacheHelpers.isRefreshTokenEntity(credObj)
|
|
297
|
-
) {
|
|
298
|
-
this.logger.trace(
|
|
299
|
-
"BrowserCacheManager:createKeyMaps - refreshToken found, saving key to token key map"
|
|
300
|
-
);
|
|
301
|
-
this.logger.tracePii(
|
|
302
|
-
`BrowserCacheManager:createKeyMaps - refreshToken with key: ${key} found, saving key to token key map`
|
|
303
|
-
);
|
|
304
|
-
const refreshTokenEntity =
|
|
305
|
-
credObj as RefreshTokenEntity;
|
|
306
|
-
const newKey =
|
|
307
|
-
this.updateCredentialCacheKey(
|
|
308
|
-
key,
|
|
309
|
-
refreshTokenEntity
|
|
310
|
-
);
|
|
311
|
-
this.addTokenKey(
|
|
312
|
-
newKey,
|
|
313
|
-
CredentialType.REFRESH_TOKEN
|
|
314
|
-
);
|
|
315
|
-
return;
|
|
316
|
-
} else {
|
|
317
|
-
this.logger.trace(
|
|
318
|
-
"BrowserCacheManager:createKeyMaps - key found matching refreshToken schema with value containing refreshToken credentialType field but value failed RefreshTokenEntity validation, skipping."
|
|
319
|
-
);
|
|
320
|
-
this.logger.tracePii(
|
|
321
|
-
`BrowserCacheManager:createKeyMaps - failed refreshToken validation on key: ${key}`
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
break;
|
|
325
|
-
default:
|
|
326
|
-
// If credentialType isn't one of our predefined ones, it may not be an MSAL cache value. Ignore.
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (this.isAccountKey(key)) {
|
|
333
|
-
const value = this.getItem(key);
|
|
334
|
-
if (value) {
|
|
335
|
-
const accountObj = this.validateAndParseJson(value);
|
|
336
|
-
if (
|
|
337
|
-
accountObj &&
|
|
338
|
-
AccountEntity.isAccountEntity(accountObj)
|
|
339
|
-
) {
|
|
340
|
-
this.logger.trace(
|
|
341
|
-
"BrowserCacheManager:createKeyMaps - account found, saving key to account key map"
|
|
342
|
-
);
|
|
343
|
-
this.logger.tracePii(
|
|
344
|
-
`BrowserCacheManager:createKeyMaps - account with key: ${key} found, saving key to account key map`
|
|
345
|
-
);
|
|
346
|
-
this.addAccountKeyToMap(key);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
|
|
353
141
|
/**
|
|
354
142
|
* Parses passed value as JSON object, JSON.parse() will throw an error.
|
|
355
143
|
* @param input
|
|
@@ -371,46 +159,15 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
371
159
|
}
|
|
372
160
|
}
|
|
373
161
|
|
|
374
|
-
/**
|
|
375
|
-
* fetches the entry from the browser storage based off the key
|
|
376
|
-
* @param key
|
|
377
|
-
*/
|
|
378
|
-
getItem(key: string): string | null {
|
|
379
|
-
return this.browserStorage.getItem(key);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* sets the entry in the browser storage
|
|
384
|
-
* @param key
|
|
385
|
-
* @param value
|
|
386
|
-
*/
|
|
387
|
-
setItem(key: string, value: string): void {
|
|
388
|
-
this.browserStorage.setItem(key, value);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* fetch the account entity from the platform cache
|
|
393
|
-
* @param accountKey
|
|
394
|
-
*/
|
|
395
|
-
getAccount(accountKey: string, logger?: Logger): AccountEntity | null {
|
|
396
|
-
this.logger.trace("BrowserCacheManager.getAccount called");
|
|
397
|
-
const accountEntity = this.getCachedAccountEntity(accountKey);
|
|
398
|
-
|
|
399
|
-
return this.updateOutdatedCachedAccount(
|
|
400
|
-
accountKey,
|
|
401
|
-
accountEntity,
|
|
402
|
-
logger
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
162
|
/**
|
|
407
163
|
* Reads account from cache, deserializes it into an account entity and returns it.
|
|
408
164
|
* If account is not found from the key, returns null and removes key from map.
|
|
409
165
|
* @param accountKey
|
|
410
166
|
* @returns
|
|
411
167
|
*/
|
|
412
|
-
|
|
413
|
-
|
|
168
|
+
getAccount(accountKey: string): AccountEntity | null {
|
|
169
|
+
this.logger.trace("BrowserCacheManager.getAccount called");
|
|
170
|
+
const serializedAccount = this.browserStorage.getUserData(accountKey);
|
|
414
171
|
if (!serializedAccount) {
|
|
415
172
|
this.removeAccountKeyFromMap(accountKey);
|
|
416
173
|
return null;
|
|
@@ -432,10 +189,10 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
432
189
|
* set account entity in the platform cache
|
|
433
190
|
* @param account
|
|
434
191
|
*/
|
|
435
|
-
setAccount(account: AccountEntity): void {
|
|
192
|
+
async setAccount(account: AccountEntity): Promise<void> {
|
|
436
193
|
this.logger.trace("BrowserCacheManager.setAccount called");
|
|
437
194
|
const key = account.generateAccountKey();
|
|
438
|
-
this.
|
|
195
|
+
await this.browserStorage.setUserData(key, JSON.stringify(account));
|
|
439
196
|
this.addAccountKeyToMap(key);
|
|
440
197
|
}
|
|
441
198
|
|
|
@@ -444,16 +201,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
444
201
|
* @returns
|
|
445
202
|
*/
|
|
446
203
|
getAccountKeys(): Array<string> {
|
|
447
|
-
this.
|
|
448
|
-
const accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
|
|
449
|
-
if (accountKeys) {
|
|
450
|
-
return JSON.parse(accountKeys);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
this.logger.verbose(
|
|
454
|
-
"BrowserCacheManager.getAccountKeys - No account keys found"
|
|
455
|
-
);
|
|
456
|
-
return [];
|
|
204
|
+
return getAccountKeys(this.browserStorage);
|
|
457
205
|
}
|
|
458
206
|
|
|
459
207
|
/**
|
|
@@ -469,7 +217,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
469
217
|
if (accountKeys.indexOf(key) === -1) {
|
|
470
218
|
// Only add key if it does not already exist in the map
|
|
471
219
|
accountKeys.push(key);
|
|
472
|
-
this.setItem(
|
|
220
|
+
this.browserStorage.setItem(
|
|
473
221
|
StaticCacheKeys.ACCOUNT_KEYS,
|
|
474
222
|
JSON.stringify(accountKeys)
|
|
475
223
|
);
|
|
@@ -496,7 +244,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
496
244
|
const removalIndex = accountKeys.indexOf(key);
|
|
497
245
|
if (removalIndex > -1) {
|
|
498
246
|
accountKeys.splice(removalIndex, 1);
|
|
499
|
-
this.setItem(
|
|
247
|
+
this.browserStorage.setItem(
|
|
500
248
|
StaticCacheKeys.ACCOUNT_KEYS,
|
|
501
249
|
JSON.stringify(accountKeys)
|
|
502
250
|
);
|
|
@@ -519,15 +267,6 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
519
267
|
this.removeAccountKeyFromMap(key);
|
|
520
268
|
}
|
|
521
269
|
|
|
522
|
-
/**
|
|
523
|
-
* Remove account entity from the platform cache if it's outdated
|
|
524
|
-
* @param accountKey
|
|
525
|
-
*/
|
|
526
|
-
removeOutdatedAccount(accountKey: string): void {
|
|
527
|
-
this.removeItem(accountKey);
|
|
528
|
-
this.removeAccountKeyFromMap(accountKey);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
270
|
/**
|
|
532
271
|
* Removes given idToken from the cache and from the key map
|
|
533
272
|
* @param key
|
|
@@ -560,35 +299,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
560
299
|
* @returns
|
|
561
300
|
*/
|
|
562
301
|
getTokenKeys(): TokenKeys {
|
|
563
|
-
this.
|
|
564
|
-
const item = this.getItem(
|
|
565
|
-
`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`
|
|
566
|
-
);
|
|
567
|
-
if (item) {
|
|
568
|
-
const tokenKeys = this.validateAndParseJson(item);
|
|
569
|
-
if (
|
|
570
|
-
tokenKeys &&
|
|
571
|
-
tokenKeys.hasOwnProperty("idToken") &&
|
|
572
|
-
tokenKeys.hasOwnProperty("accessToken") &&
|
|
573
|
-
tokenKeys.hasOwnProperty("refreshToken")
|
|
574
|
-
) {
|
|
575
|
-
return tokenKeys as TokenKeys;
|
|
576
|
-
} else {
|
|
577
|
-
this.logger.error(
|
|
578
|
-
"BrowserCacheManager.getTokenKeys - Token keys found but in an unknown format. Returning empty key map."
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
} else {
|
|
582
|
-
this.logger.verbose(
|
|
583
|
-
"BrowserCacheManager.getTokenKeys - No token keys found"
|
|
584
|
-
);
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
return {
|
|
588
|
-
idToken: [],
|
|
589
|
-
accessToken: [],
|
|
590
|
-
refreshToken: [],
|
|
591
|
-
};
|
|
302
|
+
return getTokenKeys(this.clientId, this.browserStorage);
|
|
592
303
|
}
|
|
593
304
|
|
|
594
305
|
/**
|
|
@@ -634,7 +345,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
634
345
|
);
|
|
635
346
|
}
|
|
636
347
|
|
|
637
|
-
this.setItem(
|
|
348
|
+
this.browserStorage.setItem(
|
|
638
349
|
`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`,
|
|
639
350
|
JSON.stringify(tokenKeys)
|
|
640
351
|
);
|
|
@@ -707,7 +418,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
707
418
|
);
|
|
708
419
|
}
|
|
709
420
|
|
|
710
|
-
this.setItem(
|
|
421
|
+
this.browserStorage.setItem(
|
|
711
422
|
`${StaticCacheKeys.TOKEN_KEYS}.${this.clientId}`,
|
|
712
423
|
JSON.stringify(tokenKeys)
|
|
713
424
|
);
|
|
@@ -718,7 +429,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
718
429
|
* @param idTokenKey
|
|
719
430
|
*/
|
|
720
431
|
getIdTokenCredential(idTokenKey: string): IdTokenEntity | null {
|
|
721
|
-
const value = this.
|
|
432
|
+
const value = this.browserStorage.getUserData(idTokenKey);
|
|
722
433
|
if (!value) {
|
|
723
434
|
this.logger.trace(
|
|
724
435
|
"BrowserCacheManager.getIdTokenCredential: called, no cache hit"
|
|
@@ -746,11 +457,14 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
746
457
|
* set IdToken credential to the platform cache
|
|
747
458
|
* @param idToken
|
|
748
459
|
*/
|
|
749
|
-
setIdTokenCredential(idToken: IdTokenEntity): void {
|
|
460
|
+
async setIdTokenCredential(idToken: IdTokenEntity): Promise<void> {
|
|
750
461
|
this.logger.trace("BrowserCacheManager.setIdTokenCredential called");
|
|
751
462
|
const idTokenKey = CacheHelpers.generateCredentialKey(idToken);
|
|
752
463
|
|
|
753
|
-
this.
|
|
464
|
+
await this.browserStorage.setUserData(
|
|
465
|
+
idTokenKey,
|
|
466
|
+
JSON.stringify(idToken)
|
|
467
|
+
);
|
|
754
468
|
|
|
755
469
|
this.addTokenKey(idTokenKey, CredentialType.ID_TOKEN);
|
|
756
470
|
}
|
|
@@ -760,7 +474,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
760
474
|
* @param key
|
|
761
475
|
*/
|
|
762
476
|
getAccessTokenCredential(accessTokenKey: string): AccessTokenEntity | null {
|
|
763
|
-
const value = this.
|
|
477
|
+
const value = this.browserStorage.getUserData(accessTokenKey);
|
|
764
478
|
if (!value) {
|
|
765
479
|
this.logger.trace(
|
|
766
480
|
"BrowserCacheManager.getAccessTokenCredential: called, no cache hit"
|
|
@@ -790,12 +504,17 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
790
504
|
* set accessToken credential to the platform cache
|
|
791
505
|
* @param accessToken
|
|
792
506
|
*/
|
|
793
|
-
setAccessTokenCredential(
|
|
507
|
+
async setAccessTokenCredential(
|
|
508
|
+
accessToken: AccessTokenEntity
|
|
509
|
+
): Promise<void> {
|
|
794
510
|
this.logger.trace(
|
|
795
511
|
"BrowserCacheManager.setAccessTokenCredential called"
|
|
796
512
|
);
|
|
797
513
|
const accessTokenKey = CacheHelpers.generateCredentialKey(accessToken);
|
|
798
|
-
this.
|
|
514
|
+
await this.browserStorage.setUserData(
|
|
515
|
+
accessTokenKey,
|
|
516
|
+
JSON.stringify(accessToken)
|
|
517
|
+
);
|
|
799
518
|
|
|
800
519
|
this.addTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
|
|
801
520
|
}
|
|
@@ -807,7 +526,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
807
526
|
getRefreshTokenCredential(
|
|
808
527
|
refreshTokenKey: string
|
|
809
528
|
): RefreshTokenEntity | null {
|
|
810
|
-
const value = this.
|
|
529
|
+
const value = this.browserStorage.getUserData(refreshTokenKey);
|
|
811
530
|
if (!value) {
|
|
812
531
|
this.logger.trace(
|
|
813
532
|
"BrowserCacheManager.getRefreshTokenCredential: called, no cache hit"
|
|
@@ -837,13 +556,18 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
837
556
|
* set refreshToken credential to the platform cache
|
|
838
557
|
* @param refreshToken
|
|
839
558
|
*/
|
|
840
|
-
setRefreshTokenCredential(
|
|
559
|
+
async setRefreshTokenCredential(
|
|
560
|
+
refreshToken: RefreshTokenEntity
|
|
561
|
+
): Promise<void> {
|
|
841
562
|
this.logger.trace(
|
|
842
563
|
"BrowserCacheManager.setRefreshTokenCredential called"
|
|
843
564
|
);
|
|
844
565
|
const refreshTokenKey =
|
|
845
566
|
CacheHelpers.generateCredentialKey(refreshToken);
|
|
846
|
-
this.
|
|
567
|
+
await this.browserStorage.setUserData(
|
|
568
|
+
refreshTokenKey,
|
|
569
|
+
JSON.stringify(refreshToken)
|
|
570
|
+
);
|
|
847
571
|
|
|
848
572
|
this.addTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
|
|
849
573
|
}
|
|
@@ -853,7 +577,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
853
577
|
* @param appMetadataKey
|
|
854
578
|
*/
|
|
855
579
|
getAppMetadata(appMetadataKey: string): AppMetadataEntity | null {
|
|
856
|
-
const value = this.getItem(appMetadataKey);
|
|
580
|
+
const value = this.browserStorage.getItem(appMetadataKey);
|
|
857
581
|
if (!value) {
|
|
858
582
|
this.logger.trace(
|
|
859
583
|
"BrowserCacheManager.getAppMetadata: called, no cache hit"
|
|
@@ -883,7 +607,10 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
883
607
|
setAppMetadata(appMetadata: AppMetadataEntity): void {
|
|
884
608
|
this.logger.trace("BrowserCacheManager.setAppMetadata called");
|
|
885
609
|
const appMetadataKey = CacheHelpers.generateAppMetadataKey(appMetadata);
|
|
886
|
-
this.setItem(
|
|
610
|
+
this.browserStorage.setItem(
|
|
611
|
+
appMetadataKey,
|
|
612
|
+
JSON.stringify(appMetadata)
|
|
613
|
+
);
|
|
887
614
|
}
|
|
888
615
|
|
|
889
616
|
/**
|
|
@@ -893,7 +620,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
893
620
|
getServerTelemetry(
|
|
894
621
|
serverTelemetryKey: string
|
|
895
622
|
): ServerTelemetryEntity | null {
|
|
896
|
-
const value = this.getItem(serverTelemetryKey);
|
|
623
|
+
const value = this.browserStorage.getItem(serverTelemetryKey);
|
|
897
624
|
if (!value) {
|
|
898
625
|
this.logger.trace(
|
|
899
626
|
"BrowserCacheManager.getServerTelemetry: called, no cache hit"
|
|
@@ -928,7 +655,10 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
928
655
|
serverTelemetry: ServerTelemetryEntity
|
|
929
656
|
): void {
|
|
930
657
|
this.logger.trace("BrowserCacheManager.setServerTelemetry called");
|
|
931
|
-
this.setItem(
|
|
658
|
+
this.browserStorage.setItem(
|
|
659
|
+
serverTelemetryKey,
|
|
660
|
+
JSON.stringify(serverTelemetry)
|
|
661
|
+
);
|
|
932
662
|
}
|
|
933
663
|
|
|
934
664
|
/**
|
|
@@ -1007,35 +737,13 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1007
737
|
const activeAccountKeyFilters = this.generateCacheKey(
|
|
1008
738
|
PersistentCacheKeys.ACTIVE_ACCOUNT_FILTERS
|
|
1009
739
|
);
|
|
1010
|
-
const activeAccountValueFilters = this.getItem(
|
|
740
|
+
const activeAccountValueFilters = this.browserStorage.getItem(
|
|
741
|
+
activeAccountKeyFilters
|
|
742
|
+
);
|
|
1011
743
|
if (!activeAccountValueFilters) {
|
|
1012
|
-
// if new active account cache type isn't found, it's an old version, so look for that instead
|
|
1013
744
|
this.logger.trace(
|
|
1014
|
-
"BrowserCacheManager.getActiveAccount: No active account filters
|
|
1015
|
-
);
|
|
1016
|
-
const activeAccountKeyLocal = this.generateCacheKey(
|
|
1017
|
-
PersistentCacheKeys.ACTIVE_ACCOUNT
|
|
745
|
+
"BrowserCacheManager.getActiveAccount: No active account filters found"
|
|
1018
746
|
);
|
|
1019
|
-
const activeAccountValueLocal = this.getItem(activeAccountKeyLocal);
|
|
1020
|
-
if (!activeAccountValueLocal) {
|
|
1021
|
-
this.logger.trace(
|
|
1022
|
-
"BrowserCacheManager.getActiveAccount: No active account found"
|
|
1023
|
-
);
|
|
1024
|
-
return null;
|
|
1025
|
-
}
|
|
1026
|
-
const activeAccount = this.getAccountInfoFilteredBy({
|
|
1027
|
-
localAccountId: activeAccountValueLocal,
|
|
1028
|
-
});
|
|
1029
|
-
if (activeAccount) {
|
|
1030
|
-
this.logger.trace(
|
|
1031
|
-
"BrowserCacheManager.getActiveAccount: Legacy active account cache schema found"
|
|
1032
|
-
);
|
|
1033
|
-
this.logger.trace(
|
|
1034
|
-
"BrowserCacheManager.getActiveAccount: Adding active account filters cache schema"
|
|
1035
|
-
);
|
|
1036
|
-
this.setActiveAccount(activeAccount);
|
|
1037
|
-
return activeAccount;
|
|
1038
|
-
}
|
|
1039
747
|
return null;
|
|
1040
748
|
}
|
|
1041
749
|
const activeAccountValueObj = this.validateAndParseJson(
|
|
@@ -1065,9 +773,6 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1065
773
|
const activeAccountKey = this.generateCacheKey(
|
|
1066
774
|
PersistentCacheKeys.ACTIVE_ACCOUNT_FILTERS
|
|
1067
775
|
);
|
|
1068
|
-
const activeAccountKeyLocal = this.generateCacheKey(
|
|
1069
|
-
PersistentCacheKeys.ACTIVE_ACCOUNT
|
|
1070
|
-
);
|
|
1071
776
|
if (account) {
|
|
1072
777
|
this.logger.verbose("setActiveAccount: Active account set");
|
|
1073
778
|
const activeAccountValue: ActiveAccountFilters = {
|
|
@@ -1079,16 +784,11 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1079
784
|
activeAccountKey,
|
|
1080
785
|
JSON.stringify(activeAccountValue)
|
|
1081
786
|
);
|
|
1082
|
-
this.browserStorage.setItem(
|
|
1083
|
-
activeAccountKeyLocal,
|
|
1084
|
-
account.localAccountId
|
|
1085
|
-
);
|
|
1086
787
|
} else {
|
|
1087
788
|
this.logger.verbose(
|
|
1088
789
|
"setActiveAccount: No account passed, active account not set"
|
|
1089
790
|
);
|
|
1090
791
|
this.browserStorage.removeItem(activeAccountKey);
|
|
1091
|
-
this.browserStorage.removeItem(activeAccountKeyLocal);
|
|
1092
792
|
}
|
|
1093
793
|
}
|
|
1094
794
|
|
|
@@ -1097,7 +797,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1097
797
|
* @param throttlingCacheKey
|
|
1098
798
|
*/
|
|
1099
799
|
getThrottlingCache(throttlingCacheKey: string): ThrottlingEntity | null {
|
|
1100
|
-
const value = this.getItem(throttlingCacheKey);
|
|
800
|
+
const value = this.browserStorage.getItem(throttlingCacheKey);
|
|
1101
801
|
if (!value) {
|
|
1102
802
|
this.logger.trace(
|
|
1103
803
|
"BrowserCacheManager.getThrottlingCache: called, no cache hit"
|
|
@@ -1133,7 +833,10 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1133
833
|
throttlingCache: ThrottlingEntity
|
|
1134
834
|
): void {
|
|
1135
835
|
this.logger.trace("BrowserCacheManager.setThrottlingCache called");
|
|
1136
|
-
this.setItem(
|
|
836
|
+
this.browserStorage.setItem(
|
|
837
|
+
throttlingCacheKey,
|
|
838
|
+
JSON.stringify(throttlingCache)
|
|
839
|
+
);
|
|
1137
840
|
}
|
|
1138
841
|
|
|
1139
842
|
/**
|
|
@@ -1144,7 +847,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1144
847
|
getTemporaryCache(cacheKey: string, generateKey?: boolean): string | null {
|
|
1145
848
|
const key = generateKey ? this.generateCacheKey(cacheKey) : cacheKey;
|
|
1146
849
|
if (this.cacheConfig.storeAuthStateInCookie) {
|
|
1147
|
-
const itemCookie = this.
|
|
850
|
+
const itemCookie = this.cookieStorage.getItem(key);
|
|
1148
851
|
if (itemCookie) {
|
|
1149
852
|
this.logger.trace(
|
|
1150
853
|
"BrowserCacheManager.getTemporaryCache: storeAuthStateInCookies set to true, retrieving from cookies"
|
|
@@ -1198,7 +901,12 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1198
901
|
this.logger.trace(
|
|
1199
902
|
"BrowserCacheManager.setTemporaryCache: storeAuthStateInCookie set to true, setting item cookie"
|
|
1200
903
|
);
|
|
1201
|
-
this.
|
|
904
|
+
this.cookieStorage.setItem(
|
|
905
|
+
key,
|
|
906
|
+
value,
|
|
907
|
+
undefined,
|
|
908
|
+
this.cacheConfig.secureCookies
|
|
909
|
+
);
|
|
1202
910
|
}
|
|
1203
911
|
}
|
|
1204
912
|
|
|
@@ -1221,7 +929,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1221
929
|
this.logger.trace(
|
|
1222
930
|
"BrowserCacheManager.removeItem: storeAuthStateInCookie is true, clearing item cookie"
|
|
1223
931
|
);
|
|
1224
|
-
this.
|
|
932
|
+
this.cookieStorage.removeItem(key);
|
|
1225
933
|
}
|
|
1226
934
|
}
|
|
1227
935
|
|
|
@@ -1301,96 +1009,6 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1301
1009
|
}
|
|
1302
1010
|
}
|
|
1303
1011
|
|
|
1304
|
-
/**
|
|
1305
|
-
* Add value to cookies
|
|
1306
|
-
* @param cookieName
|
|
1307
|
-
* @param cookieValue
|
|
1308
|
-
* @param expires
|
|
1309
|
-
* @deprecated
|
|
1310
|
-
*/
|
|
1311
|
-
setItemCookie(
|
|
1312
|
-
cookieName: string,
|
|
1313
|
-
cookieValue: string,
|
|
1314
|
-
expires?: number
|
|
1315
|
-
): void {
|
|
1316
|
-
let cookieStr = `${encodeURIComponent(cookieName)}=${encodeURIComponent(
|
|
1317
|
-
cookieValue
|
|
1318
|
-
)};path=/;SameSite=Lax;`;
|
|
1319
|
-
if (expires) {
|
|
1320
|
-
const expireTime = this.getCookieExpirationTime(expires);
|
|
1321
|
-
cookieStr += `expires=${expireTime};`;
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
if (this.cacheConfig.secureCookies) {
|
|
1325
|
-
cookieStr += "Secure;";
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
document.cookie = cookieStr;
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
/**
|
|
1332
|
-
* Get one item by key from cookies
|
|
1333
|
-
* @param cookieName
|
|
1334
|
-
* @deprecated
|
|
1335
|
-
*/
|
|
1336
|
-
getItemCookie(cookieName: string): string {
|
|
1337
|
-
const name = `${encodeURIComponent(cookieName)}=`;
|
|
1338
|
-
const cookieList = document.cookie.split(";");
|
|
1339
|
-
for (let i: number = 0; i < cookieList.length; i++) {
|
|
1340
|
-
let cookie = cookieList[i];
|
|
1341
|
-
while (cookie.charAt(0) === " ") {
|
|
1342
|
-
cookie = cookie.substring(1);
|
|
1343
|
-
}
|
|
1344
|
-
if (cookie.indexOf(name) === 0) {
|
|
1345
|
-
return decodeURIComponent(
|
|
1346
|
-
cookie.substring(name.length, cookie.length)
|
|
1347
|
-
);
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
return Constants.EMPTY_STRING;
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
/**
|
|
1354
|
-
* Clear all msal-related cookies currently set in the browser. Should only be used to clear temporary cache items.
|
|
1355
|
-
* @deprecated
|
|
1356
|
-
*/
|
|
1357
|
-
clearMsalCookies(): void {
|
|
1358
|
-
const cookiePrefix = `${Constants.CACHE_PREFIX}.${this.clientId}`;
|
|
1359
|
-
const cookieList = document.cookie.split(";");
|
|
1360
|
-
cookieList.forEach((cookie: string): void => {
|
|
1361
|
-
while (cookie.charAt(0) === " ") {
|
|
1362
|
-
// eslint-disable-next-line no-param-reassign
|
|
1363
|
-
cookie = cookie.substring(1);
|
|
1364
|
-
}
|
|
1365
|
-
if (cookie.indexOf(cookiePrefix) === 0) {
|
|
1366
|
-
const cookieKey = cookie.split("=")[0];
|
|
1367
|
-
this.clearItemCookie(cookieKey);
|
|
1368
|
-
}
|
|
1369
|
-
});
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
/**
|
|
1373
|
-
* Clear an item in the cookies by key
|
|
1374
|
-
* @param cookieName
|
|
1375
|
-
* @deprecated
|
|
1376
|
-
*/
|
|
1377
|
-
clearItemCookie(cookieName: string): void {
|
|
1378
|
-
this.setItemCookie(cookieName, Constants.EMPTY_STRING, -1);
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
/**
|
|
1382
|
-
* Get cookie expiration time
|
|
1383
|
-
* @param cookieLifeDays
|
|
1384
|
-
* @deprecated
|
|
1385
|
-
*/
|
|
1386
|
-
getCookieExpirationTime(cookieLifeDays: number): string {
|
|
1387
|
-
const today = new Date();
|
|
1388
|
-
const expr = new Date(
|
|
1389
|
-
today.getTime() + cookieLifeDays * this.COOKIE_LIFE_MULTIPLIER
|
|
1390
|
-
);
|
|
1391
|
-
return expr.toUTCString();
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
1012
|
/**
|
|
1395
1013
|
* 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)
|
|
1396
1014
|
* @param key
|
|
@@ -1399,10 +1017,7 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1399
1017
|
generateCacheKey(key: string): string {
|
|
1400
1018
|
const generatedKey = this.validateAndParseJson(key);
|
|
1401
1019
|
if (!generatedKey) {
|
|
1402
|
-
if (
|
|
1403
|
-
StringUtils.startsWith(key, Constants.CACHE_PREFIX) ||
|
|
1404
|
-
StringUtils.startsWith(key, PersistentCacheKeys.ADAL_ID_TOKEN)
|
|
1405
|
-
) {
|
|
1020
|
+
if (StringUtils.startsWith(key, Constants.CACHE_PREFIX)) {
|
|
1406
1021
|
return key;
|
|
1407
1022
|
}
|
|
1408
1023
|
return `${Constants.CACHE_PREFIX}.${this.clientId}.${key}`;
|
|
@@ -1570,7 +1185,6 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1570
1185
|
);
|
|
1571
1186
|
this.resetRequestCache(cachedState || Constants.EMPTY_STRING);
|
|
1572
1187
|
}
|
|
1573
|
-
this.clearMsalCookies();
|
|
1574
1188
|
}
|
|
1575
1189
|
|
|
1576
1190
|
/**
|
|
@@ -1609,7 +1223,6 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1609
1223
|
this.resetRequestCache(stateValue);
|
|
1610
1224
|
}
|
|
1611
1225
|
});
|
|
1612
|
-
this.clearMsalCookies();
|
|
1613
1226
|
this.setInteractionInProgress(false);
|
|
1614
1227
|
}
|
|
1615
1228
|
|
|
@@ -1735,86 +1348,6 @@ export class BrowserCacheManager extends CacheManager {
|
|
|
1735
1348
|
}
|
|
1736
1349
|
}
|
|
1737
1350
|
|
|
1738
|
-
/**
|
|
1739
|
-
* Returns username retrieved from ADAL or MSAL v1 idToken
|
|
1740
|
-
* @deprecated
|
|
1741
|
-
*/
|
|
1742
|
-
getLegacyLoginHint(): string | null {
|
|
1743
|
-
// Only check for adal/msal token if no SSO params are being used
|
|
1744
|
-
const adalIdTokenString = this.getTemporaryCache(
|
|
1745
|
-
PersistentCacheKeys.ADAL_ID_TOKEN
|
|
1746
|
-
);
|
|
1747
|
-
if (adalIdTokenString) {
|
|
1748
|
-
this.browserStorage.removeItem(PersistentCacheKeys.ADAL_ID_TOKEN);
|
|
1749
|
-
this.logger.verbose("Cached ADAL id token retrieved.");
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
// Check for cached MSAL v1 id token
|
|
1753
|
-
const msalIdTokenString = this.getTemporaryCache(
|
|
1754
|
-
PersistentCacheKeys.ID_TOKEN,
|
|
1755
|
-
true
|
|
1756
|
-
);
|
|
1757
|
-
if (msalIdTokenString) {
|
|
1758
|
-
this.browserStorage.removeItem(
|
|
1759
|
-
this.generateCacheKey(PersistentCacheKeys.ID_TOKEN)
|
|
1760
|
-
);
|
|
1761
|
-
this.logger.verbose("Cached MSAL.js v1 id token retrieved");
|
|
1762
|
-
}
|
|
1763
|
-
|
|
1764
|
-
const cachedIdTokenString = msalIdTokenString || adalIdTokenString;
|
|
1765
|
-
if (cachedIdTokenString) {
|
|
1766
|
-
const idTokenClaims = AuthToken.extractTokenClaims(
|
|
1767
|
-
cachedIdTokenString,
|
|
1768
|
-
base64Decode
|
|
1769
|
-
);
|
|
1770
|
-
if (idTokenClaims.preferred_username) {
|
|
1771
|
-
this.logger.verbose(
|
|
1772
|
-
"No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 preferred_username as loginHint"
|
|
1773
|
-
);
|
|
1774
|
-
return idTokenClaims.preferred_username;
|
|
1775
|
-
} else if (idTokenClaims.upn) {
|
|
1776
|
-
this.logger.verbose(
|
|
1777
|
-
"No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 upn as loginHint"
|
|
1778
|
-
);
|
|
1779
|
-
return idTokenClaims.upn;
|
|
1780
|
-
} else {
|
|
1781
|
-
this.logger.verbose(
|
|
1782
|
-
"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."
|
|
1783
|
-
);
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
return null;
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
/**
|
|
1791
|
-
* Updates a credential's cache key if the current cache key is outdated
|
|
1792
|
-
*/
|
|
1793
|
-
updateCredentialCacheKey(
|
|
1794
|
-
currentCacheKey: string,
|
|
1795
|
-
credential: ValidCredentialType
|
|
1796
|
-
): string {
|
|
1797
|
-
const updatedCacheKey = CacheHelpers.generateCredentialKey(credential);
|
|
1798
|
-
|
|
1799
|
-
if (currentCacheKey !== updatedCacheKey) {
|
|
1800
|
-
const cacheItem = this.getItem(currentCacheKey);
|
|
1801
|
-
if (cacheItem) {
|
|
1802
|
-
this.browserStorage.removeItem(currentCacheKey);
|
|
1803
|
-
this.setItem(updatedCacheKey, cacheItem);
|
|
1804
|
-
this.logger.verbose(
|
|
1805
|
-
`Updated an outdated ${credential.credentialType} cache key`
|
|
1806
|
-
);
|
|
1807
|
-
return updatedCacheKey;
|
|
1808
|
-
} else {
|
|
1809
|
-
this.logger.error(
|
|
1810
|
-
`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`
|
|
1811
|
-
);
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
return currentCacheKey;
|
|
1816
|
-
}
|
|
1817
|
-
|
|
1818
1351
|
/**
|
|
1819
1352
|
* Builds credential entities from AuthenticationResult object and saves the resulting credentials to the cache
|
|
1820
1353
|
* @param result
|