14 lines
439 B
Python
14 lines
439 B
Python
from fastapi import Header, HTTPException, status
|
|
|
|
from app.core.config import get_settings
|
|
|
|
|
|
async def require_api_key(x_api_key: str | None = Header(default=None)) -> str:
|
|
settings = get_settings()
|
|
if not x_api_key or x_api_key not in settings.api_key_set:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Invalid or missing X-API-Key header",
|
|
)
|
|
return x_api_key
|