feat:限制必须api-key或登录1
parent
fc73869fa5
commit
96d8404924
|
|
@ -36,6 +36,20 @@ class AnonymousAuthenticationSerializer(serializers.Serializer):
|
||||||
platform_auth = request.META.get('HTTP_X_PLATFORM_AUTHORIZATION')
|
platform_auth = request.META.get('HTTP_X_PLATFORM_AUTHORIZATION')
|
||||||
if platform_auth is None or not platform_auth.startswith('Bearer '):
|
if platform_auth is None or not platform_auth.startswith('Bearer '):
|
||||||
return None
|
return None
|
||||||
|
token = platform_auth[7:]
|
||||||
|
token_details = None
|
||||||
|
|
||||||
|
def get_token_details():
|
||||||
|
nonlocal token_details
|
||||||
|
if token_details is None:
|
||||||
|
token_details = signing.loads(token)
|
||||||
|
return token_details
|
||||||
|
|
||||||
|
try:
|
||||||
|
user, auth = UserToken().handle(request, token, get_token_details)
|
||||||
|
return user
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_application_api_key(application_id, api_key):
|
def validate_application_api_key(application_id, api_key):
|
||||||
|
|
@ -48,20 +62,6 @@ class AnonymousAuthenticationSerializer(serializers.Serializer):
|
||||||
).first()
|
).first()
|
||||||
if application_api_key is None:
|
if application_api_key is None:
|
||||||
raise AppUnauthorizedFailed(401, _("Authentication information is incorrect"))
|
raise AppUnauthorizedFailed(401, _("Authentication information is incorrect"))
|
||||||
token = platform_auth[7:]
|
|
||||||
token_details = None
|
|
||||||
|
|
||||||
def get_token_details():
|
|
||||||
nonlocal token_details
|
|
||||||
if token_details is None:
|
|
||||||
token_details = signing.loads(token)
|
|
||||||
return token_details
|
|
||||||
|
|
||||||
try:
|
|
||||||
user, _ = UserToken().handle(request, token, get_token_details)
|
|
||||||
return user
|
|
||||||
except Exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def auth(self, request, with_valid=True):
|
def auth(self, request, with_valid=True):
|
||||||
token = request.META.get('HTTP_AUTHORIZATION')
|
token = request.META.get('HTTP_AUTHORIZATION')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue