Spaces:
Sleeping
Sleeping
Download core/security.py from Qurrah/replyflow-rag: direct link, hf CLI and curl.
- Browser
- Download file 607 Bytes
-
https://huggingface.co/spaces/Qurrah/replyflow-rag/resolve/main/core/security.py
- Command line
-
hf download hf://spaces/Qurrah/replyflow-rag/core/security.py
-
curl -L -o security.py https://huggingface.co/spaces/Qurrah/replyflow-rag/resolve/main/core/security.py
607 Bytes
| import logging | |
| import secrets | |
| from fastapi import HTTPException, Security | |
| from fastapi.security.api_key import APIKeyHeader | |
| from core.config import settings | |
| logger = logging.getLogger(__name__) | |
| API_KEY = settings.api_key | |
| api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False) | |
| async def verify_api_key(key: str = Security(api_key_header)): | |
| if not key or not API_KEY or not secrets.compare_digest(key, API_KEY): | |
| logger.warning("Unauthorized request — invalid or missing API key") | |
| raise HTTPException(status_code=401, detail="Invalid or missing API key") | |
| return key | |