authflow

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package authflow drives the device login: it asks the server for a request, tells the person where to approve it, and polls until the server has an answer.

Index

Constants

This section is empty.

Variables

View Source
var ErrDenied = errors.New("the device login was denied")

ErrDenied is a request the user refused.

View Source
var ErrExpired = errors.New("the device login expired")

ErrExpired is a request that ran out of time before it was approved.

View Source
var ErrSessionGone = errors.New("the device login is no longer available")

ErrSessionGone is a request the server no longer has: it was consumed by an earlier exchange, evicted, or lost with the process that held it. The only recovery is a new login, which is what the caller reports it as.

Functions

This section is empty.

Types

type DeviceLoginClient

DeviceLoginClient is the part of the auth client the flow needs. Narrowing it here is what lets the flow be tested against a fake.

type Options

type Options struct {
	// ClientName and ClientVersion are shown on the confirmation page. They are
	// display only and the server never trusts them.
	ClientName    string
	ClientVersion string
	// Timeout bounds the whole flow, waiting for the person included.
	Timeout time.Duration
	// BareURL prints the page address without the code, so it has to be typed
	// there. The default carries the code: the terminal that starts the request
	// is the one that prints the link, so retyping the code it just showed only
	// adds a way to mistype it. The page still shows the code next to the client
	// name, version, source address and time, and still asks for an explicit
	// decision, which is what lets a person notice a request they did not start.
	BareURL bool
	// NoBrowser skips the attempt to open a browser.
	NoBrowser bool
	// ServerURL is the address the client is talking to. It is the fallback
	// confirmation address when the workspace has no external URL configured,
	// which is the normal state of a fresh or local deployment: the server
	// cannot name a page it does not know about, but the client at least knows
	// where it is sending requests.
	ServerURL string
	// OpenBrowser opens a URL. It is injected so tests do not launch anything.
	OpenBrowser func(url string) error
	// Sleep waits between polls. It is injected so tests do not wait.
	Sleep func(time.Duration)
	// Now reports the current time.
	Now func() time.Time
}

Options are the flow's knobs.

type Progress

type Progress func(format string, args ...any)

Progress receives the lines meant for a person. They never go to stdout.

type Result

type Result struct {
	Token     string
	ExpiresIn int64
	User      *v1pb.User
}

Result is a completed login.

func Run

func Run(ctx context.Context, api DeviceLoginClient, progress Progress, opts Options) (*Result, error)

Run performs the whole flow and returns once the server has answered.

Jump to

Keyboard shortcuts

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