Skip to content

feat(users): Microsoft (Entra ID) OAuth + DB-settings-driven providers - #189

Merged
antosubash merged 11 commits into
mainfrom
feat/microsoft-oidc-db-settings
Jun 3, 2026
Merged

feat(users): Microsoft (Entra ID) OAuth + DB-settings-driven providers#189
antosubash merged 11 commits into
mainfrom
feat/microsoft-oidc-db-settings

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

  • Adds a first-class Microsoft (Entra ID) OAuth provider (httpx_oauth's MicrosoftGraphOAuth2), alongside Google/GitHub/OIDC.
  • Moves all OAuth provider config off SM_USERS_OAUTH_* env vars onto the DB-backed admin settings UI (/settings/modules → Users), with secret masking and grouped fields (matches the background_tasks/file_storage settings pattern).
  • Replaces the per-provider routers with a single request-time dispatcher (/api/users/auth/{provider}/{login,callback}) that resolves the provider from a cache built in on_startup from hydrated settings. This fixes a latent bug: routes mount at app construction (before DB settings hydrate), so a provider configured only via the UI previously showed a login button whose route was never mounted (a 404).
  • Providers hot-reload on the SettingsReloaded event — add/remove a provider in the UI with no restart. The login-button list is derived from the same cache, eliminating button/route drift.
  • Removes the now-redundant enabled_provider_names; adds README setup docs + an env→settings migration note.

⚠️ Behavior change

OAuth credentials (Google/GitHub/OIDC/Microsoft) are no longer read from SM_USERS_OAUTH_* env vars at runtime — they're DB-backed settings now. Existing deployments migrate once:

uv run smpy settings import-from-env

(Same migration background_tasks already made. Token secrets keep their env bootstrap path, untouched.)

Test plan

  • make test-py1295 passed
  • New tests: provider construction + tenant-in-authorize-URL, dispatcher (302 / 404 / bad-state), hot-reload add/remove/package-filter (modules/users/tests/test_oauth.py, test_oauth_routes.py)
  • Live smoke test vs a real create_app instance: configure Microsoft via settings → button appears + /auth/microsoft/login 302s to login.microsoftonline.com with the client_id/tenant; clear creds + reload → 404; re-add → 302 — all without a restart
  • Python lint / typecheck / format / 300-line file cap all clean
  • Manual real sign-in (needs an Entra app registration; redirect URI <base-url>/api/users/auth/microsoft/callback)

Notes

  • No DB migration — OAuthAccount.oauth_name is already a string; settings persist in the existing settings store.
  • Microsoft identity email comes from Graph userPrincipalName (stock httpx_oauth client); guest/external accounts may have a non-email UPN — documented in the README rather than worked around, consistent with the Google/GitHub clients.

Spec: docs/superpowers/specs/2026-06-03-microsoft-oidc-design.md · Plan: docs/superpowers/plans/2026-06-03-microsoft-oidc.md

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 40427f8
Status: ✅  Deploy successful!
Preview URL: https://c618bac7.simple-module-python.pages.dev
Branch Preview URL: https://feat-microsoft-oidc-db-setti.simple-module-python.pages.dev

View logs

@antosubash
antosubash merged commit 91c4aa9 into main Jun 3, 2026
12 checks passed
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