import { AxiosInstance } from 'axios'; import { ExchangeRefreshTokenResult } from './oidc-functions.js'; /** * Callback for the refresh token. */ export type RefreshTokenCallback = (refreshToken: ExchangeRefreshTokenResult) => Promise; /** * Options for the RefreshTokenManager. */ export interface RefreshTokenManagerProps { /** * The client ID. */ readonly clientId: string; /** * The refresh token. */ readonly refreshToken: string; /** * The date the access token expires. */ readonly expiration: number; /** * The token endpoint. */ readonly tokenEndpoint: string; /** * The number of seconds before the access token expires to refresh the access token. Default is 60 seconds. * @default 60 */ readonly refreshBufferSeconds?: number; /** * The number of seconds to subtract from the token expiration time when calculating if the token is expired. * Default is 45 seconds. Recommended to be less than the refreshBufferSeconds. * * @default 45 */ readonly expirationBufferSeconds?: number; /** * Disable the background refresh of the access token. Default is false. * @default false */ readonly disableBackgroundRefresh?: boolean; /** * Callback for the refresh token. */ readonly callback?: RefreshTokenCallback | RefreshTokenCallback[]; /** * The client to use for making requests. If not specified, a new client will be created. */ readonly client?: AxiosInstance; } /** * Manages refreshing an access token using a refresh token. */ export declare class RefreshTokenManager { protected clientId: string; protected refreshToken: string; protected tokenEndpoint: string; protected refreshBufferSeconds: number; protected disableBackgroundRefresh: boolean; protected expirationBufferSeconds: number; protected client: AxiosInstance; protected expiration: number; protected intervalId?: ReturnType; protected callbacks: RefreshTokenCallback[]; constructor(props: RefreshTokenManagerProps); /** * Adds a callback for the refresh token. * * @param callback the callback to add */ callback(callback: RefreshTokenCallback): void; /** * Stops the background refresh of the access and refresh token. */ stop(): void; /** * Starts the background refresh of the access and refresh token. This is called automatically unless disableBackgroundRefresh is set to true. */ start(): void; protected executeCallback(callback: RefreshTokenCallback, response: ExchangeRefreshTokenResult): Promise; protected executeCallbacks(response: ExchangeRefreshTokenResult): Promise; /** * Refreshes the access and refresh token. This is called automatically unless disableBackgroundRefresh is set to true. * Be aware this function doesn't schedule the next refresh until all callbacks return. */ refresh(): Promise; /** * Retrieves the current refresh token and expiration. */ getRefreshToken(): string; /** * Closes the manager instance by stopping the background refresh and clearing the refresh token. */ close(): void; } //# sourceMappingURL=refresh-token-manager.d.ts.map