Skip to main content

Module auth

Module auth 

Source
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.

Re-exports§

pub use self::account::normalize_email;
pub use self::columns::ColumnPreference;
pub use self::email_change::EmailChange;
pub use self::email_change::request_email_change;
pub use self::impersonation::IMPERSONATE_FIELD;
pub use self::impersonation::impersonate;
pub use self::impersonation::impersonate_button;
pub use self::impersonation::impersonator;
pub use self::login::LOGIN_FIELD;
pub use self::login::NEXT_FIELD;
pub use self::login::PASSWORD_FIELD;
pub use self::login::TENANT_FIELD;
pub use self::login::safe_next;
pub use self::password::AdminUser;
pub use self::password::create_admin;
pub use self::password::hash_password;
pub use self::password::verify_password;
pub use self::password_reset::RESET_LIFETIME;
pub use self::registration::MIN_PASSWORD_CHARS;
pub use self::registration::new_password_errors;
pub use self::session::AuthSession;
pub use self::session::SESSION_LIFETIME;
pub use self::session::revoke_sessions_for_user;
pub use self::throttle::AuthThrottle;
pub use self::token::AuthToken;
pub use self::token::TokenPurpose;
pub use self::verification::VERIFICATION_LIFETIME;

Structs§

AdminUser
Shipped credential model with unique email, Argon2id PHC hash, display name, and active flag; belongs to no tenant. PasswordAuth stores 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. Its PanelModel leave 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 calls revoke_sessions_for_user itself; one that changes active to false ends them at the admin’s next request.
AuthFactor
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.
AuthSession
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.
AuthThrottle
Shipped sign-in throttle record: how many attempts one login made from one address since the window began, for a LoginThrottle that counts in the database.
AuthToken
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.
ColumnPreference
Shipped record of the toggleable columns one user shows or hides in one resource’s list, on one panel.

Enums§

EmailChange
What request_email_change did with a new address.
FactorKind
What an AuthFactor is. Stored as its snake_case name in a text column, so a kind a later release adds needs no migration.
TokenPurpose
What an AuthToken does when used. Stored as its snake_case name in a text column, so a purpose a later release adds needs no migration.

Constants§

IMPERSONATE_FIELD
The field of a POST {prefix}/impersonate form naming the user to act as: their PanelUser::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::sessions says 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; None when nobody is signed in to the request’s panel.
create_admin
Creates an active AdminUser that signs in with email and password, 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_password does, one hash per core at once.
impersonate
Makes the request’s session act as target through ex, and records it through ex too, so a transaction commits both or neither; 403 when the signed-in user may not under the panel’s Impersonation rule, 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 the Impersonate action cannot go: a form that posts target’s user_id to {prefix}/impersonate with the CSRF field.
impersonator
The user acting as the signed-in user, as U; None while the signed-in user acts as themselves, or when the actor is not a U.
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’s default_tenant, else the first. None without a signed-in user, for a user with no tenant, and when a Tenant override names a tenant the user is not a member of.
new_password_errors
Refuses a new password shorter than MIN_PASSWORD_CHARS under the password key, and a confirmation that differs from it under password_confirmation: the checks a sign-up form with SignUp’s password keys runs in Registrar::validate.
normalize_email
email as a PasswordAccount stores it: trimmed and lowercased.
request_email_change
Asks the account user to confirm email as its new address before it changes, when the request’s panel installs Auth::email_verification; call it from ProfileEditor::save through the save’s transaction ex, 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
next when it is a same-origin path, the only post-login destination Tablo follows: an absolute URL, a //host target, a backslash or a control character answers None. An app that reads a next of its own, as an ExternalAuth login 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; panel is spelled as for Panel::new. Each panel has its own, so a browser stays signed in to several. Tablo keeps them apart from the router’s SessionTokenStore, 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 None for an unknown account; unknown accounts verify against a dummy hash so response times do not reveal which accounts exist.