|
18 | 18 | from pydantic import BaseModel, Field |
19 | 19 |
|
20 | 20 | from mcp.client.auth import OAuthClientProvider, OAuthFlowError, OAuthTokenError, TokenStorage |
| 21 | +from mcp.client.auth.utils import create_token_request_headers |
21 | 22 | from mcp.shared.auth import AuthorizationCodeResult, OAuthClientInformationFull, OAuthClientMetadata |
22 | 23 |
|
23 | 24 |
|
@@ -92,7 +93,7 @@ async def _exchange_token_client_credentials(self) -> httpx.Request: |
92 | 93 | "grant_type": "client_credentials", |
93 | 94 | } |
94 | 95 |
|
95 | | - headers: dict[str, str] = {"Content-Type": "application/x-www-form-urlencoded"} |
| 96 | + headers = create_token_request_headers() |
96 | 97 |
|
97 | 98 | # Use standard auth methods (client_secret_basic, client_secret_post, none) |
98 | 99 | token_data, headers = self.context.prepare_token_auth(token_data, headers) |
@@ -320,7 +321,7 @@ async def _exchange_token_client_credentials(self) -> httpx.Request: |
320 | 321 | "grant_type": "client_credentials", |
321 | 322 | } |
322 | 323 |
|
323 | | - headers: dict[str, str] = {"Content-Type": "application/x-www-form-urlencoded"} |
| 324 | + headers = create_token_request_headers() |
324 | 325 |
|
325 | 326 | # Add JWT client authentication (RFC 7523 Section 2.2) |
326 | 327 | await self._add_client_authentication_jwt(token_data=token_data) |
@@ -480,6 +481,4 @@ async def _exchange_token_jwt_bearer(self) -> httpx.Request: |
480 | 481 | token_data["scope"] = self.context.client_metadata.scope |
481 | 482 |
|
482 | 483 | token_url = self._get_token_endpoint() |
483 | | - return httpx.Request( |
484 | | - "POST", token_url, data=token_data, headers={"Content-Type": "application/x-www-form-urlencoded"} |
485 | | - ) |
| 484 | + return httpx.Request("POST", token_url, data=token_data, headers=create_token_request_headers()) |
0 commit comments