Skip to main content
← Back to list
01Issue
FeatureShippedSwamp CLI
Assigneesstack72

Relationships

#1372 CLI command to create scoped collective tokens (phase 8 of #960)

Opened by stack72 · 7/23/2026· Shipped 7/23/2026

Context

Phase 8 of #960. Users can create scoped collective tokens in the web UI (#1299), and the CLI can use them (#1264) and enforce their scopes (#7 shipped). But there's no way to create collective tokens from the CLI — users must go to the web UI at /o/[slug]/settings.

A CLI command lets CI pipelines provision their own tokens without manual web UI steps.

Proposed command

swamp auth token create --collective <slug> --scopes extensions:push,serve:*

Behavior

  1. Requires authentication (requireAuthenticated) — the user must be logged in with a personal API key or session
  2. Calls POST /api/v1/collectives/<slug>/api-tokens with { name: <generated or --name flag>, scopes: [...] }
  3. On success, displays the raw token key (shown once, not stored) and the granted scopes
  4. On 403 (not admin/owner of the collective), shows a clear error
  5. On 422 (invalid scopes), shows the invalid scope names

Flags

  • --collective <slug> (required) — which collective to create the token for
  • --scopes <comma-separated> (required) — scopes to grant (e.g. extensions:push,serve:*)
  • --name <label> (optional) — token label, defaults to cli-<hostname>-<timestamp> (same pattern as swamp auth login)
  • --json — output in JSON format for scripting

Output (log mode)

Token created for collective "myorg"
Scopes: extensions:push, serve:*

swamp_org_cf...  (shown once — save it now)

Output (JSON mode)

{
  "key": "swamp_org_cf...",
  "id": "...",
  "name": "cli-hostname-1721700000",
  "collective": "myorg",
  "scopes": ["extensions:push", "serve:*"]
}

What this does NOT change

  • No changes to swamp-club web app (API already supports scoped token creation from #1299)
  • No changes to swamp auth login (still creates personal keys)
  • No changes to token enforcement or validation

Files likely affected

  • src/cli/commands/auth_token_create.ts (new command)
  • src/cli/commands/auth.ts (register subcommand)
  • src/infrastructure/http/swamp_club_client.ts (add createCollectiveToken method)
  • src/presentation/renderers/auth_token_create.ts (new renderer)
  • Tests for all of the above

Verification

  • swamp auth token create --collective myorg --scopes extensions:push creates a token with correct scopes
  • Token works with swamp extension push
  • Token is rejected for operations outside its scopes
  • --json output is parseable
  • Missing collective returns clear error
  • Invalid scopes return clear error
  • Non-admin/owner of collective returns 403
02Bog Flow
OPENTRIAGEDIN PROGRESSSHIPPED+ 1 MOREASSIGNED+ 2 MOREREVIEW+ 4 MOREPR_MERGED+ 1 MORENOTIFICATION_SKIPPED

Shipped

7/23/2026, 11:13:14 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
stack72 assigned stack727/23/2026, 10:04:38 PM

Sign in to post a ripple.