I'm trying to set a Custom Authentication class on Django Rest Framework, but all client requests return the same error:
{"detail":"Authentication credentials were not provided."}
So, debugging the Custom class and printing the request.META atributte it has no X_USERNAME key.
CustomAuth class:
class TecnicoAuthentication(authentication.BaseAuthentication):
def authenticate(self, request):
username = request.META.get('X_USERNAME')
if not username:
return None
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise exceptions.AuthenticationFailed('No such user')
return (user,None)
on settings.py file:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES' : (
'os_hotlink.auth.TecnicoAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
)
}
on apache config file:
WSGIPassAuthorization On
And finally the request method using httpie:
http -a user:pass http://127.0.0.1/