authflow

package
v0.7.46 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
const Timeout = 5 * time.Minute

Timeout bounds how long a sign-in may sit waiting on the browser.

Variables

View Source
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 Start

func Start() (*Flow, error)

Start binds 127.0.0.1:0 and begins serving the one-shot callback.

func (*Flow) AuthorizeRunhostURL added in v0.7.3

func (f *Flow) AuthorizeRunhostURL(registry, runhost string) string

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

func (f *Flow) AuthorizeURL(registry string) string

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.

func (*Flow) Wait

func (f *Flow) Wait(ctx context.Context) (string, error)

Wait blocks until the callback arrives, the context ends, or Timeout.

func (*Flow) WaitPAT added in v0.7.3

func (f *Flow) WaitPAT(ctx context.Context) (PAT, error)

WaitPAT is Wait with the token as the registry described it: its id, name and scopes, which a token handed over as ?token= by an older registry lacks.

type PAT added in v0.7.3

type PAT struct {
	ID     string
	Name   string
	Token  string
	Scopes []string
}

PAT is the token an exchange minted, as the registry describes it.

Jump to

Keyboard shortcuts

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