From 465404bf10082c8a0a5613566ee1b59d67127da4 Mon Sep 17 00:00:00 2001 From: Tony Rewin Date: Tue, 3 Oct 2023 19:16:37 +0300 Subject: [PATCH] server-start-7 --- requirements-dev.txt | 4 ---- requirements.txt | 9 +++++++-- services/auth.py | 20 +++++++++++--------- 3 files changed, 18 insertions(+), 15 deletions(-) delete mode 100755 requirements-dev.txt diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100755 index d221f3b..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -isort -brunette -flake8 -mypy diff --git a/requirements.txt b/requirements.txt index 59f2956..7c5c016 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,9 +2,14 @@ sentry-sdk aioredis ariadne starlette -starlette sqlalchemy graphql-core gql uvicorn -httpx +aiohttp +######## development deps +isort +brunette +flake8 +mypy +its diff --git a/services/auth.py b/services/auth.py index 133138d..d3d8483 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 httpx import AsyncClient +from aiohttp import ClientSession as AsyncClient from services.db import local_session from settings import AUTH_URL from orm.author import Author @@ -45,14 +45,16 @@ async def check_auth(req): else {"query": "{ session { user { id } } }"} ) headers = {"Authorization": token, "Content-Type": "application/json"} - 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 + 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 def author_id_by_user_id(user_id):