import { OAuthConfig, Token } from './types'; /** * Default value to determine when a token is expired locally (means * when to issue a new token): if the token exists for * ((1 - DEFAULT_PERCENTAGE_LEFT) * lifetime) then issue a new one. */ declare const DEFAULT_PERCENTAGE_LEFT = 0.75; /** * Class to request and cache tokens on client-side. * * Usage: * const tokenCache = new TokenCache({ * 'nucleus': ['write.all', 'read.all'] * }, oAuthConfig); * * tokenCache.get('nucleus') * .then((token) => { * console.log(token.access_token); * }); * */ declare class TokenCache { private tokenConfig; private oauthConfig; private _tokens; /** * `oauthConfig`: * `credentialsDir` string * `grantType` string * `accessTokenEndpoint` string * `tokenInfoEndpoint` string * `realm` string * `scopes` string[] optional * `queryParams` {} optional * `redirect_uri` string optional (required with `AUTHORIZATION_CODE_GRANT`) * `code` string optional (required with `AUTHORIZATION_CODE_GRANT`) * * @param tokenConfig * @param oauthConfig */ constructor(tokenConfig: { [key: string]: string[]; }, oauthConfig: OAuthConfig); /** * The resolveAccessTokenFactory function, creates a function, * which resolves a specific access_token. * * @param {string} The key configured on the tokenCache instance * @return {Promise} the resolved access_token */ resolveAccessTokenFactory(key: string): () => Promise; /** * Resolves with either a cached token for the given name or with a newly requested one (which is then cached). * Rejects if there is no token present and is not able to request a new one. * * @param tokenName * @returns {Promise} */ get(tokenName: string): Promise; /** * Forces the cache to delete present token for the given name. * Will resolve the newly requested token if the request was successful. * Otherwise, rejects. * * @param tokenName * @returns {Promise} */ refreshToken(tokenName: string): Promise; /** * Forces the cache to delete present tokens and request new ones. * Will resolve with an hashmap of the newly requested tokens if the request was successful. * Otherwise, rejects. * * @returns {Promise} */ refreshAllTokens(): Promise<{ [key: string]: Token; }>; /** * Checks whether a valid token for the given name is present. * Resolves with that token if that is the case. * Rejects otherwise. * * @param tokenName * @returns {Promise} */ private validateToken(tokenName); } export { TokenCache, DEFAULT_PERCENTAGE_LEFT };