Skip to content

feat: Add OAuth authentication with dynamic client registration - #6

Merged
scottlovegrove merged 1 commit into
mainfrom
scottl/oauth
Jan 22, 2026
Merged

feat: Add OAuth authentication with dynamic client registration#6
scottlovegrove merged 1 commit into
mainfrom
scottl/oauth

Conversation

@scottlovegrove

@scottlovegrove scottlovegrove commented Jan 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements secure OAuth 2.0 authentication for twist-cli using Dynamic Client Registration (DCR) and PKCE flow:

  • OAuth 2.0 with PKCE (S256) for secure authentication without storing client secrets
  • Dynamic Client Registration (DCR) creates fresh twd_* client credentials per session
  • Local callback server on port 8766 with automatic browser opening
  • Proper resource cleanup to prevent server leaks (based on fix: ensure OAuth server cleanup on error before callback resolves todoist-cli#5)
  • HTTP Basic auth for token exchange following RFC 6749 standards
  • Comprehensive error handling with user-friendly messages

New Authentication Flow

tw auth login              # New: OAuth browser authentication
tw auth token <token>      # Existing: Manual token entry (unchanged)  
tw auth status             # Existing: Show auth status (updated help text)
tw auth logout             # Existing: Clear saved token (unchanged)

Security Features

  • No hardcoded secrets: Uses DCR to generate fresh client credentials per session
  • PKCE flow: S256 method prevents authorization code interception
  • CSRF protection: State parameter validation
  • Resource management: Guaranteed server cleanup on success/failure
  • Secure storage: Tokens stored using existing config system

Why DCR?

Dynamic Client Registration eliminates the security risk of hardcoded client secrets while providing the same user experience as other OAuth flows. Each authentication session gets fresh, temporary credentials that are discarded after use.

🤖 Generated with Claude Code

Implements secure OAuth 2.0 authentication flow with PKCE for twist-cli:

- OAuth 2.0 with PKCE (S256) for secure authentication without client secrets
- Dynamic Client Registration (DCR) creates fresh client credentials per session
- Local callback server (port 8766) with automatic browser opening
- Proper resource cleanup to prevent server leaks (inspired by todoist-cli PR #5)
- HTTP Basic auth for token exchange following RFC 6749
- Comprehensive error handling and user-friendly messages
- Full test coverage including edge cases and cleanup scenarios

Security improvements:
- No hardcoded client secrets in source code
- Fresh client credentials per authentication session
- State parameter validation for CSRF protection
- Secure code challenge/verifier generation and validation

New commands:
- `tw auth login` - OAuth browser authentication (new)
- `tw auth token <token>` - Manual token entry (existing, unchanged)
- `tw auth status` - Show authentication status (updated help text)
- `tw auth logout` - Clear saved token (existing, unchanged)

Backward compatibility maintained for existing token-based authentication.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
@scottlovegrove scottlovegrove added the 👀 Show PR PR must be reviewed before or after merging label Jan 22, 2026
@scottlovegrove scottlovegrove self-assigned this Jan 22, 2026
@scottlovegrove
scottlovegrove merged commit 2845ebd into main Jan 22, 2026
2 checks passed
@scottlovegrove
scottlovegrove deleted the scottl/oauth branch January 22, 2026 17:01
@scottlovegrove
scottlovegrove requested a review from gnapse January 22, 2026 17:02
github-actions Bot pushed a commit that referenced this pull request Jan 22, 2026
# 1.0.0 (2026-01-22)

### Bug Fixes

* add UTF-8 charset to OAuth callback HTML responses ([#8](#8)) ([fcb2d49](fcb2d49))

### Features

* Add Biome linting, upgrade to Node 20, and add CI workflows ([#3](#3)) ([57f802e](57f802e))
* add loading animations with global API proxy integration ([#7](#7)) ([bf53bfb](bf53bfb))
* Add OAuth authentication with dynamic client registration ([#6](#6)) ([2845ebd](2845ebd)), closes [#5](#5)
* add semantic release automation for NPM publishing ([#10](#10)) ([c756324](c756324))
* Refactor login command to auth with status/logout subcommands ([#4](#4)) ([59e6493](59e6493))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released 👀 Show PR PR must be reviewed before or after merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant