Skip to content

Support PKCE in the OAuth device authorization flow - #1749

Open
zyx1121 wants to merge 1 commit into
smallstep:masterfrom
zyx1121:device-flow-pkce
Open

zyx1121 wants to merge 1 commit into
smallstep:masterfrom
zyx1121:device-flow-pkce

Conversation

@zyx1121

@zyx1121 zyx1121 commented Dec 5, 2026

Copy link
Copy Markdown

Name of feature:

PKCE in the OAuth device authorization flow

Pain or issue this feature alleviates:

step oauth --console, and so step ssh login --console, fails with a Keycloak client that enforces PKCE. Keycloak checks the PKCE setting of the client in the device flow too (DeviceEndpoint.java), and step stops with:

device code response from server missing 'verification_uri' parameter. http body response: {"error":"invalid_request","error_description":"Missing parameter: code_challenge_method"}

With this change, step retries the request with an S256 code challenge when the server asks for one, and then sends the code_verifier with the token request.

I first sent the PKCE parameters on every request, but that breaks Google. It rejects the token request with Parameter not allowed for this message type: code_verifier. So step only sends them after the server asks, and the requests to servers that work today stay the same.

Is there documentation on how to use this feature? If so, where?

It needs no configuration. I added a line to the changelog.

In what environments or workflows is this feature explicitly NOT supported (if any)?

A client that requires the plain method. The retry looks for code_challenge in the error_description, which is what Keycloak returns. I don't know of another server that requires PKCE in this flow.

Supporting links/other PRs/issues:

How I tested it:

  • The new test covers both paths and fails without the fix. make lint reports 0 issues. make test passes except Test_healthAction, which also fails on master now and then (1 of 20 runs here).

  • Keycloak 26.8.2 in Docker with two public clients. I ran step oauth --provider <issuer> --client-id <client> --console --console-flow device --oidc --bare and signed in as a test user:

    step client that enforces PKCE client without PKCE
    v0.31.0 fails with the error above ID token
    master (84b4473) fails with the error above ID token
    this PR ID token ID token
  • Keycloak does check the verifier. A token request without it gets PKCE code verifier not specified, and a wrong one gets PKCE verification failed: Code mismatch.

  • Our own Keycloak with the OIDC provisioner of step-ca: step ssh login --console fails with v0.30.2 and returns an SSH certificate with this PR.

  • I did not sign in with Google. The test checks that a server that doesn't ask for PKCE gets no PKCE parameter, so those requests are the same as before.

💔Thank you!

🤖 Generated with Claude Code

Keycloak rejects the device authorization request with "Missing
parameter: code_challenge_method" when the client enforces PKCE, so
`step oauth --console` and commands that use it, like
`step ssh login --console`, fail with those clients.

Retry the request with a code challenge when the server asks for one,
and send the code verifier when polling for the token. The PKCE
parameters are not sent by default because RFC 8628 doesn't define
them, and Google rejects a token request that has a code_verifier.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CLAassistant

CLAassistant commented Dec 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants