UNPKG

@duosecurity/duo_universal

Version:
100 lines (99 loc) 2.71 kB
import { HealthCheckResponse, TokenResponsePayload } from './http'; export type ClientOptions = { clientId: string; clientSecret: string; apiHost: string; redirectUrl: string; useDuoCodeAttribute?: boolean; }; export declare class Client { readonly HEALTH_CHECK_ENDPOINT = "/oauth/v1/health_check"; readonly AUTHORIZE_ENDPOINT = "/oauth/v1/authorize"; readonly TOKEN_ENDPOINT = "/oauth/v1/token"; private clientId; private clientSecret; private apiHost; private baseURL; private redirectUrl; private useDuoCodeAttribute; private axios; constructor(options: ClientOptions); /** * Validate that the clientId and clientSecret are the proper length. * * @private * @param {ClientOptions} options * @memberof Client */ private validateInitialConfig; /** * Retrieves exception message for DuoException from HTTPS result message. * * @private * @param {*} result * @returns {string} * @memberof Client */ private getExceptionFromResult; /** * Create client JWT payload * * @private * @param {string} audience * @returns {string} * @memberof Client */ private createJwtPayload; /** * Verify JWT token * * @private * @template T * @param {string} token * @returns {Promise<T>} * @memberof Client */ private verifyToken; /** * Error handler to throw relevant error * * @private * @param {unknown} error * @returns {never} * @memberof Client */ private handleErrorResponse; /** * Generate a random hex string with a length of DEFAULT_STATE_LENGTH. * * @returns {string} * @memberof Client */ generateState(): string; /** * Makes a call to HEALTH_CHECK_ENDPOINT to see if Duo is available. * * @returns {Promise<HealthCheckResponse>} * @memberof Client */ healthCheck(): Promise<HealthCheckResponse>; /** * Generate URI to redirect to for the Duo prompt. * * @param {string} username * @param {string} state * @returns {string} * @memberof Client */ createAuthUrl(username: string, state: string): string; /** * Exchange a code returned by Duo for a token that contains information about the authorization. * * @param {string} code * @param {string} username * @param {(string | null)} [nonce=null] * @returns {Promise<TokenResponsePayload>} * @memberof Client */ exchangeAuthorizationCodeFor2FAResult(code: string, username: string, nonce?: string | null): Promise<TokenResponsePayload>; }