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
- Variables
- type Session
- type Sessions
- func (s *Sessions) Current(ctx context.Context, r *http.Request) (Session, bool)
- func (s *Sessions) End(ctx context.Context, w http.ResponseWriter, r *http.Request) error
- func (s *Sessions) Start(ctx context.Context, w http.ResponseWriter, r *http.Request, slug, by string) (Session, error)
- func (s *Sessions) Sweep(ctx context.Context) (int64, error)
Constants ¶
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.
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 ¶
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 Sessions ¶
type Sessions struct {
// contains filtered or unexported fields
}
Sessions mints and reads driver sessions.
func (*Sessions) Current ¶
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.