Add WebSocket authentication via api_key

- When --api_key is set, WebSocket connections require auth too
- Supports Authorization: Bearer <key> header or ?token=<key> query param
- Unauthenticated connections receive HTTP 401 before upgrade
- Uses websockets process_request callback (no resource allocation before auth)
- Added 5 unit tests for WebSocket auth handler
This commit is contained in:
Aaron Boxer
2026-04-17 10:21:14 -04:00
committed by Aaron Boxer
parent b648bcb2a4
commit 5334ea0f7a
3 changed files with 63 additions and 3 deletions
+2 -2
View File
@@ -100,8 +100,8 @@ if __name__ == "__main__":
'--api_key',
type=str,
default=None,
help='Optional API key for authenticating REST API requests. '
'Clients must send "Authorization: Bearer <key>" header.'
help='Optional API key for authenticating REST API and WebSocket connections. '
'Clients must send "Authorization: Bearer <key>" header or "?token=<key>" query parameter.'
)
parser.add_argument(
'--rate_limit_rpm',