Add complete NexaMFA push MFA system with: - FastAPI backend with PostgreSQL, Redis, OIDC provider, and Prometheus metrics - React TypeScript admin console - Android Kotlin/Jetpack Compose app with biometric authentication - Docker Compose deployment configuration - Gitea CI workflow for backend, frontend, and Android builds - Environment configuration template with security settings - Documentation for security model, deployment
26 lines
813 B
Python
26 lines
813 B
Python
from fastapi import Depends, Header, HTTPException, Request, status
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.config import Settings, get_settings
|
|
from app.core.database import get_session
|
|
|
|
|
|
async def get_db(session: AsyncSession = Depends(get_session)) -> AsyncSession:
|
|
return session
|
|
|
|
|
|
def get_app_settings() -> Settings:
|
|
return get_settings()
|
|
|
|
|
|
async def require_admin(
|
|
request: Request,
|
|
authorization: str | None = Header(default=None),
|
|
settings: Settings = Depends(get_app_settings),
|
|
) -> None:
|
|
token = None
|
|
if authorization and authorization.lower().startswith("bearer "):
|
|
token = authorization.split(" ", 1)[1]
|
|
if token != settings.admin_token:
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid admin token")
|