pairing

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package pairing implements device-code secrets and transitions independently of HTTP, storage, and credential issuance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Secret

func Secret() string

Secret generates an independent 256-bit bearer secret.

func UserCode

func UserCode(alphabet string, symbols int) string

UserCode samples symbols uniformly from the adapter's fixed ASCII alphabet. Adapters choose their existing display length and formatting, independently of the private device secret. The alphabet must contain 2–256 unique bytes.

Types

type Flow

type Flow struct {
	State     State
	Subject   string
	CreatedAt time.Time
	ExpiresAt time.Time
	NextPoll  time.Time
	Interval  time.Duration
}

Flow owns the decision and polling state for one request. Callers synchronize access and atomically persist or consume it together with their own records. No callbacks run here. Browser login reserves a decision across its audit; OAuth reserves and finishes within its durable transaction.

func New

func New(now time.Time, interval time.Duration) Flow

New creates a ten-minute pending request. A positive interval enforces polling cadence and cumulative five-second slow_down. Zero leaves cadence enforcement to the adapter's existing rate limiter.

func (*Flow) Expired

func (f *Flow) Expired(now time.Time) bool

Expired reports whether the request has reached its deadline.

func (*Flow) Finish

func (f *Flow) Finish(now time.Time, subject string, approved, commit bool) bool

Finish commits a reserved decision, or restores pending when its audit failed. Expiry prevents a blocked audit from resurrecting a request. The caller also checks that its reservation still belongs to the stored request.

func (*Flow) Poll

func (f *Flow) Poll(now time.Time) State

Poll checks expiry and cadence before exposing a decision. A decision awaiting audit remains pending. This does not consume approval: the adapter must couple consumption to its own session or OAuth grant lifecycle.

func (*Flow) Reserve

func (f *Flow) Reserve(now time.Time) bool

Reserve exclusively claims a live pending decision. The caller must verify approver identity and any CSRF proof before reserving it.

type State

type State string

State identifies a stored decision or a polling outcome. Expired and SlowDown are outcomes only; adapters consume terminal requests in their own store.

const (
	Approved State = "approved"
	Deciding State = "deciding"
	Denied   State = "denied"
	Expired  State = "expired"
	Pending  State = "pending"
	SlowDown State = "slow_down"
)

Pairing states and polling outcomes.

Jump to

Keyboard shortcuts

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