This commit is contained in:
parent
3b7b47599c
commit
954c3740cd
|
@ -6,34 +6,35 @@ from settings import AUTH_URL
|
||||||
|
|
||||||
async def check_auth(req):
|
async def check_auth(req):
|
||||||
token = req.headers.get("Authorization")
|
token = req.headers.get("Authorization")
|
||||||
print(f"[services.auth] checking auth token: {token}")
|
if token:
|
||||||
|
print(f"[services.auth] checking auth token: {token}")
|
||||||
|
|
||||||
headers = {"Authorization": "Bearer " + token, "Content-Type": "application/json"}
|
headers = {"Authorization": "Bearer " + token, "Content-Type": "application/json"}
|
||||||
# query getSession($params: SessionQueryInput){ session(params: $params) { message user { id } } }
|
# query getSession($params: SessionQueryInput){ session(params: $params) { message user { id } } }
|
||||||
gql = {
|
gql = {
|
||||||
"query": "query GetSession($params: SessionQueryInput)"
|
"query": "query GetSession($params: SessionQueryInput)"
|
||||||
+ "{ session(params: $params) { message user { id } } }",
|
+ "{ session(params: $params) { message user { id } } }",
|
||||||
"operationName": "GetSession",
|
"operationName": "GetSession",
|
||||||
"variables": {},
|
"variables": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=30.0)) as session:
|
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=30.0)) as session:
|
||||||
async with session.post(AUTH_URL, headers=headers, json=gql) as response:
|
async with session.post(AUTH_URL, headers=headers, json=gql) as response:
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
return False, None
|
return False, None
|
||||||
r = await response.json()
|
r = await response.json()
|
||||||
print(f"[services.auth] response: {r}")
|
print(f"[services.auth] response: {r}")
|
||||||
try:
|
try:
|
||||||
data = r.get("data")
|
data = r.get("data")
|
||||||
is_authenticated = False
|
is_authenticated = False
|
||||||
user_id = None
|
user_id = None
|
||||||
if data:
|
if data:
|
||||||
user_id = data.get("session", {}).get("user", {}).get("id", None)
|
user_id = 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
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"{e}: {r}")
|
print(f"{e}: {r}")
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
|
|
||||||
def login_required(f):
|
def login_required(f):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user