You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 26, 2020. It is now read-only.
Recently I had to implement an authenticator that received the token via query parameters. Use case is creating a download file button that hits an endpoint e.g. /api/reports/somereport?export=csv
I thought I'd paste it here to see if you would like it added to the lib, maybe others could use it?
import jwt
from rest_framework_jwt.settings import api_settings
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
class QueryParameterAuthentication(JSONWebTokenAuthentication):
def authenticate(self, request):
"""
Parses the request's Query Parameters for a `token` and sets it
on the authorization header for authentication.
"""
if 'token' not in request.QUERY_PARAMS:
return None
token = request.QUERY_PARAMS['token']
header = '{} {}'.format(api_settings.JWT_AUTH_HEADER_PREFIX, token)
request.META['HTTP_AUTHORIZATION'] = header
return super(QueryParameterAuthentication, self).authenticate(request)