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.
Protocol walkthrough
Section titled “Protocol walkthrough”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=S256Optional standard parameters supported:
prompt=loginormax_age=<seconds>— require fresh authentication; verifyauth_timein the returned ID token.prompt=none— returnslogin_requiredorconsent_requiredwhen user interaction is needed.
2. User consent and callback
Section titled “2. User consent and callback”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_uriwithcode,state, andiss=https://jointtex.com/oidc. - If the user cancels, JointTex redirects with
error=access_deniedand your originalstate.
On your callback route, first verify that state matches the browser’s stored session value and that iss equals https://jointtex.com/oidc.
3. Exchange the authorization code
Section titled “3. Exchange the authorization code”Send a form POST to https://jointtex.com/oidc/token:
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.
4. Validate the ID token
Section titled “4. Validate the ID token”Verify the returned id_token using the public keys from https://jointtex.com/oidc/jwks:
- Require
RS256and a trustedkidfrom JWKS (refetch JWKS if an unknownkidappears during key rotation). - Require exact
iss(https://jointtex.com/oidc), exactaud(yourclient_id), validexp/iat, matchingnonce, and a non-emptysub. - Check
auth_timeif you passedmax_ageorprompt=login. - Never trust a decoded JWT payload without cryptographic signature verification.
5. Fetch UserInfo
Section titled “5. Fetch UserInfo”Call GET https://jointtex.com/oidc/userinfo with Authorization: Bearer <access_token> and assert that the returned sub matches the ID token’s sub:
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}Node.js example (openid-client v6)
Section titled “Node.js example (openid-client v6)”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 handlerconst 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)