memleketmeselesi/mm_api/middleware.py
Mukan Erkin 2498e75594 init: memleketmeselesi platform — API + migrations
FastAPI + PostgreSQL 16. KYC, issue sistemi, permission/group yönetimi,
session yönetimi, API client auth (kışla kapısı), officials/persons CRUD.
Migration 0001–0013 dahil.
2026-04-27 23:06:59 +03:00

20 lines
738 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from fastapi import Request
from fastapi.responses import JSONResponse
from mm_api.services.client import verify_client
EXEMPT_PATHS = {"/docs", "/redoc", "/openapi.json"}
async def client_auth_middleware(request: Request, call_next):
if request.url.path in EXEMPT_PATHS:
return await call_next(request)
secret = request.headers.get("X-Api-Key")
if not secret:
return JSONResponse(status_code=401, content={"detail": "API anahtarı gerekli"})
async with request.app.state.pool.connection() as conn:
if not await verify_client(conn, secret):
return JSONResponse(status_code=401, content={"detail": "Geçersiz veya devre dışı API anahtarı"})
return await call_next(request)