Django Microsoft AD Authentication

谁都会走 提交于 2021-02-05 09:24:06

问题


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

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.

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?

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

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

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.

Quick Edit :

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?

Let's jump to my code :

  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'

And my urls.py

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

Thank you all in advance.

来源:https://stackoverflow.com/questions/66043316/django-microsoft-ad-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!