Expand description
Authentication primitives: extractors, middleware, password hashing, token generation, and session helpers.
Structs§
- Current
User - Information about the currently authenticated user, attached to handlers
that opt in to the
CurrentUserextractor. - LslBearer
- Bearer-token guard for the LSL-facing registration endpoint. Constant- time-compares against the configured shared secret.
Functions§
- create_
session - Insert a fresh session for the given user and produce the signed cookie to set on the response.
- delete_
session - Delete a session row by the raw 32-byte id from the cookie. Used on logout. Hashes internally so callers continue to pass cookie bytes.
- generate_
session_ id - Generate a fresh 32-byte session id. The id is what goes into the cookie
(base64-encoded, then signed) and what we look up in the
sessionstable. - generate_
token - Generate a fresh 32-byte random token and return both the raw bytes (to be base64-encoded into the link) and the SHA-256 hash (to be stored in the DB).
- hash_
password - Hash a password using Argon2id with default parameters and a fresh random salt.
- hash_
token - Hash an incoming token string (the one carried in the URL) so it can be
looked up in the
set_password_tokenstable. - lookup_
user_ by_ identifier - Look up a user row by identifier. Tries (in order): UUID parse,
firstname.lastnameusername, “Firstname Lastname” legacy name. Used by both the login flow and the invitation creation flow, which is why it lives here inauth.rsrather than in a route module. - removal_
cookie - Build a removal cookie that clears the session on the client.
- require_
session - Middleware that enforces a valid session on the wrapped routes.
- run_
cleanup - Background task that prunes expired sessions and set-password tokens.
Spawned alongside the existing job evictor in
bin/sl_map_web.rs. - session_
id_ from_ jar - Look up the raw session id from the cookie jar of the current request.
Returns
Noneif there is no cookie or the cookie does not decode. - uuid_
from_ bytes - Convert a 16-byte SQLite BLOB back into a
Uuid. ReturnsNoneif the blob is the wrong length. - verify_
password - Verify a password against a PHC-encoded Argon2 hash. Returns
Ok(false)on mismatch andOk(true)on match.
Type Aliases§
- Session
Row (user_id_bytes, legacy_name, username, sessions.expires_at)— the columns selected in theCurrentUserextractor’s session/user join.- SetPassword
Token Row (user_id_bytes, expires_at, used_at)— columns selected when looking up a set-password token.- UserRow
(user_id_bytes, legacy_name, username, password_hash)— the four columns returned by every users lookup variant.