Skip to content

Commit b2a3b27

Browse files
committed
merge with recent branch
1 parent df6b26d commit b2a3b27

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

src/mcp/client/auth/extensions/client_credentials.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def _exchange_token_authorization_code(
9292

9393
async def _perform_authorization(self) -> httpx.Request: # pragma: no cover
9494
"""Perform the authorization flow."""
95-
if "urn:ietf:params:oauth:grant-type:jwt-bearer" in self.context.client_metadata.grant_types:
95+
if "jwt-bearer" in self.context.client_metadata.grant_types:
9696
token_request = await self._exchange_token_jwt_bearer()
9797
return token_request
9898
else:
@@ -112,7 +112,7 @@ def _add_client_authentication_jwt(self, *, token_data: dict[str, Any]): # prag
112112

113113
# When using private_key_jwt, in a client_credentials flow, we use RFC 7523 Section 2.2
114114
token_data["client_assertion"] = assertion
115-
token_data["client_assertion_type"] = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
115+
token_data["client_assertion_type"] = "jwt-bearer"
116116
# We need to set the audience to the resource server, the audience is difference from the one in claims
117117
# it represents the resource server that will validate the token
118118
token_data["audience"] = self.context.get_resource_url()
@@ -132,7 +132,7 @@ async def _exchange_token_jwt_bearer(self) -> httpx.Request:
132132
assertion = self.jwt_parameters.to_assertion(with_audience_fallback=issuer)
133133

134134
token_data = {
135-
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
135+
"grant_type": "jwt-bearer",
136136
"assertion": assertion,
137137
}
138138

src/mcp/shared/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class OAuthClientMetadata(BaseModel):
5454
"client_credentials",
5555
"token_exchange",
5656
"device_code",
57-
"urn:ietf:params:oauth:grant-type:jwt-bearer",
57+
"jwt-bearer",
5858
]
5959
| str
6060
] = [

tests/client/auth/extensions/test_client_credentials.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def test_token_exchange_request_jwt_predefined(self, rfc7523_oauth_provide
7070
"""Test token exchange request building with a predefined JWT assertion."""
7171
# Set up required context
7272
rfc7523_oauth_provider.context.client_info = OAuthClientInformationFull(
73-
grant_types=["urn:ietf:params:oauth:grant-type:jwt-bearer"],
73+
grant_types=["jwt-bearer"],
7474
token_endpoint_auth_method="private_key_jwt",
7575
redirect_uris=None,
7676
scope="read write",
@@ -96,7 +96,7 @@ async def test_token_exchange_request_jwt_predefined(self, rfc7523_oauth_provide
9696

9797
# Check form data
9898
content = urllib.parse.unquote_plus(request.content.decode())
99-
assert "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer" in content
99+
assert "grant_type=jwt-bearer" in content
100100
assert "scope=read write" in content
101101
assert "resource=https://api.example.com/v1/mcp" in content
102102
assert (
@@ -109,7 +109,7 @@ async def test_token_exchange_request_jwt(self, rfc7523_oauth_provider: RFC7523O
109109
"""Test token exchange request building wiith a generated JWT assertion."""
110110
# Set up required context
111111
rfc7523_oauth_provider.context.client_info = OAuthClientInformationFull(
112-
grant_types=["urn:ietf:params:oauth:grant-type:jwt-bearer"],
112+
grant_types=["jwt-bearer"],
113113
token_endpoint_auth_method="private_key_jwt",
114114
redirect_uris=None,
115115
scope="read write",
@@ -143,7 +143,7 @@ async def test_token_exchange_request_jwt(self, rfc7523_oauth_provider: RFC7523O
143143

144144
# Check form data
145145
content = urllib.parse.unquote_plus(request.content.decode()).split("&")
146-
assert "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer" in content
146+
assert "grant_type=jwt-bearer" in content
147147
assert "scope=read write" in content
148148
assert "resource=https://api.example.com/v1/mcp" in content
149149

tests/unit/client/test_oauth2_providers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ async def provide_actor() -> str:
400400
subject_token_supplier=provide_subject,
401401
subject_token_type="access_token",
402402
actor_token_supplier=provide_actor,
403-
actor_token_type="urn:ietf:params:oauth:token-type:jwt",
403+
actor_token_type="jwt",
404404
audience="https://audience.example.com",
405405
resource="https://resource.example.com",
406406
)
@@ -454,6 +454,7 @@ async def provide_subject() -> str:
454454
async def test_token_exchange_validate_token_scopes_rejects_extra() -> None:
455455
storage = InMemoryStorage()
456456
client_metadata = OAuthClientMetadata(redirect_uris=["https://client.example.com/callback"], scope="alpha")
457+
457458
async def provide_subject() -> str:
458459
return "subject-token"
459460

tests/unit/server/auth/test_token_handler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ async def load_refresh_token(self, client_info: object, token: str) -> object:
6161
assert token == "refresh-token"
6262
return self.refresh_token
6363

64-
async def exchange_refresh_token(
65-
self, client_info: object, refresh_token: object, scopes: list[str]
66-
) -> OAuthToken:
64+
async def exchange_refresh_token(self, client_info: object, refresh_token: object, scopes: list[str]) -> OAuthToken:
6765
return OAuthToken(access_token="refreshed-token")
6866

6967

0 commit comments

Comments
 (0)