Django Microsoft AD 身份验证 [英] Django Microsoft AD Authentication

查看:19
本文介绍了Django Microsoft AD 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到这个问题被重复了几次,但我仍然无法通过所有资源使其正常工作.

I noticed that this question was repeated few times, but still, from all the resources, I couldn't manage to make it work properly.

我只是想在我的 Django 应用中使用 Azure Active Directory 身份验证.我正在使用 这个模块,我按照文档中的说明配置了所有内容.

I'm simply trying to use Azure Active Directory authentication with my Django app. I am using this module, and I configured everything as noted in the docs.

问题是 - 我不知道用户应该在哪里输入凭据 - 因为模块只有一个网址('auth-callback/').我不知道如何跳转到 Microsoft 登录 html 页面.我应该使用我的 login.html 还是?

The thing is - I can't figure out where should user enter the credentials - since the module has only one url ('auth-callback/'). I can't find out how to jump to Microsoft login html page. Should I use my login.html or?

另外,我猜 'auth-callback/' url 显然是一个回调 URL,它位于登录页面之后.

Also, I guess that 'auth-callback/' url is obviously a callback URL, which comes after the login page.

我正在使用 django auth.views LoginView 进行登录,以及自定义 login.html 页面.

I am using django auth.views LoginView for login, and custom login.html page.

在重定向 URI 方面,我将重定向 URI 配置为直接匹配 'http://localhost:8000/microsoft/auth-callback/' url,我猜这也是它需要的方式.

In terms of Redirect URI's I configured redirect URI to match directly the 'http://localhost:8000/microsoft/auth-callback/' url, which is also how it needs to be I guess.

主要问题是 - 我在哪里可以输入登录凭据?:)

Main problem is - where can I enter the credentials for login? :)

此外,当我尝试此操作时 - 我的管理员登录页面上出现无效凭据错误:

Also, when I try this - I get invalid credentials error on my Admin login page :

Start site and go to /admin and logout if you are logged in.
Login as Microsoft/Office 365/Xbox Live user. It will fail. This will automatically create your new user.
Login as a Password user with access to change user accounts.

快速

我注意到,当我进入控制台内的 django/admin 页面 '..../admin/login' 时出现此错误:

I noticed that when i go to django/admin page '..../admin/login' inside the console i have this error :

https://static/microsoft/css/login.css Failed to load resource (404)
https://static/microsoft/js/login.js Failed to load resource (404)

我在哪里可以得到这些文件?

Where can i get those files?

让我们跳到我的代码:

  1. settings.py

INSTALLED_APPS = [
    ...
    'django.contrib.sites',
    'microsoft_auth',
    ...
]

#Choped from templates
'context_processors': [
                ...
                'microsoft_auth.context_processors.microsoft',
            ],


AUTHENTICATION_BACKENDS = [
    'microsoft_auth.backends.MicrosoftAuthenticationBackend',
    'django.contrib.auth.backends.ModelBackend',
]


SITE_ID = 1


LOGIN_REDIRECT_URL = 'main:index'
LOGOUT_REDIRECT_URL = 'main:index'

LOGIN_URL = '/'
LOGOUT_URL = '/'

# AZURE AUTH CONFIG
MICROSOFT_AUTH_CLIENT_ID = 'THIS IS MY CLIENT KEY'
MICROSOFT_AUTH_CLIENT_SECRET = 'THIS IS MY SECRET KEY'
MICROSOFT_AUTH_TENANT_ID = 'THIS IS MY TENANT KEY'

# include Microsoft Accounts, Office 365 Enterpirse and Azure AD accounts
MICROSOFT_AUTH_LOGIN_TYPE = 'ma'

还有我的 urls.py

And my urls.py

...
    path('microsoft/', include('microsoft_auth.urls', namespace='microsoft')),
...

提前谢谢大家.

推荐答案

django-microsoft-auth 使用标准的 django 登录页面并对其进行了扩展.我的猜测是您的自定义登录页面正在干扰它.您可以尝试删除该视图并再次测试以查看登录是否显示在/admin.

django-microsoft-auth uses the standard django login page and extends that. My guess is that your custom login page is interfering with that. You could try removing that view and test again to see if the login appears at /admin.

文件应该来自 django-microsoft-auth 包.您可以尝试使用 pip 卸载并重新安装它

The files should be coming from the django-microsoft-auth package. You could try uninstalling and reinstalling it again with pip

这篇关于Django Microsoft AD 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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