Spaces:
Running
Running
Download auth.py from aliaddo/pdf-generator: direct link, hf CLI and curl.
- Browser
- Download file 542 Bytes
-
https://huggingface.co/spaces/aliaddo/pdf-generator/resolve/main/auth.py
- Command line
-
hf download hf://spaces/aliaddo/pdf-generator/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/aliaddo/pdf-generator/resolve/main/auth.py
542 Bytes
| from fastapi import Security, HTTPException, status | |
| from fastapi.security.api_key import APIKeyHeader | |
| from config import settings | |
| api_key_header = APIKeyHeader(name=settings.API_KEY_NAME, auto_error=True) | |
| async def verify_api_key(api_key: str = Security(api_key_header)) -> str: | |
| """Validate X-API-Key header against the configured secret.""" | |
| if api_key != settings.API_KEY: | |
| raise HTTPException( | |
| status_code=status.HTTP_403_FORBIDDEN, | |
| detail="Invalid or missing API Key", | |
| ) | |
| return api_key | |