OAuth 2.1 and RFC 9700 rules for PKCE S256, Implicit, and ROPC
How RFC 9700 and the OAuth 2.1 draft require PKCE S256, retire Implicit and ROPC grants, and behave in Keycloak 26.8.2 verification tests.
Older OAuth 2.0 tutorials still point SPAs to Implicit Flow and backend scripts to ROPC, both of which expose tokens or raw passwords. This post explains why RFC 9700 and the OAuth 2.1 draft drop those grants in favor of Authorization Code with PKCE
S256and exactredirect_urimatching, backed by five verification cases against Keycloak 26.8.2.
Standard status as of December 2026: RFC 9700, RFC 7636, and RFC 9207 are finalized IETF RFCs, while OAuth 2.1 (
draft-ietf-oauth-v2-1-17) is still an IETF Internet-Draft.
RFC 9700 vs. the OAuth 2.1 Internet-Draft
OAuth 2.0 (RFC 6749) shipped in 2012, before modern browser security controls and widespread CORS support existed. Over the past decade, the IETF patched protocol gaps across separate RFCs. Teams often cite RFC 9700 and OAuth 2.1 together, but they do not carry the same formal status.
| Specification | Status (Dec 2026) | Role |
|---|---|---|
| RFC 7636 (PKCE) | Finalized RFC | Adds code_verifier and code_challenge to stop authorization code interception |
| RFC 9207 (Issuer ID) | Finalized RFC | Adds iss to authorization responses to prevent Authorization Server Mix-Up attacks |
| RFC 9700 (OAuth 2.0 Security BCP) | Finalized RFC (BCP 240) | Authoritative security baseline that current OAuth 2.0 deployments should enforce now |
OAuth 2.1 (draft-ietf-oauth-v2-1-17) | IETF Internet-Draft | Consolidation draft folding RFC 6749, 6750, 7636, and 9700 into one specification |
When writing internal security guidelines or architecture decision records, cite RFC 9700 as the finalized standard and note the exact draft revision (draft-ietf-oauth-v2-1-17) whenever you reference OAuth 2.1. Both documents converge on four baseline rules:
- Drop Implicit Grant (
response_type=token): Never return an Access Token directly in a browser URL fragment. - Drop ROPC (
grant_type=password): Never collect a user’s password inside a client app to trade it for tokens. - Require PKCE (
S256) for all Authorization Code clients: Protect both public and confidential clients against code interception and injection. - Enforce exact
redirect_urimatching and ban query-string bearer tokens: Eliminate wildcard redirect matching and?access_token=...transport.
Why Implicit Flow and ROPC were retired
Both flows solved real constraints in 2012, but they leave structural weaknesses that modern browsers and identity providers no longer need to accept.
Implicit Flow exposes tokens in the front channel
Implicit Flow skips the back-channel token exchange and delivers the Access Token directly in the redirect fragment (https://app.example.test/callback#access_token=...). That shortcut creates three concrete risks:
- URL leakage: Tokens sitting in URL fragments can leak through browser history, proxy or debugging extensions, and open redirectors on the client domain.
- Access Token injection: Because there is no back-channel exchange binding the authorization request to token delivery, a client cannot reliably tell whether an injected token came from its own login request.
- No safe Refresh Token path: Front-channel delivery cannot safely issue long-lived refresh tokens, pushing apps toward brittle silent-iframe renewal workarounds.
Every modern browser supports CORS, so SPAs can run Authorization Code + PKCE (S256) directly against the token endpoint—or move tokens off the browser entirely using a Backend for Frontend (BFF).
ROPC breaks delegation and blocks modern MFA
The Resource Owner Password Credentials grant (grant_type=password) asks the client app to render its own username/password form and POST those credentials directly to the authorization server.
- Wider credential exposure: OAuth exists so clients never touch user passwords. ROPC forces every client app to handle raw credentials across its UI, memory, and HTTP layer.
- Incompatible with modern authentication: TOTP, WebAuthn/Passkeys, federated SSO, passwordless login, and step-up risk checks all require interactive flows hosted by the authorization server. A single credential POST has no room for them.
How PKCE S256 works and why plain was dropped
PKCE (RFC 7636) originally protected mobile native apps whose custom URI schemes could be hijacked by another app on the same device. RFC 9700 and OAuth 2.1 apply PKCE to every Authorization Code client so that only the client instance that started the /auth request can redeem the resulting code at /token.
sequenceDiagram
participant Client as Client
participant Browser as Browser
participant IdP as Auth Server
Client->>Client: Generate verifier
Client->>Client: challenge = S256(verifier)
Client->>Browser: /auth (challenge, S256)
Browser->>IdP: Authenticate user
IdP->>IdP: Bind code + challenge
IdP-->>Browser: 302 code + iss
Browser->>Client: Deliver auth code
Client->>IdP: /token (code + verifier)
IdP->>IdP: Verify S256(verifier)
IdP-->>Client: 200 OK (tokens)
The protection comes from splitting a hash and its preimage across two channels:
- For each login attempt, the client generates a high-entropy random
code_verifier(43 to 128 characters). - It hashes
code_verifierwith SHA-256 and Base64URL-encodes the digest without=padding to producecode_challenge. - The front-channel
/authredirect carries onlycode_challengeandcode_challenge_method=S256. The authorization server stores that challenge alongside the issuedcode. - When the callback returns
code, the client sends bothcodeand the originalcode_verifierto/token. The server hashescode_verifierand checks that it matches the storedcode_challenge.
Even if an attacker intercepts both the /auth request (code_challenge) and the callback (code), SHA-256 cannot be reversed to recover code_verifier, so the token exchange fails.
Why plain is gone
RFC 7636 originally allowed code_challenge_method=plain (code_challenge == code_verifier) for constrained environments that lacked SHA-256. If an attacker can inspect the authorization request URL through a local proxy, log, or malicious extension, plain hands over code_verifier immediately. RFC 9700 requires S256 whenever the client supports it, and the OAuth 2.1 draft removes plain completely.
Choosing a grant type and where PKCE stops
Match the grant type to whether a human user is present and whether the client can keep a secret:
| Scenario | Recommended grant type | PKCE (S256) | Notes |
|---|---|---|---|
| Server-side web app (Confidential Client) | Authorization Code | Strongly recommended | Pair with client_secret or private_key_jwt to block code injection |
| SPA / mobile / desktop app (Public Client) | Authorization Code | Required | Consider a BFF for high-security SPAs |
| Service-to-service / batch jobs (M2M) | Client Credentials | Not applicable | Direct back-channel token issuance with no user or auth code |
| Input-constrained devices (TV / CLI) | Device Authorization (RFC 8628) | Not applicable | User completes sign-in on a secondary browser |
| Legacy Implicit / ROPC | Do not use | — | Retired by RFC 9700 and OAuth 2.1; migrate to Auth Code + PKCE |
Where PKCE does not protect you
PKCE secures the gap between the authorization redirect and the token exchange, nothing more. Plan separately for three boundaries:
- PKCE is not client authentication: It proves the same client instance started and finished the flow, not that the client owns a registered credential. Confidential clients still need
client_secret,private_key_jwt, or mTLS. - PKCE cannot stop post-issuance XSS theft: Once an Access Token lands in browser memory or
localStorage, an XSS payload can read and replay it. For public clients using Refresh Tokens, RFC 9700 requires either sender-constrained tokens (DPoP/mTLS) or Refresh Token Rotation with reuse detection. - Token validation stays the client’s job: Getting tokens safely through PKCE does not replace verifying the ID Token signature and its
iss,aud, andnonceclaims. I covered the boundary between Access, ID, and Refresh Tokens in my post on OAuth 2.0 vs. OIDC token roles.
Verifying PKCE S256 and redirect_uri checks in Keycloak 26.8.2
To see how a production IdP enforces these rules, I ran an isolated quay.io/keycloak/keycloak:26.8.2 container over local HTTPS (https://127.0.0.1:18443, self-signed certificate) and imported demo-realm-realm.json with --import-realm. Here is the app1-client excerpt:
1
2
3
4
5
6
7
8
9
10
{
"clientId": "app1-client",
"publicClient": true,
"protocol": "openid-connect",
"standardFlowEnabled": true,
"implicitFlowEnabled": false,
"directAccessGrantsEnabled": false,
"redirectUris": ["http://app1.example.test/callback"],
"attributes": { "pkce.code.challenge.method": "S256" }
}
Keycloak 26.8.2’s
--import-realmrequires the<realm>-realm.jsonfilename pattern (heredemo-realm-realm.json). Also, a default realm does not force PKCE automatically—you must setpkce.code.challenge.method: S256on each client or enforce it globally via Realm Client Policies.
Observed results across five test cases
Running five real HTTPS requests against app1-client produced these exact responses:
| Case | Request condition | HTTP status | Observed response / error |
|---|---|---|---|
1. Missing code_challenge | /auth without PKCE parameters | 302 Found | error=invalid_requestMissing parameter: code_challenge_method |
2. plain method | /auth with code_challenge_method=plain | 302 Found | error=invalid_requestInvalid parameter: code challenge method is not matching the configured one |
3. Unregistered redirect_uri | /auth with /callback/extra | 400 Bad Request | Blocked immediately with no Location headerInvalid parameter: redirect_uri |
4. Wrong code_verifier | /token with valid S256 code and mismatched verifier | 400 Bad Request | {"error": "invalid_grant", "error_description": "PKCE verification failed: Code mismatch"} |
5. Valid code_verifier | /token with matching verifier | 200 OK | token_type: "Bearer", expires_in: 300, plus access_token, id_token, and refresh_token |
You can reproduce cases 1 and 2 directly with curl:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 1) Missing code_challenge (replace with your local self-signed CA cert path)
curl -sS -D - -o /dev/null --cacert /path/to/local-ca-cert.pem \
"https://127.0.0.1:18443/realms/demo-realm/protocol/openid-connect/auth?client_id=app1-client&response_type=code&scope=openid&redirect_uri=http%3A%2F%2Fapp1.example.test%2Fcallback&state=s1" \
| grep -iE "^(HTTP/|location:)"
# Actual output:
# HTTP/2 302
# location: http://app1.example.test/callback?error=invalid_request&error_description=Missing+parameter%3A+code_challenge_method&state=s1&iss=https%3A%2F%2F127.0.0.1%3A18443%2Frealms%2Fdemo-realm
# 2) code_challenge_method=plain
curl -sS -D - -o /dev/null --cacert /path/to/local-ca-cert.pem \
"https://127.0.0.1:18443/realms/demo-realm/protocol/openid-connect/auth?client_id=app1-client&response_type=code&scope=openid&redirect_uri=http%3A%2F%2Fapp1.example.test%2Fcallback&state=s2&code_challenge=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&code_challenge_method=plain" \
| grep -iE "^(HTTP/|location:)"
# Actual output:
# HTTP/2 302
# location: http://app1.example.test/callback?error=invalid_request&error_description=Invalid+parameter%3A+code+challenge+method+is+not+matching+the+configured+one&state=s2&iss=https%3A%2F%2F127.0.0.1%3A18443%2Frealms%2Fdemo-realm
Two details in those responses matter in production:
- No redirect on an invalid
redirect_uri(Case 3): Whencode_challengefails, Keycloak safely redirects the error back to the registered callback URI. Whenredirect_uriitself does not match (/callback/extra), Keycloak stops with400 Bad Requestand emits noLocationheader, refusing to act as an open redirector. - Automatic RFC 9207
issparameter: Both error redirects appendiss=https%3A%2F%2F127.0.0.1%3A18443%2Frealms%2Fdemo-realm. Clients that integrate with multiple IdPs can compare thisissvalue against the issuer they initiated login with to stop Authorization Server Mix-Up attacks. Keycloak 26.8.2 enables this behavior by default.
For a full client-side walkthrough combining PKCE S256, state, nonce, and JWKS verification against Keycloak 26.8.2 in PHP, see my Gnuboard5 Keycloak OIDC SSO plugin guide.
Production pitfalls and checklist
Watch out: Supporting PKCE on the client is not enough. If the authorization server does not require
S256for that client, an attacker can stripcode_challengefrom the request and downgrade the flow. Likewise, leaving a wildcard entry likehttps://app.example.com/*inredirectUrisreopens code-leakage paths through open redirectors.
Before shipping an OAuth 2.0 or OIDC integration, check these five items:
- Disable retired grants: Confirm Implicit Flow (
implicitFlowEnabled) and ROPC (directAccessGrantsEnabled) are off in your IdP client configuration. - Enforce PKCE
S256server-side: Verify withcurlthat the IdP actively rejects both missingcode_challengeparameters andcode_challenge_method=plain. - Lock down
redirect_urivalues: Remove wildcards (*) and register exact callback URLs only. - Validate
issandstate: In multi-IdP clients, verify the RFC 9207issparameter alongsidestateon every callback. - Protect Refresh Tokens on public clients: Pair public-client refresh tokens with rotation and reuse detection, DPoP/mTLS, or move token handling to a BFF.