Hint
PKCE replaces the client secret for public clients (SPAs, mobile apps) — proves the token recipient is the same app that started the flow
PKCE (Proof Key for Code Exchange, pronounced "pixie") is an OAuth 2.0 extension that protects the authorization code flow for public clients (SPAs, mobile apps) that can't securely store a client secret.
The problem with SPAs: A client secret embedded in a SPA's JavaScript bundle is public — anyone can extract it and impersonate your app.
How PKCE works:
// Step 1: generate
const codeVerifier = generateRandomString(64);
const codeChallenge = base64urlEncode(sha256(codeVerifier));
// Step 2: redirect with challenge
window.location.href = `${authServer}/authorize?
code_challenge=${codeChallenge}&code_challenge_method=S256&...`;
Use PKCE for: all SPAs, mobile apps, any public client. It's now recommended even for confidential clients.