Easily integrate Microsoft Authentication into your Django projects
This library aims to simplify the process of authenticating users with Microsoft 365 in Django Admin pages, inspired by libraries like django_microsoft_auth and django-admin-sso
$ pip install django-microsoft-ssoCompatibility
- Python 3.11, 3.12, 3.13
- Django 4.2, 5.0, 5.1, 5.2
Older python/django versions are not supported.
- Add the following to your
settings.pyINSTALLED_APPS:
# settings.py
INSTALLED_APPS = [
# other django apps
"django.contrib.messages", # Need for Auth messages
"django_microsoft_sso", # Add django_microsoft_sso
]- In Microsoft Entra Administration Center create a multi-tenant app registration and at Application Register, retrieve your
Application ID. Navigate to Certificate & secrets link, and get the Client Secret Value. Add both in your
settings.py:
# settings.py
MICROSOFT_SSO_APPLICATION_ID = "your Application ID here"
MICROSOFT_SSO_CLIENT_SECRET = "your Client Secret Value here"
MICROSOFT_SSO_SCOPES = ["User.Read.All"]-
Add the callback uri
http://localhost:8000/microsoft_sso/callback/in your Microsoft Console, on the "Authorized Redirect URL". -
Let Django Microsoft SSO auto create users for allowable domains:
# settings.py
MICROSOFT_SSO_ALLOWABLE_DOMAINS = ["contoso.com"]- In
urls.pyplease add the Django-Microsoft-SSO views:
# urls.py
from django.urls import include, path
urlpatterns = [
# other urlpatterns...
path(
"microsoft_sso/", include("django_microsoft_sso.urls", namespace="django_microsoft_sso")
),
]- And run migrations:
$ python manage.py migrateThat's it. Start django on port 8000 and open your browser in http://localhost:8000/admin/login and you should see the
Microsoft SSO button.
A minimal Django project using this library is included in this repository under example_microsoft_app/.
- Read the step-by-step instructions in example_microsoft_app/README.md
- Use it as a reference to configure your own project settings and URLs
This project is licensed under the terms of the MIT license.

