Skip to content

fix(gateway): keep the sign-in URL, abort cancelled logins, proxy the token exchange - #351

Merged
quickbeard merged 2 commits into
mainfrom
fix/sso-login-fallbacks
Sep 10, 2026
Merged

quickbeard merged 2 commits into
mainfrom
fix/sso-login-fallbacks

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Summary

Follow-ups from an investigation of the TUI and desktop SSO login.

  • Desktop dropped the sign-in URL immediately. setState in the SSO controller never merged authUrl, and the real login() logs synchronously inside openBrowser(), so the URL was wiped one event after onReady. The renderer only shows Open link, Copy and the paste-back field while authUrl is set, so those controls flashed and vanished; with no browser the only exits were Back or the five-minute timeout. Reproduced against the real login(); the existing test missed it because its fake browser opener never logged. authUrl is now carried forward and cleared explicitly on ready/error/idle.
  • Cancelling a login now actually stops it. login() accepts an AbortSignal: abort closes the loopback server and rejects with a cancellation (isLoginCancelled) at whichever step the flow is on, including mid-exchange and just before the disk write. The desktop controller aborts on cancelLogin and logout, so a late browser callback can no longer re-sign a user who just logged out.
  • TUI: escape backs out of the SSO step. The step is dismissable until a session is in hand; its onClose aborts the attempt. With nothing configured the gate invariant reopens the entry chooser; otherwise the dialog simply closes. Previously the only ways out were quitting or the timeout, which also quit the app.
  • Desktop proxy gap. login() and silentSso() take fetchImpl; the controller passes Electron's net.fetch so the token exchange, userinfo and silent refresh (including the one inside ensureKey) honour proxies, PAC files and enterprise roots like the gateway calls already did.

All touched files are fork-only, so no DIVERGENCES.md row; CHANGELOG has the user-facing entries.

Test plan

  • packages/codev-gateway: bun test (68 pass) — new login suite covers abort closing the real loopback server, an already-aborted signal, and the injected fetch reaching the refresh and userinfo calls
  • packages/desktop: bun test src/main/gateway-sso (22 pass) — the submitCode test now has the browser opener log like the real one, plus abort-on-cancel/logout and fetchImpl plumbing tests
  • packages/tui: configure-gate and custom-provider view tests pass
  • bun typecheck in codev-gateway, desktop, tui
  • Manual: desktop Login with SSO keeps Open/Copy/paste visible while waiting; TUI esc on the SSO step returns to the chooser

🤖 Generated with Claude Code

https://claude.ai/code/session_01UtPnKQ9ATvc9kd1v74zC4Y

quickbeard and others added 2 commits September 10, 2026 10:25
… token exchange

The desktop controller's state merge never carried authUrl forward, and the
real login() logs as it opens the browser, so the URL vanished on the very
next event and the renderer hid its open/copy/paste-back fallback for the
whole wait. Merge it like email and clear it on the transitions that end
the wait.

login() now takes an AbortSignal: aborting closes the loopback server and
rejects with a cancellation at whichever step the flow is on, so a callback
landing after Back, Log out, or the TUI's new escape from the SSO step can
no longer write a session to disk. login() and silentSso() also take the
caller's fetchImpl so the desktop's token exchange and silent refresh ride
Electron's net.fetch like the gateway calls already do.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtPnKQ9ATvc9kd1v74zC4Y
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtPnKQ9ATvc9kd1v74zC4Y
@quickbeard
quickbeard merged commit b2390f6 into main Sep 10, 2026
1 of 5 checks passed
@quickbeard
quickbeard deleted the fix/sso-login-fallbacks branch September 10, 2026 03:43
@quickbeard
quickbeard restored the fix/sso-login-fallbacks branch September 10, 2026 03:46
@quickbeard
quickbeard deleted the fix/sso-login-fallbacks branch September 10, 2026 03:46
@quickbeard
quickbeard restored the fix/sso-login-fallbacks branch September 10, 2026 03:46
@quickbeard
quickbeard deleted the fix/sso-login-fallbacks branch September 10, 2026 03:46
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