@azure/msal-browser 2.33.0 → 2.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/_virtual/_tslib.js +1 -1
- package/dist/app/ClientApplication.d.ts +2 -2
- package/dist/app/ClientApplication.d.ts.map +1 -1
- package/dist/app/ClientApplication.js +49 -36
- package/dist/app/ClientApplication.js.map +1 -1
- package/dist/app/IPublicClientApplication.js +1 -1
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.js +1 -6
- package/dist/app/PublicClientApplication.js.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +10 -7
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.js +18 -8
- package/dist/broker/nativeBroker/NativeMessageHandler.js.map +1 -1
- package/dist/cache/AsyncMemoryStorage.js +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +60 -2
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.js +310 -9
- package/dist/cache/BrowserCacheManager.js.map +1 -1
- package/dist/cache/BrowserStorage.js +1 -1
- package/dist/cache/CryptoKeyStore.js +1 -1
- package/dist/cache/DatabaseStorage.js +1 -1
- package/dist/cache/MemoryStorage.js +1 -1
- package/dist/cache/TokenCache.js +1 -1
- package/dist/config/Configuration.d.ts +4 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.js +4 -2
- package/dist/config/Configuration.js.map +1 -1
- package/dist/crypto/BrowserCrypto.js +1 -1
- package/dist/crypto/CryptoOps.js +1 -1
- package/dist/crypto/GuidGenerator.js +1 -1
- package/dist/crypto/ModernBrowserCrypto.js +1 -1
- package/dist/crypto/MsBrowserCrypto.js +1 -1
- package/dist/crypto/MsrBrowserCrypto.js +1 -1
- package/dist/crypto/PkceGenerator.js +1 -1
- package/dist/crypto/SignedHttpRequest.js +1 -1
- package/dist/encode/Base64Decode.js +1 -1
- package/dist/encode/Base64Encode.js +1 -1
- package/dist/error/BrowserAuthError.d.ts +8 -0
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.js +11 -1
- package/dist/error/BrowserAuthError.js.map +1 -1
- package/dist/error/BrowserConfigurationAuthError.js +1 -1
- package/dist/error/NativeAuthError.js +1 -1
- package/dist/event/EventHandler.js +1 -1
- package/dist/event/EventMessage.js +1 -1
- package/dist/event/EventType.js +1 -1
- package/dist/index.cjs.js +1388 -816
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/interaction_client/BaseInteractionClient.js +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +1 -1
- package/dist/interaction_client/NativeInteractionClient.d.ts +66 -3
- package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.js +177 -72
- package/dist/interaction_client/NativeInteractionClient.js.map +1 -1
- package/dist/interaction_client/PopupClient.js +1 -1
- package/dist/interaction_client/RedirectClient.js +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.js +1 -1
- package/dist/interaction_client/SilentCacheClient.js +1 -1
- package/dist/interaction_client/SilentIframeClient.js +1 -1
- package/dist/interaction_client/SilentRefreshClient.js +1 -1
- package/dist/interaction_client/StandardInteractionClient.js +1 -1
- package/dist/interaction_handler/InteractionHandler.js +1 -1
- package/dist/interaction_handler/RedirectHandler.js +1 -1
- package/dist/interaction_handler/SilentHandler.js +1 -1
- package/dist/internals.d.ts +3 -0
- package/dist/internals.d.ts.map +1 -1
- package/dist/internals.js +2 -1
- package/dist/internals.js.map +1 -1
- package/dist/navigation/NavigationClient.js +1 -1
- package/dist/network/FetchClient.js +1 -1
- package/dist/network/XhrClient.js +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.js +2 -2
- package/dist/packageMetadata.js.map +1 -1
- package/dist/telemetry/BrowserPerformanceClient.d.ts +5 -3
- package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/BrowserPerformanceClient.js +37 -16
- package/dist/telemetry/BrowserPerformanceClient.js.map +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.d.ts +14 -5
- package/dist/telemetry/BrowserPerformanceMeasurement.d.ts.map +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.js +36 -4
- package/dist/telemetry/BrowserPerformanceMeasurement.js.map +1 -1
- package/dist/utils/BrowserConstants.d.ts +4 -0
- package/dist/utils/BrowserConstants.d.ts.map +1 -1
- package/dist/utils/BrowserConstants.js +7 -2
- package/dist/utils/BrowserConstants.js.map +1 -1
- package/dist/utils/BrowserProtocolUtils.js +1 -1
- package/dist/utils/BrowserStringUtils.js +1 -1
- package/dist/utils/BrowserUtils.js +1 -1
- package/dist/utils/MathUtils.js +1 -1
- package/lib/msal-browser.js +1388 -816
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +38 -40
- package/package.json +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/*! @azure/msal-browser v2.
|
|
1
|
+
/*! @azure/msal-browser v2.35.0 2023-04-03 */
|
|
2
2
|
'use strict';
|
|
3
|
-
import { __extends,
|
|
4
|
-
import {
|
|
3
|
+
import { __extends, __awaiter, __generator, __spread } from '../_virtual/_tslib.js';
|
|
4
|
+
import { CredentialType, RefreshTokenEntity, CacheManager, AccessTokenEntity, IdTokenEntity, AccountEntity, ClientAuthError, AppMetadataEntity, ServerTelemetryEntity, AuthorityMetadataEntity, Constants, PersistentCacheKeys, ThrottlingEntity, StringUtils, ProtocolUtils, CcsCredentialType, IdToken, DEFAULT_CRYPTO_IMPLEMENTATION } from '@azure/msal-common';
|
|
5
5
|
import { BrowserAuthError } from '../error/BrowserAuthError.js';
|
|
6
|
-
import { BrowserCacheLocation, InMemoryCacheKeys, TemporaryCacheKeys } from '../utils/BrowserConstants.js';
|
|
6
|
+
import { BrowserCacheLocation, StaticCacheKeys, InMemoryCacheKeys, TemporaryCacheKeys } from '../utils/BrowserConstants.js';
|
|
7
7
|
import { BrowserStorage } from './BrowserStorage.js';
|
|
8
8
|
import { MemoryStorage } from './MemoryStorage.js';
|
|
9
9
|
import { BrowserProtocolUtils } from '../utils/BrowserProtocolUtils.js';
|
|
@@ -20,7 +20,7 @@ import { BrowserProtocolUtils } from '../utils/BrowserProtocolUtils.js';
|
|
|
20
20
|
var BrowserCacheManager = /** @class */ (function (_super) {
|
|
21
21
|
__extends(BrowserCacheManager, _super);
|
|
22
22
|
function BrowserCacheManager(clientId, cacheConfig, cryptoImpl, logger) {
|
|
23
|
-
var _this = _super.call(this, clientId, cryptoImpl) || this;
|
|
23
|
+
var _this = _super.call(this, clientId, cryptoImpl, logger) || this;
|
|
24
24
|
// Cookie life calculation (hours * minutes * seconds * ms)
|
|
25
25
|
_this.COOKIE_LIFE_MULTIPLIER = 24 * 60 * 60 * 1000;
|
|
26
26
|
_this.cacheConfig = cacheConfig;
|
|
@@ -28,8 +28,11 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
28
28
|
_this.internalStorage = new MemoryStorage();
|
|
29
29
|
_this.browserStorage = _this.setupBrowserStorage(_this.cacheConfig.cacheLocation);
|
|
30
30
|
_this.temporaryCacheStorage = _this.setupTemporaryCacheStorage(_this.cacheConfig.cacheLocation);
|
|
31
|
-
// Migrate
|
|
32
|
-
|
|
31
|
+
// Migrate cache entries from older versions of MSAL.
|
|
32
|
+
if (cacheConfig.cacheMigrationEnabled) {
|
|
33
|
+
_this.migrateCacheEntries();
|
|
34
|
+
_this.createKeyMaps();
|
|
35
|
+
}
|
|
33
36
|
return _this;
|
|
34
37
|
}
|
|
35
38
|
/**
|
|
@@ -102,6 +105,91 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
102
105
|
this.setTemporaryCache(newKey, value, true);
|
|
103
106
|
}
|
|
104
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Searches all cache entries for MSAL accounts and creates the account key map
|
|
110
|
+
* This is used to migrate users from older versions of MSAL which did not create the map.
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
BrowserCacheManager.prototype.createKeyMaps = function () {
|
|
114
|
+
var _this = this;
|
|
115
|
+
this.logger.trace("BrowserCacheManager - createKeyMaps called.");
|
|
116
|
+
var accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
|
|
117
|
+
var tokenKeys = this.getItem(StaticCacheKeys.TOKEN_KEYS + "." + this.clientId);
|
|
118
|
+
if (accountKeys && tokenKeys) {
|
|
119
|
+
this.logger.verbose("BrowserCacheManager:createKeyMaps - account and token key maps already exist, skipping migration.");
|
|
120
|
+
// Key maps already exist, no need to iterate through cache
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
var allKeys = this.browserStorage.getKeys();
|
|
124
|
+
allKeys.forEach(function (key) {
|
|
125
|
+
if (_this.isCredentialKey(key)) {
|
|
126
|
+
// Get item, parse, validate and write key to map
|
|
127
|
+
var value = _this.getItem(key);
|
|
128
|
+
if (value) {
|
|
129
|
+
var credObj = _this.validateAndParseJson(value);
|
|
130
|
+
if (credObj && credObj.hasOwnProperty("credentialType")) {
|
|
131
|
+
switch (credObj["credentialType"]) {
|
|
132
|
+
case CredentialType.ID_TOKEN:
|
|
133
|
+
if (IdTokenEntity.isIdTokenEntity(credObj)) {
|
|
134
|
+
_this.logger.trace("BrowserCacheManager:createKeyMaps - idToken found, saving key to token key map");
|
|
135
|
+
_this.logger.tracePii("BrowserCacheManager:createKeyMaps - idToken with key: " + key + " found, saving key to token key map");
|
|
136
|
+
var idTokenEntity = CacheManager.toObject(new IdTokenEntity(), credObj);
|
|
137
|
+
var newKey = _this.updateCredentialCacheKey(key, idTokenEntity);
|
|
138
|
+
_this.addTokenKey(newKey, CredentialType.ID_TOKEN);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
_this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching idToken schema with value containing idToken credentialType field but value failed IdTokenEntity validation, skipping.");
|
|
143
|
+
_this.logger.tracePii("BrowserCacheManager:createKeyMaps - failed idToken validation on key: " + key);
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
case CredentialType.ACCESS_TOKEN:
|
|
147
|
+
case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
|
|
148
|
+
if (AccessTokenEntity.isAccessTokenEntity(credObj)) {
|
|
149
|
+
_this.logger.trace("BrowserCacheManager:createKeyMaps - accessToken found, saving key to token key map");
|
|
150
|
+
_this.logger.tracePii("BrowserCacheManager:createKeyMaps - accessToken with key: " + key + " found, saving key to token key map");
|
|
151
|
+
var accessTokenEntity = CacheManager.toObject(new AccessTokenEntity(), credObj);
|
|
152
|
+
var newKey = _this.updateCredentialCacheKey(key, accessTokenEntity);
|
|
153
|
+
_this.addTokenKey(newKey, CredentialType.ACCESS_TOKEN);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
_this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching accessToken schema with value containing accessToken credentialType field but value failed AccessTokenEntity validation, skipping.");
|
|
158
|
+
_this.logger.tracePii("BrowserCacheManager:createKeyMaps - failed accessToken validation on key: " + key);
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
case CredentialType.REFRESH_TOKEN:
|
|
162
|
+
if (RefreshTokenEntity.isRefreshTokenEntity(credObj)) {
|
|
163
|
+
_this.logger.trace("BrowserCacheManager:createKeyMaps - refreshToken found, saving key to token key map");
|
|
164
|
+
_this.logger.tracePii("BrowserCacheManager:createKeyMaps - refreshToken with key: " + key + " found, saving key to token key map");
|
|
165
|
+
var refreshTokenEntity = CacheManager.toObject(new RefreshTokenEntity(), credObj);
|
|
166
|
+
var newKey = _this.updateCredentialCacheKey(key, refreshTokenEntity);
|
|
167
|
+
_this.addTokenKey(newKey, CredentialType.REFRESH_TOKEN);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
_this.logger.trace("BrowserCacheManager:createKeyMaps - key found matching refreshToken schema with value containing refreshToken credentialType field but value failed RefreshTokenEntity validation, skipping.");
|
|
172
|
+
_this.logger.tracePii("BrowserCacheManager:createKeyMaps - failed refreshToken validation on key: " + key);
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
// If credentialType isn't one of our predefined ones, it may not be an MSAL cache value. Ignore.
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (_this.isAccountKey(key)) {
|
|
181
|
+
var value = _this.getItem(key);
|
|
182
|
+
if (value) {
|
|
183
|
+
var accountObj = _this.validateAndParseJson(value);
|
|
184
|
+
if (accountObj && AccountEntity.isAccountEntity(accountObj)) {
|
|
185
|
+
_this.logger.trace("BrowserCacheManager:createKeyMaps - account found, saving key to account key map");
|
|
186
|
+
_this.logger.tracePii("BrowserCacheManager:createKeyMaps - account with key: " + key + " found, saving key to account key map");
|
|
187
|
+
_this.addAccountKeyToMap(key);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
};
|
|
105
193
|
/**
|
|
106
194
|
* Parses passed value as JSON object, JSON.parse() will throw an error.
|
|
107
195
|
* @param input
|
|
@@ -141,12 +229,15 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
141
229
|
* @param accountKey
|
|
142
230
|
*/
|
|
143
231
|
BrowserCacheManager.prototype.getAccount = function (accountKey) {
|
|
232
|
+
this.logger.trace("BrowserCacheManager.getAccount called");
|
|
144
233
|
var account = this.getItem(accountKey);
|
|
145
234
|
if (!account) {
|
|
235
|
+
this.removeAccountKeyFromMap(accountKey);
|
|
146
236
|
return null;
|
|
147
237
|
}
|
|
148
238
|
var parsedAccount = this.validateAndParseJson(account);
|
|
149
239
|
if (!parsedAccount || !AccountEntity.isAccountEntity(parsedAccount)) {
|
|
240
|
+
this.removeAccountKeyFromMap(accountKey);
|
|
150
241
|
return null;
|
|
151
242
|
}
|
|
152
243
|
return CacheManager.toObject(new AccountEntity(), parsedAccount);
|
|
@@ -160,6 +251,207 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
160
251
|
this.logger.trace("BrowserCacheManager.setAccount called");
|
|
161
252
|
var key = account.generateAccountKey();
|
|
162
253
|
this.setItem(key, JSON.stringify(account));
|
|
254
|
+
this.addAccountKeyToMap(key);
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Returns the array of account keys currently cached
|
|
258
|
+
* @returns
|
|
259
|
+
*/
|
|
260
|
+
BrowserCacheManager.prototype.getAccountKeys = function () {
|
|
261
|
+
this.logger.trace("BrowserCacheManager.getAccountKeys called");
|
|
262
|
+
var accountKeys = this.getItem(StaticCacheKeys.ACCOUNT_KEYS);
|
|
263
|
+
if (accountKeys) {
|
|
264
|
+
return JSON.parse(accountKeys);
|
|
265
|
+
}
|
|
266
|
+
this.logger.verbose("BrowserCacheManager.getAccountKeys - No account keys found");
|
|
267
|
+
return [];
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Add a new account to the key map
|
|
271
|
+
* @param key
|
|
272
|
+
*/
|
|
273
|
+
BrowserCacheManager.prototype.addAccountKeyToMap = function (key) {
|
|
274
|
+
this.logger.trace("BrowserCacheManager.addAccountKeyToMap called");
|
|
275
|
+
this.logger.tracePii("BrowserCacheManager.addAccountKeyToMap called with key: " + key);
|
|
276
|
+
var accountKeys = this.getAccountKeys();
|
|
277
|
+
if (accountKeys.indexOf(key) === -1) {
|
|
278
|
+
// Only add key if it does not already exist in the map
|
|
279
|
+
accountKeys.push(key);
|
|
280
|
+
this.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
|
|
281
|
+
this.logger.verbose("BrowserCacheManager.addAccountKeyToMap account key added");
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
this.logger.verbose("BrowserCacheManager.addAccountKeyToMap account key already exists in map");
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Remove an account from the key map
|
|
289
|
+
* @param key
|
|
290
|
+
*/
|
|
291
|
+
BrowserCacheManager.prototype.removeAccountKeyFromMap = function (key) {
|
|
292
|
+
this.logger.trace("BrowserCacheManager.removeAccountKeyFromMap called");
|
|
293
|
+
this.logger.tracePii("BrowserCacheManager.removeAccountKeyFromMap called with key: " + key);
|
|
294
|
+
var accountKeys = this.getAccountKeys();
|
|
295
|
+
var removalIndex = accountKeys.indexOf(key);
|
|
296
|
+
if (removalIndex > -1) {
|
|
297
|
+
accountKeys.splice(removalIndex, 1);
|
|
298
|
+
this.setItem(StaticCacheKeys.ACCOUNT_KEYS, JSON.stringify(accountKeys));
|
|
299
|
+
this.logger.trace("BrowserCacheManager.removeAccountKeyFromMap account key removed");
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
this.logger.trace("BrowserCacheManager.removeAccountKeyFromMap key not found in existing map");
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Extends inherited removeAccount function to include removal of the account key from the map
|
|
307
|
+
* @param key
|
|
308
|
+
*/
|
|
309
|
+
BrowserCacheManager.prototype.removeAccount = function (key) {
|
|
310
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
311
|
+
return __generator(this, function (_a) {
|
|
312
|
+
_super.prototype.removeAccount.call(this, key);
|
|
313
|
+
this.removeAccountKeyFromMap(key);
|
|
314
|
+
return [2 /*return*/];
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Removes given idToken from the cache and from the key map
|
|
320
|
+
* @param key
|
|
321
|
+
*/
|
|
322
|
+
BrowserCacheManager.prototype.removeIdToken = function (key) {
|
|
323
|
+
_super.prototype.removeIdToken.call(this, key);
|
|
324
|
+
this.removeTokenKey(key, CredentialType.ID_TOKEN);
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Removes given accessToken from the cache and from the key map
|
|
328
|
+
* @param key
|
|
329
|
+
*/
|
|
330
|
+
BrowserCacheManager.prototype.removeAccessToken = function (key) {
|
|
331
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
+
return __generator(this, function (_a) {
|
|
333
|
+
_super.prototype.removeAccessToken.call(this, key);
|
|
334
|
+
this.removeTokenKey(key, CredentialType.ACCESS_TOKEN);
|
|
335
|
+
return [2 /*return*/];
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Removes given refreshToken from the cache and from the key map
|
|
341
|
+
* @param key
|
|
342
|
+
*/
|
|
343
|
+
BrowserCacheManager.prototype.removeRefreshToken = function (key) {
|
|
344
|
+
_super.prototype.removeRefreshToken.call(this, key);
|
|
345
|
+
this.removeTokenKey(key, CredentialType.REFRESH_TOKEN);
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* Gets the keys for the cached tokens associated with this clientId
|
|
349
|
+
* @returns
|
|
350
|
+
*/
|
|
351
|
+
BrowserCacheManager.prototype.getTokenKeys = function () {
|
|
352
|
+
this.logger.trace("BrowserCacheManager.getTokenKeys called");
|
|
353
|
+
var item = this.getItem(StaticCacheKeys.TOKEN_KEYS + "." + this.clientId);
|
|
354
|
+
if (item) {
|
|
355
|
+
var tokenKeys = this.validateAndParseJson(item);
|
|
356
|
+
if (tokenKeys &&
|
|
357
|
+
tokenKeys.hasOwnProperty("idToken") &&
|
|
358
|
+
tokenKeys.hasOwnProperty("accessToken") &&
|
|
359
|
+
tokenKeys.hasOwnProperty("refreshToken")) {
|
|
360
|
+
return tokenKeys;
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
this.logger.error("BrowserCacheManager.getTokenKeys - Token keys found but in an unknown format. Returning empty key map.");
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
this.logger.verbose("BrowserCacheManager.getTokenKeys - No token keys found");
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
idToken: [],
|
|
371
|
+
accessToken: [],
|
|
372
|
+
refreshToken: []
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Adds the given key to the token key map
|
|
377
|
+
* @param key
|
|
378
|
+
* @param type
|
|
379
|
+
*/
|
|
380
|
+
BrowserCacheManager.prototype.addTokenKey = function (key, type) {
|
|
381
|
+
this.logger.trace("BrowserCacheManager addTokenKey called");
|
|
382
|
+
var tokenKeys = this.getTokenKeys();
|
|
383
|
+
switch (type) {
|
|
384
|
+
case CredentialType.ID_TOKEN:
|
|
385
|
+
if (tokenKeys.idToken.indexOf(key) === -1) {
|
|
386
|
+
this.logger.info("BrowserCacheManager: addTokenKey - idToken added to map");
|
|
387
|
+
tokenKeys.idToken.push(key);
|
|
388
|
+
}
|
|
389
|
+
break;
|
|
390
|
+
case CredentialType.ACCESS_TOKEN:
|
|
391
|
+
if (tokenKeys.accessToken.indexOf(key) === -1) {
|
|
392
|
+
this.logger.info("BrowserCacheManager: addTokenKey - accessToken added to map");
|
|
393
|
+
tokenKeys.accessToken.push(key);
|
|
394
|
+
}
|
|
395
|
+
break;
|
|
396
|
+
case CredentialType.REFRESH_TOKEN:
|
|
397
|
+
if (tokenKeys.refreshToken.indexOf(key) === -1) {
|
|
398
|
+
this.logger.info("BrowserCacheManager: addTokenKey - refreshToken added to map");
|
|
399
|
+
tokenKeys.refreshToken.push(key);
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
default:
|
|
403
|
+
this.logger.error("BrowserCacheManager:addTokenKey - CredentialType provided invalid. CredentialType: " + type);
|
|
404
|
+
ClientAuthError.createUnexpectedCredentialTypeError();
|
|
405
|
+
}
|
|
406
|
+
this.setItem(StaticCacheKeys.TOKEN_KEYS + "." + this.clientId, JSON.stringify(tokenKeys));
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* Removes the given key from the token key map
|
|
410
|
+
* @param key
|
|
411
|
+
* @param type
|
|
412
|
+
*/
|
|
413
|
+
BrowserCacheManager.prototype.removeTokenKey = function (key, type) {
|
|
414
|
+
this.logger.trace("BrowserCacheManager removeTokenKey called");
|
|
415
|
+
var tokenKeys = this.getTokenKeys();
|
|
416
|
+
switch (type) {
|
|
417
|
+
case CredentialType.ID_TOKEN:
|
|
418
|
+
this.logger.infoPii("BrowserCacheManager: removeTokenKey - attempting to remove idToken with key: " + key + " from map");
|
|
419
|
+
var idRemoval = tokenKeys.idToken.indexOf(key);
|
|
420
|
+
if (idRemoval > -1) {
|
|
421
|
+
this.logger.info("BrowserCacheManager: removeTokenKey - idToken removed from map");
|
|
422
|
+
tokenKeys.idToken.splice(idRemoval, 1);
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
this.logger.info("BrowserCacheManager: removeTokenKey - idToken does not exist in map. Either it was previously removed or it was never added.");
|
|
426
|
+
}
|
|
427
|
+
break;
|
|
428
|
+
case CredentialType.ACCESS_TOKEN:
|
|
429
|
+
this.logger.infoPii("BrowserCacheManager: removeTokenKey - attempting to remove accessToken with key: " + key + " from map");
|
|
430
|
+
var accessRemoval = tokenKeys.accessToken.indexOf(key);
|
|
431
|
+
if (accessRemoval > -1) {
|
|
432
|
+
this.logger.info("BrowserCacheManager: removeTokenKey - accessToken removed from map");
|
|
433
|
+
tokenKeys.idToken.splice(accessRemoval, 1);
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
this.logger.info("BrowserCacheManager: removeTokenKey - accessToken does not exist in map. Either it was previously removed or it was never added.");
|
|
437
|
+
}
|
|
438
|
+
break;
|
|
439
|
+
case CredentialType.REFRESH_TOKEN:
|
|
440
|
+
this.logger.infoPii("BrowserCacheManager: removeTokenKey - attempting to remove refreshToken with key: " + key + " from map");
|
|
441
|
+
var refreshRemoval = tokenKeys.refreshToken.indexOf(key);
|
|
442
|
+
if (refreshRemoval > -1) {
|
|
443
|
+
this.logger.info("BrowserCacheManager: removeTokenKey - refreshToken removed from map");
|
|
444
|
+
tokenKeys.idToken.splice(refreshRemoval, 1);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
this.logger.info("BrowserCacheManager: removeTokenKey - refreshToken does not exist in map. Either it was previously removed or it was never added.");
|
|
448
|
+
}
|
|
449
|
+
break;
|
|
450
|
+
default:
|
|
451
|
+
this.logger.error("BrowserCacheManager:removeTokenKey - CredentialType provided invalid. CredentialType: " + type);
|
|
452
|
+
ClientAuthError.createUnexpectedCredentialTypeError();
|
|
453
|
+
}
|
|
454
|
+
this.setItem(StaticCacheKeys.TOKEN_KEYS + "." + this.clientId, JSON.stringify(tokenKeys));
|
|
163
455
|
};
|
|
164
456
|
/**
|
|
165
457
|
* generates idToken entity from a string
|
|
@@ -169,11 +461,13 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
169
461
|
var value = this.getItem(idTokenKey);
|
|
170
462
|
if (!value) {
|
|
171
463
|
this.logger.trace("BrowserCacheManager.getIdTokenCredential: called, no cache hit");
|
|
464
|
+
this.removeTokenKey(idTokenKey, CredentialType.ID_TOKEN);
|
|
172
465
|
return null;
|
|
173
466
|
}
|
|
174
467
|
var parsedIdToken = this.validateAndParseJson(value);
|
|
175
468
|
if (!parsedIdToken || !IdTokenEntity.isIdTokenEntity(parsedIdToken)) {
|
|
176
469
|
this.logger.trace("BrowserCacheManager.getIdTokenCredential: called, no cache hit");
|
|
470
|
+
this.removeTokenKey(idTokenKey, CredentialType.ID_TOKEN);
|
|
177
471
|
return null;
|
|
178
472
|
}
|
|
179
473
|
this.logger.trace("BrowserCacheManager.getIdTokenCredential: cache hit");
|
|
@@ -187,6 +481,7 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
187
481
|
this.logger.trace("BrowserCacheManager.setIdTokenCredential called");
|
|
188
482
|
var idTokenKey = idToken.generateCredentialKey();
|
|
189
483
|
this.setItem(idTokenKey, JSON.stringify(idToken));
|
|
484
|
+
this.addTokenKey(idTokenKey, CredentialType.ID_TOKEN);
|
|
190
485
|
};
|
|
191
486
|
/**
|
|
192
487
|
* generates accessToken entity from a string
|
|
@@ -196,11 +491,13 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
196
491
|
var value = this.getItem(accessTokenKey);
|
|
197
492
|
if (!value) {
|
|
198
493
|
this.logger.trace("BrowserCacheManager.getAccessTokenCredential: called, no cache hit");
|
|
494
|
+
this.removeTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
|
|
199
495
|
return null;
|
|
200
496
|
}
|
|
201
497
|
var parsedAccessToken = this.validateAndParseJson(value);
|
|
202
498
|
if (!parsedAccessToken || !AccessTokenEntity.isAccessTokenEntity(parsedAccessToken)) {
|
|
203
499
|
this.logger.trace("BrowserCacheManager.getAccessTokenCredential: called, no cache hit");
|
|
500
|
+
this.removeTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
|
|
204
501
|
return null;
|
|
205
502
|
}
|
|
206
503
|
this.logger.trace("BrowserCacheManager.getAccessTokenCredential: cache hit");
|
|
@@ -214,6 +511,7 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
214
511
|
this.logger.trace("BrowserCacheManager.setAccessTokenCredential called");
|
|
215
512
|
var accessTokenKey = accessToken.generateCredentialKey();
|
|
216
513
|
this.setItem(accessTokenKey, JSON.stringify(accessToken));
|
|
514
|
+
this.addTokenKey(accessTokenKey, CredentialType.ACCESS_TOKEN);
|
|
217
515
|
};
|
|
218
516
|
/**
|
|
219
517
|
* generates refreshToken entity from a string
|
|
@@ -223,11 +521,13 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
223
521
|
var value = this.getItem(refreshTokenKey);
|
|
224
522
|
if (!value) {
|
|
225
523
|
this.logger.trace("BrowserCacheManager.getRefreshTokenCredential: called, no cache hit");
|
|
524
|
+
this.removeTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
|
|
226
525
|
return null;
|
|
227
526
|
}
|
|
228
527
|
var parsedRefreshToken = this.validateAndParseJson(value);
|
|
229
528
|
if (!parsedRefreshToken || !RefreshTokenEntity.isRefreshTokenEntity(parsedRefreshToken)) {
|
|
230
529
|
this.logger.trace("BrowserCacheManager.getRefreshTokenCredential: called, no cache hit");
|
|
530
|
+
this.removeTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
|
|
231
531
|
return null;
|
|
232
532
|
}
|
|
233
533
|
this.logger.trace("BrowserCacheManager.getRefreshTokenCredential: cache hit");
|
|
@@ -241,6 +541,7 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
241
541
|
this.logger.trace("BrowserCacheManager.setRefreshTokenCredential called");
|
|
242
542
|
var refreshTokenKey = refreshToken.generateCredentialKey();
|
|
243
543
|
this.setItem(refreshTokenKey, JSON.stringify(refreshToken));
|
|
544
|
+
this.addTokenKey(refreshTokenKey, CredentialType.REFRESH_TOKEN);
|
|
244
545
|
};
|
|
245
546
|
/**
|
|
246
547
|
* fetch appMetadata entity from the platform cache
|
|
@@ -538,7 +839,6 @@ var BrowserCacheManager = /** @class */ (function (_super) {
|
|
|
538
839
|
this.logger.trace("BrowserCacheManager.removeItem: storeAuthStateInCookie is true, clearing item cookie");
|
|
539
840
|
this.clearItemCookie(key);
|
|
540
841
|
}
|
|
541
|
-
return true;
|
|
542
842
|
};
|
|
543
843
|
/**
|
|
544
844
|
* Checks whether key is in cache.
|
|
@@ -966,7 +1266,8 @@ var DEFAULT_BROWSER_CACHE_MANAGER = function (clientId, logger) {
|
|
|
966
1266
|
var cacheOptions = {
|
|
967
1267
|
cacheLocation: BrowserCacheLocation.MemoryStorage,
|
|
968
1268
|
storeAuthStateInCookie: false,
|
|
969
|
-
secureCookies: false
|
|
1269
|
+
secureCookies: false,
|
|
1270
|
+
cacheMigrationEnabled: false
|
|
970
1271
|
};
|
|
971
1272
|
return new BrowserCacheManager(clientId, cacheOptions, DEFAULT_CRYPTO_IMPLEMENTATION, logger);
|
|
972
1273
|
};
|