HMAC-SHA256 signing secret. Use a strong random string from an environment variable (≥ 32 bytes recommended).
Name of the HTTP cookie. Defaults to "sc_pkce".
ReadonlycookieName of the HTTP cookie. Defaults to "sc_pkce".
Remove a verifier entry (one-time-use enforcement).
Retrieve a verifier by state from the in-process map.
Returns undefined if absent or expired.
Read the PKCE cookie from a raw Cookie header string.
Useful when working with Node.js IncomingMessage (Pages Router).
The raw Cookie header value from the request.
Read the PKCE cookie from an incoming request, verify its HMAC signature, and load the state → verifier mapping into the in-process map.
Call this at the start of your OAuth callback handler so that
exchangeCode() can find the verifier via get(state).
Returns the verifier string if the cookie is valid, undefined otherwise
(missing, tampered, or expired cookie).
The incoming Request object (Web API / Next.js App Router).
Store a verifier in the in-process map. The verifier is embedded into the cookie via setCookieHeader.
Generate the Set-Cookie header value for the PKCE verifier cookie.
Call this after initLogin() (which calls set() internally) to get
the header string to set in your login response. The cookie embeds the
state → verifier mapping signed with HMAC-SHA256 so the server can verify
integrity on callback.
The state token returned by initLogin().
Cookie lifetime in milliseconds (should match the PKCE TTL).
Whether to add the Secure cookie flag.
Defaults to true when NODE_ENV === "production".
Cookie-based PkceStore implementation.
Encodes the PKCE verifier into a signed HTTP cookie so it survives across serverless cold starts and multiple server instances without needing an external store (Redis, database, etc.).
How it works:
initLogin(), thensetCookieHeader(state, ttlMs)to get theSet-Cookieheader value. Include this in the login response so the browser stores the signed verifier.getFromRequest(req)to read, verify, and load the verifier from the cookie into the in-process map. ThenexchangeCode()will find it viaget(state).Security: The cookie value is HMAC-SHA256 signed with
secret(via Web CryptoSubtleCrypto). Always use a strong random secret (≥ 32 bytes) from an environment variable. The cookie must be setHttpOnly,Secure(in production), andSameSite=Lax.Suitable for: Vercel, AWS Lambda, edge runtimes, and any deployment where you cannot share process memory across instances.
Example