Skip to content

feat: Add Microsoft Identity Provider - #4716

Merged
marcelomendoncasoares merged 6 commits into
serverpod:mainfrom
vfiruz97:feat/auth-microsoft
Feb 13, 2026
Merged

marcelomendoncasoares merged 6 commits into
serverpod:mainfrom
vfiruz97:feat/auth-microsoft

Conversation

@vfiruz97

Copy link
Copy Markdown
Contributor

This PR adds Microsoft OAuth authentication support to the serverpod_auth module. It implements a complete Microsoft identity provider (IDP) using the OAuth 2.0 Authorization Code flow with PKCE, with cross-platform support and no additional dependencies.

Key features:

  • Microsoft OAuth 2.0 authorization code flow with PKCE (Proof Key for Code Exchange)
  • Cross-platform support (iOS, Android, Web, macOS)
  • Multi-tenant support (common, organizations, consumers, or specific tenant ID)
  • Customizable sign-in button widget with Microsoft branding following Microsoft's design guidelines
  • Complete server-side token exchange, user profile fetching via Microsoft Graph API (/v1.0/me), profile photo retrieval, and account management
  • Integration with existing Serverpod auth system
  • Comprehensive test coverage (OAuth2 PKCE util tests, config tests, admin tests, IDP utils tests)

Dependencies added:

None. Unlike other OAuth providers that have well-maintained official Flutter packages, there is no official or reliably maintained Microsoft OAuth package for Flutter. Instead, this implementation reuses the existing OAuth2PkceUtil infrastructure (shared with the GitHub IDP) for both client-side authorization and server-side token exchange. This keeps the dependency footprint minimal and consistent with the existing codebase.

Note on includeClientSecret: Microsoft's OAuth2 implementation differs from most providers, public clients (mobile, desktop) using PKCE must not include the client_secret in the token exchange request, while confidential clients (web) must include it. To accommodate this, the shared OAuth2PkceUtil.exchangeCodeForToken() method was extended with an includeClientSecret parameter. The Microsoft IDP sets this based on the isWebPlatform flag sent from the client. This change is backward-compatible, the default remains true, so existing providers like GitHub are unaffected. This also confirms that OAuth2PkceUtil is now flexible enough to support providers with varying credential requirements.

Demo:

A short video demonstration of Microsoft Sign-In working end-to-end is available here: e2e test video

Fixes #3923.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None. This is a new feature that adds Microsoft Identity provider to auth module without modifying existing authentication methods or APIs.

@vfiruz97

Copy link
Copy Markdown
Contributor Author

Hi @marcelomendoncasoares,
This PR is ready for review. Please review if you have any chance. I followed the same pattern as other IDPs and rebased it on upstream/main to ensure smooth merging. I will proceed with the docs next.

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Another great work, @vfiruz97!! Just one comment on the style of the widget. Very nice to see this provider built with the Oauth2 utils you've built for GitHub. Already paying off :)

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! 🪟

Once the CI is green, we can merge and work on the docs. When testing, I also noticed GitHub sliding together with the icon when alignment is on the left, but we should fix it separately.

Image

@marcelomendoncasoares

marcelomendoncasoares commented Feb 12, 2026 •

Copy link
Copy Markdown
Collaborator

@vfiruz97 Let's just first fix the GitHub IDP icon before merging this PR so we can release a patch version right away. Otherwise we'll need to either branch the 3.3.0 to fix the logo or await for the next minor with the new providers.

@marcelomendoncasoares
marcelomendoncasoares dismissed their stale review February 12, 2026 16:48

Await a fix on other part of the framework before merging this to release the fix as patch version. Otherwise, this feature would require bumping to next minor version.

@vfiruz97
vfiruz97 force-pushed the feat/auth-microsoft branch from fe9c00f to 1dc94f0 Compare February 12, 2026 19:04
@vfiruz97

Copy link
Copy Markdown
Contributor Author

I rebased with upstream/main since this was behind and force-pushed to fix a CI failure after the last commit it was red (1 failure, 1 cancelled. apologies if that messes your review).
The GitHub icon alignment is now fixed, and I've also added the Microsoft IdP documentation.
Please take a look when you have a moment!

@vfiruz97

Copy link
Copy Markdown
Contributor Author

I noticed your update to #4723, thanks for that. I've mirrored those changes for the Microsoft IDP button.

image

@marcelomendoncasoares marcelomendoncasoares left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, @vfiruz97!! Now it is ready to merge! I'll just merge main first and generate the models to incorporate the latest changes to the repository class.

@marcelomendoncasoares
marcelomendoncasoares merged commit 152fa38 into serverpod:main Feb 13, 2026
72 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sign in with Microsoft

2 participants