feat(link_codes): linking method between telegram and website

This commit is contained in:
2026-08-18 21:10:57 +07:00
parent 7ae3c98585
commit 771d44d34c
12 changed files with 247 additions and 9 deletions

View File

@@ -3,9 +3,11 @@ from sqlalchemy.ext.asyncio import AsyncSession
from config import cfg
from core.auth import jwt
from core.secrets import get_kid_from_token
from db.session import get_db
from external.pally import PallyClient
from schemas.dto import AuthContext
from repositories.service_signatures import get_active_signature_by_kid
from schemas.dto import AuthContext, ServiceIdentity
from services.subscriptions import sync_user_subscription
@@ -25,5 +27,21 @@ async def get_auth_context(
return ctx
async def get_service_identity(
request: Request, session: AsyncSession = Depends(get_db)
) -> ServiceIdentity | None:
auth = request.headers.get("Authorization")
if auth.startswith("Bearer"):
token = auth.removeprefix("Bearer ").strip()
kid = get_kid_from_token(token)
if not kid:
raise HTTPException(401, detail="No kid provided.")
signature = await get_active_signature_by_kid(session, kid)
if not signature:
raise HTTPException(401, detail="Invalid signature")
return ServiceIdentity(service=signature.kid)
def get_pally_client() -> PallyClient:
return PallyClient(api_token=cfg.pally_token, payer_pays_commission=True)