Guide 01 · OIDC & OAuth 2.1

OpenID Connect & OAuth 2.1 PKCE Integration

Integrate Sign in with Protext using OpenID Connect Core discovery, OAuth 2.1 authorization code flow with S256 PKCE, RFC 9207 iss checks, and RS256 ID tokens.

SPEC.md §6SPEC.md §6.1SPEC.md §6.2SPEC.md §8SPEC.md §9
Quick answer · PROTEXT/0.1

Protext implements the OpenID Connect Core authorization code flow with OAuth 2.1 PKCE (S256) and standard discovery at /.well-known/openid-configuration.

Implicit, hybrid, and resource owner password grants are not supported. Public clients must send code_challenge with code_challenge_method=S256, authorization codes expire in 300 seconds and are single-use with replay revocation, and POST /oidc/token returns both id_token and the consented context bundle in one round-trip.

PROTEXT/0.1 OIDC & OAuth 2.1 endpoints and security parameters

Parameter / EndpointValue on protext.orgSpec requirement
DiscoveryGET /.well-known/openid-configurationPublishes OIDC metadata plus protext_context_endpoint and protext_metadata (§8)
AuthorizationGET /oidc/authorizeresponse_type=code, exact redirect_uri match (RFC 8252 loopback ports allowed), state, PKCE S256 (§6.1)
Authorization redirectcode, state, issIncludes RFC 9207 iss parameter for issuer mix-up defense (§6.1)
Token exchangePOST /oidc/tokengrant_type=authorization_code or refresh_token; Cache-Control: no-store (§6.2)
Code lifetime & replay300 seconds (5 min), single-usePresenting a code twice revokes every token minted from its grant (§6.2, §9)
Token lifetimesaccess_token: 3600s · id_token: 3600s · refresh_token: 90dOpaque access/refresh tokens stored as SHA-256 hashes; refresh tokens rotate (§6.3, §9)
Wire format & code example

Minimal Node.js relying party using OIDC discovery, PKCE S256, and jose

Adapted directly from examples/node-relying-party/server.mjs in the Protext repository.

import { createHash, randomBytes } from "node:crypto";
import { createRemoteJWKSet, jwtVerify } from "jose";

const ISSUER = "https://protext.org";
const disc = await (await fetch(`${ISSUER}/.well-known/openid-configuration`)).json();
const jwks = createRemoteJWKSet(new URL(disc.jwks_uri));

// 1. Build the authorization URL with S256 PKCE
const verifier = randomBytes(32).toString("base64url");
const challenge = createHash("sha256").update(verifier).digest("base64url");
const authUrl = new URL(disc.authorization_endpoint);
authUrl.searchParams.set("client_id", process.env.PROTEXT_CLIENT_ID);
authUrl.searchParams.set("redirect_uri", "http://localhost:4000/cb");
authUrl.searchParams.set("response_type", "code");
authUrl.searchParams.set("scope", "openid profile email context:work offline_access");
authUrl.searchParams.set("state", randomBytes(12).toString("base64url"));
authUrl.searchParams.set("code_challenge", challenge);
authUrl.searchParams.set("code_challenge_method", "S256");

// 2. Exchange the code and verify the RS256 id_token
const tok = await (await fetch(disc.token_endpoint, {
  method: "POST",
  headers: { "content-type": "application/x-www-form-urlencoded" },
  body: new URLSearchParams({
    grant_type: "authorization_code",
    code,
    redirect_uri: "http://localhost:4000/cb",
    client_id: process.env.PROTEXT_CLIENT_ID,
    client_secret: process.env.PROTEXT_CLIENT_SECRET,
    code_verifier: verifier,
  }),
})).json();

const { payload } = await jwtVerify(tok.id_token, jwks, {
  issuer: ISSUER,
  audience: process.env.PROTEXT_CLIENT_ID,
});
// tok.context holds the consented PROTEXT/0.1 bundle

How standard OIDC clients work with zero Protext-specific code

PROTEXT/0.1 maps well-known vault items onto standard OpenID Connect claims automatically. When a person consents to identity.name, identity.handle, identity.avatar, contact.email, contact.phone, link.website, identity.birthdate, or pref.timezone, the reference provider derives standard OIDC claims (name, preferred_username, picture, email, phone_number, website, birthdate, zoneinfo) inside both the RS256 id_token and GET /oidc/userinfo.

In addition to standard claims, id_token and /oidc/userinfo include protext_handle and protext_url, and /oidc/token returns context and context_token inline so Protext-aware applications do not need an extra network round-trip after login.

PKCE, redirect URI rules, and replay detection

Public clients registered with token_endpoint_auth_method set to none must provide PKCE using code_challenge_method=S256; plain PKCE is rejected. Confidential clients authenticate with either HTTP Basic (client_secret_basic) or form body parameters (client_secret_post), and PKCE is recommended for confidential clients as well.

Redirect URIs are matched strictly against registered URIs. For local development, loopback URLs on localhost or 127.0.0.1 permit any port while preserving hostname and pathname per RFC 8252 §7.3. If an authorization code is submitted a second time, /oidc/token deletes every access and refresh token minted from that grant and returns invalid_grant.

  • Always verify the returned state parameter and confirm iss matches https://protext.org (RFC 9207).
  • Use prompt=consent when you explicitly want the user to revisit item checkboxes even if an existing grant already covers the requested scopes.
  • Treat contact.email carefully: Protext 0.1 emits email_verified: false because the reference provider does not verify email ownership before releasing the claim (§9).
Next step

Verify against the normative specification or register your client.

Read PROTEXT/0.1 SpecDeveloper Quickstart10 Languages
FAQ

Frequently asked questions

Which OAuth 2.1 and OIDC grant types does Protext support?

Protext supports authorization_code (with mandatory S256 PKCE for public clients) and refresh_token (when offline_access is requested). Implicit, hybrid, and password grants are explicitly unsupported under SPEC.md §6.

What client authentication methods work at /oidc/token?

The token endpoint advertises and supports none (public PKCE clients), client_secret_basic (HTTP Basic Authorization header), and client_secret_post (client_id and client_secret in the form body).

How long do Protext authorization codes and tokens last?

In the reference provider (lib/oidc.ts), authorization codes expire after 300 seconds (5 minutes), access tokens and RS256 ID tokens expire after 3600 seconds (1 hour), and refresh tokens expire after 90 days with rotation on every refresh.

What happens if an authorization code is replayed?

Authorization codes are single-use. If a code is presented a second time at POST /oidc/token, the server immediately deletes all tokens associated with that grant and responds with an invalid_grant error.

Does Protext return email_verified as true?

No. PROTEXT/0.1 sets email_verified: false whenever an email claim is present because the 0.1 reference provider does not verify email ownership. Relying parties should not use Protext emails for account recovery without their own verification.

When does Protext skip the consent screen for returning users?

If an existing grant for the relying party already covers all requested scopes and prompt=consent is not passed, the provider may re-issue an authorization code directly without showing the consent screen. It must never widen a grant silently.

Related guides

Continue exploring PROTEXT/0.1

Guide 04 · RFC 7591 Registration

RFC 7591 Dynamic Client Registration

Register public PKCE or confidential OIDC relying parties immediately at POST https://protext.org/oidc/register using RFC 7591 without creating a provider account first.

Read guide →
Guide 02 · Data Model & Scopes

Context Bundles, Categories & Scopes Reference

Complete PROTEXT/0.1 reference for the 7 context categories, 23 well-known item kinds, OIDC claim mappings, structured values, and bundle envelope fields.

Read guide →
Guide 05 · Cryptographic Verification

Signed context_token & JWKS Verification

Verify RS256 signed id_token and context_token JWS payloads against /.well-known/jwks.json using standard JOSE libraries for verifiable third-party bundle handoff.

Read guide →