π The fast, Pythonic way to build MCP servers and clients.
Default upstream token auth method to none without a client secret (#5879)
Asem ahmedceb465a2dfd6
diff --git a/docs/servers/auth/oauth-proxy.mdx b/docs/servers/auth/oauth-proxy.mdxindex 1071b8a6d..73a26960a 100644--- a/docs/servers/auth/oauth-proxy.mdx+++ b/docs/servers/auth/oauth-proxy.mdx@@ -187,9 +187,10 @@ mcp = FastMCP(name="My Server", auth=auth)tokens with the upstream provider. - `"client_secret_basic"`: Send credentialsin Authorization header (most common) - `"client_secret_post"`: Sendcredentials in request body (required by some providers) - `"none"`: No- authentication (for public clients) - `None` (default): Uses authlib's default- (typically `"client_secret_basic"`) Set this if your provider requires a- specific authentication method and the default doesn't work.+ authentication (for public clients) - `None` (default):+ `"client_secret_basic"` when a client secret is configured, `"none"`+ otherwise. Set this if your provider requires a specific authentication method+ and the default doesn't work.</ParamField><ParamField body="allowed_client_redirect_uris" type="list[str] | None">diff --git a/docs/servers/auth/oidc-proxy.mdx b/docs/servers/auth/oidc-proxy.mdxindex 3a7314a4b..25c0ead01 100644--- a/docs/servers/auth/oidc-proxy.mdx+++ b/docs/servers/auth/oidc-proxy.mdx@@ -146,7 +146,7 @@ These patterns apply to MCP client loopback redirects. Configure the upstream OA- `"client_secret_basic"`: Send credentials in Authorization header (most common)- `"client_secret_post"`: Send credentials in request body (required by some providers)- `"none"`: No authentication (for public clients)- - `None` (default): Uses authlib's default (typically `"client_secret_basic"`)+ - `None` (default): `"client_secret_basic"` when a client secret is configured, `"none"` otherwiseSet this if your provider requires a specific authentication method and the default doesn't work.diff --git a/fastmcp_slim/fastmcp/server/auth/oauth_proxy/proxy.py b/fastmcp_slim/fastmcp/server/auth/oauth_proxy/proxy.pyindex 9be3c6342..7baef6f60 100644--- a/fastmcp_slim/fastmcp/server/auth/oauth_proxy/proxy.py+++ b/fastmcp_slim/fastmcp/server/auth/oauth_proxy/proxy.py@@ -379,7 +379,8 @@ class OAuthProxy(OAuthProvider, ConsentMixin):Disable only if upstream provider doesn't support PKCE.token_endpoint_auth_method: Token endpoint authentication method for upstream server.Common values: "client_secret_basic", "client_secret_post", "none".- Defaults to "client_secret_basic".+ Defaults to "client_secret_basic" when a client secret is configured+ and to "none" (public client, no secret sent) otherwise.extra_authorize_params: Additional parameters to forward to the upstream authorization endpoint.Useful for provider-specific parameters like Auth0's "audience".Example: {"audience": "https://api.example.com"}diff --git a/fastmcp_slim/fastmcp/server/auth/oauth_proxy/upstream.py b/fastmcp_slim/fastmcp/server/auth/oauth_proxy/upstream.pyindex bed40f670..1784aeda3 100644--- a/fastmcp_slim/fastmcp/server/auth/oauth_proxy/upstream.py+++ b/fastmcp_slim/fastmcp/server/auth/oauth_proxy/upstream.py@@ -55,8 +55,8 @@ class AsyncOAuth2Client:) -> None:self.client_id = client_idself.client_secret = client_secret- self.token_endpoint_auth_method = (- token_endpoint_auth_method or "client_secret_basic"+ self.token_endpoint_auth_method = token_endpoint_auth_method or (+ "client_secret_basic" if client_secret else "none")self._client = httpx2.AsyncClient(timeout=timeout)diff --git a/fastmcp_slim/fastmcp/server/auth/oidc_proxy.py b/fastmcp_slim/fastmcp/server/auth/oidc_proxy.pyindex a9a898a0a..a9fb355e4 100644--- a/fastmcp_slim/fastmcp/server/auth/oidc_proxy.py+++ b/fastmcp_slim/fastmcp/server/auth/oidc_proxy.py@@ -360,7 +360,8 @@ class OIDCProxy(OAuthProxy):provided, the upstream client secret will be used to derive a 32-byte key using PBKDF2.token_endpoint_auth_method: Token endpoint authentication method for upstream server.Common values: "client_secret_basic", "client_secret_post", "none".- Defaults to "client_secret_basic".+ Defaults to "client_secret_basic" when a client secret is configured+ and to "none" (public client, no secret sent) otherwise.require_authorization_consent: Whether to require user consent before authorizing clients (default True).When True, users see a consent screen before being redirected to the upstream IdP.When False, authorization proceeds directly without user confirmation.diff --git a/tests/server/auth/oauth_proxy/test_oauth_proxy.py b/tests/server/auth/oauth_proxy/test_oauth_proxy.pyindex f5f15f5ab..490987dcc 100644--- a/tests/server/auth/oauth_proxy/test_oauth_proxy.py+++ b/tests/server/auth/oauth_proxy/test_oauth_proxy.py@@ -340,6 +340,7 @@ class TestOptionalClientSecret:client = proxy._create_upstream_oauth_client()assert isinstance(client, AsyncOAuth2Client)assert client.client_id == "client-123"+ assert client.token_endpoint_auth_method == "none"def test_factory_method_with_secret(self, jwt_verifier):"""_create_upstream_oauth_client includes the secret when configured."""@@ -356,6 +357,7 @@ class TestOptionalClientSecret:client = proxy._create_upstream_oauth_client()assert isinstance(client, AsyncOAuth2Client)assert client.client_secret == "secret-456"+ assert client.token_endpoint_auth_method == "client_secret_basic"def test_consent_cookies_work_without_secret(self, jwt_verifier):"""Cookie signing/verification works using JWT key when no secret is configured."""diff --git a/tests/server/auth/oauth_proxy/test_upstream_client.py b/tests/server/auth/oauth_proxy/test_upstream_client.pyindex 884edcc3e..7ada1542a 100644--- a/tests/server/auth/oauth_proxy/test_upstream_client.py+++ b/tests/server/auth/oauth_proxy/test_upstream_client.py@@ -37,6 +37,59 @@ class TestClientAuthMethods:assert request.headers["Authorization"] == f"Basic {expected}"assert "client_secret" not in _form(request)+ @pytest.mark.parametrize(+ ("client_secret", "method", "expected"),+ [+ ("sec", None, "client_secret_basic"),+ (None, None, "none"),+ ("", None, "none"),+ ("sec", "client_secret_post", "client_secret_post"),+ ("sec", "none", "none"),+ (None, "client_secret_post", "client_secret_post"),+ ],+ )+ async def test_default_method_follows_client_secret(+ self, client_secret: str | None, method: str | None, expected: str+ ):+ client = AsyncOAuth2Client(+ client_id="cid",+ client_secret=client_secret,+ token_endpoint_auth_method=method,+ )+ await client.aclose()++ assert client.token_endpoint_auth_method == expected++ async def test_public_client_fetch_token_sends_client_id_in_body(+ self, httpx_mock: HTTPXMock+ ):+ httpx_mock.add_response(url=TOKEN_URL, json={"access_token": "tok"})+ client = AsyncOAuth2Client(client_id="cid")+ await client.fetch_token(TOKEN_URL, code="abc", code_verifier="ver")+ await client.aclose()++ request = httpx_mock.get_request()+ assert request is not None+ assert "Authorization" not in request.headers+ form = _form(request)+ assert form["client_id"] == ["cid"]+ assert "client_secret" not in form++ async def test_public_client_refresh_token_sends_client_id_in_body(+ self, httpx_mock: HTTPXMock+ ):+ httpx_mock.add_response(url=TOKEN_URL, json={"access_token": "tok"})+ client = AsyncOAuth2Client(client_id="cid")+ await client.refresh_token(TOKEN_URL, refresh_token="old")+ await client.aclose()++ request = httpx_mock.get_request()+ assert request is not None+ assert "Authorization" not in request.headers+ form = _form(request)+ assert form["client_id"] == ["cid"]+ assert "client_secret" not in form+async def test_client_secret_post(self, httpx_mock: HTTPXMock):httpx_mock.add_response(url=TOKEN_URL, json={"access_token": "tok"})client = AsyncOAuth2Client(