Repository navigation
feat(auth): finish OAuth login by pasting the redirect URL - #450
Conversation
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>
|
/lc-review |
|
Self-review (author):
No open issues from my side. |
There was a problem hiding this comment.
AI Code Review Summary
No high or medium issues found. Two low-priority notes are inline.
General Feedback
- No
test-time-budgetcheck run was found for this commit. Themasterbranch 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
statecheck. Today this does not matter:expected_stateis never set in the Firebase flow, and Firebase checks the pasted query againstsessionId. Ifexpected_stateis used later, apply the same check to pasted input in_parse_pasted_redirect.
Blast Radius
SimpleFirebaseAuth.start_auth_flowis used byauth login --oauth,auth signupand the public helperperform_simple_firebase_auth. All three now read stdin when a browser is not opened (--no-browser,webbrowser.openfailed, or SSH with no display).- Behavior change: over SSH with no
DISPLAY/WAYLAND_DISPLAY,webbrowser.openis 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_callbackis a new public method.wait_for_callbackis unchanged.- Windows behavior is unchanged.
This review was generated automatically by Claude Code.
…astes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/lc-review |
There was a problem hiding this comment.
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.masterdoes 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 toos.isatty(fd)in_stdin_can_be_polled.
Blast Radius
SimpleFirebaseAuth.start_auth_flowbacksauth login --oauth,auth signupand the publicperform_simple_firebase_authhelper. All three now read raw stdin (POSIX only) when no browser is opened.- Over SSH with no
DISPLAY/WAYLAND_DISPLAY,webbrowser.openis no longer called, even without--no-browser. OAuthCallbackServer.poll_callbackis a new public method.wait_for_callbackis unchanged. Windows behavior is unchanged.
This review was generated automatically by Claude Code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/lc-review |
There was a problem hiding this comment.
AI Code Review Summary
Re-reviewed at f8f201f. The earlier findings are fixed:
start(port=0)now reads the bound port fromserver_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
codeandstate. - 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.masterdoes 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_flowbacksauth login --oauth,auth signupand the publicperform_simple_firebase_authhelper. 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.openis no longer called, even without--no-browser. OAuthCallbackServer.start()takes a new optionalportargument, andpoll_callbackis a new public method. The default behavior (ports 8085-8089) andwait_for_callbackare unchanged. Windows runtime behavior is unchanged.
This review was generated automatically by Claude Code.
Problem
limacharlie auth login --oauth --no-browserprints the sign-in URL, but after signing in, the provider sends the browser tohttp://localhost:808x/callbackon 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 upssh -Lport forwarding.Change
--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 samesignInWithIdpexchange as before. The full URL, the path, or the bare query string are all accepted. Input withoutcode=/error=gets a hint and the CLI keeps waiting.DISPLAY/WAYLAND_DISPLAY, the CLI no longer trieswebbrowser.open(which can start a text browser in the terminal). It acts as if--no-browserwas passed.select(), so it can be watched alongside the callback server.sys.stdinbuffers ahead and would hide pasted lines fromselect(). Because of this, pasting is POSIX only. On Windows the behavior is unchanged.auth login --oauthandauth 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
sessionIdfrom this CLI'screateAuthUricall, the same as a callback received by the server. A code from someone else's session is rejected.Testing
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 realOAuthCallbackServer), fullstart_auth_flowfrom a paste checking thesignInWithIdppayload, and SSH/display detection.pytest tests/unit/ tests/microbenchmarks/, 5238 passed (5 skips predate this change).SSH_CONNECTIONset: no browser opened, a garbage line got the hint, and the pasted URL reachedsignInWithIdp, 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