[WEBXP-469] Add circleci signup command — Magic Path v2#1199
Open
Fab10-CircleCi wants to merge 1 commit intoCircleCI-Public:mainfrom
Open
[WEBXP-469] Add circleci signup command — Magic Path v2#1199Fab10-CircleCi wants to merge 1 commit intoCircleCI-Public:mainfrom
Fab10-CircleCi wants to merge 1 commit intoCircleCI-Public:mainfrom
Conversation
Opens browser directly to /cli-auth with CLI params as top-level query params. The frontend handles session detection: authenticated users get instant PAT creation; unauthenticated users are redirected to signup first. Bypasses auth-svc return-to bug entirely. Security hardening: - Strict Origin validation (reject missing/wrong with 403) - Constant-time state comparison via crypto/subtle - CORS pinned to https://app.circleci.com (static, never reflected) - Access-Control-Allow-Private-Network for Chrome PNA - Method validation (GET only on /token) - 127.0.0.1 binding only Features: - Unique PAT label (hostname + timestamp) prevents 422 duplicates - Already-authenticated guard with --force bypass - --no-browser fallback for headless/SSH - JSON responses for structured error handling - Human-readable URL display in terminal - 24 unit tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6db9f76 to
352a958
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
=========
Internal Checklist
Changes
=======
newSignupCommandtocmd/signup.go— newcircleci signupcommand with hybrid browser flowcorsMiddlewaretocmd/signup.go— CORS + Origin validation + Chrome Private Network Access headershandleTokentocmd/signup.go— localhost/tokenendpoint with constant-time state validation and JSON responsesgenerateStatetocmd/signup.go— 128-bit cryptographic nonce viacrypto/randstateMatchestocmd/signup.go— constant-time comparison viacrypto/subtle--no-browserflag for headless/SSH environments (manual PAT paste)--forceflag to bypass already-authenticated guardcircleci-cli-HOSTNAME-TIMESTAMP) to prevent 422 duplicate errorssignupcommand incmd/root.gocmd/root_test.go(29 → 30)cmd/signup_unit_test.goRationale
=========
This implements the CLI side of the "Magic Path" hybrid signup flow (WEBXP-469). The goal: run
circleci signup, complete signup (or authenticate) in the browser, and have the CLI automatically configured — no manual token copy-paste.The CLI opens the browser directly to
app.circleci.com/cli-authwith CLI params as top-level query params. The frontend handles session detection:This is "Magic Path v2" — v1 routed through
/authentication/signup/where auth-svc drops thereturn-toparameter for already-authenticated users. v2 bypasses auth-svc entirely by going directly to the frontend application page.Greenfield — no existing commands or behaviors are modified. The
setupcommand is untouched.Considerations
==============
/cli-authinstead of/authentication/signup/? Auth-svc has a bug where it dropsreturn-tofor already-authenticated users, causing the CLI to time out. Going directly to a frontend page bypasses this entirely.app.circleci.comorigins at the application level.crypto/subtlefor state comparison? Prevents timing-based attacks on thecli_statenonce. Practical risk is low (localhost, 128-bit nonce), but it's a best practice for secret comparison.Access-Control-Allow-Private-Network: true? Chrome's Private Network Access policy blocksfetch()from public websites to localhost without this header. Confirmed in production testing.POST /api/v1/user/tokenreturns 422 if a token with the same label exists. Users running signup from multiple machines or re-running after config deletion would hit this.circleci-cli-HOSTNAME-TIMESTAMPprevents collisions.fetch()benefits from structured responses ({"status":"ok"}/{"status":"error"}) for error handling and future extensibility.Screenshots
============
Before
N/A — new command, no prior behavior.After
🤖 Generated with Claude Code