π The fast, Pythonic way to build MCP servers and clients.
fix(auth): keep Google tokens out of request URLs (#5185)
nate nowack3e20bba71abd
diff --git a/fastmcp_slim/fastmcp/server/auth/providers/google.py b/fastmcp_slim/fastmcp/server/auth/providers/google.pyindex d15bb6df5..f2cc12c75 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/google.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/google.py@@ -58,7 +58,7 @@ class GoogleTokenVerifier(TokenVerifier):"""Token verifier for Google OAuth tokens.Google OAuth tokens are opaque (not JWTs), so we verify them by calling- Google's tokeninfo endpoint with the access token as a query parameter.+ Google's tokeninfo endpoint with the access token as a bearer credential.This returns the OAuth app ID (``aud``), granted scopes, and expiry time.User profile data (name, picture, etc.) is fetched separately from thev2 userinfo endpoint when the token is valid.@@ -100,7 +100,7 @@ class GoogleTokenVerifier(TokenVerifier):async def verify_token(self, token: str) -> AccessToken | None:"""Verify a Google OAuth token using the tokeninfo endpoint.- Calls ``https://oauth2.googleapis.com/tokeninfo?access_token=TOKEN``+ Calls ``https://oauth2.googleapis.com/tokeninfo`` with bearer authorizationto validate the token and retrieve the OAuth app ID (``aud``), grantedscopes, and expiry time. On success, fetches user profile data fromthe v2 userinfo endpoint to populate name, picture, and locale claims.@@ -115,8 +115,10 @@ class GoogleTokenVerifier(TokenVerifier):# Returns aud (OAuth app ID), scope (space-separated), expires_in, sub, email.response = await client.get("https://oauth2.googleapis.com/tokeninfo",- params={"access_token": token},- headers={"User-Agent": "FastMCP-Google-OAuth"},+ headers={+ "Authorization": f"Bearer {token}",+ "User-Agent": "FastMCP-Google-OAuth",+ },)if response.status_code != 200:diff --git a/tests/server/auth/providers/test_google.py b/tests/server/auth/providers/test_google.pyindex 068185e1b..36a00ccb7 100644--- a/tests/server/auth/providers/test_google.py+++ b/tests/server/auth/providers/test_google.py@@ -251,7 +251,7 @@ class TestGoogleScopeNormalization:assert "profile" in GOOGLE_SCOPE_ALIASES-# Regex patterns for URL matching (tokeninfo uses query params)+# Regex patterns for Google OAuth endpoints_TOKENINFO_RE = re.compile(r"https://oauth2\.googleapis\.com/tokeninfo")_USERINFO_RE = re.compile(r"https://www\.googleapis\.com/oauth2/v2/userinfo")@@ -478,8 +478,8 @@ class TestGoogleTokenVerifier:assert result is None- async def test_uses_query_param_not_bearer_header(self, httpx_mock: HTTPXMock):- """verify_token sends the token as a query parameter to tokeninfo, not a Bearer header."""+ async def test_uses_bearer_header_not_query_param(self, httpx_mock: HTTPXMock):+ """verify_token keeps the access token out of the tokeninfo URL."""httpx_mock.add_response(url=_TOKENINFO_RE,json={@@ -499,8 +499,8 @@ class TestGoogleTokenVerifier:requests = httpx_mock.get_requests()tokeninfo_req = requests[0]- assert "access_token=my-access-token" in str(tokeninfo_req.url)- assert "Authorization" not in tokeninfo_req.headers+ assert "my-access-token" not in str(tokeninfo_req.url)+ assert tokeninfo_req.headers["Authorization"] == "Bearer my-access-token"async def test_calls_tokeninfo_endpoint(self, httpx_mock: HTTPXMock):"""verify_token calls the tokeninfo endpoint, not the userinfo endpoint, for verification."""