Skip to content

Commit 53efb65

Browse files
jo-arroyotnorling
andauthored
[v5] Changes to Configuration - CacheOptions (Config #2) (#7697)
This PR updates the CacheOptions for MSAL Browser v5, including the removal of implementation, tests, and doc references for the following options: - `temporaryCacheLocation` - `claimsBasedCachingEnabled` - `storeAuthStateInCookie` - `secureCookies` - `cacheMigrationEnabled` Deprecation notices for the above options were added in #7707 --------- Co-authored-by: Thomas Norling <[email protected]>
1 parent 65acd86 commit 53efb65

37 files changed

+207
-1946
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ body:
109109
},
110110
cache: {
111111
cacheLocation: "sessionStorage"
112-
storeAuthStateInCookie: false
113112
}
114113
}
115114
validations:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Configuration changes to CacheOptions #7697",
4+
"packageName": "@azure/msal-browser",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Deprecate claimsBasedCachingEnabled as part of Configuration change #7697",
4+
"packageName": "@azure/msal-common",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

docs/errors.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ This error occurs when MSAL.js surpasses the allotted storage limit when attempt
1717

1818
**Mitigation**:
1919

20-
1. Make sure the configured cache storage has enough capacity to allow MSAL.js to persist token payload. The amount of cache storage required depends on the number of [cached artifacts](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-browser/docs/caching.md#cached-artifacts).
21-
2. Disable [claimsBasedCachingEnabled](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-browser/docs/configuration.md#cache-config-options) cache config option. When enabled, it caches access tokens under a key containing the hash of the requested claims. Depending on the MSAL.js API usage, it may result in the vast number of access tokens persisted in the cache storage.
20+
1. Make sure the configured cache storage has enough capacity to allow MSAL.js to persist token payload. The amount of cache storage required depends on the number of [cached artifacts](./caching.md#cached-artifacts).
2221

2322
### `cache_error_unknown`
2423
- An unknown error occurred while accessing the browser cache.

lib/msal-angular/docs/configuration.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import { PublicClientApplication, InteractionType, BrowserCacheLocation } from "
5858
},
5959
cache: {
6060
cacheLocation: BrowserCacheLocation.LocalStorage,
61-
storeAuthStateInCookie: true, // Deprecated, will be removed in the next major version
6261
},
6362
system: {
6463
loggerOptions: {
@@ -261,7 +260,6 @@ fetch("/assets/configuration.json")
261260
},
262261
"cache": {
263262
"cacheLocation": "localStorage",
264-
"storeAuthStateInCookie": true
265263
}
266264
},
267265
"guard": {
@@ -471,7 +469,6 @@ export class AppModule {}
471469
},
472470
"cache": {
473471
"cacheLocation": "localStorage",
474-
"storeAuthStateInCookie": true
475472
}
476473
},
477474
"guard": {

lib/msal-angular/docs/events.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ import { PublicClientApplication, InteractionType, BrowserCacheLocation } from "
222222
},
223223
cache: {
224224
cacheLocation : BrowserCacheLocation.LocalStorage,
225-
storeAuthStateInCookie: true, // set to true for IE 11
226225
},
227226
system: {
228227
loggerOptions: {

lib/msal-angular/docs/initialization.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { PublicClientApplication, InteractionType, BrowserCacheLocation } from "
3131
},
3232
cache: {
3333
cacheLocation : BrowserCacheLocation.LocalStorage,
34-
storeAuthStateInCookie: true, // Deprecated, will be removed in future version
3534
},
3635
system: {
3736
loggerOptions: {
@@ -115,7 +114,6 @@ import { PublicClientApplication, InteractionType, BrowserCacheLocation } from "
115114
},
116115
cache: {
117116
cacheLocation : BrowserCacheLocation.LocalStorage,
118-
storeAuthStateInCookie: true, // Deprecated, will be removed in future version
119117
},
120118
system: {
121119
loggerOptions: {

lib/msal-browser/apiReview/msal-browser.api.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,6 @@ export type CacheLookupPolicy = (typeof CacheLookupPolicy)[keyof typeof CacheLoo
403403
// @public
404404
export type CacheOptions = {
405405
cacheLocation?: BrowserCacheLocation | string;
406-
temporaryCacheLocation?: BrowserCacheLocation | string;
407-
storeAuthStateInCookie?: boolean;
408-
cacheMigrationEnabled?: boolean;
409-
claimsBasedCachingEnabled?: boolean;
410406
};
411407

412408
// Warning: (ae-missing-release-tag) "ClearCacheRequest" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
@@ -1491,7 +1487,7 @@ export type WrapperSKU = (typeof WrapperSKU)[keyof typeof WrapperSKU];
14911487
// src/cache/LocalStorage.ts:296:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
14921488
// src/cache/LocalStorage.ts:354:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
14931489
// src/cache/LocalStorage.ts:385:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
1494-
// src/config/Configuration.ts:231:5 - (ae-forgotten-export) The symbol "InternalAuthOptions" needs to be exported by the entry point index.d.ts
1490+
// src/config/Configuration.ts:211:5 - (ae-forgotten-export) The symbol "InternalAuthOptions" needs to be exported by the entry point index.d.ts
14951491
// src/event/EventHandler.ts:113:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
14961492
// src/event/EventHandler.ts:139:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
14971493
// src/index.ts:8:12 - (tsdoc-characters-after-block-tag) The token "@azure" looks like a TSDoc tag but contains an invalid character "/"; if it is not a tag, use a backslash to escape the "@"

lib/msal-browser/docs/caching.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,10 @@ To faciliate efficient token acquisition while maintaining a good UX, MSAL cache
6666
- previous failed request
6767
- performance data
6868

69-
> :bulb: Temporary cache entries will always be stored in session storage or in memory unless overridden by the user with the `temporaryCacheLocation` cache option. MSAL will fallback to memory storage if local/session storage is not available. Please read the warning below for more information.
69+
> :bulb: Temporary cache entries will always be stored in session storage or in memory. MSAL will fallback to memory storage if sessionStorage is not available.
7070
7171
> :bulb: The authorization code is only stored in memory and will be discarded after redeeming it for tokens.
7272
73-
## Warning :warning:
74-
75-
**NOTE: `temporaryCacheLocation` is deprecated will be removed in the next major version.**
76-
77-
Overriding `temporaryCacheLocation` should be done with caution. Specifically when choosing `localStorage`. Interaction in more than one tab/window will not be supported and you may receive `interaction_in_progress` errors unexpectedly. This is an escape hatch, not a fully supported feature.
78-
79-
When using MSAL.js with the default configuration in a scenario where the user is redirected after successful authentication in a new window or tab, the OAuth 2.0 Authorization Code with PKCE flow will be interrupted. In this case, the original window or tab where the authentication state (code verifier and challenge) are stored, will be lost, and the authentication flow will fail.
80-
81-
To handle this scenario, you can configure MSAL to use `localStorage` as the cache location by overriding the `temporaryCacheLocation` configuration property. This allows the code verifier and challenge to be stored in the browser's `localStorage,` which is persistent across multiple tabs and windows.
82-
8373
## Remarks
8474

8575
- We do not recommend apps having business logic dependent on direct use of entities in the cache. Instead, use the appropriate MSAL API when you need to acquire tokens or retrieve accounts.

lib/msal-browser/docs/configuration.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ const msalConfig = {
2222
},
2323
cache: {
2424
cacheLocation: "sessionStorage",
25-
temporaryCacheLocation: "sessionStorage",
26-
storeAuthStateInCookie: false,
27-
secureCookies: false,
28-
claimsBasedCachingEnabled: true,
2925
},
3026
system: {
3127
loggerOptions: {
@@ -96,16 +92,6 @@ const msalInstance = new PublicClientApplication(msalConfig);
9692
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
9793
| `cacheLocation` | Location of token cache in browser. | String value that must be one of the following: `"sessionStorage"`, `"localStorage"`, `"memoryStorage"` | `sessionStorage` |
9894

99-
**Note: The following cache config options are deprecated and will be removed in the next major version**
100-
101-
| Option | Description | Format | Default Value |
102-
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
103-
| `temporaryCacheLocation` | Location of temporary cache in browser. This option should only be changed for specific edge cases. Please refer to [caching](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/caching.md#cached-artifacts) for more. | String value that must be one of the following: `"sessionStorage"`, `"localStorage"`, `"memoryStorage"` | `sessionStorage` |
104-
| `storeAuthStateInCookie` | If true, stores cache items in cookies as well as browser cache. Should be set to true for use cases using IE. | boolean | `false` |
105-
| `secureCookies` | If true and `storeAuthStateInCookies` is also enabled, MSAL adds the `Secure` flag to the browser cookie so it can only be sent over HTTPS. | boolean | `false` |
106-
| `cacheMigrationEnabled` | If true, cache entries from older versions of MSAL will be updated to conform to the latest cache schema on startup. If your application has not been recently updated to a new version of MSAL.js you can safely turn this off. In the event old cache entries are not migrated it may result in a cache miss when attempting to retrieve accounts or tokens and affected users may need to re-authenticate to get up to date. | boolean | `true` when using `localStorage`, `false` otherwise |
107-
| `claimsBasedCachingEnabled` | If `true`, access tokens will be cached under a key containing the hash of the requested claims string, resulting in a cache miss and new network token request when the same token request is made with different or missing claims. If set to `false`, tokens will be cached without claims, but all requests containing claims will go to the network and overwrite any previously cached token with the same scopes. | boolean | `false` |
108-
10995
See [Caching in MSAL](./caching.md) for more.
11096

11197
### System Config Options

lib/msal-browser/src/cache/BrowserCacheManager.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ import { clearHash } from "../utils/BrowserUtils.js";
7070

7171
/**
7272
* This class implements the cache storage interface for MSAL through browser local or session storage.
73-
* Cookies are only used if storeAuthStateInCookie is true, and are only used for
74-
* parameters such as state and nonce, generally.
7573
*/
7674
export class BrowserCacheManager extends CacheManager {
7775
// Cache configuration, either set by user or default values.
@@ -112,7 +110,7 @@ export class BrowserCacheManager extends CacheManager {
112110
);
113111
this.temporaryCacheStorage = getStorageImplementation(
114112
clientId,
115-
cacheConfig.temporaryCacheLocation,
113+
BrowserCacheLocation.SessionStorage,
116114
logger,
117115
performanceClient
118116
);
@@ -890,21 +888,10 @@ export class BrowserCacheManager extends CacheManager {
890888

891889
/**
892890
* Gets cache item with given key.
893-
* Will retrieve from cookies if storeAuthStateInCookie is set to true.
894891
* @param key
895892
*/
896893
getTemporaryCache(cacheKey: string, generateKey?: boolean): string | null {
897894
const key = generateKey ? this.generateCacheKey(cacheKey) : cacheKey;
898-
if (this.cacheConfig.storeAuthStateInCookie) {
899-
const itemCookie = this.cookieStorage.getItem(key);
900-
if (itemCookie) {
901-
this.logger.trace(
902-
"BrowserCacheManager.getTemporaryCache: storeAuthStateInCookies set to true, retrieving from cookies"
903-
);
904-
return itemCookie;
905-
}
906-
}
907-
908895
const value = this.temporaryCacheStorage.getItem(key);
909896
if (!value) {
910897
// If temp cache item not found in session/memory, check local storage for items set by old versions
@@ -933,8 +920,6 @@ export class BrowserCacheManager extends CacheManager {
933920

934921
/**
935922
* Sets the cache item with the key and value given.
936-
* Stores in cookie if storeAuthStateInCookie is set to true.
937-
* This can cause cookie overflow if used incorrectly.
938923
* @param key
939924
* @param value
940925
*/
@@ -944,14 +929,7 @@ export class BrowserCacheManager extends CacheManager {
944929
generateKey?: boolean
945930
): void {
946931
const key = generateKey ? this.generateCacheKey(cacheKey) : cacheKey;
947-
948932
this.temporaryCacheStorage.setItem(key, value);
949-
if (this.cacheConfig.storeAuthStateInCookie) {
950-
this.logger.trace(
951-
"BrowserCacheManager.setTemporaryCache: storeAuthStateInCookie set to true, setting item cookie"
952-
);
953-
this.cookieStorage.setItem(key, value, undefined);
954-
}
955933
}
956934

957935
/**
@@ -964,17 +942,10 @@ export class BrowserCacheManager extends CacheManager {
964942

965943
/**
966944
* Removes the temporary cache item with the given key.
967-
* Will also clear the cookie item if storeAuthStateInCookie is set to true.
968945
* @param key
969946
*/
970947
removeTemporaryItem(key: string): void {
971948
this.temporaryCacheStorage.removeItem(key);
972-
if (this.cacheConfig.storeAuthStateInCookie) {
973-
this.logger.trace(
974-
"BrowserCacheManager.removeItem: storeAuthStateInCookie is true, clearing item cookie"
975-
);
976-
this.cookieStorage.removeItem(key);
977-
}
978949
}
979950

980951
/**
@@ -1385,10 +1356,6 @@ export const DEFAULT_BROWSER_CACHE_MANAGER = (
13851356
): BrowserCacheManager => {
13861357
const cacheOptions: Required<CacheOptions> = {
13871358
cacheLocation: BrowserCacheLocation.MemoryStorage,
1388-
temporaryCacheLocation: BrowserCacheLocation.MemoryStorage,
1389-
storeAuthStateInCookie: false,
1390-
cacheMigrationEnabled: false,
1391-
claimsBasedCachingEnabled: false,
13921359
};
13931360
return new BrowserCacheManager(
13941361
clientId,

lib/msal-browser/src/config/Configuration.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,6 @@ export type CacheOptions = {
113113
* Used to specify the cacheLocation user wants to set. Valid values are "localStorage", "sessionStorage" and "memoryStorage".
114114
*/
115115
cacheLocation?: BrowserCacheLocation | string;
116-
/**
117-
* Used to specify the temporaryCacheLocation user wants to set. Valid values are "localStorage", "sessionStorage" and "memoryStorage".
118-
* @deprecated This option is deprecated and will be removed in the next major version.
119-
*/
120-
temporaryCacheLocation?: BrowserCacheLocation | string;
121-
/**
122-
* If set, MSAL stores the auth request state required for validation of the auth flows in the browser cookies. By default this flag is set to false.
123-
* @deprecated This option is deprecated and will be removed in the next major version.
124-
*/
125-
storeAuthStateInCookie?: boolean;
126-
/**
127-
* If set, MSAL will attempt to migrate cache entries from older versions on initialization. By default this flag is set to true if cacheLocation is localStorage, otherwise false.
128-
* @deprecated This option is deprecated and will be removed in the next major version.
129-
*/
130-
cacheMigrationEnabled?: boolean;
131-
/**
132-
* Flag that determines whether access tokens are stored based on requested claims
133-
* @deprecated This option is deprecated and will be removed in the next major version.
134-
*/
135-
claimsBasedCachingEnabled?: boolean;
136116
};
137117

138118
export type BrowserSystemOptions = SystemOptions & {
@@ -282,15 +262,6 @@ export function buildConfiguration(
282262
// Default cache options for browser
283263
const DEFAULT_CACHE_OPTIONS: Required<CacheOptions> = {
284264
cacheLocation: BrowserCacheLocation.SessionStorage,
285-
temporaryCacheLocation: BrowserCacheLocation.SessionStorage,
286-
storeAuthStateInCookie: false,
287-
// Default cache migration to true if cache location is localStorage since entries are preserved across tabs/windows. Migration has little to no benefit in sessionStorage and memoryStorage
288-
cacheMigrationEnabled:
289-
userInputCache &&
290-
userInputCache.cacheLocation === BrowserCacheLocation.LocalStorage
291-
? true
292-
: false,
293-
claimsBasedCachingEnabled: false,
294265
};
295266

296267
// Default logger options for browser

0 commit comments

Comments
 (0)