Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/mcp/client/auth/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ async def _exchange_token_authorization_code(
token_data["resource"] = self.context.get_resource_url() # RFC 8707

# Prepare authentication based on preferred method
headers = {"Content-Type": "application/x-www-form-urlencoded"}
headers = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
}
token_data, headers = self.context.prepare_token_auth(token_data, headers)

return httpx.Request("POST", token_url, data=token_data, headers=headers)
Expand Down Expand Up @@ -447,7 +450,10 @@ async def _refresh_token(self) -> httpx.Request:
refresh_data["resource"] = self.context.get_resource_url() # RFC 8707

# Prepare authentication based on preferred method
headers = {"Content-Type": "application/x-www-form-urlencoded"}
headers = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
}
refresh_data, headers = self.context.prepare_token_auth(refresh_data, headers)

return httpx.Request("POST", token_url, data=refresh_data, headers=headers)
Expand Down
2 changes: 2 additions & 0 deletions tests/client/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ async def test_token_exchange_request_authorization_code(self, oauth_provider: O

assert request.method == "POST"
assert str(request.url) == "https://api.example.com/token"
assert request.headers["Accept"] == "application/json"
assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"

# Check form data
Expand All @@ -622,6 +623,7 @@ async def test_refresh_token_request(self, oauth_provider: OAuthClientProvider,

assert request.method == "POST"
assert str(request.url) == "https://api.example.com/token"
assert request.headers["Accept"] == "application/json"
assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"

# Check form data
Expand Down
Loading