cors-fix-33
All checks were successful
Deploy on push / deploy (push) Successful in 57s

This commit is contained in:
2024-12-24 14:04:52 +03:00
parent 608bf8f33a
commit dcbdd01f53
2 changed files with 18 additions and 4 deletions

View File

@@ -6,6 +6,11 @@ from services.schema import request_graphql_data
from settings import ADMIN_SECRET, AUTH_URL
from utils.logger import root_logger as logger
# Список разрешенных заголовков
ALLOWED_HEADERS = [
'Authorization',
'Content-Type'
]
async def check_auth(req):
"""
@@ -40,6 +45,15 @@ async def check_auth(req):
operation = "ValidateToken"
variables = {"params": {"token_type": "access_token", "token": token}}
# Добавляем CORS заголовки
headers = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': ', '.join(ALLOWED_HEADERS),
'Access-Control-Allow-Credentials': 'true'
}
gql = {
"query": f"query {operation}($params: ValidateJWTTokenInput!)"
+ "{"
@@ -48,7 +62,7 @@ async def check_auth(req):
"variables": variables,
"operationName": operation,
}
data = await request_graphql_data(gql, url=auth_url)
data = await request_graphql_data(gql, url=auth_url, headers=headers)
if data:
logger.debug(f"Auth response: {data}")
validation_result = data.get("data", {}).get(query_name, {})