feat: service token introduction

This commit is contained in:
2026-08-18 19:56:14 +07:00
parent 3d79ffb384
commit 3b7606107b
12 changed files with 170 additions and 14 deletions

17
core/auth/fetch_sub.py Normal file
View File

@@ -0,0 +1,17 @@
from sqlalchemy.ext.asyncio import AsyncSession
from db.models import User
from repositories.users import UserRepository
from schemas.jwt import ServiceJWTPayload
async def fetch_subject_from_service(
payload: ServiceJWTPayload, session: AsyncSession
) -> User | None:
repo = UserRepository(session)
if payload.acting_as.startswith("telegram:"):
telegram_id = int(payload.acting_as.split("telegram:")[1])
return await repo.get_user_by_telegram_id(telegram_id)
return