UNPKG

@azure/msal-browser

Version:
156 lines (155 loc) 5.29 kB
import { AuthorizationCodeRequest, ICrypto, CacheManager } from "@azure/msal-common"; import { CacheOptions } from "../config/Configuration"; import { CryptoOps } from "../crypto/CryptoOps"; /** * This class implements the cache storage interface for MSAL through browser local or session storage. * Cookies are only used if storeAuthStateInCookie is true, and are only used for * parameters such as state and nonce, generally. */ export declare class BrowserStorage extends CacheManager { private cacheConfig; private windowStorage; private clientId; private cryptoImpl; constructor(clientId: string, cacheConfig: CacheOptions, cryptoImpl: CryptoOps); /** * Validates the the given cache location string is an expected value: * - localStorage * - sessionStorage (default) * Also validates if given cacheLocation is supported on the browser. * @param cacheLocation */ private validateWindowStorage; /** * Migrate all old cache entries to new schema. No rollback supported. * @param storeAuthStateInCookie */ private migrateCacheEntries; /** * Utility function to help with migration. * @param newKey * @param value * @param storeAuthStateInCookie */ private migrateCacheEntry; /** * Parses key as JSON object, JSON.parse() will throw an error. * @param key */ private validateObjectKey; /** * Sets the cache item with the key and value given. * Stores in cookie if storeAuthStateInCookie is set to true. * This can cause cookie overflow if used incorrectly. * @param key * @param value */ setItem(key: string, value: string | object, type: string): void; /** * Gets cache item with given key. * Will retrieve frm cookies if storeAuthStateInCookie is set to true. * @param key */ getItem(key: string, type: string): string | object; /** * Removes the cache item with the given key. * Will also clear the cookie item if storeAuthStateInCookie is set to true. * @param key */ removeItem(key: string): boolean; /** * Checks whether key is in cache. * @param key */ containsKey(key: string): boolean; /** * Gets all keys in window. */ getKeys(): string[]; /** * Clears all cache entries created by MSAL (except tokens). */ clear(): void; /** * Add value to cookies * @param cookieName * @param cookieValue * @param expires */ setItemCookie(cookieName: string, cookieValue: string, expires?: number): void; /** * Get one item by key from cookies * @param cookieName */ getItemCookie(cookieName: string): string; /** * Clear an item in the cookies by key * @param cookieName */ clearItemCookie(cookieName: string): void; /** * Clear all msal cookies */ clearMsalCookie(stateString?: string): void; /** * Get cookie expiration time * @param cookieLifeDays */ getCookieExpirationTime(cookieLifeDays: number): string; /** * Gets the cache object referenced by the browser */ getCache(): object; /** * interface compat, we cannot overwrite browser cache; Functionality is supported by individual entities in browser */ setCache(): void; /** * 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) * @param key * @param addInstanceId */ generateCacheKey(key: string): string; /** * Create authorityKey to cache authority * @param state */ generateAuthorityKey(stateString: string): string; /** * Create Nonce key to cache nonce * @param state */ generateNonceKey(stateString: string): string; /** * Creates full cache key for the request state * @param stateString State string for the request */ generateStateKey(stateString: string): string; /** * Sets the cacheKey for and stores the authority information in cache * @param state * @param authority */ setAuthorityCache(authority: string, state: string): void; /** * Gets the cached authority based on the cached state. Returns empty if no cached state found. */ getCachedAuthority(cachedState: string): string; /** * Updates account, authority, and state in cache * @param serverAuthenticationRequest * @param account */ updateCacheEntries(state: string, nonce: string, authorityInstance: string): void; /** * Reset all temporary cache items * @param state */ resetRequestCache(state: string): void; cleanRequest(stateString?: string): void; cacheCodeRequest(authCodeRequest: AuthorizationCodeRequest, browserCrypto: ICrypto): void; /** * Gets the token exchange parameters from the cache. Throws an error if nothing is found. */ getCachedRequest(state: string, browserCrypto: ICrypto): AuthorizationCodeRequest; }