CS › Web-Network

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.

OAuth 2.1 and RFC 9700 rules for PKCE S256, Implicit, and ROPC

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 S256 and exact redirect_uri matching, 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.

SpecificationStatus (Dec 2026)Role
RFC 7636 (PKCE)Finalized RFCAdds code_verifier and code_challenge to stop authorization code interception
RFC 9207 (Issuer ID)Finalized RFCAdds 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-DraftConsolidation 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:

  1. Drop Implicit Grant (response_type=token): Never return an Access Token directly in a browser URL fragment.
  2. Drop ROPC (grant_type=password): Never collect a user’s password inside a client app to trade it for tokens.
  3. Require PKCE (S256) for all Authorization Code clients: Protect both public and confidential clients against code interception and injection.
  4. Enforce exact redirect_uri matching 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:

  1. For each login attempt, the client generates a high-entropy random code_verifier (43 to 128 characters).
  2. It hashes code_verifier with SHA-256 and Base64URL-encodes the digest without = padding to produce code_challenge.
  3. The front-channel /auth redirect carries only code_challenge and code_challenge_method=S256. The authorization server stores that challenge alongside the issued code.
  4. When the callback returns code, the client sends both code and the original code_verifier to /token. The server hashes code_verifier and checks that it matches the stored code_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:

ScenarioRecommended grant typePKCE (S256)Notes
Server-side web app (Confidential Client)Authorization CodeStrongly recommendedPair with client_secret or private_key_jwt to block code injection
SPA / mobile / desktop app (Public Client)Authorization CodeRequiredConsider a BFF for high-security SPAs
Service-to-service / batch jobs (M2M)Client CredentialsNot applicableDirect back-channel token issuance with no user or auth code
Input-constrained devices (TV / CLI)Device Authorization (RFC 8628)Not applicableUser completes sign-in on a secondary browser
Legacy Implicit / ROPCDo 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, and nonce claims. 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-realm requires the <realm>-realm.json filename pattern (here demo-realm-realm.json). Also, a default realm does not force PKCE automatically—you must set pkce.code.challenge.method: S256 on 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:

CaseRequest conditionHTTP statusObserved response / error
1. Missing code_challenge/auth without PKCE parameters302 Founderror=invalid_request
Missing parameter: code_challenge_method
2. plain method/auth with code_challenge_method=plain302 Founderror=invalid_request
Invalid parameter: code challenge method is not matching the configured one
3. Unregistered redirect_uri/auth with /callback/extra400 Bad RequestBlocked immediately with no Location header
Invalid parameter: redirect_uri
4. Wrong code_verifier/token with valid S256 code and mismatched verifier400 Bad Request{"error": "invalid_grant", "error_description": "PKCE verification failed: Code mismatch"}
5. Valid code_verifier/token with matching verifier200 OKtoken_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): When code_challenge fails, Keycloak safely redirects the error back to the registered callback URI. When redirect_uri itself does not match (/callback/extra), Keycloak stops with 400 Bad Request and emits no Location header, refusing to act as an open redirector.
  • Automatic RFC 9207 iss parameter: Both error redirects append iss=https%3A%2F%2F127.0.0.1%3A18443%2Frealms%2Fdemo-realm. Clients that integrate with multiple IdPs can compare this iss value 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 S256 for that client, an attacker can strip code_challenge from the request and downgrade the flow. Likewise, leaving a wildcard entry like https://app.example.com/* in redirectUris reopens 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 S256 server-side: Verify with curl that the IdP actively rejects both missing code_challenge parameters and code_challenge_method=plain.
  • Lock down redirect_uri values: Remove wildcards (*) and register exact callback URLs only.
  • Validate iss and state: In multi-IdP clients, verify the RFC 9207 iss parameter alongside state on 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.

References

This document describes best current security practice for OAuth 2.0. It updates and extends the threat model and security advice given in RFCs 6749, 6750, and 6819 to incorporate practical experiences gathered since OAuth 2.0 was published and covers new threats relevant due to the broader application of OAuth 2.0. Further, it deprecates some modes of operation that are deemed less secure or even insecure.
The OAuth 2.1 authorization framework enables an application to obtain limited access to a protected resource, either on behalf of a resource owner by orchestrating an approval interaction between the resource owner and an authorization service, or by allowing the application to obtain access on its own behalf. This specification replaces and obsoletes the OAuth 2.0 Authorization Framework described in RFC 6749 and the Bearer Token Usage in RFC 6750.
OAuth 2.0 public clients utilizing the Authorization Code Grant are susceptible to the authorization code interception attack. This specification describes the attack as well as a technique to mitigate against the threat through the use of Proof Key for Code Exchange (PKCE, pronounced "pixy").
This document specifies a new parameter called iss. This parameter is used to explicitly include the issuer identifier of the authorization server in the authorization response of an OAuth authorization flow. The iss parameter serves as an effective countermeasure to "mix-up attacks".
This post is licensed under CC BY 4.0 by the author.