Skip to content

Commit cdae014

Browse files
committed
refactor: simplify auth to only use Bearer token
- Remove X-Late-API-Key, X-API-Key, and query param support - Use only standard 'Authorization: Bearer' header - Simpler for users and more HTTP standard - Better compatibility with OAuth-expecting tools - Update all documentation and error messages
1 parent 76a75f0 commit cdae014

3 files changed

Lines changed: 19 additions & 46 deletions

File tree

docs/HTTP_DEPLOYMENT.md

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ curl http://localhost:8080/health
2727
curl http://localhost:8080/
2828

2929
# SSE endpoint (requires your Late API key)
30-
curl -H "X-Late-API-Key: your_late_api_key" http://localhost:8080/sse
30+
curl -H "Authorization: Bearer your_late_api_key" http://localhost:8080/sse
3131
```
3232

3333
## Railway Deployment
@@ -65,7 +65,7 @@ Configuration in MCP settings:
6565
"late": {
6666
"url": "https://your-app.railway.app/sse",
6767
"headers": {
68-
"X-Late-API-Key": "your_late_api_key_here"
68+
"Authorization": "Bearer your_late_api_key_here"
6969
}
7070
}
7171
}
@@ -76,9 +76,9 @@ Configuration in MCP settings:
7676
```python
7777
from mcp.client.sse import sse_client
7878

79-
# Provide your Late API key in headers
79+
# Provide your Late API key as Bearer token
8080
headers = {
81-
"X-Late-API-Key": "your_late_api_key_here"
81+
"Authorization": "Bearer your_late_api_key_here"
8282
}
8383

8484
async with sse_client(
@@ -91,27 +91,17 @@ async with sse_client(
9191

9292
## Authentication
9393

94-
Each user must provide their own Late API key when connecting. The server accepts API keys via:
94+
Each user must provide their own Late API key when connecting using the standard HTTP Authorization header:
9595

96-
1. **X-Late-API-Key header** (recommended):
97-
```
98-
X-Late-API-Key: your_late_api_key
99-
```
100-
101-
2. **Authorization header** (Bearer token):
102-
```
103-
Authorization: Bearer your_late_api_key
104-
```
105-
106-
3. **X-API-Key header** (alternative):
107-
```
108-
X-API-Key: your_late_api_key
109-
```
96+
```
97+
Authorization: Bearer YOUR_LATE_API_KEY
98+
```
11099

111-
4. **Query parameter** (not recommended for production):
112-
```
113-
https://your-app.railway.app/sse?api_key=your_late_api_key
114-
```
100+
Example:
101+
```bash
102+
curl -H "Authorization: Bearer sk_your_api_key_here" \
103+
https://your-app.railway.app/sse
104+
```
115105

116106
The server validates the API key by making a test request to the Late API. If valid, the connection is established and the API key is used for all subsequent operations.
117107

src/late/mcp/auth.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,20 @@
66

77
def extract_late_api_key(request: Request) -> str | None:
88
"""
9-
Extract Late API key from request.
9+
Extract Late API key from request Authorization header.
1010
11-
Checks in order:
12-
1. X-Late-API-Key header
13-
2. Authorization header (Bearer token)
14-
3. X-API-Key header
15-
4. api_key query parameter
11+
Expects: Authorization: Bearer <your_late_api_key>
1612
1713
Args:
1814
request: The incoming Starlette request.
1915
2016
Returns:
2117
The extracted API key, or None if not found.
2218
"""
23-
# Try X-Late-API-Key header first (most specific)
24-
late_key = request.headers.get("X-Late-API-Key")
25-
if late_key:
26-
return late_key
27-
28-
# Try Authorization header: "Bearer <key>"
2919
auth_header = request.headers.get("Authorization")
3020
if auth_header and auth_header.startswith("Bearer "):
31-
return auth_header[7:]
32-
33-
# Try X-API-Key header
34-
api_key_header = request.headers.get("X-API-Key")
35-
if api_key_header:
36-
return api_key_header
37-
38-
# Try query parameter as fallback
39-
return request.query_params.get("api_key")
21+
return auth_header[7:] # Remove "Bearer " prefix
22+
return None
4023

4124

4225
async def verify_late_api_key(api_key: str) -> bool:

src/late/mcp/routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def handle_root(_request: Request) -> JSONResponse:
3131
"health": f"{ENDPOINT_HEALTH} (GET) - Health check",
3232
},
3333
"documentation": DOCS_URL,
34-
"authentication": "Required (use X-API-Key header or Bearer token)",
34+
"authentication": "Required: 'Authorization: Bearer YOUR_LATE_API_KEY'",
3535
}
3636
)
3737

@@ -67,7 +67,7 @@ async def handle_sse(request: Request) -> Response:
6767
late_api_key = extract_late_api_key(request)
6868
if not late_api_key:
6969
return JSONResponse(
70-
{"error": "Missing Late API key. Provide via X-Late-API-Key header, Authorization: Bearer header, or X-API-Key header"},
70+
{"error": "Missing Late API key. Provide via Authorization header: 'Authorization: Bearer YOUR_API_KEY'"},
7171
status_code=401
7272
)
7373

0 commit comments

Comments
 (0)