fix: 嵌入认证跨域问题
This commit is contained in:
parent
592dfaa8e5
commit
855684472d
@ -6,7 +6,7 @@
|
|||||||
@date:2023/10/27 14:56
|
@date:2023/10/27 14:56
|
||||||
@desc:
|
@desc:
|
||||||
"""
|
"""
|
||||||
|
from django.http import HttpResponse
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
@ -147,6 +147,12 @@ class Application(APIView):
|
|||||||
ApplicationSerializer.AccessTokenSerializer(data={'application_id': application_id}).one())
|
ApplicationSerializer.AccessTokenSerializer(data={'application_id': application_id}).one())
|
||||||
|
|
||||||
class Authentication(APIView):
|
class Authentication(APIView):
|
||||||
|
@action(methods=['OPTIONS'], detail=False)
|
||||||
|
def options(self, request, *args, **kwargs):
|
||||||
|
return HttpResponse(headers={"Access-Control-Allow-Origin": "*", "Access-Control-Allow-Credentials": "true",
|
||||||
|
"Access-Control-Allow-Methods": "POST",
|
||||||
|
"Access-Control-Allow-Headers": "Origin,Content-Type,Cookie,Accept,Token"}, )
|
||||||
|
|
||||||
@action(methods=['POST'], detail=False)
|
@action(methods=['POST'], detail=False)
|
||||||
@swagger_auto_schema(operation_summary="应用认证",
|
@swagger_auto_schema(operation_summary="应用认证",
|
||||||
operation_id="应用认证",
|
operation_id="应用认证",
|
||||||
@ -154,8 +160,14 @@ class Application(APIView):
|
|||||||
tags=["应用/认证"],
|
tags=["应用/认证"],
|
||||||
security=[])
|
security=[])
|
||||||
def post(self, request: Request):
|
def post(self, request: Request):
|
||||||
return result.success(
|
response = result.success(
|
||||||
ApplicationSerializer.Authentication(data={'access_token': request.data.get("access_token")}).auth())
|
ApplicationSerializer.Authentication(data={'access_token': request.data.get("access_token")}).auth(),
|
||||||
|
headers={"Access-Control-Allow-Origin": "*", "Access-Control-Allow-Credentials": "true",
|
||||||
|
"Access-Control-Allow-Methods": "POST",
|
||||||
|
"Access-Control-Allow-Headers": "Origin,Content-Type,Cookie,Accept,Token"}
|
||||||
|
)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
@action(methods=['POST'], detail=False)
|
@action(methods=['POST'], detail=False)
|
||||||
@swagger_auto_schema(operation_summary="创建应用",
|
@swagger_auto_schema(operation_summary="创建应用",
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class Result(JsonResponse):
|
|||||||
|
|
||||||
def __init__(self, code=200, message="成功", data=None, response_status=status.HTTP_200_OK, **kwargs):
|
def __init__(self, code=200, message="成功", data=None, response_status=status.HTTP_200_OK, **kwargs):
|
||||||
back_info_dict = {"code": code, "message": message, 'data': data}
|
back_info_dict = {"code": code, "message": message, 'data': data}
|
||||||
super().__init__(data=back_info_dict, status=response_status)
|
super().__init__(data=back_info_dict, status=response_status, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def get_page_request_params(other_request_params=None):
|
def get_page_request_params(other_request_params=None):
|
||||||
@ -147,13 +147,13 @@ def get_api_array_response(response_data_schema: openapi.Schema):
|
|||||||
)})
|
)})
|
||||||
|
|
||||||
|
|
||||||
def success(data):
|
def success(data, **kwargs):
|
||||||
"""
|
"""
|
||||||
获取一个成功的响应对象
|
获取一个成功的响应对象
|
||||||
:param data: 接口响应数据
|
:param data: 接口响应数据
|
||||||
:return: 请求响应对象
|
:return: 请求响应对象
|
||||||
"""
|
"""
|
||||||
return Result(data=data)
|
return Result(data=data, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def error(message):
|
def error(message):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user