Django authentication using Windows login

I want to authenticate a django user using the Windows domain account (active directory) that is currently logged into the computer. How can I do this without prompting the user to enter the username / password again, since he has already registered using a domain account in his system. I am using django and python 2.7. I looked at the following link but don’t understand how to use it in my submissions. Please help me.

thanks

+6
source share
1 answer

When a web server (here django hosted in IIS) performs authentication, it usually sets the REMOTE_USER environment REMOTE_USER for use in the base application. In Django, REMOTE_USER is available in the request.META attribute. Django can be configured to use the REMOTE_USER value using the RemoteUserMiddleware and RemoteUserBackend classes found in django.contrib.auth. Configurations You must add the django.contrib.auth.middleware.RemoteUserMiddleware parameter to MIDDLEWARE_CLASSES after django.contrib.auth.middleware.AuthenticationMiddleware :

 MIDDLEWARE_CLASSES = ( ... 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.RemoteUserMiddleware', ... ) 

Then you should replace ModelBackend with RemoteUserBackend in the AUTHENTICATION_BACKENDS setting:

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

With this setting, RemoteUserMiddleware will determine the username in request.META['REMOTE_USER'] and will authenticate and automatically log in using RemoteUserBackend .

(Additional information https://docs.djangoproject.com/en/1.5/howto/auth-remote-user/ )

To get REMOTE_USER in the request, complete the following IIS settings:

1. In the control panel, select "Programs and Features," and then click "Turn Windows Features On or Off."

2. Open Internet Information Services, expand the World Wide Web, expand the Security node, and select Windows Authentication.

IIS Manager

  • Open IIS Manager and go to the level you want to manage.
  • In the Features view, double-click Authentication.
  • On the Authentication page, select Windows Authentication.
  • In the Actions panel, click Enable to use Windows Authentication. ( Additional Information )
+5
source

Source: https://habr.com/ru/post/978074/


All Articles