Skip to content

Commit 7d546e6

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

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
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: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ def proxy_server(monkeypatch):
2525
# Avoid real outbound calls by pretending the upstream endpoints were
2626
# supplied explicitly via env vars – this makes `fetch_upstream_metadata`
2727
# 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")
28+
os.environ.setdefault(
29+
"UPSTREAM_AUTHORIZATION_ENDPOINT", "https://upstream.example.com/authorize"
30+
)
31+
os.environ.setdefault(
32+
"UPSTREAM_TOKEN_ENDPOINT", "https://upstream.example.com/token"
33+
)
3034
os.environ.setdefault("UPSTREAM_JWKS_URI", "https://upstream.example.com/jwks")
3135
os.environ.setdefault("UPSTREAM_CLIENT_ID", "client123")
3236
os.environ.setdefault("UPSTREAM_CLIENT_SECRET", "secret123")
3337

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

40-
<<<<<<< Updated upstream
41-
=======
4242
# Handle imports whether running from root or project directory
4343
try:
4444
# Try direct import first (when running from project directory)
@@ -51,7 +51,6 @@ def proxy_server(monkeypatch):
5151
sys.path.insert(0, project_dir)
5252
from proxy_auth import combo_server as proxy_server_module
5353

54-
>>>>>>> Stashed changes
5554
async def _fake_metadata() -> dict[str, Any]: # noqa: D401
5655
return {
5756
"issuer": proxy_server_module.UPSTREAM_BASE,
@@ -61,7 +60,9 @@ async def _fake_metadata() -> dict[str, Any]: # noqa: D401
6160
"jwks_uri": "",
6261
}
6362

64-
monkeypatch.setattr(proxy_routes, "fetch_upstream_metadata", _fake_metadata, raising=True)
63+
monkeypatch.setattr(
64+
proxy_routes, "fetch_upstream_metadata", _fake_metadata, raising=True
65+
)
6566
return proxy_server_module
6667

6768

@@ -74,7 +75,9 @@ def app(proxy_server):
7475
@pytest.fixture
7576
async def client(app) -> AsyncGenerator[httpx.AsyncClient, None]:
7677
"""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:
78+
async with httpx.AsyncClient(
79+
transport=httpx.ASGITransport(app=app), base_url="http://testserver"
80+
) as c:
7881
yield c
7982

8083

@@ -122,7 +125,9 @@ async def test_authorize_redirect(client, proxy_server):
122125
location = r.headers["location"]
123126
parsed = urllib.parse.urlparse(location)
124127
assert parsed.scheme.startswith("http")
125-
assert parsed.netloc == urllib.parse.urlparse(proxy_server.UPSTREAM_AUTHORIZE).netloc
128+
assert (
129+
parsed.netloc == urllib.parse.urlparse(proxy_server.UPSTREAM_AUTHORIZE).netloc
130+
)
126131

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

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

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

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

227237
result = await proxy_server.mcp.call_tool("user_info", {})
228238

@@ -233,5 +243,7 @@ def _fake_get_access_token(): # noqa: D401
233243
raw = result # fallback
234244

235245
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"
246+
assert ("userid" in raw and raw["userid"] == "test-user") or (
247+
"user_id" in raw and raw["user_id"] == "test-user"
248+
)
249+
assert raw["username"] == "tester"

0 commit comments

Comments
 (0)