UNPKG

@auth0/auth0-spa-js

Version:

Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE

102 lines (101 loc) 5.22 kB
import type { Auth0Client } from '../Auth0Client'; import type { TokenEndpointResponse } from '../global'; import type { PasskeySignupOptions, PasskeyLoginOptions, PasskeySignupChallengeOptions, PasskeyLoginChallengeOptions, PasskeySignupChallenge, PasskeyLoginChallenge, PasskeyGetTokenOptions } from './types'; import type { PasskeyClient } from '@auth0/auth0-auth-js'; /** * Client for Auth0 Passkey operations. * * Provides 2 public methods: * - `signup` — Register a new user with a passkey (full flow: challenge → WebAuthn → token exchange) * - `login` — Sign in with a passkey (full flow: challenge → WebAuthn → token exchange) * * @example * ```typescript * // Signup — single call handles everything * const tokens = await auth0.passkey.signup({ email: 'user@example.com' }); * * // Login — single call handles everything * const tokens = await auth0.passkey.login(); * ``` */ export declare class PasskeyApiClient { #private; /** * @internal * Do not instantiate directly. Use Auth0Client.passkey instead. */ constructor(passkeyClient: PasskeyClient, auth0Client: Auth0Client); /** * Register a new user with a passkey. * * Handles the full flow: requests a signup challenge, triggers the browser * WebAuthn credential creation ceremony, serializes the result, and exchanges * it for tokens. * * @param options - Passkey signup options (user identifier, optional scope/audience) * @returns A promise that resolves to the token endpoint response containing access/ID tokens * @throws {PasskeyError} If WebAuthn is not supported in the browser * @throws {PasskeyRegisterError} If the challenge request fails * @throws {GenericError} If the token exchange fails * @throws {PasskeyError} If the user cancels the WebAuthn prompt */ signup(options: PasskeySignupOptions): Promise<TokenEndpointResponse>; /** * Sign in with an existing passkey. * * Handles the full flow: requests a login challenge, triggers the browser * WebAuthn assertion ceremony, serializes the result, and exchanges it * for tokens. * * @param options - Optional passkey login options (optional scope/audience/realm/organization) * @returns A promise that resolves to the token endpoint response containing access/ID tokens * @throws {PasskeyError} If WebAuthn is not supported in the browser * @throws {PasskeyChallengeError} If the challenge request fails * @throws {GenericError} If the token exchange fails * @throws {PasskeyError} If the user cancels the WebAuthn prompt */ login(options?: PasskeyLoginOptions): Promise<TokenEndpointResponse>; /** * Request a passkey signup challenge. * * Step 1 of the granular signup flow. Returns the auth session and a * decoded `PublicKeyCredentialCreationOptions`. Run the WebAuthn credential * creation ceremony with `publicKey`, then hand the resulting credential and `authSession` to * `getTokenWithPasskey()`. * * @param options - Signup challenge options (user identifier, optional realm/organization/metadata) * @returns A promise resolving to `{ authSession, publicKey }` * @throws {PasskeyError} If WebAuthn is not supported in the browser * @throws {PasskeyRegisterError} If the challenge request fails */ getSignupChallenge(options: PasskeySignupChallengeOptions): Promise<PasskeySignupChallenge>; /** * Request a passkey login challenge. * * Step 1 of the granular login flow. Returns the auth session and a * decoded `PublicKeyCredentialRequestOptions`. Run the WebAuthn assertion * ceremony with `publicKey`, then hand the resulting credential and `authSession` to * `getTokenWithPasskey()`. * * @param options - Optional login challenge options (realm/organization) * @returns A promise resolving to `{ authSession, publicKey }` * @throws {PasskeyError} If WebAuthn is not supported in the browser * @throws {PasskeyChallengeError} If the challenge request fails */ getLoginChallenge(options?: PasskeyLoginChallengeOptions): Promise<PasskeyLoginChallenge>; /** * Exchange a signed passkey credential for tokens. * * Step 2 of the granular flow. Serializes the raw `PublicKeyCredential` * produced by the WebAuthn ceremony — either a creation (signup) or an * assertion (login) credential — and exchanges it for tokens. The credential * type (attestation vs assertion) is detected automatically. * * @param options - The auth session, raw credential, and optional realm/organization/scope/audience * @returns A promise resolving to the token endpoint response * @throws {PasskeyError} If WebAuthn is not supported in the browser * @throws {PasskeyError} If the credential is not a valid attestation or assertion response * @throws {GenericError} If the token exchange fails */ getTokenWithPasskey(options: PasskeyGetTokenOptions): Promise<TokenEndpointResponse>; }