Help us shape the future of Go! Take the 2026 Go Developer Survey

driverauth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package driverauth holds a driver's session.

A driver has never had a way to sign in to this server. Their *machine* holds a token, issued when the operator approved its pairing, and that token is the client's rather than the person's. This is the other thing: the person, in a browser, reading something about themselves.

This server does not authenticate them and has no way to. There is no driver password here, no email flow and no identity provider — a plugin does that, by whatever means the operator chose, and then tells this server who the driver is. This package is the half that is left: minting the session, reading it back, and ending it.

It lives in the core rather than in that plugin because of a rule in pluginweb: a plugin's cookies are namespaced to that plugin, so one plugin cannot read another's. A login plugin holding the session privately would be the only thing that knew who was signed in — not this server, and not the plugin next to it. An identity two things have to agree on has to live where both can see it.

Index

Constants

View Source
const SessionCookie = "pacenote_driver"

SessionCookie carries the driver's session. The value is random and only its SHA-256 reaches the database, so a dump of that table cannot be used to sign in as anybody.

It is named apart from the panel's on purpose: a driver signing in must never touch the operator's session, and two cookies with one name would be one mistake away from doing exactly that.

View Source
const SessionTTL = 30 * 24 * time.Hour

SessionTTL is how long a driver stays signed in without coming back. It is longer than the panel's because the consequences are smaller — a driver's session reads their own laps, where an operator's runs the team — and because a driver who has to sign in every evening will stop bothering.

Variables

View Source
var ErrNoDriver = errors.New("driverauth: no driver of that name is on this server")

ErrNoDriver reports that a plugin named a driver this server does not have. It is the plugin's mistake and it is refused rather than guessed at: creating a driver because somebody signed in would let a login plugin fill the roster.

Functions

This section is empty.

Types

type Session

type Session struct {
	DriverID   int64
	Slug       string
	Name       string
	SignedInBy string
}

Session is a signed-in driver, as a caller reads it.

type Sessions

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

Sessions mints and reads driver sessions.

func New

func New(store *db.Store, now func() time.Time) *Sessions

New builds the session store.

func (*Sessions) Current

func (s *Sessions) Current(ctx context.Context, r *http.Request) (Session, bool)

Current is the driver this request is signed in as, if any. A session that has run out is simply absent: the lookup enforces expiry, so there is no window in which an old cookie works.

func (*Sessions) End

End signs this browser out, in the database as well as in the browser. A cookie cleared and a row left behind would be a session that still works for anybody who kept the value.

func (*Sessions) Start

func (s *Sessions) Start(ctx context.Context, w http.ResponseWriter, r *http.Request,
	slug, by string,
) (Session, error)

Start signs a driver in and sets the cookie.

The slug is the plugin's word for who this is, and it is checked against the roster rather than trusted: a plugin naming a driver who is not here is a plugin that has got it wrong, and the answer is a refusal rather than a new driver nobody added.

func (*Sessions) Sweep

func (s *Sessions) Sweep(ctx context.Context) (int64, error)

Sweep clears out the sessions that have run out. Nothing depends on it: the lookup refuses an expired session either way, so a server whose sweep never runs is correct and merely larger than it needs to be.

Jump to

Keyboard shortcuts

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