Skip to content

Commit c426d76

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

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
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: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import base64
99
import json
10-
import sys
1110
import os
11+
import sys
1212
import urllib.parse
1313
from collections.abc import AsyncGenerator
1414
from typing import Any
@@ -20,25 +20,24 @@
2020
@pytest.fixture
2121
def proxy_server(monkeypatch):
2222
"""Import the proxy OAuth demo server with safe environment + stubs."""
23-
import os
2423

2524
# Avoid real outbound calls by pretending the upstream endpoints were
2625
# supplied explicitly via env vars – this makes `fetch_upstream_metadata`
2726
# construct metadata locally instead of performing an HTTP GET.
28-
os.environ.setdefault("UPSTREAM_AUTHORIZATION_ENDPOINT", "https://upstream.example.com/authorize")
29-
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+
)
3033
os.environ.setdefault("UPSTREAM_JWKS_URI", "https://upstream.example.com/jwks")
3134
os.environ.setdefault("UPSTREAM_CLIENT_ID", "client123")
3235
os.environ.setdefault("UPSTREAM_CLIENT_SECRET", "secret123")
3336

3437
# Deferred import so the env vars above are in effect.
35-
from proxy_auth import combo_server as proxy_server_module
36-
3738
# Stub library-level fetch_upstream_metadata to avoid network I/O.
3839
from mcp.server.auth.proxy import routes as proxy_routes
3940

40-
<<<<<<< Updated upstream
41-
=======
4241
# Handle imports whether running from root or project directory
4342
try:
4443
# Try direct import first (when running from project directory)
@@ -51,7 +50,6 @@ def proxy_server(monkeypatch):
5150
sys.path.insert(0, project_dir)
5251
from proxy_auth import combo_server as proxy_server_module
5352

54-
>>>>>>> Stashed changes
5553
async def _fake_metadata() -> dict[str, Any]: # noqa: D401
5654
return {
5755
"issuer": proxy_server_module.UPSTREAM_BASE,
@@ -61,7 +59,9 @@ async def _fake_metadata() -> dict[str, Any]: # noqa: D401
6159
"jwks_uri": "",
6260
}
6361

64-
monkeypatch.setattr(proxy_routes, "fetch_upstream_metadata", _fake_metadata, raising=True)
62+
monkeypatch.setattr(
63+
proxy_routes, "fetch_upstream_metadata", _fake_metadata, raising=True
64+
)
6565
return proxy_server_module
6666

6767

@@ -74,7 +74,9 @@ def app(proxy_server):
7474
@pytest.fixture
7575
async def client(app) -> AsyncGenerator[httpx.AsyncClient, None]:
7676
"""Async HTTP client bound to the in-memory ASGI application."""
77-
async with httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://testserver") as c:
77+
async with httpx.AsyncClient(
78+
transport=httpx.ASGITransport(app=app), base_url="http://testserver"
79+
) as c:
7880
yield c
7981

8082

@@ -122,7 +124,9 @@ async def test_authorize_redirect(client, proxy_server):
122124
location = r.headers["location"]
123125
parsed = urllib.parse.urlparse(location)
124126
assert parsed.scheme.startswith("http")
125-
assert parsed.netloc == urllib.parse.urlparse(proxy_server.UPSTREAM_AUTHORIZE).netloc
127+
assert (
128+
parsed.netloc == urllib.parse.urlparse(proxy_server.UPSTREAM_AUTHORIZE).netloc
129+
)
126130

127131
qs = urllib.parse.parse_qs(parsed.query)
128132
# Proxy should inject client_id & default scope
@@ -139,7 +143,8 @@ async def test_revoke_proxy(client, monkeypatch, proxy_server):
139143
async def _mock_post(self, url, data=None, timeout=10, **kwargs): # noqa: D401
140144
if url.endswith("/revoke"):
141145
return httpx.Response(200, json={"revoked": True})
142-
# For the test client's own request to /revoke, delegate to original implementation
146+
# For the test client's own request to /revoke,
147+
# delegate to original implementation
143148
return await original_post(self, url, data=data, timeout=timeout, **kwargs)
144149

145150
monkeypatch.setattr(httpx.AsyncClient, "post", _mock_post, raising=True)
@@ -220,9 +225,13 @@ async def test_user_info_tool(monkeypatch, proxy_server):
220225
from mcp.server.auth.provider import AccessToken # local import to avoid cycles
221226

222227
def _fake_get_access_token(): # noqa: D401
223-
return AccessToken(token=dummy_token, client_id="client123", scopes=["openid"], expires_at=None)
228+
return AccessToken(
229+
token=dummy_token, client_id="client123", scopes=["openid"], expires_at=None
230+
)
224231

225-
monkeypatch.setattr(auth_context, "get_access_token", _fake_get_access_token, raising=True)
232+
monkeypatch.setattr(
233+
auth_context, "get_access_token", _fake_get_access_token, raising=True
234+
)
226235

227236
result = await proxy_server.mcp.call_tool("user_info", {})
228237

@@ -233,5 +242,7 @@ def _fake_get_access_token(): # noqa: D401
233242
raw = result # fallback
234243

235244
assert raw["authenticated"] is True
236-
assert ("userid" in raw and raw["userid"] == "test-user") or ("user_id" in raw and raw["user_id"] == "test-user")
237-
assert raw["username"] == "tester"
245+
assert ("userid" in raw and raw["userid"] == "test-user") or (
246+
"user_id" in raw and raw["user_id"] == "test-user"
247+
)
248+
assert raw["username"] == "tester"

0 commit comments

Comments
 (0)