Skip to content

Commit 455d351

Browse files
committed
fix pre-commit issues
Signed-off-by: Jesse Sanford <108698+jessesanford@users.noreply.github.com>
1 parent 37d81fe commit 455d351

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-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: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,28 @@
1818
@pytest.fixture
1919
def proxy_server(monkeypatch):
2020
"""Import the proxy OAuth demo server with safe environment + stubs."""
21+
2122
import os
2223

2324
# Avoid real outbound calls by pretending the upstream endpoints were
2425
# supplied explicitly via env vars – this makes `fetch_upstream_metadata`
2526
# 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")
27+
os.environ.setdefault(
28+
"UPSTREAM_AUTHORIZATION_ENDPOINT", "https://upstream.example.com/authorize"
29+
)
30+
os.environ.setdefault(
31+
"UPSTREAM_TOKEN_ENDPOINT", "https://upstream.example.com/token"
32+
)
2833
os.environ.setdefault("UPSTREAM_JWKS_URI", "https://upstream.example.com/jwks")
2934
os.environ.setdefault("UPSTREAM_CLIENT_ID", "client123")
3035
os.environ.setdefault("UPSTREAM_CLIENT_SECRET", "secret123")
3136

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

41+
from proxy_auth import combo_server as proxy_server_module
42+
3843
async def _fake_metadata() -> dict[str, Any]: # noqa: D401
3944
return {
4045
"issuer": proxy_server_module.UPSTREAM_BASE,
@@ -44,7 +49,9 @@ async def _fake_metadata() -> dict[str, Any]: # noqa: D401
4449
"jwks_uri": "",
4550
}
4651

47-
monkeypatch.setattr(proxy_routes, "fetch_upstream_metadata", _fake_metadata, raising=True)
52+
monkeypatch.setattr(
53+
proxy_routes, "fetch_upstream_metadata", _fake_metadata, raising=True
54+
)
4855
return proxy_server_module
4956

5057

@@ -57,7 +64,9 @@ def app(proxy_server):
5764
@pytest.fixture
5865
async def client(app) -> AsyncGenerator[httpx.AsyncClient, None]:
5966
"""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:
67+
async with httpx.AsyncClient(
68+
transport=httpx.ASGITransport(app=app), base_url="http://testserver"
69+
) as c:
6170
yield c
6271

6372

@@ -105,7 +114,9 @@ async def test_authorize_redirect(client, proxy_server):
105114
location = r.headers["location"]
106115
parsed = urllib.parse.urlparse(location)
107116
assert parsed.scheme.startswith("http")
108-
assert parsed.netloc == urllib.parse.urlparse(proxy_server.UPSTREAM_AUTHORIZE).netloc
117+
assert (
118+
parsed.netloc == urllib.parse.urlparse(proxy_server.UPSTREAM_AUTHORIZE).netloc
119+
)
109120

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

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

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

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

210226
result = await proxy_server.mcp.call_tool("user_info", {})
211227

@@ -216,5 +232,7 @@ def _fake_get_access_token(): # noqa: D401
216232
raw = result # fallback
217233

218234
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"
235+
assert ("userid" in raw and raw["userid"] == "test-user") or (
236+
"user_id" in raw and raw["user_id"] == "test-user"
237+
)
238+
assert raw["username"] == "tester"

0 commit comments

Comments
 (0)