Skip to content

Authorization Code + PKCE Flow

Use a well-maintained OpenID Connect client library (such as openid-client for Node.js or authlib for Python) rather than assembling JWT verification by hand.

1. Discover and redirect to /oidc/authorize

Section titled “1. Discover and redirect to /oidc/authorize”

Fetch https://jointtex.com/oidc/.well-known/openid-configuration, generate fresh unpredictable state, nonce, and a PKCE code_verifier (43–128 unreserved characters), and store them in a short-lived, browser-bound session on your server.

Redirect the user to:

https://jointtex.com/oidc/authorize
?response_type=code
&client_id=<your-client-id>
&redirect_uri=https://app.example.com/auth/jointtex/callback
&scope=openid%20profile%20email
&state=<random-state>
&nonce=<random-nonce>
&code_challenge=<BASE64URL(SHA256(code_verifier))>
&code_challenge_method=S256

Optional standard parameters supported:

  • prompt=login or max_age=<seconds> — require fresh authentication; verify auth_time in the returned ID token.
  • prompt=none — returns login_required or consent_required when user interaction is needed.

JointTex signs the user in (if needed) and shows an explicit consent screen displaying your application name, requested scopes, and exact callback URI.

  • If the user approves, JointTex redirects to your redirect_uri with code, state, and iss=https://jointtex.com/oidc.
  • If the user cancels, JointTex redirects with error=access_denied and your original state.

On your callback route, first verify that state matches the browser’s stored session value and that iss equals https://jointtex.com/oidc.

Send a form POST to https://jointtex.com/oidc/token:

Terminal window
curl -X POST https://jointtex.com/oidc/token \
-u "<client_id>:<client_secret>" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code=<authorization-code>" \
--data-urlencode "redirect_uri=https://app.example.com/auth/jointtex/callback" \
--data-urlencode "code_verifier=<original-pkce-verifier>"

For public clients (token_endpoint_auth_method: "none"), omit HTTP Basic auth and include client_id=<client_id> in the form body.

Authorization codes live 5 minutes, are bound to client, callback, PKCE challenge, browser session, and application revision, and are atomically consumed once.

Verify the returned id_token using the public keys from https://jointtex.com/oidc/jwks:

  • Require RS256 and a trusted kid from JWKS (refetch JWKS if an unknown kid appears during key rotation).
  • Require exact iss (https://jointtex.com/oidc), exact aud (your client_id), valid exp / iat, matching nonce, and a non-empty sub.
  • Check auth_time if you passed max_age or prompt=login.
  • Never trust a decoded JWT payload without cryptographic signature verification.

Call GET https://jointtex.com/oidc/userinfo with Authorization: Bearer <access_token> and assert that the returned sub matches the ID token’s sub:

Terminal window
curl https://jointtex.com/oidc/userinfo \
-H "Authorization: Bearer <access_token>"
{
"sub": "9a7d0f4e-3c1b-4c4b-9e6a-1f2e3d4c5b6a",
"name": "Ada Lovelace",
"email": "ada@example.edu",
"email_verified": true
}
import * as client from "openid-client";
const config = await client.discovery(
new URL("https://jointtex.com/oidc"),
process.env.JOINTTEX_CLIENT_ID!,
process.env.JOINTTEX_CLIENT_SECRET!,
client.ClientSecretBasic(process.env.JOINTTEX_CLIENT_SECRET!),
);
// 1. Build the authorization URL (store verifier, state, nonce in the browser session)
const codeVerifier = client.randomPKCECodeVerifier();
const codeChallenge = await client.calculatePKCECodeChallenge(codeVerifier);
const state = client.randomState();
const nonce = client.randomNonce();
const authUrl = client.buildAuthorizationUrl(config, {
redirect_uri: "https://app.example.com/auth/jointtex/callback",
scope: "openid profile email",
code_challenge: codeChallenge,
code_challenge_method: "S256",
state,
nonce,
});
// 2. Inside the callback handler
const tokens = await client.authorizationCodeGrant(config, currentCallbackUrl, {
pkceCodeVerifier: session.codeVerifier,
expectedState: session.state,
expectedNonce: session.nonce,
});
const claims = tokens.claims()!;
const userInfo = await client.fetchUserInfo(config, tokens.access_token, claims.sub);
// Persist user keyed by (claims.iss, claims.sub)