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

feat(oauth2): support prompt=select_account #182

Merged
pat-s merged 9 commits from feat/oauth-select-account into v16.0/forgejo-codefloe 2026-09-29 19:11:05 +00:00
Owner

Add OpenID Connect prompt=select_account support to the OAuth2 authorize endpoint, so OAuth2 clients can let the user choose which CodeFloe account to continue with.
The motivating client is discourse-codefloe-auth, which uses it to switch the Discourse account a user is logged in with.

What changes

  • /login/oauth/authorize shows an account chooser when prompt contains select_account.
    It lists the signed-in account, the other accounts in the session's account switcher (inactive or login-prohibited ones are hidden), "Use another account", and Cancel.
    The client ID, redirect URI, response type and PKCE checks still run first and fail exactly as before; any other prompt value is still ignored.
  • New POST /login/oauth/select_account:
    • uid switches the session to that account (only accounts already in the session's switcher list; anything else is 400) and redirects back to the authorize URL without prompt.
    • add=1 starts the existing add-account login and returns to the authorize URL afterwards.
    • redirect_to must be the local /login/oauth/authorize URL (under AppSubURL); anything else is 400.
    • CSRF protection comes from the route-level cross-origin protection, like the grant form.
  • Cancel returns access_denied to the client through the existing grant-denial path.
  • The account switcher's switch/add logic is extracted into switchToAccount and beginAddAccount, shared by the navbar switcher and the new endpoint; the navbar endpoints keep their responses.
  • The navbar "Add an account" action now clears a stale redirect_to cookie, so an abandoned add from the chooser cannot later send the user to an OAuth client.
  • README "Account switcher" row updated.

Tests

  • Integration: tests/integration/oauth_select_account_test.go (chooser rendering, combined prompts, POST authorize, other prompts unchanged, invalid client, switching and code issued for the chosen account, unlisted accounts, foreign redirects, prohibited accounts, add flow, Cancel, stale redirect cookie).
  • Unit: routers/web/auth/oauth_select_account_test.go for the redirect helpers with and without AppSubURL.
  • TestSelectAccount*, TestAuthorize*, TestAccountSwitch*, TestOAuth* pass on sqlite.
Add OpenID Connect `prompt=select_account` support to the OAuth2 authorize endpoint, so OAuth2 clients can let the user choose which CodeFloe account to continue with. The motivating client is `discourse-codefloe-auth`, which uses it to switch the Discourse account a user is logged in with. ## What changes - `/login/oauth/authorize` shows an account chooser when `prompt` contains `select_account`. It lists the signed-in account, the other accounts in the session's account switcher (inactive or login-prohibited ones are hidden), "Use another account", and Cancel. The client ID, redirect URI, response type and PKCE checks still run first and fail exactly as before; any other `prompt` value is still ignored. - New `POST /login/oauth/select_account`: - `uid` switches the session to that account (only accounts already in the session's switcher list; anything else is 400) and redirects back to the authorize URL without `prompt`. - `add=1` starts the existing add-account login and returns to the authorize URL afterwards. - `redirect_to` must be the local `/login/oauth/authorize` URL (under `AppSubURL`); anything else is 400. - CSRF protection comes from the route-level cross-origin protection, like the grant form. - Cancel returns `access_denied` to the client through the existing grant-denial path. - The account switcher's switch/add logic is extracted into `switchToAccount` and `beginAddAccount`, shared by the navbar switcher and the new endpoint; the navbar endpoints keep their responses. - The navbar "Add an account" action now clears a stale `redirect_to` cookie, so an abandoned add from the chooser cannot later send the user to an OAuth client. - README "Account switcher" row updated. ## Tests - Integration: `tests/integration/oauth_select_account_test.go` (chooser rendering, combined prompts, POST authorize, other prompts unchanged, invalid client, switching and code issued for the chosen account, unlisted accounts, foreign redirects, prohibited accounts, add flow, Cancel, stale redirect cookie). - Unit: `routers/web/auth/oauth_select_account_test.go` for the redirect helpers with and without `AppSubURL`. - `TestSelectAccount*`, `TestAuthorize*`, `TestAccountSwitch*`, `TestOAuth*` pass on sqlite.
Cancel posts to the grant endpoint with granted=false so the client gets access_denied.
Inactive and login-prohibited switcher accounts are no longer offered.
Extend the foreign redirect test to cover add=1.
test(oauth2): cover authorize URL helpers with a non-empty AppSubURL
Some checks failed
testing / backend-checks (pull_request) Has been cancelled
testing / frontend-checks (pull_request) Has been cancelled
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
15984d85b8
docs(readme): link #182 in the account switcher row
All checks were successful
testing / frontend-checks (pull_request) Successful in 2m3s
testing / backend-checks (pull_request) Successful in 9m7s
testing / test-unit (pull_request) Successful in 12m0s
testing / test-remote-cacher (valkey) (pull_request) Successful in 1m51s
testing / test-remote-cacher (redis) (pull_request) Successful in 1m53s
testing / test-remote-cacher (garnet) (pull_request) Successful in 1m47s
testing / test-pgsql (pull_request) Successful in 46m8s
issue-labels / backporting (pull_request_target) Has been skipped
milestone / set (pull_request_target) Has been skipped
testing / test-sqlite (pull_request) Successful in 43m4s
testing / test-e2e (pull_request) Successful in 34m2s
testing / test-mysql (pull_request) Successful in 37m56s
53df9d966b
pat-s scheduled this pull request to auto merge when all checks succeed 2026-09-29 19:01:42 +00:00
pat-s merged commit a72f76e7d8 into v16.0/forgejo-codefloe 2026-09-29 19:11:05 +00:00
pat-s deleted branch feat/oauth-select-account 2026-09-29 19:11:06 +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!182
No description provided.