accept VK ID user identity fields
This commit is contained in:
parent
7575cd6dee
commit
1dcbfdf823
1 changed files with 14 additions and 5 deletions
|
|
@ -149,11 +149,20 @@ async def verify_vk_access_token(access_token: str, settings: Settings) -> None:
|
||||||
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
|
||||||
user_id = payload.get("user_id") or payload.get("user", {}).get("user_id")
|
nested_user = payload.get("user") if isinstance(payload.get("user"), dict) else {}
|
||||||
try:
|
candidate_ids = (
|
||||||
valid_user_id = int(user_id) == settings.vk_id_allowed_user_id
|
payload.get("user_id"),
|
||||||
except (TypeError, ValueError):
|
payload.get("id"),
|
||||||
valid_user_id = False
|
payload.get("sub"),
|
||||||
|
nested_user.get("user_id"),
|
||||||
|
nested_user.get("id"),
|
||||||
|
)
|
||||||
|
valid_user_id = any(
|
||||||
|
isinstance(candidate, (int, str))
|
||||||
|
and str(candidate).isdigit()
|
||||||
|
and int(candidate) == settings.vk_id_allowed_user_id
|
||||||
|
for candidate in candidate_ids
|
||||||
|
)
|
||||||
if not valid_user_id:
|
if not valid_user_id:
|
||||||
raise HTTPException(status_code=403, detail="Этот VK ID не имеет доступа к Дзен-ассистенту.")
|
raise HTTPException(status_code=403, detail="Этот VK ID не имеет доступа к Дзен-ассистенту.")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue