CoolFace
Apppublic

mydatascraper/competitor_compare

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
auth.py33 linesDownload Raw Back to app
1from fastapi import Security, HTTPException, status
2from fastapi.security import APIKeyHeader
3from app.config import settings
4
5api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
6
7# In production, these would be in a database
8VALID_API_KEYS = {
9    settings.MASTER_API_KEY: {
10        "name": "MVP Demo Key",
11        "tier": "full",
12        "rate_limit": 1000,  # requests per minute
13    },
14    "gprice_readonly_2024": {
15        "name": "Read Only Demo",
16        "tier": "basic",
17        "rate_limit": 100,
18    },
19}
20
21
22async def verify_api_key(api_key: str = Security(api_key_header)) -> dict:
23    if api_key is None:
24        raise HTTPException(
25            status_code=status.HTTP_401_UNAUTHORIZED,
26            detail="Missing API Key. Include X-API-Key header.",
27        )
28    if api_key not in VALID_API_KEYS:
29        raise HTTPException(
30            status_code=status.HTTP_403_FORBIDDEN,
31            detail="Invalid API Key.",
32        )
33    return VALID_API_KEYS[api_key]