Skip to content

fix(auth): prefer client secret auth over none when a secret is configured - #602

Open
jstar0 wants to merge 2 commits into
modelcontextprotocol:mainfrom
jstar0:fix/token-auth-method-selection
Open

jstar0 wants to merge 2 commits into
modelcontextprotocol:mainfrom
jstar0:fix/token-auth-method-selection

Conversation

@jstar0

@jstar0 jstar0 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

This fixes #601.

Problem

When an authorization server's metadata lists both none and a client-secret method in token_endpoint_auth_methods_supported, the authorization-server scenarios picked none even when a client secret was configured. The token request then went out unauthenticated, so servers supporting both methods were never exercised on the confidential-client path.

Fix

In selectTokenAuthMethod (used by both authorization-code-grant and dpop scenarios): when a client secret is configured, prefer client_secret_post / client_secret_basic over none. Behavior is unchanged otherwise:

  • Public clients (no secret) still use none when offered.
  • A configured secret with only none offered still falls back to none.
  • Servers advertising only unsupported methods (client_secret_jwt, private_key_jwt, tls_client_auth) still skip.

Tests

Added three vitest cases in authorization-code-grant.test.ts:

  1. AS offers ['none', 'client_secret_post'] + secret configured → token request carries client_id + client_secret in the body, no Authorization header.
  2. AS offers ['none', 'client_secret_basic'] + secret configured → token request carries the Basic authorization header, no client_secret body param.
  3. No secret configured + all methods offered → still uses none (regression guard).

npm run build passes; npm test passes (644/644).

…gured

When the AS metadata lists both `none` and a client_secret method, the
runner previously selected `none` even for confidential clients with a
configured secret, so the token request went out unauthenticated and the
confidential-client path was never exercised.

When a client secret is configured, prefer client_secret_post /
client_secret_basic over `none`. Public clients (no secret) still use
`none`, and servers offering only unsupported methods still skip.

This fixes modelcontextprotocol#601
@jstar0
jstar0 requested a review from a team as a code owner November 25, 2026 02:17
@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npx https://pkg.pr.new/@modelcontextprotocol/conformance@602

commit: b50b898

@dbauthplane

Copy link
Copy Markdown

Thanks for picking this up. I verified this branch against AuthPlane, whose metadata advertises none, client_secret_basic and client_secret_post, with three registered clients (one per method). I logged every token request:

Client authorization-code-grant dpop
client_secret_basic (secret passed) pass 3/3, token binding SUCCESS
client_secret_post (secret passed) pass 3/3, token binding SUCCESS
public, no secret pass 3/3, token binding SUCCESS

Before this change, both confidential clients sent the code exchange with no credentials and got invalid_client: auth-code failed, and dpop skipped token binding. With this branch, the secret is sent and the public path is unchanged. The unit tests pass locally too.

Two optional suggestions:

  1. When both secret methods are offered, consider preferring client_secret_basic. RFC 6749 §2.3.1 says servers must support HTTP Basic and that credentials in the request body are not recommended. A server that enforces each client's registered method would also reject a Basic-registered client that sends client_secret_post.
  2. A dpop test mirroring the new authorization-code-grant ones would lock in the same behavior there, since dpop.ts changes too.

Closes #601 from our side once merged. Thanks again!

@jstar0

jstar0 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough verification against a live server — especially the dpop token-binding coverage across all three client types. That's exactly the path this was meant to exercise.

@JosephDoUrden JosephDoUrden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the authorization-code-grant and dpop specs on b50b898: 29/29 pass, eslint and prettier clean. Reverting authorization-code-grant.ts fails 2 of the 3 new tests, so that path is covered. Reverting dpop.ts leaves all 29 green, so dbauthplane's second suggestion still stands: the dpop change has no test yet. LGTM once dpop gets a mirror test.

Mirror the authorization-code-grant coverage for the dpop scenario: when
the AS advertises both none and a client_secret method and a secret is
configured, the token request must carry client credentials (basic or
post); a public client still sends none. Verified by mutation: reverting
the selection fix fails the two confidential-client cases.
@jstar0

jstar0 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Added the mirror coverage in 0778837: new dpop-token-auth.test.ts exercises the dpop token exchange with a mocked AS advertising both none and a client_secret method — with a secret configured, the token request carries Basic credentials or a client_secret body parameter (post), and a public client still sends no credentials. Mutation-checked: reverting the selection fix fails the two confidential-client cases while the public-client case stays green. Full suite 647/647, eslint and prettier clean.

This branch has not been deployed

No deployments
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.

Auth scenarios use token_endpoint_auth_method "none" even when a client secret is provided

3 participants