Coverage for apis_core/utils/authentication.py: 0%
6 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
1from rest_framework.authentication import TokenAuthentication
4# not used in APIS, but can be used in downstream projects
5class TokenAuthSupportQueryString(TokenAuthentication):
6 """
7 Extend the TokenAuthentication class to support querystring authentication
8 in the form of "http://www.example.com/?auth_token=<api_key>"
9 """
11 def authenticate(self, request):
12 # Check if 'token_auth' is in the request query params.
13 # Give precedence to 'Authorization' header.
14 if (
15 "api_key" in request.query_params
16 and "HTTP_AUTHORIZATION" not in request.META
17 ):
18 return self.authenticate_credentials(request.query_params.get("api_key"))
19 else:
20 return super().authenticate(request)