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
- Variables
- func Scan(p wire.Provider, mode wire.LoginMode, out []byte) (url string, code *string, ok bool)
- type Config
- type Service
- func (s *Service) CancelLogin(_ context.Context, p wire.Provider) (wire.LoginStatus, error)
- func (s *Service) Login(_ context.Context, p wire.Provider) (wire.LoginStatus, error)
- func (s *Service) Logout(ctx context.Context, p wire.Provider) error
- func (s *Service) SaveAPIKey(ctx context.Context, p wire.Provider, key string) error
- func (s *Service) StartLogin(ctx context.Context, p wire.Provider, mode wire.LoginMode) (wire.LoginStatus, error)
- func (s *Service) SubmitLoginCode(_ context.Context, p wire.Provider, id, code string) (wire.LoginStatus, error)
Constants ¶
const ( // StartsPer is how many flows a CLI may start in StartWindow. StartsPer = 5 StartWindow = 10 * time.Minute )
const MaxLinkLen = 2048
MaxLinkLen bounds a link: the longest the vendors print is under 1 KB.
Variables ¶
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 ¶
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 (*Service) CancelLogin ¶
CancelLogin ends the flow of a CLI that is on.
func (*Service) SaveAPIKey ¶
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.