Spaces:
Sleeping
Sleeping
Download auth.py from AI-Infy/AI-application: direct link, hf CLI and curl.
- Browser
- Download file 464 Bytes
-
https://huggingface.co/spaces/AI-Infy/AI-application/resolve/main/auth.py
- Command line
-
hf download hf://spaces/AI-Infy/AI-application/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/AI-Infy/AI-application/resolve/main/auth.py
464 Bytes
| from fastapi.security.api_key import APIKeyHeader | |
| from fastapi import Security, HTTPException | |
| import os | |
| # from dotenv import load_dotenv | |
| api_key_header = APIKeyHeader(name="x-api-key", auto_error=False) | |
| async def api_key_auth(api_key: str = Security(api_key_header)): | |
| # for local | |
| # load_dotenv() | |
| API_Keys = [os.environ.get('API_KEY')] | |
| if api_key not in API_Keys: | |
| raise HTTPException(status_code=401, detail="Missing or invalid API key") |