Skip to content

integrate microsoft oauth2 client workflow#24

Merged
yoshson merged 10 commits into
mainfrom
ys/microsoft-oauth-client
Jul 2, 2026
Merged

integrate microsoft oauth2 client workflow#24
yoshson merged 10 commits into
mainfrom
ys/microsoft-oauth-client

Conversation

@yoshson

@yoshson yoshson commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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

@yoshson

yoshson commented Jun 22, 2026

Copy link
Copy Markdown
Contributor 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).
    • User data retrieval from the login token.
    • 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

@matthiask matthiask left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sieht toll aus!

Zwei Punkte:

  • Muss man nach dem Upgrade nun immer die MICROSOFT_* Settings verfügbar haben? Das wäre schade.
  • Ich fänds toll, wenn die Login-Buttons nun nur angezeigt werden, wenn die Loginmethode verfügbar ist. Das war vorher kein Issue, weil sowieso nur Google unterstützt wurde.

@yoshson

yoshson commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Muss man nach dem Upgrade nun immer die MICROSOFT_* Settings verfügbar haben? Das wäre schade.

Das sollte definitiv nicht so sein. Danke!

Ich fänds toll, wenn die Login-Buttons nun nur angezeigt werden, wenn die Loginmethode verfügbar ist. Das war vorher kein Issue, weil sowieso nur Google unterstützt wurde.

Klingt gut, mache ich.

Danke für die Review!

yoshson added 2 commits July 2, 2026 08:57
and only configured oauth clients provide a login button
@yoshson yoshson merged commit 314fefb into main Jul 2, 2026
7 checks passed
@yoshson yoshson deleted the ys/microsoft-oauth-client branch July 2, 2026 08:37
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.

2 participants