Skip to content

Commit 05dad48

Browse files
committed
Remove the token_data hook left behind by the provider deletion
The keyword-only token_data parameter on OAuthClientProvider._exchange_token_authorization_code existed only so RFC7523OAuthClientProvider could inject a client assertion into the authorization-code exchange. With that provider gone it had no callers and carried a mutable {} default, so build the request body as a local dict instead. Also spell the migration guide's constructor examples with keyword arguments so they run as written.
1 parent aeb0a57 commit 05dad48

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

docs/migration.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,13 +1930,14 @@ purpose-built provider for the flow you actually run:
19301930

19311931
- Machine-to-machine with a client secret
19321932
([`io.modelcontextprotocol/oauth-client-credentials`](https://modelcontextprotocol.io/extensions/auth/oauth-client-credentials)):
1933-
`ClientCredentialsOAuthProvider(server_url, storage, client_id, client_secret)`.
1933+
`ClientCredentialsOAuthProvider(server_url=..., storage=..., client_id=..., client_secret=...)`.
19341934
- Machine-to-machine authenticating with a JWT instead of a secret (same extension, RFC 7523 §2.2
19351935
`private_key_jwt` client authentication on the `client_credentials` grant, which is the mode the
1936-
extension actually specifies for JWTs): `PrivateKeyJWTOAuthProvider(server_url, storage,
1937-
client_id, assertion_provider)`. Build the assertion with `SignedJWTParameters(issuer, subject,
1938-
signing_key).create_assertion_provider()` (replaces `JWTParameters` signing fields), or wrap a
1939-
prebuilt JWT with `static_assertion_provider(token)` (replaces `JWTParameters(assertion=...)`).
1936+
extension actually specifies for JWTs): `PrivateKeyJWTOAuthProvider(server_url=...,
1937+
storage=..., client_id=..., assertion_provider=...)`. Build the assertion with
1938+
`SignedJWTParameters(issuer=..., subject=..., signing_key=...).create_assertion_provider()`
1939+
(replaces `JWTParameters` signing fields), or wrap a prebuilt JWT with
1940+
`static_assertion_provider(token)` (replaces `JWTParameters(assertion=...)`).
19401941
- Presenting an enterprise ID-JAG under the `jwt-bearer` grant
19411942
([SEP-990](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/990)):
19421943
`IdentityAssertionOAuthProvider` in `mcp.client.auth.extensions.identity_assertion`.

src/mcp/client/auth/oauth2.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,26 +383,21 @@ def _get_token_endpoint(self) -> str:
383383
token_url = urljoin(auth_base_url, "/token")
384384
return token_url
385385

386-
async def _exchange_token_authorization_code(
387-
self, auth_code: str, code_verifier: str, *, token_data: dict[str, Any] | None = {}
388-
) -> httpx2.Request:
386+
async def _exchange_token_authorization_code(self, auth_code: str, code_verifier: str) -> httpx2.Request:
389387
"""Build token exchange request for authorization_code flow."""
390388
if self.context.client_metadata.redirect_uris is None:
391389
raise OAuthFlowError("No redirect URIs provided for authorization code grant") # pragma: no cover
392390
if not self.context.client_info:
393391
raise OAuthFlowError("Missing client info") # pragma: no cover
394392

395393
token_url = self._get_token_endpoint()
396-
token_data = token_data or {}
397-
token_data.update(
398-
{
399-
"grant_type": "authorization_code",
400-
"code": auth_code,
401-
"redirect_uri": str(self.context.client_metadata.redirect_uris[0]),
402-
"client_id": self.context.client_info.client_id,
403-
"code_verifier": code_verifier,
404-
}
405-
)
394+
token_data: dict[str, Any] = {
395+
"grant_type": "authorization_code",
396+
"code": auth_code,
397+
"redirect_uri": str(self.context.client_metadata.redirect_uris[0]),
398+
"client_id": self.context.client_info.client_id,
399+
"code_verifier": code_verifier,
400+
}
406401

407402
# Only include resource param if conditions are met
408403
if self.context.should_include_resource_param(self.context.protocol_version):

0 commit comments

Comments
 (0)