Member Junction
    Preparing search index...

    Generates PKCE code verifier and challenge for OAuth 2.1 authorization flows.

    Uses cryptographically secure random bytes and SHA-256 hashing per RFC 7636. The code_verifier is 64 characters (48 bytes base64url encoded), providing strong entropy for security.

    const generator = new PKCEGenerator();
    const challenge = generator.generate();

    // Use in authorization request:
    const authUrl = new URL(authEndpoint);
    authUrl.searchParams.set('code_challenge', challenge.codeChallenge);
    authUrl.searchParams.set('code_challenge_method', challenge.codeChallengeMethod);

    // Store code_verifier for token exchange:
    await storeVerifier(challenge.codeVerifier);
    Index

    Constructors

    Methods

    • Generates a cryptographically secure state parameter for CSRF protection.

      The state parameter is used to:

      1. Prevent CSRF attacks on the OAuth callback
      2. Correlate the callback to the original authorization request

      Parameters

      • length: number = 32

        Number of random bytes (default: 32, resulting in 43 chars)

      Returns string

      Base64url-encoded state string

    • Validates that a code verifier meets RFC 7636 requirements.

      Parameters

      • verifier: string

        The code verifier to validate

      Returns boolean

      true if valid, false otherwise