ai / backend /app /helper /security.py
Ahmed Tarek
Add application file
61d9463
raw
history blame contribute delete
606 Bytes
from fastapi import Security, HTTPException, Depends
from fastapi.security.api_key import APIKeyHeader
from starlette.status import HTTP_403_FORBIDDEN
from backend.app.config import get_settings
API_KEY_NAME = "AI_API_Key"
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=True)
async def get_api_key(
settings = Depends(get_settings),
api_key_header: str = Security(api_key_header)
):
if api_key_header != settings.API_KEY:
raise HTTPException(
status_code=HTTP_403_FORBIDDEN,
detail="Could not validate API key"
)
return api_key_header