fetch-profile
All checks were successful
Deploy on push / deploy (push) Successful in 2m55s

This commit is contained in:
2025-09-29 00:27:16 +03:00
parent 147e227fa0
commit 6496bee531

View File

@@ -358,14 +358,48 @@ async def _fetch_yandex_profile(client: Any, token: Any) -> dict:
}
async def _fetch_google_profile(client: Any, token: Any) -> dict:
"""Получает профиль из Google API"""
try:
# Извлекаем access_token из ответа
access_token = token.get("access_token") if isinstance(token, dict) else token
if not access_token:
logger.error("No access_token found in Google token response")
return {}
# Используем прямой HTTP запрос к Google API
headers = {
"Authorization": f"Bearer {access_token}",
"Accept": "application/json",
}
async with httpx.AsyncClient() as http_client:
# Получаем профиль пользователя
profile_response = await http_client.get("https://www.googleapis.com/oauth2/v2/userinfo", headers=headers)
if profile_response.status_code != 200:
logger.error(f"Google API error: {profile_response.status_code} - {profile_response.text}")
return {}
profile_data = profile_response.json()
return {
"id": str(profile_data.get("id", "")),
"email": profile_data.get("email"),
"name": profile_data.get("name", ""),
"picture": profile_data.get("picture", "").replace("=s96", "=s600"),
}
except Exception as e:
logger.error(f"Error fetching Google profile: {e}")
return {}
async def get_user_profile(provider: str, client: Any, token: Any) -> dict:
"""Получает профиль пользователя от провайдера OAuth"""
# Простые провайдеры с обработкой через lambda
if provider in PROVIDER_HANDLERS:
return PROVIDER_HANDLERS[provider](token, None)
# Провайдеры требующие API вызовов
profile_fetchers = {
"google": _fetch_google_profile,
"github": _fetch_github_profile,
"facebook": _fetch_facebook_profile,
"x": _fetch_x_profile,
@@ -376,6 +410,10 @@ async def get_user_profile(provider: str, client: Any, token: Any) -> dict:
if provider in profile_fetchers:
return await profile_fetchers[provider](client, token)
# Простые провайдеры с обработкой через lambda (только для telegram теперь)
if provider in PROVIDER_HANDLERS:
return PROVIDER_HANDLERS[provider](token, None)
return {}