Skip to content

feat(flow): sign in to Cloud from the terminal with the browser (openadapt login) - #2379

Merged
abrichr merged 1 commit into
mainfrom
claude/cli-browser-login
Nov 21, 2026
Merged

abrichr merged 1 commit into
mainfrom
claude/cli-browser-login

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

openadapt login needed an ingest token pasted from Settings. With no token given or stored, it now signs in through the browser, the way vercel login, fly auth login and gh auth login do. This is slice 1 of quickstart v2 (design: openadapt-internal#248).

What it does

  1. Makes an S256 PKCE verifier and challenge, and listens on 127.0.0.1:<random port>/callback. The listener serves only that path and keeps the first callback.
  2. Prints https://app.openadapt.ai/login?redirect_to=…&code_challenge=…&state=…. It opens a browser only with --open.
  3. The person signs in (Google or a magic link). A first-time user gets a workspace from onboarding on the way. Cloud's existing /auth/loopback page asks them to approve this computer and redirects to the listener with a one-use oap_ code.
  4. hosted.connect redeems the code with the verifier (new code_verifier argument) and keeps its existing stage, validate, promote, confirm and rollback steps. The credential lands in the same keychain entry that push and report-run read.

No Cloud change is needed: OpenAdapt Desktop already uses this grant in production. openadapt-cloud#501 changes the approval page copy from "Connect OpenAdapt Desktop?" to "Connect this computer?".

Compatibility. --token, OPENADAPT_INGEST_TOKEN or a stored token keep the old path, so login still re-validates a stored token. --browser forces the browser and --no-browser forbids it. No secret appears in any URL the CLI builds.

Files

  • packages/flow/openadapt_flow/browser_login.py: new. Loopback receiver, browser_login() and the CLI wiring.
  • hosted.py: connect(code_verifier=...), validated against RFC 7636.
  • __main__.py: a 3-line hook. The docstring is trimmed so the file stays within its line budget.
  • CAPABILITIES.md row and llms-full.txt.

Checks

  • tests/test_browser_login.py, 11 tests:
    • A real loopback listener, driven by real HTTP requests.
    • The PKCE binding is enforced by the fake claim.
    • State mismatch, refusal, a malformed code and a timeout each spend nothing.
    • The browser opens only on request, and the listener serves only /callback.
    • The CLI prints the link and never the token.
  • test_hosted.py, test_import_layers.py and test_capabilities_map.py: 2,432 passed, 1 skipped. ruff, ruff format and mypy are clean on the new module, and the file-size ratchet passes.
  • End to end against real Cloud routes: openadapt-cloud next dev in mock mode, driven by an httpx "browser" with cookies, with the keychain in memory.
('approval page', 200, 'Connect this computer?')
('redirect', 302, 'http://127.0.0.1:62502/callback', ['code', 'state'])
('result', {'host': 'http://localhost:3917', 'paired': True, 'token_storage': 'keyring', 'device_name': '<this computer>'})
('stored token works', 200, 'oai_ingest_...')

Cancel ended with Sign-in was not approved: The user cancelled this connection request., and nothing was stored.

Not tested: a real sign-in on production app.openadapt.ai, which needs a person at a browser. Users get this with the next Flow release.

@abrichr

abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: a194563

openadapt login with no stored token is an RFC 8252 loopback grant with S256 PKCE. I reviewed the unique diff versus origin/main (browser_login.py, the hosted.connect verifier argument, __main__.py wiring, and tests/test_browser_login.py).

  • The listener binds 127.0.0.1 with an ephemeral port, never 0.0.0.0, and serves only /callback. Anything else is 404.
  • The first callback is the one that is kept. A later request cannot replace it. There is no lock around the first-vs-later check, so two same-machine requests could theoretically race; secrets.compare_digest still rejects a mismatched state, and this is a local loopback. Residual, not a blocker.
  • login_url carries only redirect_to, code_challenge, code_challenge_method=S256, and an opaque state. The verifier never leaves the process except in the claim body. The pairing code must match PAIRING_SECRET_RE before connect is called.
  • Refusal, timeout, a state mismatch, or a malformed callback raise before connect, so nothing is claimed or stored. Tests cover each of those paths and that the printed URL does not contain the verifier or the oap_ code.
  • connect(..., code_verifier=) is optional. When it is omitted, the claim body is unchanged (Desktop / already-bound codes). When it is present, it must match PKCE_VERIFIER_RE (43–128 unreserved characters). The existing snapshot → claim → stage → validate → promote → confirm / rollback sequence is intact.
  • uses_browser still takes the stored-token path by default, so login with a keychain token re-validates as before. --browser forces a new loopback; --token / --no-browser / --no-save stay on the token path.

Do not merge this yet. Public OpenAdapt merges wait on the packages-gate and the coordinator's order (KDF/#2375, then the Flow floor, then the rest).

Coordinator inbox: this review is also recorded on openadapt-internal#211 (comment 7056202521).

@abrichr
abrichr merged commit e3021c0 into main Nov 21, 2026
58 checks passed
@abrichr
abrichr deleted the claude/cli-browser-login branch November 21, 2026 03:12
yunusarda-sudo pushed a commit to yunusarda-sudo/OpenAdapt that referenced this pull request Nov 22, 2026
Raise the privacy extra's floor to openadapt-privacy[presidio]>=1.1.4, which
has sanitization_config(); restore the dated v3.4.0 heading; note the Flow
changes merged since the cut (OpenAdaptAI#2379, OpenAdaptAI#2392, OpenAdaptAI#2313, OpenAdaptAI#2369).
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