mirror of
https://gitverse.ru/kpa39l/telepost.git
synced 2026-09-29 18:05:08 +00:00
27 lines
841 B
Python
27 lines
841 B
Python
from typing import Dict, Any
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from ....database.database import get_db
|
|
from ....auth.telegram_auth import authenticate_user_telegram
|
|
from ....schemas.token import Token
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/telegram-login", response_model=Token)
|
|
async def telegram_login(auth_data: Dict[str, Any], db: Session = Depends(get_db)):
|
|
"""
|
|
Authenticate user via Telegram Login Widget
|
|
Expects data received from Telegram Login Widget
|
|
"""
|
|
result = authenticate_user_telegram(db, auth_data)
|
|
|
|
if not result:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Invalid Telegram login data",
|
|
headers={"WWW-Authenticate": "Bearer"},
|
|
)
|
|
|
|
return result |