server-start-8
This commit is contained in:
parent
465404bf10
commit
46cc285c2d
|
@ -6,7 +6,7 @@ sqlalchemy
|
||||||
graphql-core
|
graphql-core
|
||||||
gql
|
gql
|
||||||
uvicorn
|
uvicorn
|
||||||
aiohttp
|
httpx
|
||||||
######## development deps
|
######## development deps
|
||||||
isort
|
isort
|
||||||
brunette
|
brunette
|
||||||
|
|
|
@ -4,7 +4,7 @@ from functools import wraps
|
||||||
from starlette.authentication import AuthenticationBackend
|
from starlette.authentication import AuthenticationBackend
|
||||||
from starlette.requests import HTTPConnection
|
from starlette.requests import HTTPConnection
|
||||||
from graphql.error import GraphQLError
|
from graphql.error import GraphQLError
|
||||||
from aiohttp import ClientSession as AsyncClient
|
from httpx import AsyncClient
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
from settings import AUTH_URL
|
from settings import AUTH_URL
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
|
@ -45,14 +45,12 @@ async def check_auth(req):
|
||||||
else {"query": "{ session { user { id } } }"}
|
else {"query": "{ session { user { id } } }"}
|
||||||
)
|
)
|
||||||
headers = {"Authorization": token, "Content-Type": "application/json"}
|
headers = {"Authorization": token, "Content-Type": "application/json"}
|
||||||
async with AsyncClient(headers=headers) as session:
|
async with AsyncClient() as client:
|
||||||
async with session.post(AUTH_URL, data=gql) as response:
|
response = await client.post(AUTH_URL, headers=headers, data=gql)
|
||||||
if response.status != 200:
|
if response.status_code != 200:
|
||||||
return False, None
|
return False, None
|
||||||
r = await response.json()
|
r = response.json()
|
||||||
user_id = (
|
user_id = r.get("data", {}).get("session", {}).get("user", {}).get("id", None)
|
||||||
r.get("data", {}).get("session", {}).get("user", {}).get("id", None)
|
|
||||||
)
|
|
||||||
is_authenticated = user_id is not None
|
is_authenticated = user_id is not None
|
||||||
return is_authenticated, user_id
|
return is_authenticated, user_id
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user