browserflow

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 13 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 browserflow runs a browser-driven authorization flow over a local HTTP listener.

Index

Constants

View Source
const DefaultCallbackPath = "/callback"

DefaultCallbackPath is the conventional path for the OAuth-style callback handler.

View Source
const DefaultTimeout = 5 * time.Minute

DefaultTimeout is the wall-clock limit on a flow.

Variables

This section is empty.

Functions

func FindAvailableListener

func FindAvailableListener() (net.Listener, error)

FindAvailableListener binds to a free port on 127.0.0.1 only.

func GenerateState

func GenerateState() (string, error)

GenerateState returns a 16-byte random URL-safe string suitable for OAuth state / CSRF protection.

Types

type Logger

type Logger interface {
	Info(format string, args ...any)
	Warn(format string, args ...any)
}

Logger is a small interface for status updates during a flow; *output.Printer satisfies it.

type Options

type Options struct {
	Listener     net.Listener       // ownership transfers to Run; closed on return
	State        string             // expected state value; required
	OpenURL      string             // URL the browser is sent to; required
	Open         func(string) error // optional; replaces the default browser opener once the listener is serving
	StartHandler http.Handler       // optional; mounted at /start so OpenURL can be the local listener
	CallbackPath string             // path that captures code+state; defaults to DefaultCallbackPath
	Timeout      time.Duration      // 0 → DefaultTimeout
	Logger       Logger             // optional
	SuccessTitle string             // shown on the callback page; defaults to "Authentication successful"
	SuccessBody  string             // shown on the callback page; defaults to a generic close-tab message
	ErrorTitle   string             // shown on the callback page when GitHub/upstream returns an error
}

Options configure a single browser-driven flow run.

type Result

type Result struct {
	Code string
}

Result holds the validated callback code; state is checked in the callback handler and not exposed.

func Run

func Run(ctx context.Context, opts Options) (*Result, error)

Run hosts opts.Listener, opens opts.OpenURL, waits for opts.CallbackPath, validates state in constant time, and closes the listener on return.

Jump to

Keyboard shortcuts

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