import { AuthorizationCodeRequest, ICrypto, AccountEntity, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, CacheManager, ServerTelemetryEntity, ThrottlingEntity, Logger } 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 BrowserCacheManager extends CacheManager { private cacheConfig; private browserStorage; private logger; private readonly COOKIE_LIFE_MULTIPLIER; constructor(clientId: string, cacheConfig: CacheOptions, cryptoImpl: CryptoOps, logger: Logger); /** * Returns a window storage class implementing the IWindowStorage interface that corresponds to the configured cacheLocation. * @param cacheLocation */ private setupBrowserStorage; /** * 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 passed value as JSON object, JSON.parse() will throw an error. * @param input */ private validateAndParseJson; /** * fetches the entry from the browser storage based off the key * @param key */ getItem(key: string): string; /** * sets the entry in the browser storage * @param key * @param value */ setItem(key: string, value: string): void; /** * fetch the account entity from the platform cache * @param accountKey */ getAccount(accountKey: string): AccountEntity | null; /** * set account entity in the platform cache * @param key * @param value */ setAccount(account: AccountEntity): void; /** * generates idToken entity from a string * @param idTokenKey */ getIdTokenCredential(idTokenKey: string): IdTokenEntity; /** * set IdToken credential to the platform cache * @param idToken */ setIdTokenCredential(idToken: IdTokenEntity): void; /** * generates accessToken entity from a string * @param key */ getAccessTokenCredential(accessTokenKey: string): AccessTokenEntity; /** * set accessToken credential to the platform cache * @param accessToken */ setAccessTokenCredential(accessToken: AccessTokenEntity): void; /** * generates refreshToken entity from a string * @param refreshTokenKey */ getRefreshTokenCredential(refreshTokenKey: string): RefreshTokenEntity; /** * set refreshToken credential to the platform cache * @param refreshToken */ setRefreshTokenCredential(refreshToken: RefreshTokenEntity): void; /** * fetch appMetadata entity from the platform cache * @param appMetadataKey */ getAppMetadata(appMetadataKey: string): AppMetadataEntity; /** * set appMetadata entity to the platform cache * @param appMetadata */ setAppMetadata(appMetadata: AppMetadataEntity): void; /** * fetch server telemetry entity from the platform cache * @param serverTelemetryKey */ getServerTelemetry(serverTelemetryKey: string): ServerTelemetryEntity | null; /** * set server telemetry entity to the platform cache * @param serverTelemetryKey * @param serverTelemetry */ setServerTelemetry(serverTelemetryKey: string, serverTelemetry: ServerTelemetryEntity): void; /** * fetch throttling entity from the platform cache * @param throttlingCacheKey */ getThrottlingCache(throttlingCacheKey: string): ThrottlingEntity | null; /** * set throttling entity to the platform cache * @param throttlingCacheKey * @param throttlingCache */ setThrottlingCache(throttlingCacheKey: string, throttlingCache: ThrottlingEntity): void; /** * Gets cache item with given key. * Will retrieve frm cookies if storeAuthStateInCookie is set to true. * @param key */ getTemporaryCache(cacheKey: string, generateKey?: boolean): string; /** * 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 */ setTemporaryCache(cacheKey: string, value: string, generateKey?: boolean): void; /** * 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. 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; }