django microsoft authentication

Ali Shavaiz 1 Reputation point
2022-07-19T09:27:41.28+00:00

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"
}

222213-setting1.png

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

222214-sett2.png

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'))
]
222187-3.png

Microsoft Security Microsoft Authenticator
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Carlos Solís Salazar 18,191 Reputation points MVP Volunteer Moderator
    2022-07-25T14:04:59.38+00:00

    Hi @Ali Shavaiz

    Thank you for asking this question on the **Microsoft Q&A Platform. **

    I understand that you want to authenticate with Azure AD on your Django App.

    Please review this documentation https://django-auth-adfs.readthedocs.io/en/latest/azure_ad_config_guide.html

    Hope this helps,
    Carlos Solís Salazar

    ----------

    Accept Answer and Upvote, if any of the above helped, this thread can help others in the community looking for remediation for similar issues.
    NOTE: To answer you as quickly as possible, please mention me in your reply.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.