Model/backend/app/dependencies.py
2023-07-06 11:33:13 +01:00

14 lines
495 B
Python

from fastapi import Depends, HTTPException, status
from fastapi.security import APIKeyHeader
from app.config import get_settings
api_key_header = APIKeyHeader(name=get_settings().API_KEY_NAME, auto_error=False)
async def validate_api_key(api_key_header: str = Depends(api_key_header)):
if api_key_header != get_settings().API_KEY:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, detail="Could not validate credentials"
)
return api_key_header