1

I have a problem with basic authentication in Rest Django framework. When I run the project on locallhost authentication work properly. I send login information in the request header (Authorization: Basic cm9vdDoxMjM0). In my API view, parameter request.user returns the logged in user. But if I try project in a production environment on a server, so parameter request.user returns value "AnonymousUser". Django rest framewrok runs on server with mod_fcgid.

My .htaccess:

AuthType None
Allow from All

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /projekty/qgame/mysite.cgi/$1 [QSA,L]

My settings.py:

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.BasicAuthentication',
    ),
}

enter image description here

I think there will be a need to modify the Apache configuration. Do you know what it could be? Can it by something like this?

thanks

4
  • Do you have ALLOWED_HOSTS propely configured in your settings.py ? docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts Commented Jan 13, 2014 at 7:16
  • Yes, in my setting I've ALLOWED_HOSTS = ['nlp.fi.muni.cz']. Now I'm trying to add a value of '*' and no change. Commented Jan 13, 2014 at 7:28
  • The problem is that it does not get value from the request. When I try, for example, request.META.get('HTTP_REFERER')) or request.META.get('HTTP_HOST')) so it works properly. But request.META.get('HTTP_AUTHORIZATION')) returns None. Where may be problem? Commented Jan 13, 2014 at 8:13
  • strange, if request.META.get('HTTP_AUTHORIZATION') returns None, it's certainly an apache problem. You can log the request in this integrality Commented Jan 13, 2014 at 9:00

1 Answer 1

1

Thanks for your answers. Hovewer, I read a couple of topics and I found the solution. When I added to .htaccess this rewrite rule:

RewriteCond% {HTTP: Authorization} ^ (. *)
RewriteRule. * - [E = HTTP_AUTHORIZATION:% 1]

Authorization header can already read.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.