import MicroEmitter from '../micro-emitter'; import type { OAPIRequestResult, HTTPMethodType } from '../types'; declare type Options = { /** * The token to use for authentication. */ token?: string | null; /** * The expiry of that token, assumed to be absolute. */ expiry?: number; /** * The url for refreshing the token. */ tokenRefreshUrl?: string; /** * Any headers to be included in the token refresh call. It should be the same format as other calls. * The object key names are the header names and the values the header values. */ tokenRefreshHeaders?: Record; /** * The credentials option passed to fetch. */ tokenRefreshCredentials?: RequestCredentials; /** * The http method for refreshing the token e.g. "POST" or "GET" etc. */ tokenRefreshMethod?: HTTPMethodType; /** * The property name of the token after doing a refresh. */ tokenRefreshPropertyNameToken?: string; /** * The property name of the relative expiry after doing a refresh. */ tokenRefreshPropertyNameExpires?: string; /** * The number of ms that the refresh call should be done early. * e.g. if this is 1000 it will be refreshed 1000 ms before the token expires. */ tokenRefreshMarginMs?: number; /** * The delay before retrying auth */ retryDelayMs?: number; /** * The maximum number of times to retry the auth url */ maxRetryCount?: number; }; declare const EVENT_TOKEN_REFRESH: "tokenRefresh"; declare const EVENT_TOKEN_RECEIVED: "tokenReceived"; declare const EVENT_TOKEN_REFRESH_FAILED: "tokenRefreshFailed"; declare type EmittedEvents = { [EVENT_TOKEN_REFRESH]: () => void; [EVENT_TOKEN_RECEIVED]: (token?: string, refresh?: number) => void; [EVENT_TOKEN_REFRESH_FAILED]: (result?: OAPIRequestResult) => void; }; /** * This class builds on top of {@link TransportCore} and adds authentication management. You need only * construct one or the other, they automatically wrap each other. All of the options from the {@link TransportCore} * class are valid here as well. * For authentication management, this class will wait until just before the authentication expires (see tokenRefreshMarginMs) * and will refresh the token generating an event which is picked up by some of the other Transports. */ declare class AuthProvider extends MicroEmitter { private expiry; private token; tokenRefreshUrl?: string; tokenRefreshHeaders?: Record; tokenRefreshCredentials: RequestCredentials; tokenRefreshMethod: HTTPMethodType; tokenRefreshPropertyNameToken: string; tokenRefreshPropertyNameExpires: string; tokenRefreshMarginMs: number; retryDelayMs: number; maxRetryCount: number; state: number; retries: number; tokenRefreshTimerFireTime: number; tokenRefreshTimer: number | null; lastTokenFetchTime: number; EVENT_TOKEN_REFRESH: "tokenRefresh"; EVENT_TOKEN_RECEIVED: "tokenReceived"; EVENT_TOKEN_REFRESH_FAILED: "tokenRefreshFailed"; constructor(options: Options); /** * This internal method refreshes the token no matter what and should only * be called if we know we are in the correct state to do it. */ private refreshToken; private fetchToken; private isValidTokenResponse; private onApiTokenReceived; private onApiTokenReceiveFail; /** * Called when the token has changed. */ createTimerForNextToken(): void; getToken(): string | null; getExpiry(): number; set(newToken: string, newExpiry: number): void; isFetchingNewToken(): boolean; /** * Refresh the open api token if we are not already doing so */ refreshOpenApiToken: () => void; /** * Call this method when a 401 unauthenticated is received */ tokenRejected(url: string, expiryOfRejectedToken?: number): void; /** * Stops the AuthProvider from refreshing the token. */ dispose(): void; } export default AuthProvider;