Skip to content

Commit 712b700

Browse files
committed
fix pre-commit issues
Signed-off-by: Jesse Sanford <108698+jessesanford@users.noreply.github.com>
1 parent f0be658 commit 712b700

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

examples/servers/proxy-auth/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ The servers can be configured using either:
2020
2. **Environment variables** (loaded from `.env` file when present)
2121

2222
Example `.env` file:
23-
```
23+
24+
```env
2425
# Auth Server Configuration
2526
AUTH_SERVER_HOST=localhost
2627
AUTH_SERVER_PORT=9000
@@ -58,6 +59,7 @@ uv run mcp-proxy-auth-as
5859
```
5960

6061
**What it provides:**
62+
6163
- OAuth 2.0 flows (authorization, token exchange)
6264
- Token introspection endpoint for Resource Servers (`/introspect`)
6365
- Client registration endpoint (`/register`)
@@ -87,9 +89,13 @@ uv run mcp-proxy-auth-combo
8789
## How It Works
8890

8991
The proxy OAuth server acts as a transparent proxy between:
92+
9093
1. Client applications requesting OAuth tokens
9194
2. Upstream OAuth providers (like GitHub, Google, etc.)
9295

9396
This allows MCP servers to leverage existing OAuth providers without implementing their own authentication systems.
9497

95-
The server code is organized in the `proxy_auth` package for better modularity.
98+
The server code is organized in the `proxy_auth` package for better modularity.
99+
100+
```text
101+
```

examples/servers/proxy-auth/tests/test_proxy_oauth_endpoints.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ def proxy_server(monkeypatch):
2323
# Avoid real outbound calls by pretending the upstream endpoints were
2424
# supplied explicitly via env vars – this makes `fetch_upstream_metadata`
2525
# construct metadata locally instead of performing an HTTP GET.
26-
os.environ.setdefault("UPSTREAM_AUTHORIZATION_ENDPOINT", "https://upstream.example.com/authorize")
27-
os.environ.setdefault("UPSTREAM_TOKEN_ENDPOINT", "https://upstream.example.com/token")
26+
os.environ.setdefault(
27+
"UPSTREAM_AUTHORIZATION_ENDPOINT", "https://upstream.example.com/authorize"
28+
)
29+
os.environ.setdefault(
30+
"UPSTREAM_TOKEN_ENDPOINT", "https://upstream.example.com/token"
31+
)
2832
os.environ.setdefault("UPSTREAM_JWKS_URI", "https://upstream.example.com/jwks")
2933
os.environ.setdefault("UPSTREAM_CLIENT_ID", "client123")
3034
os.environ.setdefault("UPSTREAM_CLIENT_SECRET", "secret123")
3135

3236
# Deferred import so the env vars above are in effect.
33-
from proxy_auth import combo_server as proxy_server_module
34-
3537
# Stub library-level fetch_upstream_metadata to avoid network I/O.
3638
from mcp.server.auth.proxy import routes as proxy_routes
3739

40+
from proxy_auth import combo_server as proxy_server_module
41+
3842
async def _fake_metadata() -> dict[str, Any]: # noqa: D401
3943
return {
4044
"issuer": proxy_server_module.UPSTREAM_BASE,
@@ -44,7 +48,9 @@ async def _fake_metadata() -> dict[str, Any]: # noqa: D401
4448
"jwks_uri": "",
4549
}
4650

47-
monkeypatch.setattr(proxy_routes, "fetch_upstream_metadata", _fake_metadata, raising=True)
51+
monkeypatch.setattr(
52+
proxy_routes, "fetch_upstream_metadata", _fake_metadata, raising=True
53+
)
4854
return proxy_server_module
4955

5056

@@ -57,7 +63,9 @@ def app(proxy_server):
5763
@pytest.fixture
5864
async def client(app) -> AsyncGenerator[httpx.AsyncClient, None]:
5965
"""Async HTTP client bound to the in-memory ASGI application."""
60-
async with httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://testserver") as c:
66+
async with httpx.AsyncClient(
67+
transport=httpx.ASGITransport(app=app), base_url="http://testserver"
68+
) as c:
6169
yield c
6270

6371

@@ -105,7 +113,9 @@ async def test_authorize_redirect(client, proxy_server):
105113
location = r.headers["location"]
106114
parsed = urllib.parse.urlparse(location)
107115
assert parsed.scheme.startswith("http")
108-
assert parsed.netloc == urllib.parse.urlparse(proxy_server.UPSTREAM_AUTHORIZE).netloc
116+
assert (
117+
parsed.netloc == urllib.parse.urlparse(proxy_server.UPSTREAM_AUTHORIZE).netloc
118+
)
109119

110120
qs = urllib.parse.parse_qs(parsed.query)
111121
# Proxy should inject client_id & default scope
@@ -122,7 +132,8 @@ async def test_revoke_proxy(client, monkeypatch, proxy_server):
122132
async def _mock_post(self, url, data=None, timeout=10, **kwargs): # noqa: D401
123133
if url.endswith("/revoke"):
124134
return httpx.Response(200, json={"revoked": True})
125-
# For the test client's own request to /revoke, delegate to original implementation
135+
# For the test client's own request to /revoke,
136+
# delegate to original implementation
126137
return await original_post(self, url, data=data, timeout=timeout, **kwargs)
127138

128139
monkeypatch.setattr(httpx.AsyncClient, "post", _mock_post, raising=True)
@@ -203,9 +214,13 @@ async def test_user_info_tool(monkeypatch, proxy_server):
203214
from mcp.server.auth.provider import AccessToken # local import to avoid cycles
204215

205216
def _fake_get_access_token(): # noqa: D401
206-
return AccessToken(token=dummy_token, client_id="client123", scopes=["openid"], expires_at=None)
217+
return AccessToken(
218+
token=dummy_token, client_id="client123", scopes=["openid"], expires_at=None
219+
)
207220

208-
monkeypatch.setattr(auth_context, "get_access_token", _fake_get_access_token, raising=True)
221+
monkeypatch.setattr(
222+
auth_context, "get_access_token", _fake_get_access_token, raising=True
223+
)
209224

210225
result = await proxy_server.mcp.call_tool("user_info", {})
211226

@@ -216,5 +231,7 @@ def _fake_get_access_token(): # noqa: D401
216231
raw = result # fallback
217232

218233
assert raw["authenticated"] is True
219-
assert ("userid" in raw and raw["userid"] == "test-user") or ("user_id" in raw and raw["user_id"] == "test-user")
220-
assert raw["username"] == "tester"
234+
assert ("userid" in raw and raw["userid"] == "test-user") or (
235+
"user_id" in raw and raw["user_id"] == "test-user"
236+
)
237+
assert raw["username"] == "tester"

0 commit comments

Comments
 (0)