UNPKG

@dvsa/appdev-api-common

Version:

Utils library for common API functionality

44 lines (43 loc) 1.63 kB
export interface ClientCredentialsResponse { token_type: string; expires_in: number; ext_expires_in: number; access_token: string; } export declare class ClientCredentials { private readonly tokenUrl; private readonly clientId; private readonly clientSecret; private readonly scope; private readonly resource; private readonly debugMode; private static accessToken; private static readonly grantType; /** * Create a new instance of the ClientCredentials class * @param tokenUrl - The URL to fetch the access token from * @param clientId - The client id * @param clientSecret - The client secret * @param scope - The scope of the access token * @param debugMode - Whether to log debug messages */ constructor(tokenUrl: string, clientId: string, clientSecret: string, scope: string | undefined, resource: string | undefined, debugMode?: boolean); /** * Helper method to perform the client credentials flow and return the access token * This method will check for the existence of the token and if it is expired, it will fetch a new one * @returns {Promise<string>} - The access token */ getAccessToken(): Promise<string>; /** * Fetch the client credentials from the token URL * @returns {Promise<ClientCredentialsResponse>} - The response from the token URL * @private */ private fetchClientCredentials; /** * Check if the access token is expired * @returns {boolean} - Whether the access token is expired * @private */ private isAccessTokenExpired; }