Skip to content

feat: Go rewrite + OAuth authentication#71

Merged
jakeschepis merged 2 commits intomainfrom
feature/go-rewrite
Mar 2, 2026
Merged

feat: Go rewrite + OAuth authentication#71
jakeschepis merged 2 commits intomainfrom
feature/go-rewrite

Conversation

@jakeschepis
Copy link
Copy Markdown
Contributor

Summary

  • Complete rewrite from TypeScript to Go (v6.0.0) — single binary, 2 dependencies, instant startup
  • OAuth authenticationauth login, auth logout, auth status commands for browser-based login
  • All 26 commands ported with identical CLI interface and JSON envelope format
  • 196 tests passing across 9 packages

OAuth Details

  • Browser-based flow: notion-cli auth login opens Notion, user authorizes, token saved automatically
  • Token precedence: NOTION_TOKEN env var > OAuth token > manual config token
  • CSRF protection via cryptographic state parameter
  • 6 OAuth error codes with actionable suggestions
  • doctor command shows auth method (oauth/env/token/none)

New Files

  • internal/oauth/oauth.go — OAuth flow (localhost server, browser open, token exchange)
  • internal/oauth/oauth_test.go — 9 tests
  • internal/cli/commands/auth.go — auth login/logout/status commands

Modified Files

  • internal/config/config.go — OAuth fields, HasOAuthToken(), ClearOAuth(), AuthMethod()
  • internal/errors/errors.go — 6 OAuth error codes + factory functions
  • internal/cli/commands/db.go — Token precedence: env > OAuth > manual
  • internal/cli/root.go — Register auth commands
  • internal/cli/commands/doctor.go — Auth method diagnostic check
  • Makefile — OAuth client ID/secret ldflags

Test plan

  • make test — 196 tests pass
  • make build — compiles with OAuth ldflags
  • go vet — clean
  • notion-cli auth login — browser opens, authorize, token saved
  • notion-cli auth status — shows OAuth workspace info
  • notion-cli whoami — works with OAuth token
  • notion-cli auth logout — clears tokens
  • notion-cli doctor — shows auth method check

🤖 Generated with Claude Code

jakeschepis and others added 2 commits March 2, 2026 00:11
Complete Go rewrite with Cobra CLI framework. All 26 commands,
in-memory caching, retry with backoff, JSON envelope output,
and npm binary distribution. 183 tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Browser-based OAuth flow for interactive authentication. Users can run
`notion-cli auth login` to authorize via Notion in their browser instead
of manually managing API tokens.

- New `internal/oauth` package with localhost callback server and token exchange
- New `auth login`, `auth logout`, `auth status` commands
- Token precedence: NOTION_TOKEN env > OAuth token > manual config token
- 6 OAuth error codes with actionable suggestions
- Doctor command shows auth method with workspace info
- Build-time OAuth client ID/secret injection via Makefile ldflags
- 14 new tests across oauth and config packages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jakeschepis jakeschepis merged commit 47b10a7 into main Mar 2, 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.

1 participant