fix VK ID user info verification
This commit is contained in:
parent
5a819b8642
commit
c80f35b32c
1 changed files with 7 additions and 3 deletions
|
|
@ -143,14 +143,18 @@ async def verify_vk_access_token(access_token: str, settings: Settings) -> None:
|
||||||
raise HTTPException(status_code=422, detail="VK ID не вернул access token.")
|
raise HTTPException(status_code=422, detail="VK ID не вернул access token.")
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(timeout=15) as client:
|
async with httpx.AsyncClient(timeout=15) as client:
|
||||||
response = await client.get(
|
response = await client.post(
|
||||||
settings.vk_id_user_info_url,
|
settings.vk_id_user_info_url,
|
||||||
headers={"Authorization": f"Bearer {access_token.strip()}"},
|
params={"client_id": settings.vk_id_app_id},
|
||||||
|
data={"access_token": access_token.strip()},
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
payload = response.json()
|
payload = response.json()
|
||||||
except (httpx.HTTPError, ValueError) as exc:
|
except (httpx.HTTPError, ValueError) as exc:
|
||||||
raise HTTPException(status_code=401, detail="Не удалось проверить VK ID.") from exc
|
raise HTTPException(status_code=401, detail="Не удалось проверить VK ID.") from exc
|
||||||
|
if payload.get("error"):
|
||||||
|
logger.warning("VK ID user info returned error=%s", payload.get("error"))
|
||||||
|
raise HTTPException(status_code=401, detail="VK ID не подтвердил access token.")
|
||||||
nested_user = payload.get("user") if isinstance(payload.get("user"), dict) else {}
|
nested_user = payload.get("user") if isinstance(payload.get("user"), dict) else {}
|
||||||
candidate_ids = (
|
candidate_ids = (
|
||||||
payload.get("user_id"),
|
payload.get("user_id"),
|
||||||
|
|
@ -159,7 +163,7 @@ async def verify_vk_access_token(access_token: str, settings: Settings) -> None:
|
||||||
nested_user.get("user_id"),
|
nested_user.get("user_id"),
|
||||||
nested_user.get("id"),
|
nested_user.get("id"),
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.warning(
|
||||||
"VK ID user info fields=%s candidate_ids=%s allowed_user_id=%s",
|
"VK ID user info fields=%s candidate_ids=%s allowed_user_id=%s",
|
||||||
sorted(payload.keys()),
|
sorted(payload.keys()),
|
||||||
[candidate for candidate in candidate_ids if candidate is not None],
|
[candidate for candidate in candidate_ids if candidate is not None],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue