Expand description
Authenticates panel users and gates panel routes.
Gates panels by default with PasswordAuth or a custom
Authenticator, reads the signed-in
user through user and require_user, and keeps each panel’s AuthSessions.
Structs§
- Admin
User - Shipped credential model with unique email, Argon2id PHC hash, display name,
and active flag; belongs to no tenant.
PasswordAuthstores the email, and looks it up, trimmed and lowercased, so one address holds one account whatever case it is typed in; a resource that edits the email must store it the same way. ItsPanelModelleave out the hash, so a resource over the panel’s admins lists them. A resource’s edit form that changes an admin’s email or password hash ends that admin’s sessions, pending sign-ins, reset links and pending email change in the same transaction; a custom action that changes them does not, and callsrevoke_sessions_for_useritself; one that changesactivetofalseends them at the admin’s next request. - Auth
Factor - Shipped second-factor record: an account’s authenticator secret, sealed, or the hash of one of its recovery codes. It signs in to the panel that enrolled it and to every panel whose authenticator loads the same user type.
- Auth
Session - Shipped server-side session record: the SHA-256 hash of the client token, the user it authenticates, the panel that signed the user in, and its expiry. The raw token is never stored.
- Auth
Throttle - Shipped sign-in throttle record: how many attempts one login made from one address since the
window began, for a
LoginThrottlethat counts in the database. - Auth
Token - Shipped single-use secret record: the SHA-256 hash of the token a mailed link or a pending sign-in carries, what it is for, the account and the panel it acts on, and its expiry. The raw token is never stored.
- Column
Preference - Shipped record of the toggleable columns one user shows or hides in one resource’s list, on one panel.
Enums§
- Email
Change - What
request_email_changedid with a new address. - Factor
Kind - What an
AuthFactoris. Stored as itssnake_casename in a text column, so a kind a later release adds needs no migration. - Token
Purpose - What an
AuthTokendoes when used. Stored as itssnake_casename in a text column, so a purpose a later release adds needs no migration.
Constants§
- IMPERSONATE_
FIELD - The field of a
POST {prefix}/impersonateform naming the user to act as: theirPanelUser::user_id. - LOGIN_
FIELD - Form field carrying the login identifier (the shipped default reads it as an email address).
- MIN_
PASSWORD_ CHARS - The fewest characters a new password holds, as NIST SP 800-63B asks of a password a user chooses.
- NEXT_
FIELD - Hidden form field carrying the validated post-login destination.
- PASSWORD_
FIELD - Form field carrying the password.
- RESET_
LIFETIME - How long a reset link works: one hour, fixed.
- SESSION_
LIFETIME - How long a session stays valid unless
Auth::sessionssays otherwise: seven days. - TENANT_
FIELD - Form field carrying the tenant the tenant switch selects.
- VERIFICATION_
LIFETIME - How long a verification link works: one day, fixed.
Functions§
- actor
- The person behind the request: the user acting as another through
impersonation, else the signed-in user;
Nonewhen nobody is signed in to the request’s panel. - create_
admin - Creates an active
AdminUserthat signs in withemailandpassword, storing only the password’s Argon2id hash: the account a new app seeds to reach its panel. The email is stored trimmed and lowercased, and verified: whoever seeds the account vouches for the address. - enforced
- Whether the request’s panel requires a signed-in user.
- guard
- Require a signed-in user when the request’s panel requires sign-in.
- hash_
password - Hashes a password with Argon2id into a PHC string for storage; never stores
the plaintext. Runs on Tokio’s blocking pool, as
verify_passworddoes, one hash per core at once. - impersonate
- Makes the request’s session act as
targetthroughex, and records it throughextoo, so a transaction commits both or neither; 403 when the signed-in user may not under the panel’sImpersonationrule, or acts as someone already. - impersonate_
button - A button that acts as
target, for a page of the app’s own, such as a staff list over a user type that is no model, where theImpersonateaction cannot go: a form that poststarget’suser_idto{prefix}/impersonatewith the CSRF field. - impersonator
- The user acting as the signed-in user, as
U;Nonewhile the signed-in user acts as themselves, or when the actor is not aU. - membership
- The signed-in user’s membership the request acts under: the tenant the
session selected while it is still one of the user’s
tenants, else the user’sdefault_tenant, else the first.Nonewithout a signed-in user, for a user with no tenant, and when aTenantoverride names a tenant the user is not a member of. - new_
password_ errors - Refuses a new
passwordshorter thanMIN_PASSWORD_CHARSunder thepasswordkey, and aconfirmationthat differs from it underpassword_confirmation: the checks a sign-up form withSignUp’s password keys runs inRegistrar::validate. - normalize_
email emailas aPasswordAccountstores it: trimmed and lowercased.- request_
email_ change - Asks the account
userto confirmemailas its new address before it changes, when the request’s panel installsAuth::email_verification; call it fromProfileEditor::savethrough the save’s transactionex, in place of writing the address. - require_
user - Require the signed-in user, as the app’s own user type.
- revoke_
sessions_ for_ user - Revokes every live session of
user_id, its pending sign-ins, its reset links and its pending email change, on the current panel and on each panel sharing its users, whose authenticator loads the same user type, or on every panel outside any panel; call it whenever a credential changes. A link that proves an address or undoes an email change survives. - safe_
next nextwhen it is a same-origin path, the only post-login destination Tablo follows: an absolute URL, a//hosttarget, a backslash or a control character answersNone. An app that reads anextof its own, as anExternalAuthlogin page does, checks it here before redirecting to it.- session_
cookie - The cookie that carries a session’s token on the panel
Panel::new(panel)mounts;panelis spelled as forPanel::new. Each panel has its own, so a browser stays signed in to several. Tablo keeps them apart from the router’sSessionTokenStore, so a host app’s own Topcoat sessions and a panel’s never replace each other’s token. - signed_
in - Whether a user is signed in to the request’s panel.
- user
- The signed-in user, as the app’s own user type.
- verify_
password - Verifies a password against an Argon2id PHC hash, or
Nonefor an unknown account; unknown accounts verify against a dummy hash so response times do not reveal which accounts exist.