mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Fix openapi authorize (#8794)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import asyncio
|
||||
import os
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
from urllib.parse import urlparse
|
||||
|
||||
@@ -206,22 +205,3 @@ class AttachConversationMiddleware(SessionMiddlewareInterface):
|
||||
await self._detach_session(request)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@dataclass
|
||||
class SessionApiKeyMiddleware:
|
||||
"""Middleware which ensures that all requests contain a header with the token given"""
|
||||
|
||||
session_api_key: str
|
||||
|
||||
async def __call__(
|
||||
self, request: Request, call_next: RequestResponseEndpoint
|
||||
) -> Response:
|
||||
if request.method != 'OPTIONS' and request.url.path.startswith('/api'):
|
||||
if self.session_api_key != request.headers.get('X-Session-API-Key'):
|
||||
return JSONResponse(
|
||||
{'code': 'invalid_session_api_key'},
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
)
|
||||
response = await call_next(request)
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user