def _is_api_key_authentication(request): authorization_header = request.META.get('HTTP_AUTHORIZATION', '') api_key_authentication = ApiKeyAuthentication() try: username, api_key = api_key_authentication.extract_credentials(request) except ValueError: raise Http400("Bad HTTP_AUTHORIZATION header {}" .format(authorization_header)) else: return username and api_key
def _is_api_key_authentication(request): authorization_header = request.META.get('HTTP_AUTHORIZATION', '') api_key_authentication = ApiKeyAuthentication() try: username, api_key = api_key_authentication.extract_credentials(request) except ValueError: raise Http400( "Bad HTTP_AUTHORIZATION header {}".format(authorization_header)) else: return username and api_key
def process_request(self, request): from tastypie.models import ApiKey from tastypie.authentication import ApiKeyAuthentication log.debug('request_headers=%s', extract_headers(request)) # ApiKey from header apikeyauth = ApiKeyAuthentication() username, api_key = apikeyauth.extract_credentials(request) if api_key is not None: log.debug('api_key:%s', api_key) else: return api = ApiKey.objects.filter(key=api_key) if api.count() == 0: return user = api[0].user log.debug('User from api=%s', user) # login(request, api.user) if user is not None: if user.is_active: user.backend = 'django.contrib.auth.backends.ModelBackend' auth.login(request, user) request.user = user # auth.login(request, user) return