Skip to content

Log in through the browser instead of pasting an API key - #48

Merged
czue merged 5 commits into
mainfrom
cli-device-login
Oct 21, 2026
Merged

czue merged 5 commits into
mainfrom
cli-device-login

Conversation

@czue

@czue czue commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

The CLI side of https://github.com/czue/pegasus-site/pull/356.

pegasus auth / pegasus auth login now:

  1. Starts a device-code login on the server (sending the machine's hostname so the approval page can show it).
  2. Prints the approval link and the code, and opens the browser. Pass --no-browser to skip opening it.
  3. Polls until the user approves (signing up first if they don't have an account), then saves the new API key to ~/.pegasus/credentials.

It never reads stdin, so an agent can run it directly instead of telling the user to open a separate terminal. The old paste flow is still available as --with-key, and PEGASUS_API_KEY works as before.

The server's RFC 8628 errors are handled: authorization_pending keeps polling, slow_down backs off, and access_denied / expired_token / invalid_grant exit with a message. On a server without the endpoint (404), the error points to --with-key.

Testing

  • New tests/test_device_login.py covers polling, backoff, error codes, expiry, and the command itself (browser open, --no-browser, saving the key, denial). The existing auth test now uses --with-key.
  • Ran the real command against a server without the new endpoints and got the --with-key fallback message.
  • Not tested end to end against a server running pegasus-site#356.

Merge order

Merge and deploy pegasus-site#356 before releasing this. Until then, bare pegasus auth would fail with the fallback message.

🤖 Generated with Claude Code

czue and others added 5 commits October 19, 2026 09:17
'pegasus auth login' now starts a device-code login, prints the link and
code, opens the browser, and waits for approval before saving the new key.
It never reads stdin, so agents can run it. The old paste flow is still
available as --with-key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A 429, a dropped connection or a 5xx during a deploy no longer ends the
login: the CLI waits (for Retry-After, on a 429) and polls again until the
login expires. Non-JSON or incomplete responses now give a clean error
instead of a traceback, and a 429 when starting says when to retry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Browser login no longer asks before replacing an existing key, so an
  agent re-running it can't hang or abort on the prompt (--with-key still asks).
- Warn when PEGASUS_API_KEY is set, since it overrides the saved key.
- Don't try to open a browser on Linux without a display, where Python
  falls back to terminal browsers like lynx, and say to open the link by
  hand when no browser opened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@czue
czue merged commit 412a709 into main Oct 21, 2026
10 checks passed
@czue
czue deleted the cli-device-login branch October 21, 2026 12:26
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