feat(auth): record OAuth2 logins in the account switcher #45
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!45
Loading…
Reference in a new issue
No description provided.
Delete branch "t3code/forgejo-oauth-multi-account"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Integrate the OAuth2 login-source sign-in path with the native account switcher so an additional account can be added by authenticating through an OAuth2 provider (another Forgejo/Gitea instance, GitHub, GitLab, ...), not only through the internal username/password form.
Why
The switcher records each authenticated account into the session's
switch_accountslist insidehandleSignInFull, which covers password, 2FA and WebAuthn logins.The OAuth2 path (
handleOAuth2SignIn) instead wrote the session directly with justuid, bypassing that bookkeeping.So adding an account via an OAuth2 provider dropped the previously signed-in account instead of keeping it available to switch back to.
How
switch_addflag, mirroringhandleSignInFull.handleOAuth2SignIn.handleSignInFull, andupdateSession's preservation loop carries the switcher state across the OAuth2 round-trip, so no other changes are needed.Tests
Add
TestAccountSwitchAddOAuth: sign in as user2, start "add an account", complete an OAuth2 callback, and assert the OAuth2 account becomes active while user2 stays available to switch back to (and vice versa).TestAccountSwitch*,TestSignInOAuthCallback*andTestSignUpViaOAuth*remain green.