browserflow

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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
	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 inside Run 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