Skip to content

Commit becbd55

Browse files
committed
Remove storeAuthStateInCookie
1 parent 0cb8305 commit becbd55

File tree

22 files changed

+39
-404
lines changed

22 files changed

+39
-404
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

-1
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:

lib/msal-angular/docs/configuration.md

-3
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, // set to true for IE 11
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

-1
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

-2
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, // set to true for IE 11
3534
},
3635
system: {
3736
loggerOptions: {
@@ -115,7 +114,6 @@ import { PublicClientApplication, InteractionType, BrowserCacheLocation } from "
115114
},
116115
cache: {
117116
cacheLocation : BrowserCacheLocation.LocalStorage,
118-
storeAuthStateInCookie: true, // set to true for IE 11
119117
},
120118
system: {
121119
loggerOptions: {

lib/msal-browser/docs/configuration.md

-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const msalConfig = {
2424
cache: {
2525
cacheLocation: "sessionStorage",
2626
temporaryCacheLocation: "sessionStorage",
27-
storeAuthStateInCookie: false,
2827
secureCookies: false,
2928
claimsBasedCachingEnabled: true,
3029
},
@@ -98,7 +97,6 @@ const msalInstance = new PublicClientApplication(msalConfig);
9897
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
9998
| `cacheLocation` | Location of token cache in browser. | String value that must be one of the following: `"sessionStorage"`, `"localStorage"`, `"memoryStorage"` | `sessionStorage` |
10099
| `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` |
101-
| `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` |
102100
| `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` |
103101
| `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 |
104102
| `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` |

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

-30
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ import { EventHandler } from "../event/EventHandler.js";
6868

6969
/**
7070
* This class implements the cache storage interface for MSAL through browser local or session storage.
71-
* Cookies are only used if storeAuthStateInCookie is true, and are only used for
72-
* parameters such as state and nonce, generally.
7371
*/
7472
export class BrowserCacheManager extends CacheManager {
7573
// Cache configuration, either set by user or default values.
@@ -885,21 +883,10 @@ export class BrowserCacheManager extends CacheManager {
885883

886884
/**
887885
* Gets cache item with given key.
888-
* Will retrieve from cookies if storeAuthStateInCookie is set to true.
889886
* @param key
890887
*/
891888
getTemporaryCache(cacheKey: string, generateKey?: boolean): string | null {
892889
const key = generateKey ? this.generateCacheKey(cacheKey) : cacheKey;
893-
if (this.cacheConfig.storeAuthStateInCookie) {
894-
const itemCookie = this.cookieStorage.getItem(key);
895-
if (itemCookie) {
896-
this.logger.trace(
897-
"BrowserCacheManager.getTemporaryCache: storeAuthStateInCookies set to true, retrieving from cookies"
898-
);
899-
return itemCookie;
900-
}
901-
}
902-
903890
const value = this.temporaryCacheStorage.getItem(key);
904891
if (!value) {
905892
// If temp cache item not found in session/memory, check local storage for items set by old versions
@@ -928,8 +915,6 @@ export class BrowserCacheManager extends CacheManager {
928915

929916
/**
930917
* Sets the cache item with the key and value given.
931-
* Stores in cookie if storeAuthStateInCookie is set to true.
932-
* This can cause cookie overflow if used incorrectly.
933918
* @param key
934919
* @param value
935920
*/
@@ -939,14 +924,7 @@ export class BrowserCacheManager extends CacheManager {
939924
generateKey?: boolean
940925
): void {
941926
const key = generateKey ? this.generateCacheKey(cacheKey) : cacheKey;
942-
943927
this.temporaryCacheStorage.setItem(key, value);
944-
if (this.cacheConfig.storeAuthStateInCookie) {
945-
this.logger.trace(
946-
"BrowserCacheManager.setTemporaryCache: storeAuthStateInCookie set to true, setting item cookie"
947-
);
948-
this.cookieStorage.setItem(key, value, undefined);
949-
}
950928
}
951929

952930
/**
@@ -959,17 +937,10 @@ export class BrowserCacheManager extends CacheManager {
959937

960938
/**
961939
* Removes the temporary cache item with the given key.
962-
* Will also clear the cookie item if storeAuthStateInCookie is set to true.
963940
* @param key
964941
*/
965942
removeTemporaryItem(key: string): void {
966943
this.temporaryCacheStorage.removeItem(key);
967-
if (this.cacheConfig.storeAuthStateInCookie) {
968-
this.logger.trace(
969-
"BrowserCacheManager.removeItem: storeAuthStateInCookie is true, clearing item cookie"
970-
);
971-
this.cookieStorage.removeItem(key);
972-
}
973944
}
974945

975946
/**
@@ -1370,7 +1341,6 @@ export const DEFAULT_BROWSER_CACHE_MANAGER = (
13701341
const cacheOptions: Required<CacheOptions> = {
13711342
cacheLocation: BrowserCacheLocation.MemoryStorage,
13721343
temporaryCacheLocation: BrowserCacheLocation.MemoryStorage,
1373-
storeAuthStateInCookie: false,
13741344
cacheMigrationEnabled: false,
13751345
claimsBasedCachingEnabled: false,
13761346
};

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

-5
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ export type CacheOptions = {
127127
* Used to specify the temporaryCacheLocation user wants to set. Valid values are "localStorage", "sessionStorage" and "memoryStorage".
128128
*/
129129
temporaryCacheLocation?: BrowserCacheLocation | string;
130-
/**
131-
* 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.
132-
*/
133-
storeAuthStateInCookie?: boolean;
134130
/**
135131
* 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.
136132
*/
@@ -287,7 +283,6 @@ export function buildConfiguration(
287283
const DEFAULT_CACHE_OPTIONS: Required<CacheOptions> = {
288284
cacheLocation: BrowserCacheLocation.SessionStorage,
289285
temporaryCacheLocation: BrowserCacheLocation.SessionStorage,
290-
storeAuthStateInCookie: false,
291286
// 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
292287
cacheMigrationEnabled:
293288
userInputCache &&

lib/msal-browser/src/controllers/StandardController.ts

-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ export class StandardController implements IController {
257257
const nativeCacheOptions: Required<CacheOptions> = {
258258
cacheLocation: BrowserCacheLocation.MemoryStorage,
259259
temporaryCacheLocation: BrowserCacheLocation.MemoryStorage,
260-
storeAuthStateInCookie: false,
261260
cacheMigrationEnabled: false,
262261
claimsBasedCachingEnabled: false,
263262
};

lib/msal-browser/src/error/BrowserConfigurationAuthError.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const BrowserConfigurationAuthErrorMessages = {
1313
[BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled]:
1414
"Stub instance of Public Client Application was called. If using msal-react, please ensure context is not used without a provider. For more visit: aka.ms/msaljs/browser-errors",
1515
[BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable]:
16-
"Redirect cannot be supported. In-memory storage was selected and storeAuthStateInCookie=false, which would cause the library to be unable to handle the incoming hash. If you would like to use the redirect API, please use session/localStorage or set storeAuthStateInCookie=true.",
16+
"Redirect cannot be supported. In-memory storage was selected, which would cause the library to be unable to handle the incoming hash. If you would like to use the redirect API, please use session/localStorage.",
1717
};
1818

1919
/**

lib/msal-browser/src/utils/BrowserUtils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,9 @@ export function redirectPreflightCheck(
171171
): void {
172172
preflightCheck(initialized);
173173
blockRedirectInIframe(config.system.allowRedirectInIframe);
174-
// Block redirects if memory storage is enabled but storeAuthStateInCookie is not
174+
// Block redirects if memory storage is enabled
175175
if (
176-
config.cache.cacheLocation === BrowserCacheLocation.MemoryStorage &&
177-
!config.cache.storeAuthStateInCookie
176+
config.cache.cacheLocation === BrowserCacheLocation.MemoryStorage
178177
) {
179178
throw createBrowserConfigurationAuthError(
180179
BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable

lib/msal-browser/test/app/PublicClientApplication.spec.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ import { INTERACTION_TYPE } from "../../src/utils/BrowserConstants.js";
119119
const cacheConfig = {
120120
temporaryCacheLocation: BrowserCacheLocation.SessionStorage,
121121
cacheLocation: BrowserCacheLocation.SessionStorage,
122-
storeAuthStateInCookie: false,
123122
cacheMigrationEnabled: false,
124123
claimsBasedCachingEnabled: false,
125124
};
@@ -1933,14 +1932,13 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
19331932
}
19341933
});
19351934

1936-
it("throws error if cacheLocation is Memory Storage and storeAuthStateInCookie is false", async () => {
1935+
it("throws error if cacheLocation is Memory Storage", async () => {
19371936
pca = new PublicClientApplication({
19381937
auth: {
19391938
clientId: TEST_CONFIG.MSAL_CLIENT_ID,
19401939
},
19411940
cache: {
19421941
cacheLocation: BrowserCacheLocation.MemoryStorage,
1943-
storeAuthStateInCookie: false,
19441942
},
19451943
system: {
19461944
allowPlatformBroker: false,
@@ -7281,7 +7279,6 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
72817279
{
72827280
cacheLocation: BrowserCacheLocation.LocalStorage,
72837281
temporaryCacheLocation: BrowserCacheLocation.SessionStorage,
7284-
storeAuthStateInCookie: false,
72857282
cacheMigrationEnabled: false,
72867283
claimsBasedCachingEnabled: false,
72877284
},

0 commit comments

Comments
 (0)