Documentation
¶
Overview ¶
Package claudecodeauth wraps the `claude auth` subcommand so the Web UI can drive Claude Code login/logout/status from the browser. The login flow is inherently interactive: `claude auth login` prints a one-shot OAuth URL and then blocks on stdin reading a paste-back authorization code. We model that as a server-side session: Start spawns the CLI, captures the URL, and keeps the process handle; SubmitCode writes the code to stdin and waits for the process to exit; Cancel/Stop kills it.
Only one in-flight login session is supported at a time per process. That matches the single-user assumption of the local dashboard and avoids leaking processes if the operator opens multiple browser tabs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LoginOptions ¶
type LoginOptions struct {
// Console switches the OAuth target to api.anthropic.com (console billing)
// instead of claude.ai subscription auth.
Console bool
// Email pre-populates the login page's email field.
Email string
// SSO forces the SSO login flow.
SSO bool
}
LoginOptions controls how `claude auth login` is invoked. The defaults match the CLI's default flow (Claude subscription, no email pre-fill).
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the single in-flight login session per process. Methods are safe for concurrent use by multiple HTTP handlers.
func (*Manager) Cancel ¶
func (m *Manager) Cancel()
Cancel kills the current login session (if any) and clears the manager's reference so a fresh Start can begin.
func (*Manager) Snapshot ¶
Snapshot returns the current session's state, or an inactive zero State if no session is in flight.
func (*Manager) Start ¶
Start spawns `claude auth login` and waits for it to emit the OAuth URL, returning a Session that the caller can later complete by passing the authorization code to SubmitCode. If another session is already active it is killed first so the new flow can take over.
func (*Manager) SubmitCode ¶
SubmitCode pipes the OAuth authorization code to the running login session and waits up to 30 seconds for the CLI to exit. On success the session is cleared. The returned State describes the final outcome regardless of whether the CLI exited cleanly.
type Session ¶
Session represents a live `claude auth login` subprocess waiting for the pasted authorization code on stdin.
type State ¶
type State struct {
Active bool `json:"active"`
StartedAt time.Time `json:"started_at,omitempty"`
URL string `json:"url,omitempty"`
Done bool `json:"done,omitempty"`
Success bool `json:"success,omitempty"`
Output string `json:"output,omitempty"`
Error string `json:"error,omitempty"`
}
State is a snapshot of session progress safe to serialize for the UI.
type Status ¶
type Status struct {
LoggedIn bool `json:"loggedIn"`
AuthMethod string `json:"authMethod,omitempty"`
APIProvider string `json:"apiProvider,omitempty"`
Email string `json:"email,omitempty"`
OrgID string `json:"orgId,omitempty"`
OrgName string `json:"orgName,omitempty"`
SubscriptionType string `json:"subscriptionType,omitempty"`
}
Status mirrors the JSON shape that `claude auth status --json` returns. Fields not emitted by the CLI are simply left zero-valued.
func FetchStatus ¶
FetchStatus runs `claude auth status --json` and parses the result. The CLI returns exit code 0 even when logged out (loggedIn=false in the JSON), so any non-nil error here is a real environmental failure (binary missing, timeout, malformed output) and the UI should surface it as such.