pkce-challenge
Generate or verify a Proof Key for Code Exchange (PKCE) challenge pair
Last updated 2 months ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pkce-challenge 
SYNC missed versions from official npm registry.

pkce-challenge

Generate or verify a Proof Key for Code Exchange (PKCE) challenge pair.

Read more about PKCE.

Installation

npm install pkce-challenge

Usage

Default length for the verifier is 43

import pkceChallenge from "pkce-challenge";

await pkceChallenge();

gives something like:

{
    code_verifier: 'u1ta-MQ0e7TcpHjgz33M2DcBnOQu~aMGxuiZt0QMD1C',
    code_challenge: 'CUZX5qE8Wvye6kS_SasIsa8MMxacJftmWdsIA_iKp3I',
    code_challenge_method: 'S256'
}

Specify a verifier length

const challenge = await pkceChallenge(128);

challenge.code_verifier.length === 128; // true

Specify a challenge method

The library supports two challenge methods:

  • S256 (default): SHA-256 hashing
  • plain: No hashing (verifier equals challenge)
// Use S256 method (default)
const challenge = await pkceChallenge(43, "S256");
challenge.code_challenge_method === "S256"; // true

// Use plain method
const plainChallenge = await pkceChallenge(43, "plain");
plainChallenge.code_challenge_method === "plain"; // true
plainChallenge.code_challenge === plainChallenge.code_verifier; // true

Challenge verification

import { verifyChallenge } from "pkce-challenge";

(await verifyChallenge(challenge.code_verifier, challenge.code_challenge)) ===
  true; // true

// Verify with specific method
(await verifyChallenge(
  challenge.code_verifier,
  challenge.code_challenge,
  "S256"
)) === true; // true

Challenge generation from existing code verifier

import { generateChallenge } from "pkce-challenge";

(await generateChallenge(challenge.code_verifier)) === challenge.code_challenge; // true

// Generate with specific method
(await generateChallenge(challenge.code_verifier, "S256")) ===
  challenge.code_challenge; // true

Current Tags

  • 6.0.0                                ...           latest (2 months ago)

15 Versions

  • 6.0.0                                ...           2 months ago
  • 5.0.1                                ...           5 months ago
  • 5.0.0                                ...           a year ago
  • 4.1.0                                ...           2 years ago
  • 4.0.1                                ...           3 years ago
  • 4.0.0                                ...           3 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.0                                ...           4 years ago
  • 2.2.0                                ...           5 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.0.3                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 18
Last Day 0
Last Week 18
Last Month 15
Dependencies (0)
None
Dev Dependencies (8)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |