From 46cc285c2da0c99e23706ac95a8fdb3789a44107 Mon Sep 17 00:00:00 2001 From: Tony Rewin Date: Tue, 3 Oct 2023 19:19:04 +0300 Subject: [PATCH] server-start-8 --- requirements.txt | 2 +- services/auth.py | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7c5c016..32e74b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ sqlalchemy graphql-core gql uvicorn -aiohttp +httpx ######## development deps isort brunette diff --git a/services/auth.py b/services/auth.py index d3d8483..133138d 100644 --- a/services/auth.py +++ b/services/auth.py @@ -4,7 +4,7 @@ from functools import wraps from starlette.authentication import AuthenticationBackend from starlette.requests import HTTPConnection from graphql.error import GraphQLError -from aiohttp import ClientSession as AsyncClient +from httpx import AsyncClient from services.db import local_session from settings import AUTH_URL from orm.author import Author @@ -45,16 +45,14 @@ async def check_auth(req): else {"query": "{ session { user { id } } }"} ) headers = {"Authorization": token, "Content-Type": "application/json"} - async with AsyncClient(headers=headers) as session: - async with session.post(AUTH_URL, data=gql) as response: - if response.status != 200: - return False, None - r = await response.json() - user_id = ( - r.get("data", {}).get("session", {}).get("user", {}).get("id", None) - ) - is_authenticated = user_id is not None - return is_authenticated, user_id + async with AsyncClient() as client: + response = await client.post(AUTH_URL, headers=headers, data=gql) + if response.status_code != 200: + return False, None + r = response.json() + user_id = r.get("data", {}).get("session", {}).get("user", {}).get("id", None) + is_authenticated = user_id is not None + return is_authenticated, user_id def author_id_by_user_id(user_id):