Django使用登录的Windows域用户进行身份验证 [英] Django authenticate using logged in windows domain user

查看:387
本文介绍了Django使用登录的Windows域用户进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用当前登录到计算机的Windows域帐户(活动目录)对django Web用户进行身份验证。如何执行此操作而不提示用户再次输入用户名/密码,因为该用户已经使用域帐户登录到了系统。我正在使用django和python 2.7。我通过以下链接进行了操作,但是了解了如何使用它在我看来。

I want to authenticate django web user using windows domain account (active directory) who currently logged in to computer. How can I do this without prompting user to enter username/password again since he is already logged in using domain account to his system. I am using django and python 2.7. I went through following link but dint understand how to use it in my views. Please help me.

谢谢

推荐答案

当Web服务器(在IIS上托管的django)负责身份验证,它通常设置 REMOTE_USER 环境变量以在基础应用程序中使用。在Django中, REMOTE_USER 在request.META属性中可用。可以使用 RemoteUserMiddleware RemoteUserBackend 将Django配置为使用 REMOTE_USER 值。 code>在django.contrib.auth中找到的类。
配置
必须将 django.contrib.auth.middleware.RemoteUserMiddleware 添加到 MIDDLEWARE_CLASSES django.contrib.auth.middleware.AuthenticationMiddleware 之后设置:

When the Web server (here django hosted on IIS) takes care of authentication it typically sets the REMOTE_USER environment variable for use in the underlying application. In Django, REMOTE_USER is made available in the request.META attribute. Django can be configured to make use of 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 to the MIDDLEWARE_CLASSES setting after the django.contrib.auth.middleware.AuthenticationMiddleware:

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

接下来,您必须替换 ModelBackend AUTHENTICATION_BACKENDS 设置中具有 RemoteUserBackend

Next, you must replace the ModelBackend with RemoteUserBackend in the AUTHENTICATION_BACKENDS setting:

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

使用此设置, RemoteUserMiddleware 将在 request.META ['REMOTE_USER' ] ,然后将使用 RemoteUserBackend 对该用户进行身份验证和自动登录。

With this setup, RemoteUserMiddleware will detect the username in request.META['REMOTE_USER'] and will authenticate and auto-login that user using the RemoteUserBackend.

(更多信息 https:// docs .djangoproject.com / en / 1.5 / howto / auth-remote-user /

获得 REMOTE_USER 在请求中执行以下IIS设置:

To get REMOTE_USER in request do the following IIS settings:

1。在控制面板中,单击程序和功能,然后单击打开或关闭Windows功能。

1.In Control Panel, click Programs and Features, and then click Turn Windows features on or off.

2。展开Internet信息服务,展开万维网服务,展开安全性,然后选择Windows身份验证。

2.Expand Internet Information Services, expand World Wide Web Services, expand Security, and then select Windows Authentication.

IIS管理器


  1. 打开IIS管理器并导航到要管理的级别。

  2. 在功能视图中,双击身份验证。

  3. 在身份验证页上,选择 Windows身份验证。

  4. 在操作窗格中,单击确定。启用以使用Windows身份验证。
    更多信息

  1. Open IIS Manager and navigate to the level you want to manage.
  2. In Features View, double-click Authentication.
  3. On the Authentication page, select Windows Authentication.
  4. In the Actions pane, click Enable to use Windows authentication. (More info)

这篇关于Django使用登录的Windows域用户进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆