init
This commit is contained in:
commit
d282e2bcae
3481 files changed
+568488
No files matched your search
+7
@@ -0,0 +1,7 @@
|
||||
import { ICache, Cacheable, MaybePromise } from './shared';
|
||||
export declare class LocalStorageCache implements ICache {
|
||||
set<T = Cacheable>(key: string, entry: T): void;
|
||||
get<T = Cacheable>(key: string): MaybePromise<T | undefined>;
|
||||
remove(key: string): void;
|
||||
allKeys(): string[];
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
import { CacheKeyManifest } from './key-manifest';
|
||||
import { CacheEntry, ICache, CacheKey, DecodedToken, IdTokenEntry } from './shared';
|
||||
export declare class CacheManager {
|
||||
private cache;
|
||||
private keyManifest?;
|
||||
private nowProvider;
|
||||
constructor(cache: ICache, keyManifest?: CacheKeyManifest | undefined, nowProvider?: () => number | Promise<number>);
|
||||
setIdToken(clientId: string, idToken: string, decodedToken: DecodedToken): Promise<void>;
|
||||
getIdToken(cacheKey: CacheKey): Promise<IdTokenEntry | undefined>;
|
||||
get(cacheKey: CacheKey, expiryAdjustmentSeconds?: number, useMrrt?: boolean, cacheMode?: string): Promise<Partial<CacheEntry> | undefined>;
|
||||
private modifiedCachedEntry;
|
||||
set(entry: CacheEntry): Promise<void>;
|
||||
remove(client_id: string, audience?: string, scope?: string): Promise<void>;
|
||||
clear(clientId?: string): Promise<void>;
|
||||
private wrapCacheEntry;
|
||||
private getCacheKeys;
|
||||
/**
|
||||
* Returns the cache key to be used to store the id token
|
||||
* @param clientId The client id used to link to the id token
|
||||
* @returns The constructed cache key, as a string, to store the id token
|
||||
*/
|
||||
private getIdTokenCacheKey;
|
||||
/**
|
||||
* Finds the corresponding key in the cache based on the provided cache key.
|
||||
* The keys inside the cache are in the format {prefix}::{clientId}::{audience}::{scope}.
|
||||
* The first key in the cache that satisfies the following conditions is returned
|
||||
* - `prefix` is strict equal to Auth0's internally configured `keyPrefix`
|
||||
* - `clientId` is strict equal to the `cacheKey.clientId`
|
||||
* - `audience` is strict equal to the `cacheKey.audience`
|
||||
* - `scope` contains at least all the `cacheKey.scope` values
|
||||
* *
|
||||
* @param keyToMatch The provided cache key
|
||||
* @param allKeys A list of existing cache keys
|
||||
*/
|
||||
private matchExistingCacheKey;
|
||||
/**
|
||||
* Returns the first entry that contains a refresh_token that satisfies the following conditions
|
||||
* The keys inside the cache are in the format {prefix}::{clientId}::{audience}::{scope}.
|
||||
* - `prefix` is strict equal to Auth0's internally configured `keyPrefix`
|
||||
* - `clientId` is strict equal to the `cacheKey.clientId`
|
||||
* @param keyToMatch The provided cache key
|
||||
* @param allKeys A list of existing cache keys
|
||||
*/
|
||||
private getEntryWithRefreshToken;
|
||||
/**
|
||||
* Updates in the cache all entries that has a match with previous refresh_token with the
|
||||
* new refresh_token obtained from the server
|
||||
* @param oldRefreshToken Old refresh_token used on refresh
|
||||
* @param newRefreshToken New refresh_token obtained from the server after refresh
|
||||
*/
|
||||
updateEntry(oldRefreshToken: string, newRefreshToken: string): Promise<void>;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import { ICache } from './shared';
|
||||
export declare class InMemoryCache {
|
||||
enclosedCache: ICache;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export * from './cache-localstorage';
|
||||
export * from './cache-memory';
|
||||
export * from './cache-manager';
|
||||
export * from './shared';
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { ICache, KeyManifestEntry, MaybePromise } from './shared';
|
||||
export declare class CacheKeyManifest {
|
||||
private cache;
|
||||
private clientId;
|
||||
private readonly manifestKey;
|
||||
constructor(cache: ICache, clientId: string);
|
||||
add(key: string): Promise<void>;
|
||||
remove(key: string): Promise<void>;
|
||||
get(): MaybePromise<KeyManifestEntry | undefined>;
|
||||
clear(): MaybePromise<void>;
|
||||
private createManifestKeyFrom;
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
import { IdToken, User } from '../global';
|
||||
export declare const CACHE_KEY_PREFIX = "@@auth0spajs@@";
|
||||
export declare const CACHE_KEY_ID_TOKEN_SUFFIX = "@@user@@";
|
||||
export type CacheKeyData = {
|
||||
audience?: string;
|
||||
scope?: string;
|
||||
clientId: string;
|
||||
};
|
||||
export declare class CacheKey {
|
||||
prefix: string;
|
||||
suffix?: string | undefined;
|
||||
clientId: string;
|
||||
scope?: string;
|
||||
audience?: string;
|
||||
constructor(data: CacheKeyData, prefix?: string, suffix?: string | undefined);
|
||||
/**
|
||||
* Converts this `CacheKey` instance into a string for use in a cache
|
||||
* @returns A string representation of the key
|
||||
*/
|
||||
toKey(): string;
|
||||
/**
|
||||
* Converts a cache key string into a `CacheKey` instance.
|
||||
* @param key The key to convert
|
||||
* @returns An instance of `CacheKey`
|
||||
*/
|
||||
static fromKey(key: string): CacheKey;
|
||||
/**
|
||||
* Utility function to build a `CacheKey` instance from a cache entry
|
||||
* @param entry The entry
|
||||
* @returns An instance of `CacheKey`
|
||||
*/
|
||||
static fromCacheEntry(entry: CacheEntry): CacheKey;
|
||||
}
|
||||
export interface DecodedToken {
|
||||
claims: IdToken;
|
||||
user: User;
|
||||
}
|
||||
export interface IdTokenEntry {
|
||||
id_token: string;
|
||||
decodedToken: DecodedToken;
|
||||
}
|
||||
export type CacheEntry = {
|
||||
id_token?: string;
|
||||
token_type?: string;
|
||||
access_token: string;
|
||||
expires_in: number;
|
||||
decodedToken?: DecodedToken;
|
||||
audience: string;
|
||||
scope: string;
|
||||
client_id: string;
|
||||
refresh_token?: string;
|
||||
oauthTokenScope?: string;
|
||||
};
|
||||
export type WrappedCacheEntry = {
|
||||
body: Partial<CacheEntry>;
|
||||
expiresAt: number;
|
||||
};
|
||||
export type KeyManifestEntry = {
|
||||
keys: string[];
|
||||
};
|
||||
export type Cacheable = WrappedCacheEntry | KeyManifestEntry;
|
||||
export type MaybePromise<T> = Promise<T> | T;
|
||||
export interface ICache {
|
||||
set<T = Cacheable>(key: string, entry: T): MaybePromise<void>;
|
||||
get<T = Cacheable>(key: string): MaybePromise<T | undefined>;
|
||||
remove(key: string): MaybePromise<void>;
|
||||
allKeys?(): MaybePromise<string[]>;
|
||||
}
|
||||
Reference in new issue
Block a user