Skip to content

feat(toolpath-cli): add path auth command for Pathbase login#52

Merged
eliothedeman merged 2 commits intomainfrom
eliot/sweet-pare-c44db4
Apr 23, 2026
Merged

feat(toolpath-cli): add path auth command for Pathbase login#52
eliothedeman merged 2 commits intomainfrom
eliot/sweet-pare-c44db4

Conversation

@eliothedeman
Copy link
Copy Markdown
Collaborator

Summary

  • New top-level `path auth` subcommand with `login` / `logout` / `status` / `whoami`.
  • `login` prints `/auth/cli`, user signs in via browser, pastes back an 8-character code; CLI trades it for a bearer token via `POST /api/v1/auth/cli/redeem`.
  • Credentials persist to `~/.toolpath/credentials.json` (file 0600, parent dir 0700 on Unix). `$TOOLPATH_CONFIG_DIR` overrides the directory. All authenticated requests use `Authorization: Bearer `.

Configuration

  • Server URL: `--url` → `$PATHBASE_URL` → `https://pathbase.dev\` default.
  • CLI sends `User-Agent: toolpath-cli/` so sessions are distinguishable on the server's session-management UI.

Test plan

  • `cargo test -p toolpath-cli` — 158 unit + 14 integration (includes 6 new auth unit tests + 2 integration tests)
  • `cargo clippy -p toolpath-cli -- -D warnings` clean
  • Storage helpers fully unit-tested: disk roundtrip, nested parent-dir creation, 0600 mode on Unix, empty/missing-file handling
  • Manual: run against a local Pathbase with the companion PR → `PATHBASE_URL=http://localhost:5173 path auth login` → `path auth status` persists across invocations → `path auth whoami` hits `/auth/me` with Bearer

Requires

Companion server change: empathic/pathbase#4 (CLI grant endpoints + Bearer auth extractor)

Adds a new top-level `path auth` subcommand with `login` / `logout` /
`status` / `whoami` that authenticates the CLI against a Pathbase instance
so future `path upload` calls can attach a bearer token.

`path auth login` prints `<base>/auth/cli`, prompts the user to visit the
URL in a browser, sign in, and paste the 8-character code. The CLI posts
the code to `/api/v1/auth/cli/redeem` to trade it for a session token,
then writes `{url, token, user}` to `~/.toolpath/credentials.json`
(file 0600, parent dir 0700 on Unix). All authenticated calls use
`Authorization: Bearer <token>`.

- Server URL resolves from `--url`, then `$PATHBASE_URL`, then the
  `https://pathbase.dev` default.
- `$TOOLPATH_CONFIG_DIR` overrides the credentials directory.
- Storage helpers take a `&Path` so they are unit-testable without a real
  `$HOME`; 6 unit tests cover disk roundtrip, parent-dir creation, 0600
  mode, and empty/missing files. Integration tests cover `auth --help`
  and a login against an unreachable URL.

Requires the matching Pathbase PR (CLI grant endpoints + Bearer auth
extractor) to be live on the target server.
The wasm build target compiles out `reqwest::blocking`, so the new
`cmd_auth` module (which relies on a blocking HTTP client and a local
credentials file) can't link for `wasm32-unknown-emscripten`. The CLI
`auth` command doesn't make sense in a browser context anyway — there's
no persistent filesystem or HOME — so the cleanest fix is to hide it
from the wasm build entirely.

- Move `reqwest` under `[target.'cfg(not(target_os = "emscripten"))']`.
- Gate `mod cmd_auth`, the `Commands::Auth` enum variant, and its
  dispatch arm behind `#[cfg(not(target_os = "emscripten"))]`.
@github-actions
Copy link
Copy Markdown

🔍 Preview deployed: https://9ed2423d.toolpath.pages.dev

@eliothedeman eliothedeman merged commit 05ae025 into main Apr 23, 2026
2 checks passed
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