loginflow

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package loginflow signs the machine's agent CLIs in and out for the page. The CLI does the signing in; the service drives it through a terminal of its own and lets the page see only what the person needs: the vendor's link, the one-time code of a device flow, and where the flow is.

What it keeps from the CLI's output is the link and that code, taken before anything is typed; after that the output is read and thrown away. A code the person pastes back goes to the terminal's input and is dropped; an API key goes to a CLI's standard input (never its arguments or environment). Nothing here is logged: not the output, not the code, not the key.

Index

Constants

View Source
const (
	// StartsPer is how many flows a CLI may start in StartWindow.
	StartsPer   = 5
	StartWindow = 10 * time.Minute
)
View Source
const MaxLinkLen = 2048

MaxLinkLen bounds a link: the longest the vendors print is under 1 KB.

Variables

View Source
var (
	// FlowTimeout is how long a flow lives: the vendors' own codes last 10 to 15 minutes.
	FlowTimeout = 15 * time.Minute
	// CheckTimeout is how long the CLI has to take a pasted code.
	CheckTimeout = 90 * time.Second
	// StartTimeout is how long the CLI has to print its link.
	StartTimeout = 30 * time.Second
	// KeyTimeout bounds one call that hands a key or signs out.
	KeyTimeout = 30 * time.Second
)

Limits of the service (variables so that a test can shorten them).

Functions

func Scan

func Scan(p wire.Provider, mode wire.LoginMode, out []byte) (url string, code *string, ok bool)

Scan looks through the terminal output for the link of a flow and, for a device flow, its one-time code; ok is false until all the flow needs is in the output.

Types

type Config

type Config struct {
	// Bin finds the CLI; an error means it is not installed.
	Bin func(p wire.Provider) (string, error)
	// Env is the environment a CLI starts with, built by the caller from the person's own (HOME, PATH, proxies…): the
	// service adds nothing to it and passes on nothing else, so none of the runtime's tokens reach a CLI.
	Env func() []string
	// OnChange is told when an account changed: a flow ended in a sign-in, a key was saved, the CLI signed out.
	OnChange func(p wire.Provider)
	// Forget erases what signing out leaves behind (a key in the CLI's settings); nil does nothing.
	Forget func(p wire.Provider) error
	// Now is the clock; nil is the system's.
	Now func() time.Time
}

Config is what the service needs from the machine.

type Service

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

Service is the wire's LoginSource over the CLIs.

func New

func New(cfg Config) *Service

New is a service over cfg.

func (*Service) CancelLogin

func (s *Service) CancelLogin(_ context.Context, p wire.Provider) (wire.LoginStatus, error)

CancelLogin ends the flow of a CLI that is on.

func (*Service) Login

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, p wire.Provider) error

Logout signs the CLI out; a flow that is on ends first.

func (*Service) SaveAPIKey

func (s *Service) SaveAPIKey(ctx context.Context, p wire.Provider, key string) error

SaveAPIKey hands an API key to the CLI on its standard input: Codex reads it there and writes it into its own file. Claude reads none that way.

func (*Service) StartLogin

func (s *Service) StartLogin(ctx context.Context, p wire.Provider, mode wire.LoginMode) (wire.LoginStatus, error)

StartLogin starts a flow and answers once the CLI has given its link (or failed to), so the page has something to show.

func (*Service) SubmitLoginCode

func (s *Service) SubmitLoginCode(_ context.Context, p wire.Provider, id, code string) (wire.LoginStatus, error)

SubmitLoginCode types the code into the CLI's terminal. The code is checked again here for what a terminal would take as more than text, and is dropped when it has been written.

Jump to

Keyboard shortcuts

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