@dvsa/appdev-api-common
Version:
Utils library for common API functionality
65 lines (64 loc) • 2.21 kB
TypeScript
export interface AzureTokenResponse {
token_type: string;
expires_in: number;
ext_expires_in?: number;
access_token: string;
}
interface Options {
/**
*
* Whether to log debug messages & tokens during the token retrieval process.
* Useful for troubleshooting and understanding the flow of operations.
*
* Use with Caution, this could leak secrets!
*/
debugMode?: boolean;
/**
* Whether to skip any token caching and force fresh retrievals
*
*/
forceFreshAuth?: boolean;
/**
* Treat token as expired if it has less than this many seconds remaining.
* Helps avoid clock skew / in-flight expiry. (Default 30 secs)
*/
expirySkewSeconds?: number;
}
export declare class AwsOIDCAzureTokenClient {
private readonly tenantId;
private readonly clientId;
private readonly tokenDurationSeconds;
private readonly options;
private static accessToken;
private static readonly stsClient;
/**
* Create a new instance of the AwsToAzureFederatedCredentials class
* @param tenantId - The Azure AD tenant ID
* @param clientId - The Azure AD application (client) ID
* @param tokenDurationSeconds - Duration for the AWS token (default: 300)
* @param options - Credentials options
*/
constructor(tenantId: string, clientId: string, tokenDurationSeconds?: number, options?: Options);
/**
* Returns an Azure AD access token for the configured application.
*
* Uses an in-memory cached token when it’s still valid; otherwise it obtains a fresh token
* by exchanging an AWS OIDC web identity JWT against the Azure v2 token endpoint.
*
* @returns {Promise<string>} - The Azure access token
*/
getAccessToken(): Promise<string>;
/**
* Fetch the AWS JWT and exchange it for an Azure token
* @returns {Promise<AzureTokenResponse>} - The Azure token response
* @internal
*/
private fetchFederatedCredentials;
/**
* Check if the access token is expired
* @returns {boolean} - Whether the access token is expired
* @internal
*/
private static isAccessTokenExpired;
}
export {};