Skip to content

Commit 2443150

Browse files
committed
merge fix
1 parent fe0e62e commit 2443150

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

‎src/mcp/client/auth/oauth2.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
importhttpx
2020
frompydanticimportBaseModel, Field, ValidationError
2121

22-
frommcp.client.authimportOAuthFlowError, OAuthTokenError
22+
frommcp.client.auth.exceptionsimportOAuthFlowError, OAuthRegistrationError, OAuthTokenError
2323
frommcp.client.auth.utilsimport (
2424
build_oauth_authorization_server_metadata_discovery_urls,
2525
build_protected_resource_metadata_discovery_urls,
@@ -193,7 +193,11 @@ def prepare_token_auth(
193193

194194
auth_method=self.client_info.token_endpoint_auth_method
195195

196-
ifauth_method=="client_secret_basic"andself.client_info.client_secret:
196+
if (
197+
auth_method=="client_secret_basic"
198+
andself.client_info.client_id
199+
andself.client_info.client_secret
200+
):
197201
# URL-encode client ID and secret per RFC 6749 Section 2.3.1
198202
encoded_id=quote(self.client_info.client_id, safe="")
199203
encoded_secret=quote(self.client_info.client_secret, safe="")
@@ -426,7 +430,7 @@ async def _refresh_token(self) -> httpx.Request:
426430
ifnotself.context.current_tokensornotself.context.current_tokens.refresh_token:
427431
raiseOAuthTokenError("No refresh token available") # pragma: no cover
428432

429-
ifnotself.context.client_info:
433+
ifnotself.context.client_infoornotself.context.client_info.client_id:
430434
raiseOAuthTokenError("No client info available") # pragma: no cover
431435

432436
ifself.context.oauth_metadataandself.context.oauth_metadata.token_endpoint:
@@ -435,7 +439,7 @@ async def _refresh_token(self) -> httpx.Request:
435439
auth_base_url=self.context.get_authorization_base_url(self.context.server_url)
436440
token_url=urljoin(auth_base_url, "/token")
437441

438-
refresh_data={
442+
refresh_data: dict[str, str]={
439443
"grant_type": "refresh_token",
440444
"refresh_token": self.context.current_tokens.refresh_token,
441445
"client_id": self.context.client_info.client_id,

‎tests/client/test_auth.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ async def test_basic_auth_token_exchange(self, oauth_provider: OAuthClientProvid
707707
token_endpoint_auth_method="client_secret_basic",
708708
)
709709

710-
request=awaitoauth_provider._exchange_token("test_auth_code", "test_verifier")
710+
request=awaitoauth_provider._exchange_token_authorization_code("test_auth_code", "test_verifier")
711711

712712
# Should use basic auth (registered method)
713713
assert"Authorization"inrequest.headers
@@ -784,7 +784,7 @@ async def test_none_auth_method(self, oauth_provider: OAuthClientProvider):
784784
token_endpoint_auth_method="none",
785785
)
786786

787-
request=awaitoauth_provider._exchange_token("test_auth_code", "test_verifier")
787+
request=awaitoauth_provider._exchange_token_authorization_code("test_auth_code", "test_verifier")
788788

789789
# Should NOT have Authorization header
790790
assert"Authorization"notinrequest.headers

0 commit comments

Comments
(0)