Single-page applications
A browser-based SPA needs OAuth sign-in without exposing a client secret.
Kinde · Const
PKCE is Kinde’s secure Authorization Code variant for public clients such as SPAs and mobile apps. It replaces a stored client secret with a verifier-and-challenge proof.
PKCE extends Kinde’s authorization-code flow for clients that cannot safely keep a client secret. The client creates a random verifier, sends a transformed challenge during authorization, and later proves possession by presenting the original verifier when exchanging the authorization code for tokens.
Authorization Code flow with PKCE: code_challenge + code_challenge_method in the authorization request; code_verifier in the token request| Name | Type | Description |
|---|---|---|
code_verifier | string | Random secret generated by the client and later presented to prove possession. |
code_challenge | string | Hashed representation of the verifier sent in the authorization request. |
code_challenge_method | string | Transformation used to create the challenge; Kinde documentation specifies SHA-256/S256. |
An authorization code that can be exchanged for tokens after the client proves possession of the code verifier.
const verifier = crypto.randomUUID();
const challenge = await crypto.subtle.digest(
"SHA-256",
new TextEncoder().encode(verifier),
);
const codeChallenge = btoa(String.fromCharCode(...new Uint8Array(challenge)))
.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
const authorizationUrl = new URL("https://yourbusiness.kinde.com/oauth2/auth");
authorizationUrl.search = new URLSearchParams({
client_id: "YOUR_CLIENT_ID",
redirect_uri: "https://example.com/callback",
response_type: "code",
scope: "openid email offline",
code_challenge: codeChallenge,
code_challenge_method: "S256",
}).toString();
console.log(authorizationUrl.toString());Generates a verifier, derives its SHA-256 challenge, and adds the PKCE parameters to a Kinde authorization request.
A browser-based SPA needs OAuth sign-in without exposing a client secret.
A mobile app authenticates users while keeping credentials out of shipped client code.
A front-end application needs Kinde authorization-code login instead of the unsupported Implicit Flow.
PKCE is an extension to the Authorization Code flow that replaces the client secret with a one-time cryptographic proof. The application generates a code verifier, sends a hashed code challenge to Kinde, and later supplies the verifier during token exchange.
Follow-up: Why is PKCE useful for a single-page application? It avoids depending on a client secret that client-side code cannot securely keep.
Kinde requires code_challenge and code_challenge_method when using its PKCE extension. The recommended method shown in the documentation is SHA-256, represented in authorization requests as S256.
Follow-up: What must the client preserve after creating the authorization request? It must retain the original verifier so it can present it during the token request.
PKCE is recommended for mobile applications and single-page applications. It is also suitable for front-end applications because it does not require embedding a client secret in exposed client-side code.
Follow-up: What flow should a Kinde front-end application avoid? It should avoid the Implicit Flow, which Kinde does not support for front-end apps.
Authorization Code Flowcode_challengecode_challenge_methodcode_verifierstatenonceImplicit FlowAuthorization Code (With PKCE)