MultiCustomerMessenger supporting Telegram (python-telegram-bot), WhatsApp (Green API) and SMS (python-gsmmodem-new). REST API with Bearer-token auth, SQLAlchemy models for MariaDB, APScheduler for background polling, and Textual TUI running in same asyncio event-loop.
19 lines
598 B
Python
19 lines
598 B
Python
from fastapi import HTTPException, Security, status
|
|
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
|
|
|
from config import settings
|
|
|
|
_bearer = HTTPBearer(auto_error=False)
|
|
|
|
|
|
def require_api_key(
|
|
credentials: HTTPAuthorizationCredentials | None = Security(_bearer),
|
|
) -> str:
|
|
if not credentials or credentials.credentials != settings.api_key:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Invalid or missing API key",
|
|
headers={"WWW-Authenticate": "Bearer"},
|
|
)
|
|
return credentials.credentials
|