refactor: explicitly handle missing API key header
This commit is contained in:
+5
-3
@@ -19,9 +19,11 @@ def get_api_key(api_key_header: str = Security(api_key_header)):
|
|||||||
# If no key is configured, deny all requests for safety
|
# If no key is configured, deny all requests for safety
|
||||||
raise HTTPException(status_code=500, detail="API_KEY not configured on server")
|
raise HTTPException(status_code=500, detail="API_KEY not configured on server")
|
||||||
|
|
||||||
if hmac.compare_digest(api_key_header or "", expected_api_key):
|
if api_key_header is None:
|
||||||
return api_key_header
|
raise HTTPException(status_code=401, detail="Missing API Key")
|
||||||
raise HTTPException(status_code=401, detail="Invalid or missing API Key")
|
if not hmac.compare_digest(api_key_header, expected_api_key):
|
||||||
|
raise HTTPException(status_code=401, detail="Invalid API Key")
|
||||||
|
return api_key_header
|
||||||
|
|
||||||
|
|
||||||
graphql_app = GraphQLRouter(schema)
|
graphql_app = GraphQLRouter(schema)
|
||||||
|
|||||||
Reference in New Issue
Block a user