from fastapi import Depends, HTTPException, Request from sqlalchemy.ext.asyncio import AsyncSession from config import cfg from core.auth import jwt from db.session import get_db from external.pally import PallyClient from schemas.dto import AuthContext async def get_auth_context( request: Request, session: AsyncSession = Depends(get_db) ) -> AuthContext | None: auth = request.headers.get("Authorization") if not auth: raise HTTPException(status_code=403, detail="No authorization provided.") if auth.startswith("Bearer"): token = auth.removeprefix("Bearer ").strip() return await jwt.authorize(token, session) def get_pally_client() -> PallyClient: return PallyClient(api_token=cfg.pally_token, payer_pays_commission=True)