fix(auth): add Accept: application/json header to OAuth token requests#2684
Open
gauravSsinha wants to merge 1 commit into
Open
fix(auth): add Accept: application/json header to OAuth token requests#2684gauravSsinha wants to merge 1 commit into
gauravSsinha wants to merge 1 commit into
Conversation
Some OAuth providers (e.g., GitHub) return form-encoded responses by default unless the client explicitly requests JSON via the Accept header. This causes token exchange to fail with a parse error since the SDK expects JSON responses. Add 'Accept: application/json' to all token endpoint requests: - Authorization code token exchange (oauth2.py) - Token refresh (oauth2.py) - Client credentials grant (client_credentials.py) - Private key JWT grant (client_credentials.py) - Signed JWT assertion grant (client_credentials.py) This aligns with RFC 6749 Section 5.1 which specifies that token responses use JSON, and ensures interoperability with providers that require explicit content negotiation. Fixes modelcontextprotocol#1523 Signed-off-by: Gaurav Kumar Sinha <gaurav@substrai.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
Accept: application/jsonheader to all OAuth token endpoint requests. Some providers (notably GitHub) return form-encoded responses by default unless JSON is explicitly requested, causing token exchange failures.Problem
As reported in #1523, the SDK's OAuth token requests only set
Content-Typebut notAccept. Providers like GitHub's OAuth endpoint returnapplication/x-www-form-urlencodedby default, which fails to parse as JSON.From GitHub's OAuth docs:
Fix
Added
"Accept": "application/json"to headers in all token request builders:OAuthClientProvider._build_token_request()— authorization code exchangeOAuthClientProvider._refresh_token()— token refreshClientCredentialsOAuthProvider._build_token_request()— client credentialsPrivateKeyJWTOAuthProvider._build_token_request()— private key JWTSignedJWTOAuthProvider._build_token_request()— signed JWT assertionTesting
References
Fixes #1523