Skip to content

OAuth2 Authorization Code + PKCE 認証を追加#6

Merged
buty4649 merged 3 commits intomainfrom
worktree-oauth-auth
Apr 17, 2026
Merged

OAuth2 Authorization Code + PKCE 認証を追加#6
buty4649 merged 3 commits intomainfrom
worktree-oauth-auth

Conversation

@buty4649
Copy link
Copy Markdown
Contributor

Summary

  • xp auth login を追加。X-point の OAuth2 Authorization Code + PKCE フローを実行し、127.0.0.1 のランダム空きポートでコールバックを待ち受けてブラウザで認証する
  • 取得したトークンは zalando/go-keyring でシステムキーリング(Secret Service / Keychain / Credential Manager)に subdomain をキーとして保存
  • xp form list 等の認証解決順は フラグ > XPOINT_* env > キーリング(OAuth) 。キーリング経路ではアクセストークン期限切れ時に自動で refresh して再保存する
  • 補助コマンド・機能:
    • xp auth status … 保存トークンの状態確認(トークン値は *** で完全マスク)
    • XP_DEBUG=1 … HTTP リクエスト/レスポンスを stderr にダンプ(Authorization ヘッダはマスク)

主な変更ファイル

  • cmd/auth.goxp auth login / xp auth status 実装
  • internal/xpoint/oauth.go … PKCE 生成、authorization URL 構築、token endpoint 呼び出し、Authorization Code フロー
  • internal/xpoint/tokenstore.go … キーリング経由の保存/読込/削除
  • cmd/root.go, cmd/form.go … 認証解決ロジックを再構成

仕様参照

X-point API ドキュメント 2.3.1 OAuth2認証(Authorization)

Test plan

  • go test ./...
  • golangci-lint run ./...
  • 実環境で xp auth login 成功 → xp form list で API 呼び出し成功を確認
  • 別 OS(macOS / Windows)でのキーリング動作確認

🤖 Generated with Claude Code

@buty4649 buty4649 self-assigned this Apr 17, 2026
buty4649 and others added 3 commits April 17, 2026 13:39
Adds `xp auth login` which runs the X-point OAuth2 Authorization Code
flow with PKCE. The CLI binds an HTTP listener on a random free
localhost port for the redirect callback, opens the browser, exchanges
the authorization code for tokens, and persists them in the system
keyring (via zalando/go-keyring) keyed by subdomain.

Subsequent commands resolve credentials in the order:
flag > XPOINT_* env > keyring-saved OAuth token. The keyring path
auto-refreshes the access token when expired and writes the new tokens
back so the user never sees expiry errors.

Adds `xp auth status` for inspecting the saved token (values are masked
to "***", never printed) and `XP_DEBUG=1` for HTTP request/response
debug logging on stderr (with redacted Authorization header).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
成功時はstdout側で整形済み出力がすでにあるため、
stderrにもレスポンスボディを出すと `> /dev/null` しても
ターミナルにJSONが残って見えてしまう。エラー時のみ
ボディをダンプするように変更。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
`xp auth login` 時に最後に使ったsubdomainをkeyringに
`__default_subdomain__` キーで保存し、`resolveSubdomain()`
でフラグ/環境変数が未指定のときのフォールバックとして
利用する。一度ログインすればXPOINT_SUBDOMAINの指定が
不要になる。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@buty4649 buty4649 force-pushed the worktree-oauth-auth branch from eba7097 to 16ebded Compare April 17, 2026 04:39
@buty4649 buty4649 enabled auto-merge (squash) April 17, 2026 04:39
@buty4649 buty4649 merged commit b08e1d4 into main Apr 17, 2026
2 checks passed
@buty4649 buty4649 deleted the worktree-oauth-auth branch April 17, 2026 04:40
This was referenced Apr 17, 2026
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