Skip to content

Support "client_secret_basic" in token exchange #549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

SightStudio
Copy link

@SightStudio SightStudio commented May 26, 2025

Support client_secret_basic authentication method during token exchange

Motivation and Context

Some authorization servers (e.g. Auth0, internal OIDC providers) only support client_secret_basic authentication,
as required by RFC 6749 §2.3.1.

Previously, the SDK always used client_secret_post,
which caused 401 errors when servers rejected credentials in the request body.

This change adds support for client_secret_basic when it is declared in
token_endpoint_auth_methods_supported in the OAuth metadata.

How Has This Been Tested?

  • Unit test added to validate Authorization header is set correctly
  • Tested against a real OAuth 2.0 server that only accepts client_secret_basic

Breaking Changes

No breaking changes — default behavior remains the same (client_secret_post is used unless metadata says otherwise)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

This should improve compatibility with OAuth providers that strictly follow the spec.
Let me know if you'd like this logic extracted into a utility function for reuse in refreshAuthorization or token_exchange.

@SightStudio SightStudio force-pushed the feat.support_client_secret_basic branch from 2449771 to 44fcd86 Compare May 26, 2025 07:22
@SightStudio SightStudio changed the title feature. Support client_secret_basic in token exchange Support "client_secret_basic" in token exchange May 26, 2025
@SightStudio SightStudio force-pushed the feat.support_client_secret_basic branch 3 times, most recently from 1f1fcee to e445e99 Compare May 26, 2025 07:45
@SightStudio SightStudio force-pushed the feat.support_client_secret_basic branch from e445e99 to 6d60fc1 Compare May 26, 2025 07:47
@SightStudio
Copy link
Author

SightStudio commented May 26, 2025

PR #531 is trying to fix a similar issue to mine:

If that one gets merged, or if my changes aren’t needed anymore, feel free to close this PR.
(I kept my fix simple, but their PR seems to handle the problem in a more general way.)

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.

1 participant