π The fast, Pythonic way to build MCP servers and clients.
Reorganize auth and use secretstr
Jeremiah Lowin5ac996d13457
diff --git a/src/fastmcp/client/auth/__init__.py b/src/fastmcp/client/auth/__init__.pynew file mode 100644index 000000000..6ec3ecf4b--- /dev/null+++ b/src/fastmcp/client/auth/__init__.py@@ -0,0 +1,4 @@+from .bearer import BearerAuth+from .oauth import OAuth++__all__ = ["BearerAuth", "OAuth"]diff --git a/src/fastmcp/client/auth/bearer.py b/src/fastmcp/client/auth/bearer.pynew file mode 100644index 000000000..0c38a11b0--- /dev/null+++ b/src/fastmcp/client/auth/bearer.py@@ -0,0 +1,17 @@+import httpx+from pydantic import SecretStr++from fastmcp.utilities.logging import get_logger++__all__ = ["BearerAuth"]++logger = get_logger(__name__)+++class BearerAuth(httpx.Auth):+ def __init__(self, token: str):+ self.token = SecretStr(token)++ def auth_flow(self, request):+ request.headers["Authorization"] = f"Bearer {self.token.get_secret_value()}"+ yield requestdiff --git a/src/fastmcp/client/auth.py b/src/fastmcp/client/auth/oauth.pysimilarity index 98%rename from src/fastmcp/client/auth.pyrename to src/fastmcp/client/auth/oauth.pyindex 28c2bba84..43df9d442 100644--- a/src/fastmcp/client/auth.py+++ b/src/fastmcp/client/auth/oauth.py@@ -392,12 +392,3 @@ def OAuth()return oauth_provider---class BearerAuth(httpx.Auth):- def __init__(self, token: str):- self.token = token-- def auth_flow(self, request):- request.headers["Authorization"] = f"Bearer {self.token}"- yield requestdiff --git a/tests/auth/providers/test_bearer.py b/tests/auth/providers/test_bearer.pyindex ff127f727..aed70af71 100644--- a/tests/auth/providers/test_bearer.py+++ b/tests/auth/providers/test_bearer.py@@ -6,7 +6,7 @@ import pytestfrom pytest_httpx import HTTPXMockfrom fastmcp import Client, FastMCP-from fastmcp.client.auth import BearerAuth+from fastmcp.client.auth.bearer import BearerAuthfrom fastmcp.server.auth.providers.bearer import (BearerAuthProvider,JWKData,