Skip to content

integrate microsoft oauth2 client workflow#24

Open
yoshson wants to merge 6 commits into
mainfrom
ys/microsoft-oauth-client
Open

integrate microsoft oauth2 client workflow#24
yoshson wants to merge 6 commits into
mainfrom
ys/microsoft-oauth-client

Conversation

@yoshson

@yoshson yoshson commented Jun 22, 2026

Copy link
Copy Markdown

Users from Microsoft Azure AD should be able to login via OAuth2 workflow.

@yoshson

yoshson commented Jun 22, 2026

Copy link
Copy Markdown
Author

Add Microsoft OAuth2 Support

This PR introduces Microsoft OAuth2 authentication to django-authlib, enabling users to log in via Microsoft accounts (e.g., Outlook, Office 365, Azure AD).

Changes

  1. New Module: Added authlib/microsoft.py with MicrosoftOAuth2Client class, supporting:

    • OAuth2 authorization flow via Microsoft Identity Platform (common tenant).
    • User data retrieval from Microsoft Graph API (mail and displayName).
    • Configurable via MICROSOFT_CLIENT_ID and MICROSOFT_CLIENT_SECRET settings.
  2. Admin OAuth Support:

    • Extended authlib.admin_oauth to support Microsoft login for Django admin.
    • Added admin/__oauth_ms__/ endpoint and updated templates.
  3. Frontend Integration:

    • Added Microsoft OAuth2 button to login templates.
    • Updated urls.py with /oauth/microsoft/ route.
  4. Documentation:

    • Updated README.rst with Microsoft OAuth2 setup instructions.
  5. Tests:

    • Added comprehensive test coverage for MicrosoftOAuth2Client in test_authlib.py.

Usage

from authlib.microsoft import MicrosoftOAuth2Client

urlpatterns = [
    path("oauth/microsoft/", views.oauth2, {"client_class": MicrosoftOAuth2Client}),
]

Add to settings.py:

MICROSOFT_CLIENT_ID = "your-client-id"
MICROSOFT_CLIENT_SECRET = "your-client-secret"

@yoshson yoshson marked this pull request as ready for review June 22, 2026 19:15
@yoshson yoshson force-pushed the ys/microsoft-oauth-client branch from d0494df to 96dc7fd Compare June 24, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant