Skip to content

auth: improve ClientAuthenticator error messaging#2709

Open
haoxuw wants to merge 2 commits into
modelcontextprotocol:mainfrom
haoxuw:main
Open

auth: improve ClientAuthenticator error messaging#2709
haoxuw wants to merge 2 commits into
modelcontextprotocol:mainfrom
haoxuw:main

Conversation

@haoxuw
Copy link
Copy Markdown

@haoxuw haoxuw commented May 28, 2026

Summary

Aligns the ClientAuthenticator with RFC 6749 and RFC 7591 by explicitly preventing confidential clients from bypassing authentication using token_endpoint_auth_method="none".

Note: NO changes to the current behavior, only change error message and code maintainability

Closes #1842

Spec Definition:

  • RFC 7591 (Section 2): Defines the "none" method specifically for clients that "do not have a client secret."
  • RFC 6749 (Section 3.2.1): Mandates that the server MUST require authentication for any client issued credentials.

The authenticator now explicitly rejects requests where a client has a registered secret but attempts to use token_endpoint_auth_method="none". This prevents credential
downgrade attacks and clarifies configuration errors.

Changes

  • Logic: Added a check in client_auth.py to raise an AuthenticationError if a secret exists but the "none" method is requested.
  • Messaging: Updated the error to "Require valid auth method, with client secret" for better developer clarity.

Verification

Validated via tests/server/mcpserver/auth/test_auth_integration.py:

  • New Test: test_none_auth_method_fails_for_confidential_client confirms that clients with secrets are rejected when using method "none".
  • Regression: test_none_auth_method_public_client confirms that true public clients (no secret) still authenticate successfully.
  • Result: All 43 integration tests passed.

@haoxuw haoxuw changed the title auth: improve ClientAuthenticator error messaging for confidential cl… auth: improve ClientAuthenticator error messaging May 28, 2026

elif client.token_endpoint_auth_method == "none":
if client.client_secret:
raise AuthenticationError("Require valid auth method, with client secret")
Copy link
Copy Markdown
Author

@haoxuw haoxuw May 28, 2026

Choose a reason for hiding this comment

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

Even with out this if client.client_secret check, the current logic would still gives AuthenticationError, at L105

No behavior changes

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.

ClientAuthenticator ignores token_endpoint_auth_method="none" when client_secret is stored

1 participant