Skip to content

feat(cli): auth scaffold — login/logout/auth status + config + backend client (cli#83)#85

Merged
shujaatTracebloc merged 2 commits into
developfrom
feat/rfc-0001-cli-auth
Jun 19, 2026
Merged

feat(cli): auth scaffold — login/logout/auth status + config + backend client (cli#83)#85
shujaatTracebloc merged 2 commits into
developfrom
feat/rfc-0001-cli-auth

Conversation

@LukasWodka

Copy link
Copy Markdown
Contributor

Summary

RFC-0001 (epic backend#830) — the CLI auth side, scaffolded ahead of the backend device-grant so it activates the moment backend#835 ships. Part of cli#83.

What's here

  • internal/config~/.tracebloc/config.json store (mode 0600, atomic write): backend env + user token + active client. Fully functional + tested.
  • internal/api — backend REST client:
    • CLIENT_ENV{dev,stg,prod} base URL, kept in lock-step with the installer's _backend_url;
    • proxy + CA aware (honors HTTP(S)_PROXY / NO_PROXY + the system cert pool — RFC-0001 must work behind a corporate / TLS-inspecting proxy, backend#830 Q1);
    • the RFC 8628 device-flow methods (RequestDeviceCode + PollToken, with the authorization_pending / slow_down / expired_token / access_denied states). Tested via httptest.
  • internal/clitracebloc login (device flow: print URL + code, poll, store the token), logout, auth status. client create/list/use are stubbed (that's cli#84 — they need the user token from login + provisioning backend#836).

Functional now vs pending #835

Piece State
config store, env→URL, proxy/CA HTTP works + tested now
login device-flow logic written to spec; goes live when backend#835 ships (until then it reports the backend doesn't support browser sign-in yet)
logout, auth status work now (operate on local config)
client create/list/use stubs → cli#84

Test plan

  • gofmt clean · go build ./... · go test ./... (all 8 packages) green.
  • internal/config: save/load round-trip, 0600 mode, missing-file→empty, clear.
  • internal/api: BaseURL / ResolveEnv mapping; RequestDeviceCode + PollToken (pending→slow_down→success, and denied) via httptest.
  • tracebloc --help lists login / logout / auth / client.

Opening as a reviewable scaffold (not a draft) — the config + api are fully functional, and login degrades gracefully until backend#835. Reviewers can merge now or hold for #835.

🤖 Generated with Claude Code

…d client (cli#83)

RFC-0001 (backend#830) Phase-1 CLI side, scaffolded ahead of the backend
device-grant so it activates the moment backend#835 ships.

- internal/config: ~/.tracebloc config store (0600, atomic write) — backend
  env + user token + active client. Fully functional + unit-tested.
- internal/api: backend REST client. CLIENT_ENV -> {dev,stg,prod} base URL
  (matches the installer's _backend_url); proxy + CA aware (honors
  HTTP(S)_PROXY / NO_PROXY + the system cert pool, for corporate-proxy
  networks); the RFC 8628 device-flow methods (RequestDeviceCode + PollToken
  with the authorization_pending / slow_down / expired_token / access_denied
  states). Unit-tested via httptest.
- internal/cli: `tracebloc login` (device flow — show URL + code, poll, store
  the token), `logout`, `auth status`. `client create/list/use` are stubbed
  (cli#84 — they need the user token from login + provisioning backend#836).

login calls /device/code + /device/token, which land in backend#835; until
then it reports that the backend doesn't support browser sign-in yet. Builds,
gofmt-clean, unit-tested (config round-trip + 0600 mode; api URL map +
device-flow poll states); `tracebloc --help` lists the new verbs.

Part of cli#83 / backend#830 (end-to-end login activates with backend#835).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LukasWodka

Copy link
Copy Markdown
Contributor Author

👋 Heads-up — Code review queue is at 33 / 30

Above the WIP limit. The team convention is to review existing PRs before opening new work.

Open PRs currently in Code review (oldest first):

Pull from review before opening new work. (This is a nudge from the kanban WIP check, not a block.)

…86)

* feat(cli): authenticate with Bearer + verify token on login (cli#83)

Completes `tracebloc login` against the now-built device-grant endpoints
(backend#846). The token the flow issues is a ClientAccessToken, which the
backend authenticates as `Authorization: Bearer` (ClientAccessTokenAuthentication,
backend#835) — not the legacy DRF `Token` scheme the client was sending on
authenticated requests, which would have failed to authenticate a logged-in token.

- internal/api: authenticated requests now send `Bearer <token>` (was `Token`);
  add get() + WhoAmI() (GET /userinfo/) to confirm the token + fetch the account.
- login now verifies the freshly-issued token (best-effort) and stores/shows the
  account ("Signed in as you@co.com"); a failed lookup never fails a valid sign-in.
- tests: WhoAmI sends Bearer + parses the identity; a 401 surfaces as an APIError.

The device-flow contract (paths/fields/error codes) was already aligned with
backend#846 — verified, unchanged. Stacked on cli#85 (auth scaffold).
go build/vet/test green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(cli): cover the login command end-to-end + add test seams (cli#83)

internal/api was unit-tested, but the login / logout / auth status COMMANDS
weren't. Adds auth_test.go driving the full device-flow command against an
httptest backend whose shapes match backend#846 — so it also guards the
CLI<->backend contract that the Token->Bearer fix corrected:

- login: device_code -> authorization_pending -> token -> WhoAmI(Bearer) ->
  "Signed in as ..." with config persisted; the 404 "unsupported backend" gate
  (asserts no token is stored); access_denied.
- logout clears the token; auth status (signed-in + not-signed-in).

Two unexported test seams in auth.go — newAPIClient (point at an httptest
server) and pollAfter (fire the poll immediately) — since the flow otherwise
makes real HTTP calls on a timer. go build / vet / test green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shujaatTracebloc shujaatTracebloc merged commit e322613 into develop Jun 19, 2026
12 checks passed
@shujaatTracebloc shujaatTracebloc deleted the feat/rfc-0001-cli-auth branch June 19, 2026 07:10
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