codefloe/forgejo-codefloe
Watch
4
12
Fork
You've already forked forgejo-codefloe
0

feat(auth): record OAuth2 logins in the account switcher #45

Merged
pat-s merged 1 commit from t3code/forgejo-oauth-multi-account into v15.0/forgejo-codefloe 2026-07-14 16:21:02 +00:00
Owner

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_accounts list inside handleSignInFull, which covers password, 2FA and WebAuthn logins.
The OAuth2 path (handleOAuth2SignIn) instead wrote the session directly with just uid, 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

  • On OAuth2 sign-in, record the account into the session switch list and clear the transient switch_add flag, mirroring handleSignInFull.
  • This single place covers all OAuth2 completion paths: direct sign-in and the account-linking/signup flow both converge on handleOAuth2SignIn.
  • The OAuth2 + 2FA path already completes through handleSignInFull, and updateSession'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* and TestSignUpViaOAuth* remain green.

## What Integrate the OAuth2 login-source sign-in path with the native [account switcher](https://codefloe.com/codefloe/forgejo-codefloe/pulls/44) 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_accounts` list inside `handleSignInFull`, which covers password, 2FA and WebAuthn logins. The OAuth2 path (`handleOAuth2SignIn`) instead wrote the session directly with just `uid`, 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 - On OAuth2 sign-in, record the account into the session switch list and clear the transient `switch_add` flag, mirroring `handleSignInFull`. - This single place covers all OAuth2 completion paths: direct sign-in and the account-linking/signup flow both converge on `handleOAuth2SignIn`. - The OAuth2 + 2FA path already completes through `handleSignInFull`, and `updateSession`'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*` and `TestSignUpViaOAuth*` remain green.
feat(auth): record OAuth2 logins in the account switcher
All checks were successful
testing / frontend-checks (pull_request) Successful in 2m16s
testing / backend-checks (pull_request) Successful in 14m45s
testing / test-remote-cacher (garnet) (pull_request) Successful in 3m12s
testing / test-remote-cacher (redis) (pull_request) Successful in 7m21s
testing / test-remote-cacher (valkey) (pull_request) Successful in 7m17s
testing / test-unit (pull_request) Successful in 10m20s
testing / test-sqlite (pull_request) Successful in 39m14s
testing / test-pgsql (pull_request) Successful in 43m18s
testing / test-e2e (pull_request) Successful in 28m48s
testing / test-mysql (pull_request) Successful in 31m36s
milestone / set (pull_request_target) Has been skipped
issue-labels / backporting (pull_request_target) Has been skipped
d71ff6c722
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.

handleOAuth2SignIn wrote the session directly with just "uid", bypassing
the switcher bookkeeping that handleSignInFull performs for password, 2FA
and WebAuthn logins. As a result, adding an account via an OAuth2 provider
dropped the previously signed-in account instead of keeping it available
to switch back to.

Record the account into the session's switch list and clear the transient
add-account flag on OAuth2 sign-in, mirroring handleSignInFull. This single
place covers all OAuth2 completion paths (direct sign-in and the
linking/signup flow, which both converge on handleOAuth2SignIn); the
OAuth2 2FA path already completes through handleSignInFull.

Add TestAccountSwitchAddOAuth covering the add-an-account-via-OAuth2 flow.
pat-s merged commit f9f584d825 into v15.0/forgejo-codefloe 2026-07-14 16:21:02 +00:00
pat-s deleted branch t3code/forgejo-oauth-multi-account 2026-07-14 16:21:02 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
codefloe/forgejo-codefloe!45
No description provided.