Skip to content

feat(auth): add device code login flow and credential management#8

Merged
JacobFV merged 1 commit intomainfrom
jacob/cli-login-device-auth
Feb 10, 2026
Merged

feat(auth): add device code login flow and credential management#8
JacobFV merged 1 commit intomainfrom
jacob/cli-login-device-auth

Conversation

@JacobFV
Copy link
Copy Markdown
Contributor

@JacobFV JacobFV commented Feb 10, 2026

Summary

  • Rewrites agi login to use device code auth (no more copy-paste API key)
  • Opens browser to approval page, polls every 5s until authorized
  • Saves API key to ~/.agi/credentials (0o600 permissions)
  • Adds agi logout to remove stored credentials
  • loadApiKey() checks env vars first, then credentials file
  • Graceful Ctrl+C handling and network error feedback during polling

Dependencies

  • Requires agi-inc/agents#339 (API endpoints)
  • Requires agi-inc/webapp#114 (approval page)

Test plan

  • agi login → opens browser, shows confirmation code
  • Approve in browser → CLI receives key, saves to ~/.agi/credentials
  • agi "test task" → picks up saved key from credentials file
  • agi logout → removes credentials file
  • AGI_API_KEY=xxx agi "test" → env var takes precedence over file
  • Ctrl+C during polling → clean exit with "Login cancelled" message

🤖 Generated with Claude Code

@JacobFV JacobFV force-pushed the jacob/cli-login-device-auth branch from 4ad9656 to ebbb91a Compare February 10, 2026 02:03
Rewrites `agi login` to use device code auth:
- POST /v1/auth/device to initiate, opens browser automatically
- Polls /v1/auth/device/token every 5s until approved
- Saves API key to ~/.agi/credentials on success

Also adds:
- config.ts: credential file management (load/save/delete)
- logout.ts: removes stored credentials
- cli.ts: subcommand structure (login/logout/$0)
- index.tsx: loadApiKey integration with env fallback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@JacobFV JacobFV force-pushed the jacob/cli-login-device-auth branch from ebbb91a to df3cd46 Compare February 10, 2026 02:04
Copy link
Copy Markdown
Contributor

@NamanGarg20 NamanGarg20 left a comment

Choose a reason for hiding this comment

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

lgtm

@JacobFV JacobFV merged commit 932f62a into main Feb 10, 2026
4 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.

2 participants