auth

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteAPIKey

func DeleteAPIKey(profile string) error

DeleteAPIKey removes the API key for a profile.

func ExportAPIKey

func ExportAPIKey(apiKey string, dest ExportDestination) error

ExportAPIKey exports the API key to the specified destination.

func GetAPIKey

func GetAPIKey(profile string) (string, error)

GetAPIKey retrieves the API key for a profile, checking PE_API_KEY first.

func GetActiveProfile

func GetActiveProfile() string

GetActiveProfile returns the currently active profile name.

func GetStoredAPIKey

func GetStoredAPIKey(profile string) (string, error)

GetStoredAPIKey retrieves the API key from the credential store only, ignoring PE_API_KEY.

func InitStore

func InitStore() error

InitStore initializes the file-based credential store.

func IsInteractiveTerminal

func IsInteractiveTerminal() bool

IsInteractiveTerminal returns true if stdin is a terminal.

func ListProfiles

func ListProfiles() (profiles []string, activeProfile string, err error)

ListProfiles returns all stored profile names and the active profile.

func Login

func Login(profile, operatorID, keyTitle string, progress *LoginProgress) (string, error)

Login authenticates via browser and stores the API key for the given profile. If progress is nil, no progress messages are printed.

func SetActiveProfile

func SetActiveProfile(profile string) error

SetActiveProfile sets the active profile.

func StoreAPIKey

func StoreAPIKey(apiKey, profile string) error

StoreAPIKey stores an API key for a profile.

Types

type ExportDestination

type ExportDestination string

ExportDestination represents where to export the API key beyond the stored credentials file (e.g. into an OpenClaw config or a shell profile).

const (
	ExportOpenClaw ExportDestination = "openclaw"
	ExportShell    ExportDestination = "shell"
	ExportNone     ExportDestination = "none"
)

func PromptExportDestination

func PromptExportDestination(in io.Reader, out io.Writer) ExportDestination

PromptExportDestination shows an interactive menu and returns the user's choice.

type LoginProgress

type LoginProgress struct {
	// OnUserCode is called with the code the user must type in the browser, before the browser is
	// opened. Only called when the server issued one. Implementations MUST display it — a user who
	// never sees it cannot complete the login.
	OnUserCode func(code string)
	// OnBrowserOpen is called when the browser is about to open, with the fallback URL.
	OnBrowserOpen func(loginURL string)
	// OnWaiting is called when polling starts.
	OnWaiting func()
	// OnServerMessage is called with the server's advisory message, if any. Used to reach CLI
	// versions we can't otherwise update (e.g. deprecation notices), so it should be shown.
	OnServerMessage func(message string)
}

LoginProgress reports login progress to the caller.

type LoginResponse

type LoginResponse struct {
	SessionToken string    `json:"sessionToken"`
	PollSecret   string    `json:"pollSecret"`
	LoginURL     string    `json:"loginUrl"`
	ExpiresAt    time.Time `json:"expiresAt"`
	Message      string    `json:"message"`

	// UserCode is the device-flow user code (RFC 8628 §3.3). The user types it in the browser to
	// confirm they're authorizing this terminal. Present only when we advertised supportsUserCode.
	//
	// Display it, and nothing more: it must reach the browser by the user reading it here and typing
	// it in. Never put it in a URL, and don't log it.
	UserCode string `json:"userCode"`
}

type PollResponse

type PollResponse struct {
	Status string  `json:"status"`
	ApiKey *string `json:"apiKey,omitempty"`
	Error  *string `json:"error,omitempty"`
}

Jump to

Keyboard shortcuts

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