feat(users): OAuth/OIDC login (Google, GitHub, generic OIDC) - #132
Merged
Conversation
Builds on fastapi-users' existing cookie+DB auth backend by enabling its
``[oauth]`` extra and mounting one ``/auth/<provider>/{login,callback}``
pair per configured provider. Providers are gated by ``SM_USERS_OAUTH_*``
env vars — unset = unmounted, no boot-time failure.
The callback handler is a thin wrapper around ``UserManager.oauth_callback``
that returns a 303 redirect to ``login_redirect_url`` (the stock
fastapi-users router returns 204 No Content, which dead-ends a server-
rendered Inertia browser flow). Session-cookie bridge (``session["user_id"]``)
is now done in ``UserManager.on_after_login`` so OAuth and password flows
share the same path into ``AuthMiddleware``.
https://claude.ai/code/session_0117vVTBiz6EppNQ6RTT7haD
Deploying simple-module-python with
|
| Latest commit: |
d7875b5
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1fa31928.simple-module-python.pages.dev |
| Branch Preview URL: | https://claude-oauth-openid-research.simple-module-python.pages.dev |
…esearch-8GAbX # Conflicts: # modules/users/users/pages/Login.tsx
antosubash
marked this pull request as ready for review
May 6, 2026 20:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds social login to the
usersmodule on top of fastapi-users' existing cookie auth — Google, GitHub, and any OIDC-discovery-compliant provider (Keycloak, Authentik, Auth0, Zitadel, Entra ID, ...) — with no new top-level dependency.fastapi-users[sqlalchemy]→fastapi-users[sqlalchemy,oauth](pulls inhttpx-oauth).OAuthAccountSQLModel table (users_oauth_account) that links a(provider, account_id)pair to a localUser. Migration3bf3f9db7f7fcreates it.SM_USERS_OAUTH_<PROVIDER>_CLIENT_ID+_SECRETmounts the routes; unset = no-op. Generic OIDC additionally requiresSM_USERS_OAUTH_OIDC_DISCOVERY_URL./api/users/auth/<provider>/{login,callback}pair per configured provider. The callback handler is a thin wrapper aroundUserManager.oauth_callback(find-or-create + email association from fastapi-users) that returns a303tologin_redirect_url— the stock fastapi-users router returns 204, which dead-ends a server-rendered Inertia browser flow.session["user_id"](whichAuthMiddlewarereads) insideUserManager.on_after_loginso OAuth and password flows share one path into the auth middleware. Existing wrapper login endpoints already do this; the new assignment is idempotent for them.enabled_provider_names()helper that does no network or client construction.How to enable a provider
Adding a new built-in provider later is one
ifblock inusers/oauth.pyand one entry inenabled_provider_names().Test plan
make lint(ruff format / ruff check / ty / biome / tsc / 300-line cap)make test— Python 978 passed, JS 8 passedmodules/users/tests/test_oauth.py(8 tests): provider-list helper,build_clients,OAuthAccountround-trip + FK cascade,UserManager.oauth_callbackcreate-new + associate-by-emailmake doctorclean — no new SM* warningshttpx_oauthtoken-exchange + profile-fetch pair; better validated against a real provider)Out of scope (deferred)
OAuthAccount.refresh_tokenis stored but never proactively refreshed. Add when calling provider APIs on the user's behalf.https://claude.ai/code/session_0117vVTBiz6EppNQ6RTT7haD
Generated by Claude Code