Skip to content

chore: use Web Crypto API for PKCE random generation - #29

Merged
marcusolsson merged 1 commit into
mainfrom
fix/issue-10-web-crypto-pkce
May 21, 2026
Merged

chore: use Web Crypto API for PKCE random generation#29
marcusolsson merged 1 commit into
mainfrom
fix/issue-10-web-crypto-pkce

Conversation

@marcusolsson

Copy link
Copy Markdown
Contributor

Issue 10 from TODO.md

The PKCE flow used Node.js's older crypto.randomBytes() for generating the code_verifier and state nonce. While synchronous and fast for small sizes, crypto.webcrypto.getRandomValues is the idiomatic, non-blocking, Web-API-compatible choice on Node 18+.

Changes

  • Replaces crypto.randomBytes(32).toString('base64url') with crypto.webcrypto.getRandomValues(new Uint8Array(32)) + Buffer.from(bytes).toString('base64url').
  • Adds a generateRandomHex(byteLength) helper using the same Web Crypto API for the state nonce.
  • Exports generateCodeVerifier() for unit testing.
  • Adds a regression test verifying base64url format and 43-character length.

Refs: TODO.md Issue 10

@marcusolsson
marcusolsson merged commit 8d05efd into main May 21, 2026
@marcusolsson
marcusolsson deleted the fix/issue-10-web-crypto-pkce branch May 21, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant