1 ) Install the given library ( pip install django-microsoft-authentication )
2 ) create an App on azure portal.
3 ) Add the following microsoft app authentication configuration to settings.py file. (e.g. below, please replace redirect and logout_uri with correct domain)
MICROSOFT = {
"app_id": "YOUR_APP_ID_HERE",
"app_secret": "YOUR_APP_SECRET_HERE",
"redirect": "http://localhost:8000/microsoft_authentication/callback",
"scopes": ["user.read"],
"authority": "https://login.microsoftonline.com/common", # or using tenant "https://login.microsoftonline.com/{tenant}",
"valid_email_domains": ["<list_of_valid_domains>"],
"logout_uri": "http://localhost:8000/admin/logout"
}
4 ) Add the following line to settings.py to change the LOGIN_URL and LOGIN_REDIRECT_URL settings.
LOGIN_URL = "/microsoft_authentication/login"
LOGIN_REDIRECT_URL = "/admin" # optional and can be changed to any other url
5 ) Add the following to the project/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
Add the following line
path('microsoft_authentication/', include('microsoft_authentication.urls'))
]