Skip to content

feat(cli): add browser-assisted login and logout flow#1985

Merged
benflexcompute merged 11 commits into
mainfrom
maciej/codex/flow360-cli-login
Apr 23, 2026
Merged

feat(cli): add browser-assisted login and logout flow#1985
benflexcompute merged 11 commits into
mainfrom
maciej/codex/flow360-cli-login

Conversation

@maciej-flexcompute
Copy link
Copy Markdown
Collaborator

@maciej-flexcompute maciej-flexcompute commented Apr 13, 2026

Summary

  • add browser-assisted flow360 login and flow360 logout for Flow360 CLI auth
  • update the localhost callback flow to match the merged frontend handoff on flow360.dev-simulation.cloud
  • support encrypted browser->CLI handoff payloads with P-256 ECDH + HKDF + AES-GCM
  • keep the CLI branch scoped to login/auth flow files only

What changed

The CLI login callback server now supports:

  • encrypted query callbacks via payload + epk + iv
  • plaintext query callbacks for fallback/testing
  • form-encoded POST callbacks
  • browser-facing success/error pages on the localhost callback

The CLI login command also now prints a manual fallback hint for headless environments:

  • flow360 configure ... --apikey <apikey>

Why it changed

The frontend handoff now delivers an encrypted localhost callback payload, so the CLI needs to:

  • generate a one-time callback public key
  • advertise the callback encryption algorithm in the login URL
  • decrypt the localhost callback payload before storing the API key

Security notes

This improves the current flow by removing the plaintext API key from the callback URL and normal browser history.

It does not fully eliminate plaintext exposure inside the browser page itself, because the page still receives the API key before encrypting it for the localhost callback. A future one-time backend code exchange would still be stronger.

Verification

python -m pytest tests/v1/test_cli_login.py -q

Result: 10 passed

start screen:
Screenshot 2026-04-21 at 16 15 51

success:
Screenshot 2026-04-21 at 16 16 31


Note

Medium Risk
Adds new CLI auth flows that spin up a local HTTP callback server and process (including decrypt) browser handoff payloads, plus changes how API keys are stored/removed; mistakes here could break login or leak credentials.

Overview
Adds browser-assisted authentication to the CLI via new flow360 login/flow360 logout commands. login starts a localhost callback server, opens a web login URL, accepts GET/POST callback payloads (optionally encrypted via P-256 ECDH + HKDF + AES-GCM), and stores the returned API key; logout removes a stored key for the selected profile/environment and reports when none exists.

Refactors config persistence into user_config helpers (read_user_config/write_user_config/store_apikey/delete_apikey) and updates configure to use them with centralized environment flag validation. Config directory/file permissions are now best-effort hardened (0700/0600), and tests are added/updated to cover configure/logout and login callback variants (plaintext, form-encoded, encrypted, and error paths).

Reviewed by Cursor Bugbot for commit 8ec9150. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread flow360/user_config.py Fixed
Comment thread flow360/cli/app.py
Comment thread flow360/user_config.py Fixed
Comment thread flow360/cli/auth.py Outdated
Comment thread flow360/cli/app.py
Comment thread flow360/cli/auth.py
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit acd46bd. Configure here.

Comment thread flow360/cli/auth_guidance.py
@maciej-flexcompute maciej-flexcompute force-pushed the maciej/codex/flow360-cli-login branch from a78db43 to c398f2e Compare April 22, 2026 08:22
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 22, 2026

Coverage report (flow360)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  flow360
  user_config.py 24-25, 139
  flow360/cli
  api_set_func.py
  app.py 25-26, 77-80, 83-84, 89, 146, 162-163
  auth.py 46, 49, 54, 56, 142, 162, 164, 169, 180, 311-312, 323-324, 328, 332-339, 345-346, 369-370, 374-375, 380-384, 388-393, 455, 466
  auth_guidance.py 12-16, 21-27, 37
Project Total  

This report was generated by python-coverage-comment-action

Comment thread flow360/cli/app.py Outdated
Comment thread tests/test_cli.py
Comment thread tests/test_cli_login.py
@benflexcompute benflexcompute merged commit 5aa129b into main Apr 23, 2026
21 checks passed
@benflexcompute benflexcompute deleted the maciej/codex/flow360-cli-login branch April 23, 2026 22:05
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.

3 participants