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
import httpx
2020
from pydantic import BaseModel, Field, ValidationError
2121

22-
from mcp.client.auth import OAuthFlowError, OAuthTokenError
22+
from mcp.client.auth.exceptions import OAuthFlowError, OAuthRegistrationError, OAuthTokenError
2323
from mcp.client.auth.utils import (
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-
if auth_method == "client_secret_basic" and self.client_info.client_secret:
196+
if (
197+
auth_method == "client_secret_basic"
198+
and self.client_info.client_id
199+
and self.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
if not self.context.current_tokens or not self.context.current_tokens.refresh_token:
427431
raise OAuthTokenError("No refresh token available") # pragma: no cover
428432

429-
if not self.context.client_info:
433+
if not self.context.client_info or not self.context.client_info.client_id:
430434
raise OAuthTokenError("No client info available") # pragma: no cover
431435

432436
if self.context.oauth_metadata and self.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 = await oauth_provider._exchange_token("test_auth_code", "test_verifier")
710+
request = await oauth_provider._exchange_token_authorization_code("test_auth_code", "test_verifier")
711711

712712
# Should use basic auth (registered method)
713713
assert "Authorization" in request.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 = await oauth_provider._exchange_token("test_auth_code", "test_verifier")
787+
request = await oauth_provider._exchange_token_authorization_code("test_auth_code", "test_verifier")
788788

789789
# Should NOT have Authorization header
790790
assert "Authorization" not in request.headers

0 commit comments

Comments
 (0)