def authenticate(self, request):
token_from_get = request.GET.get('token', None)
token_from_headers = self._token_from_request_headers(request)
if token_from_get:
token = token_from_get
elif token_from_headers:
token = token_from_headers
else:
msg = "You must provide an API token to use this server. " \
"You can add `?token=API_TOKEN` at the end of the URL, or use a basic HTTP authentication where user=API_TOKEN with an empty password. " \
"Please check your emails for your API token."
raise exceptions.AuthenticationFailed(msg)
# Grab the API key model, make sure it exists
try:
api_key = ApiKey.objects.get(key=token)
except ApiKey.DoesNotExist:
raise exceptions.AuthenticationFailed("This API token doesn't exist")
return (api_key.account, None)
评论列表
文章目录