Documentation
¶
Overview ¶
Package authflow is the client half of browser sign-in: a one-shot loopback listener that receives a single-use CODE from the registry's /ui/authorize page after the user signs in (through the directory service) and clicks Authorize, then exchanges that code for the PAT from this process — POST /api/v1/auth/desktop/exchange — so the token never rides a URL or lands in the browser's history. `agentry login` and the desktop app share this implementation.
Trust model: the listener binds 127.0.0.1 only, accepts exactly one callback, and requires the state nonce this process generated — a browser tab cannot plant a code the app did not ask for, and a code meant for this app cannot be delivered anywhere else (the registry pins its redirect to 127.0.0.1:<port>). The code is bound to the same nonce server-side, is single-use, and expires in a minute. The token is still verified against the registry (whoami) before it is stored, exactly like a pasted PAT.
Older registries send ?token= directly; that is still accepted so the app keeps working against them, with the caveat that the token then lands in the browser's history.
Index ¶
Constants ¶
const Timeout = 5 * time.Minute
Timeout bounds how long a sign-in may sit waiting on the browser.
Variables ¶
var ( ErrDeclined = errors.New("browser sign-in declined") ErrTimeout = errors.New("browser sign-in timed out — start it again from Settings") )
Typed outcomes let machine clients distinguish a refusal from expiry.
Functions ¶
This section is empty.
Types ¶
type Flow ¶
type Flow struct {
// Port is the loopback port the registry must redirect to.
Port int
// State is the nonce the callback must echo.
State string
// Registry is the origin the code is exchanged against; set by
// AuthorizeURL, which is always called before the callback can arrive.
Registry string
// HTTP performs the exchange; tests substitute it.
HTTP *http.Client
// contains filtered or unexported fields
}
Flow is one in-flight browser sign-in.
func (*Flow) AuthorizeRunhostURL ¶ added in v0.7.3
AuthorizeRunhostURL is the authorize page asking for a remote runhost's token: one that can only open credits sessions, named for the runhost.
func (*Flow) AuthorizeURL ¶
AuthorizeURL is the page to open in the system browser: the registry server's own device authorize page — served by agentryd at /ui/authorize whether or not a site fronts it, so browser sign-in works against a headless registry too.
func (*Flow) Close ¶
func (f *Flow) Close()
Close tears the listener down. Safe after Wait, and on every exit path.