0

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

Community
  • 1
  • 1
  • Do you have ALLOWED_HOSTS propely configured in your settings.py ? https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts – Guillaume Vincent Jan 13 '14 at 07: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. – user2150077 Jan 13 '14 at 07: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? – user2150077 Jan 13 '14 at 08:13
  • strange, if request.META.get('HTTP_AUTHORIZATION') returns None, it's certainly an apache problem. You can log the request in this integrality – Guillaume Vincent Jan 13 '14 at 09:00

1 Answers1

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.