Files
boc/landvex-paket/api/auth.py
T

24 lines
678 B
Python
Raw Normal View History

"""
Enkel API-nyckel autentisering för LandveX API
"""
from fastapi import HTTPException, Header
from typing import Optional
# Demo-nycklar (i produktion: lagra säkert!)
API_KEYS = {
"demo-key-2026": {"plan": "pilot", "rate_limit": 1000},
"pro-key-2026": {"plan": "pro", "rate_limit": 10000},
}
def verify_api_key(x_api_key: Optional[str] = Header(None)):
"""Verifiera API-nyckel från header."""
if not x_api_key:
raise HTTPException(status_code=401, detail="API-nyckel saknas. Skicka X-API-Key header.")
if x_api_key not in API_KEYS:
raise HTTPException(status_code=403, detail="Ogiltig API-nyckel.")
return API_KEYS[x_api_key]