auth

package
v0.2.49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: GPL-2.0, GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package auth wires the /api/whoami, /api/login, /api/logout endpoints that shell out to the bundled kiro-cli binary for identity operations. No state persists in the package beyond the CLI path resolved at construction time.

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	LoginURLTimeout: 10 * time.Second,
	LoginProcessCap: 16 * time.Minute,
	LogoutTimeout:   10 * time.Second,
	WhoamiTimeout:   5 * time.Second,
}

DefaultConfig is the production configuration.

Functions

This section is empty.

Types

type Config

type Config struct {
	LoginURLTimeout time.Duration
	LoginProcessCap time.Duration
	LogoutTimeout   time.Duration
	WhoamiTimeout   time.Duration
}

Config holds per-instance timeout configuration. Tests construct a Handler with short timeouts directly via WithConfig; production passes a config built by the composition layer's ConfigFromEnv.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler is the /api/whoami + /api/login + /api/logout endpoint bundle. It shells out to kiro-cli for identity operations; no state persists beyond the CLI path. `loginSem` serialises login subprocesses for the full device-flow lifetime: vibekit is single-user, and a browser double-click or LAN probe would otherwise spawn duplicate kiro-cli subprocesses each pinning their own AWS device code for the full LoginProcessCap (16m). The semaphore is released by the reap goroutine when cmd.Wait returns (user completes flow, or hard cap fires), not when the HTTP handler returns — so a second POST that arrives after the first URL has been emitted but while the first subprocess is still alive still gets 409.

func NewHandler

func NewHandler(cliPath string, opts ...Option) *Handler

NewHandler returns an auth handler that shells out to the kiro-cli binary at cliPath for whoami / login / logout operations.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes wires the auth handler's HTTP endpoints onto mux:

  • GET /api/whoami — current kiro-cli identity
  • POST /api/login — device-code login flow
  • POST /api/logout — clear local credentials

type Option

type Option func(*Handler)

Option configures a Handler at construction time.

func WithConfig

func WithConfig(cfg Config) Option

WithConfig overrides the default timeout configuration. Called from the composition layer with env-derived config and from tests with shorter timeouts. Having ONE construction-time config-injection path, exercised by both production and tests, keeps deadcode happy and ensures tests exercise the same wiring production uses.

func WithTrustedProxies added in v0.1.141

func WithTrustedProxies(trusted []*net.IPNet) Option

WithTrustedProxies sets the reverse-proxy networks trusted when resolving the client IP for the login/logout audit logs via webhttp.ClientIP. Empty/nil trusts nothing, so the unspoofable socket-peer host is logged (the spoof-safe default for a directly-exposed deployment).

type WhoamiResponse

type WhoamiResponse struct {
	Email       string `json:"email,omitempty"`
	Auth        string `json:"auth,omitempty"`
	AccountType string `json:"accountType,omitempty"`
	StartURL    string `json:"startUrl,omitempty"`
	Region      string `json:"region,omitempty"`
	Error       string `json:"error,omitempty"`
}

WhoamiResponse is the typed response from /api/whoami; see the block comment above for the full field semantics and security rationale.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL