Skip to main content

Module auth

Module auth 

Source
Expand description

Local accounts (ADR-0021 § 2): the sessions login opens and the password hashes it checks. Their tables are crate::MIGRACION_USUARIOS and crate::MIGRACION_AUTH, which puerto new --auth local writes into the project.

A session is an opaque token — 32 random bytes, base64url — and its row keeps only the token’s SHA-256. Revoking is a DELETE; there is no signing key to keep or rotate, and a lookup per request is the cost.

Structs§

CredencialesPostgres
credenciales: one password hash per user.
SesionesPostgres
sesiones: an AlmacenSesiones for login and logout, and the Autenticador of a local project — the presented token’s hash, joined with its user. The roles are the usuarios.roles column (make auth/conceder).

Constants§

TTL_SESION_POR_DEFECTO
How long a session lasts when AUTH_SESSION_TTL is not set.

Functions§

generar_token
A new session token: 256 random bits, base64url without padding (43 characters).
hash_token
What a session row keeps of its token.
parsear_ttl
<n>d, <n>h or <n>m, n > 0.
ttl_sesion_from_env
AUTH_SESSION_TTL — 30d, 12h, 90m — or TTL_SESION_POR_DEFECTO when it is not set. A set but invalid value is an error: a startup error, not a silent default.