Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - Authentication using REMOTE_USER - How to test in dev server?

I want to use django.contrib.auth.middleware.RemoteUserMiddleware for authentication as outlined here:

https://docs.djangoproject.com/en/dev/howto/auth-remote-user/

Question is, how can I test this in a dev environment where there is no Apache? i.e. can I set REMOTE_USER somehow in local settings?

EDIT (adding settings)

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.RemoteUserBackend',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.RemoteUserMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    ...
)

Then I have this in my local_Settings:

os.environ['REMOTE_USER'] = "mmatyas"

I also tried the 'HTTP_REMOTE_USER' variant. Thanks!

like image 737
mynameistechno Avatar asked Mar 21 '13 17:03

mynameistechno


People also ask

How do I authenticate using email and password in Django?

Email authentication for Django 3.x For using email/username and password for authentication instead of the default username and password authentication, we need to override two methods of ModelBackend class: authenticate() and get_user():

How is authentication done in Django?

Django provides an authentication and authorization ("permission") system, built on top of the session framework discussed in the previous tutorial, that allows you to verify user credentials and define what actions each user is allowed to perform.


1 Answers

The variable has to be set in the environment in which you start the dev server. usually it's just:

REMOTE_USER=myuser ./manage.py runserver
like image 160
Brad Bell Avatar answered Oct 06 '22 05:10

Brad Bell