auth

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package auth decides whether the local X session is usable, and runs the interactive login when it is not.

Index

Constants

This section is empty.

Variables

View Source
var ErrLoginRequired = errors.New("no X session; run start_login and sign in")

ErrLoginRequired reports that no usable session exists.

Functions

This section is empty.

Types

type Lease added in v0.0.5

type Lease func(ctx context.Context) (*browser.Session, func(), error)

Lease borrows a browser session and returns a function that hands it back.

type LoginLauncher

type LoginLauncher func() (*exec.Cmd, error)

LoginLauncher opens a visible browser for the user to sign in with. It returns the running process so its exit can be observed.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns the session verdict and the login lifecycle.

Verdicts are cached because every uncached check drives a real browser at X, and checking more often makes losing the session likelier, not less.

func New

func New(opts Options) *Manager

New builds a Manager.

func (*Manager) Invalidate

func (m *Manager) Invalidate()

Invalidate drops any cached verdict, so the next Status re-probes.

func (*Manager) Require

func (m *Manager) Require(ctx context.Context) error

Require returns ErrLoginRequired unless the session is usable.

func (*Manager) StartLogin

func (m *Manager) StartLogin(ctx context.Context) (time.Time, error)

StartLogin opens a visible browser for the user to sign in with.

It returns the deadline by which the login must be completed. If one is already open, its deadline is returned rather than opening a second window onto the same profile.

func (*Manager) Status

func (m *Manager) Status(ctx context.Context) (Status, error)

Status reports whether the session is usable, using the cache when it can.

type Options

type Options struct {
	ProfileDir   string
	StatusTTL    time.Duration
	LoginTimeout time.Duration

	Lease       Lease
	Reserve     Reserver
	LaunchLogin LoginLauncher
}

Options configures a Manager.

type Reserver added in v0.0.5

type Reserver interface {
	Reserve(ctx context.Context) (pool.Reservation, error)
}

Reserver takes exclusive use of the profile.

Only one Chrome may hold a user-data-dir. The login window needs it for as long as the user is signing in, so the reservation is held until that window closes rather than released as soon as it opens.

type State

type State string

State is the coarse session status callers act on.

const (
	StateReady      State = "ready"
	StateRequired   State = "login_required"
	StateInProgress State = "login_in_progress"
)

type Status

type Status struct {
	State      State     `json:"state"`
	LoggedIn   bool      `json:"logged_in"`
	CheckedAt  time.Time `json:"checked_at"`
	ProfileDir string    `json:"profile_dir"`
}

Status is a point-in-time view of the session.

Jump to

Keyboard shortcuts

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