autho-connector-fix
All checks were successful
deploy / deploy (push) Successful in 1m3s

This commit is contained in:
Untone 2023-12-17 23:40:40 +03:00
parent 517de93ccd
commit bc8a07e619

View File

@ -13,7 +13,7 @@ async def check_auth(req) -> (bool, int | None):
# Logging the authentication token # Logging the authentication token
print(f"[services.auth] checking auth token: {token}") print(f"[services.auth] checking auth token: {token}")
query_name = "validate_jwt_token" query_name = "validate_jwt_token"
operation = "ValidateToken" opeation = "ValidateToken"
headers = { headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
} }
@ -26,18 +26,18 @@ async def check_auth(req) -> (bool, int | None):
} }
gql = { gql = {
"query": f"query {operation}($params: ValidateJWTTokenInput!) {{ {query_name}(params: $params) {{ is_valid claims }} }}", "query": f"query {opeation}($params: ValidateJWTTokenInput!) {{ {query_name}(params: $params) {{ is_valid claims }} }}",
"variables": variables, "variables": variables,
"operationName": operation, "operationName": opeation,
} }
print(f"[services.auth] Graphql: {gql}") # print(f"[services.auth] Graphql: {gql}")
try: try:
# Asynchronous HTTP request to the authentication server # Asynchronous HTTP request to the authentication server
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.post(AUTH_URL, json=gql, headers=headers) as response: async with session.post(AUTH_URL, json=gql, headers=headers) as response:
# Logging the GraphQL response # Logging the GraphQL response
response_text = await response.text() # response_text = await response.text()
print(f"[services.auth] GraphQL Response: {response_text}") # print(f"[services.auth] GraphQL Response: {response_text}")
if response.status == 200: if response.status == 200:
# Parsing JSON response # Parsing JSON response
@ -50,14 +50,16 @@ async def check_auth(req) -> (bool, int | None):
if user_id: if user_id:
# Logging the retrieved user ID # Logging the retrieved user ID
print(f"[services.auth] User ID retrieved: {user_id}") # print(f"[services.auth] User ID retrieved: {user_id}")
return True, user_id return True, user_id
else: else:
# Logging when no user ID is found in the response # Logging when no user ID is found in the response
print("[services.auth] No user ID found in the response") # print("[services.auth] No user ID found in the response")
pass
else: else:
# Logging when the request to the authentication server fails # Logging when the request to the authentication server fails
print(f"[services.auth] Request failed with status: {response.status}") # print(f"[services.auth] Request failed with status: {response.status}")
pass
except Exception as e: except Exception as e:
# Handling and logging exceptions during authentication check # Handling and logging exceptions during authentication check