auth_middleware
auth_middleware
¶
API key authentication middleware for the OpenJarvis server.
Classes¶
AuthMiddleware
¶
Bases: BaseHTTPMiddleware
Validates Authorization: Bearer <key> on /v1/* and /api/* routes.
Webhook routes and health checks are exempt — they use per-channel signature verification instead.
Source code in src/openjarvis/server/auth_middleware.py
Functions¶
generate_api_key
¶
check_bind_safety
¶
Refuse to bind non-loopback without an API key.
Raises SystemExit if host is not a loopback address and
api_key is empty.
Source code in src/openjarvis/server/auth_middleware.py
websocket_authorized
¶
Return True if a WebSocket connection presents the expected key.
AuthMiddleware is a BaseHTTPMiddleware and never sees WebSocket
upgrade requests, so streaming endpoints must check the token themselves
in the handshake before calling websocket.accept().
When expected_key is empty, authentication is disabled (the loopback /
local-only default, matching :class:AuthMiddleware) and all connections
are allowed. The token may be supplied either as a ?token= query
parameter — browsers cannot set headers on a WebSocket handshake — or via
an Authorization: Bearer <key> header for programmatic clients.