Initial MCM project: FastAPI + Textual TUI unified messenger
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.
This commit is contained in:
18
api/auth.py
Normal file
18
api/auth.py
Normal file
@@ -0,0 +1,18 @@
|
||||
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
|
||||
Reference in New Issue
Block a user