Skip to content

Accept HTTP Basic client credentials on the authorization_code grant - #81

Merged
joehoyle merged 2 commits into
WP-API:mainfrom
tomjn:fix/basic-auth-authorization-code-grant
Sep 9, 2026
Merged

Accept HTTP Basic client credentials on the authorization_code grant#81
joehoyle merged 2 commits into
WP-API:mainfrom
tomjn:fix/basic-auth-authorization-code-grant

Conversation

@tomjn

@tomjn tomjn commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

A client that authenticates at the token endpoint with HTTP Basic auth, which RFC 6749 section 2.3.1 recommends, gets "Missing parameter(s): client_id" on the authorization_code grant. The client_credentials grant already reads the header. The authorization_code grant only looked at body parameters.

Both the MCP connector and Claude Code authenticate this way, and both failed the exchange against a site running this plugin. The site's RFC 8414 discovery document advertised client_secret_basic, so the clients were behaving correctly.

The header parsing is now shared between the two grants. On the authorization_code grant it only applies when the body has no client_id, so body parameters keep precedence. A malformed header returns the same invalid_request error the client_credentials grant already uses.

This does not verify client_secret on the authorization_code grant, which #36 covers.

RFC 6749 section 2.3.1 makes Basic auth the recommended way for a client to authenticate at the token endpoint, and the client_credentials grant already parses it. The authorization_code grant only read client_id from the body, so MCP clients authenticating this way failed with a missing parameter error.
@tomjn
tomjn force-pushed the fix/basic-auth-authorization-code-grant branch from 0062ce8 to 7e1df6f Compare September 7, 2026 17:08
@roborourke

Copy link
Copy Markdown
Contributor

@joehoyle we're working around this for now but would good to get an additional review

Comment thread inc/endpoints/class-token.php Outdated
RFC 6749 section 2.3.1 has the client form-encode the id and secret before
they go in the header, so a secret containing a space or a plus only matches
once the server decodes it.
@tomjn
tomjn requested a review from joehoyle September 9, 2026 14:32
@joehoyle
joehoyle merged commit 04e2432 into WP-API:main Sep 9, 2026
21 checks passed
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.

3 participants