Skip to content

feat(auth): add td auth print-token for script and agent use#311

Open
scottlovegrove wants to merge 2 commits intomainfrom
scottl/auth-print-token
Open

feat(auth): add td auth print-token for script and agent use#311
scottlovegrove wants to merge 2 commits intomainfrom
scottl/auth-print-token

Conversation

@scottlovegrove
Copy link
Copy Markdown
Collaborator

Summary

  • New td auth print-token subcommand prints the stored API token for the active user (or --user <ref>) to stdout, so scripts can capture it via TOKEN=$(td auth print-token) without ever surfacing the token in an agent's conversation context.
  • Refuses when TODOIST_API_TOKEN is set in the environment — the token is already available there, and silently echoing it would mask multi-user --user requests when env happens to be set. New error code TOKEN_FROM_ENV with actionable hints.
  • Naming: auth print-token (flat sibling) rather than auth token view to avoid colliding with the existing auth token [token] save command.

Test plan

  • npm test -- src/commands/auth/auth.test.ts — 24/24 pass (4 new: happy path, env refusal, NoTokenError propagation, UserNotFoundError propagation)
  • npm run check — lint + format clean
  • npm run check:skill-syncskills/todoist-cli/SKILL.md regenerated and in sync
  • npm run type-check — clean
  • Manual: TOKEN=$(td auth print-token); echo "len=${#TOKEN}"
  • Manual: td auth print-token --user <other-email> resolves the right account
  • Manual: TODOIST_API_TOKEN=fake td auth print-token exits non-zero with TOKEN_FROM_ENV

🤖 Generated with Claude Code

Prints the stored API token for the active user (or `--user <ref>`)
to stdout so callers can capture it via `$(td auth print-token)`
without exposing the token to an agent's conversation context.

Refuses when `TODOIST_API_TOKEN` is set in the environment — the
token is already available there, and silently echoing it would
mask multi-user `--user` requests when env happens to be set.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@scottlovegrove scottlovegrove requested review from gnapse and henningmu May 2, 2026 12:43
@scottlovegrove scottlovegrove self-assigned this May 2, 2026
@scottlovegrove scottlovegrove added the 🙋 Ask PR PR must be reviewed before merging label May 2, 2026
Copy link
Copy Markdown
Member

@doistbot doistbot left a comment

Choose a reason for hiding this comment

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

This PR introduces the td auth print-token subcommand to securely retrieve stored API tokens for scripts and agents, complete with thoughtful environment variable handling. The addition elegantly supports automation workflows without complicating the existing authentication commands. A few minor adjustments would polish this up, specifically updating the agent quick reference examples to use shell capture rather than bare invocations to prevent transcript token leaks, and ensuring the missing --user flag is included in the user mismatch test to align with its description.

Share FeedbackReview Logs

Comment thread src/lib/skills/content.ts Outdated
Comment thread src/commands/auth/auth.test.ts Outdated
- Skill content: replace bare `td auth print-token` examples with
  shell-capture form (`TOKEN=$(td auth print-token)`) so an agent
  following the quick reference literally can't leak the secret
  into its transcript. Strengthen the prose to call this out.
- Tests: faithfully simulate `--user <ref>` in the UserNotFound
  propagation test by stubbing process.argv (where the global-args
  layer reads it from) and resetting the cache, mirroring how
  production wires `--user` around commander.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🙋 Ask PR PR must be reviewed before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants