Skip to content

feat(auth): finish OAuth login by pasting the redirect URL - #450

Merged
maximelb merged 3 commits into
masterfrom
feature/oauth-paste-callback
Nov 5, 2026
Merged

maximelb merged 3 commits into
masterfrom
feature/oauth-paste-callback

Conversation

@maximelb

@maximelb maximelb commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Problem

limacharlie auth login --oauth --no-browser prints the sign-in URL, but after signing in, the provider sends the browser to http://localhost:808x/callback on the machine the browser runs on. When the CLI runs on a remote box (over SSH, or in an isolated VM), nothing is listening there, so the login never finishes unless the user sets up ssh -L port forwarding.

Change

  • With --no-browser, or when no browser can be opened, the CLI asks the user to copy the redirect URL from the browser's address bar and paste it into the terminal. The page itself fails to load, which is expected. The CLI takes the query string from the pasted text and runs the same signInWithIdp exchange as before. The full URL, the path, or the bare query string are all accepted. Input without code=/error= gets a hint and the CLI keeps waiting.
  • The local callback server keeps listening at the same time, so port forwarding and same-machine logins still work. Whichever arrives first wins.
  • Over SSH with no DISPLAY/WAYLAND_DISPLAY, the CLI no longer tries webbrowser.open (which can start a text browser in the terminal). It acts as if --no-browser was passed.
  • stdin is read through the raw file descriptor with select(), so it can be watched alongside the callback server. sys.stdin buffers ahead and would hide pasted lines from select(). Because of this, pasting is POSIX only. On Windows the behavior is unchanged.
  • Applies to auth login --oauth and auth signup. Works for Google and Microsoft, and the MFA prompt runs after the paste as before.

Security: the pasted query is checked by Firebase against the sessionId from this CLI's createAuthUri call, the same as a callback received by the server. A code from someone else's session is rejected.

Testing

  • New tests/unit/test_oauth_paste_callback.py: parsing of pasted input, re-prompt on bad input, several lines arriving at once, stdin EOF falling back to the server, timeout, server callback while paste is enabled (fake and real OAuthCallbackServer), full start_auth_flow from a paste checking the signInWithIdp payload, and SSH/display detection.
  • Full suite: pytest tests/unit/ tests/microbenchmarks/, 5238 passed (5 skips predate this change).
  • Manual run in a real pty against live Firebase with SSH_CONNECTION set: no browser opened, a garbage line got the hint, and the pasted URL reached signInWithIdp, which rejected the fake code with a 400 as expected. A real Google/Microsoft sign-in still needs a human to try it.

🤖 Generated with Claude Code

On a remote box (SSH, isolated VMs) the provider sends the browser to
http://localhost:808x/callback on the user's own machine, so the CLI's
callback server never receives it and --no-browser could not complete.

With --no-browser (or when the browser cannot be opened), the CLI now
also accepts the redirect URL pasted into the terminal while the local
callback server keeps listening, so port forwarding still works. Over
SSH with no display, the CLI no longer tries to open a browser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maximelb

maximelb commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/lc-review

@maximelb

maximelb commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Self-review (author):

  • Pasting someone else's URL: Firebase only accepts the pasted state/code for the sessionId this CLI got from createAuthUri, which is the same check a server-received callback goes through. A redirect from another session is rejected.
  • stdin handling: the raw fd is read with select() + os.read, so lines that arrive together (paste plus extra Enter) are not stuck in sys.stdin's buffer. A test covers this. Bytes after the accepted line are dropped. The MFA prompt that follows uses input() and waits for new input, so it isn't affected.
  • Line length: Linux canonical-mode TTYs cap a line at 4095 bytes. The live createAuthUri state is ~300 chars for both Google and Microsoft, so the redirect URL stays well under the cap.
  • Ctrl-C: KeyboardInterrupt comes out of select(), the finally still stops the callback server, and auth login already handles it.
  • SSH auto-detect: a tmux session started over SSH and later attached locally still carries SSH_CONNECTION. That user gets the printed URL and the paste prompt instead of a browser, which is a safe fallback.
  • Windows: unchanged (server-only), and the docs say so.

No open issues from my side.

lcbill
lcbill previously approved these changes Nov 5, 2026

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

No high or medium issues found. Two low-priority notes are inline.

General Feedback

  • No test-time-budget check run was found for this commit. The master branch does not list it as a required check (branch protection and rulesets both return none), so this does not block.
  • The paste path skips the local server's CSRF state check. Today this does not matter: expected_state is never set in the Firebase flow, and Firebase checks the pasted query against sessionId. If expected_state is used later, apply the same check to pasted input in _parse_pasted_redirect.

Blast Radius

  • SimpleFirebaseAuth.start_auth_flow is used by auth login --oauth, auth signup and the public helper perform_simple_firebase_auth. All three now read stdin when a browser is not opened (--no-browser, webbrowser.open failed, or SSH with no display).
  • Behavior change: over SSH with no DISPLAY/WAYLAND_DISPLAY, webbrowser.open is no longer called, even without --no-browser. Scripts or library callers that depended on the old behavior will now see the URL printed instead.
  • If a library caller uses stdin for something else, such as a stdio-based protocol, this flow can now read from it on those paths.
  • OAuthCallbackServer.poll_callback is a new public method. wait_for_callback is unchanged.
  • Windows behavior is unchanged.

This review was generated automatically by Claude Code.

Comment thread limacharlie/oauth_firebase_simple.py Resolved
Comment thread tests/unit/test_oauth_paste_callback.py Resolved
…astes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maximelb

maximelb commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/lc-review

lcbill
lcbill previously approved these changes Nov 5, 2026

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Re-reviewed at af2e77d. Both earlier findings are addressed: pasted input now needs code and state, the truncation hint is added, and the test no longer needs ports 8085-8089. One medium test-robustness issue remains (inline). I found no correctness or security problems in the paste flow.

General Feedback

  • test-time-budget: no check run was found for this commit. master does not require it (branch protection and rulesets both return an empty list), so it does not block.
  • When stdin is a pipe instead of a TTY (for example echo ... | limacharlie auth login --oauth --no-browser), the flow now reads and drops stdin lines until EOF. It then falls back to the server. Before this change stdin was left alone. This is unlikely to matter, but you could limit pasting to os.isatty(fd) in _stdin_can_be_polled.

Blast Radius

  • SimpleFirebaseAuth.start_auth_flow backs auth login --oauth, auth signup and the public perform_simple_firebase_auth helper. All three now read raw stdin (POSIX only) when no browser is opened.
  • Over SSH with no DISPLAY/WAYLAND_DISPLAY, webbrowser.open is no longer called, even without --no-browser.
  • OAuthCallbackServer.poll_callback is a new public method. wait_for_callback is unchanged. Windows behavior is unchanged.

This review was generated automatically by Claude Code.

Comment thread tests/unit/test_oauth_paste_callback.py Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maximelb

maximelb commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/lc-review

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Re-reviewed at f8f201f. The earlier findings are fixed:

  • start(port=0) now reads the bound port from server_address, so the test no longer binds, closes and binds again.
  • Pasting is offered only when stdin is a TTY.
  • A pasted redirect needs both code and state.
  • A failed exchange after a paste now says the URL may have been cut short.

I found no correctness or security problems in the paste flow, the select() loop, or the new poll_callback. One low-priority note is inline.

General Feedback

  • test-time-budget: no check run was found for this commit. master does not require it (branch protection and rulesets both return an empty list), so it does not block.
  • CI runs only on ubuntu-latest, so the pty-based tests do not run on macOS. macOS is where the 1024-byte canonical line limit applies.

Blast Radius

  • SimpleFirebaseAuth.start_auth_flow backs auth login --oauth, auth signup and the public perform_simple_firebase_auth helper. On POSIX, all three now read raw stdin when it is a TTY and no browser was opened.
  • Over SSH with no DISPLAY/WAYLAND_DISPLAY, webbrowser.open is no longer called, even without --no-browser.
  • OAuthCallbackServer.start() takes a new optional port argument, and poll_callback is a new public method. The default behavior (ports 8085-8089) and wait_for_callback are unchanged. Windows runtime behavior is unchanged.

This review was generated automatically by Claude Code.

Comment thread tests/unit/test_oauth_paste_callback.py Resolved
@maximelb
maximelb merged commit 820a976 into master Nov 5, 2026
7 checks passed
@maximelb
maximelb deleted the feature/oauth-paste-callback branch November 5, 2026 14:51
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.

2 participants