pub trait Authenticator:
Send
+ Sync
+ 'static {
type User: PanelUser;
// Required methods
fn verify(
&self,
cx: &Cx,
login: &str,
password: &str,
) -> impl Future<Output = Result<Option<Self::User>>> + Send;
fn find_by_id(
&self,
cx: &Cx,
id: &str,
) -> impl Future<Output = Result<Option<Self::User>>> + Send;
// Provided methods
fn confirm_password(
&self,
cx: &Cx,
user: &Self::User,
password: &str,
) -> impl Future<Output = Result<bool>> + Send { ... }
fn store_locale(
&self,
cx: &Cx,
user: &Self::User,
locale: &Locale,
) -> impl Future<Output = Result<()>> + Send { ... }
fn changed_credentials(
&self,
before: &dyn Any,
after: &dyn Any,
) -> Option<String> { ... }
}Expand description
How a panel loads its users (ADR-0013).
PasswordAuth implements it over a
PasswordAccount: the shipped AdminUser by
default, or the app’s own model. An app whose users sign in some other way implements it and
passes the value to Panel::auth via
Auth::custom. Sessions are the framework’s, so an implementation only
maps credentials to a user and a stored id back to one. An app that signs its users in itself
implements ExternalAuth instead.
Every credential failure must return Ok(None), never a distinguishable
error: the login response is one generic message for all of them. An
infrastructure failure is not a credential verdict, so an implementation
that cannot reach its store returns the driver’s error instead — the login
handler maps it to the opaque outage page, which keeps a database outage
from rendering as a rejected password. An implementation’s own error keeps
its own mapping.
Required Associated Types§
Required Methods§
Sourcefn verify(
&self,
cx: &Cx,
login: &str,
password: &str,
) -> impl Future<Output = Result<Option<Self::User>>> + Send
fn verify( &self, cx: &Cx, login: &str, password: &str, ) -> impl Future<Output = Result<Option<Self::User>>> + Send
Verify login/password, returning the user on success.
Implementations must run comparable work for unknown accounts so
timing does not leak account existence; verify_password does,
given None for an unknown account.
Sourcefn find_by_id(
&self,
cx: &Cx,
id: &str,
) -> impl Future<Output = Result<Option<Self::User>>> + Send
fn find_by_id( &self, cx: &Cx, id: &str, ) -> impl Future<Output = Result<Option<Self::User>>> + Send
Load the session’s user by PanelUser::user_id, with everything the request
reads from it — its tenants included.
It runs on every request, which is what makes deactivation, revocation
and a removed membership take effect immediately; return None when
the user no longer authenticates.
Provided Methods§
Sourcefn confirm_password(
&self,
cx: &Cx,
user: &Self::User,
password: &str,
) -> impl Future<Output = Result<bool>> + Send
fn confirm_password( &self, cx: &Cx, user: &Self::User, password: &str, ) -> impl Future<Output = Result<bool>> + Send
Whether password is user’s current password: what a page asks before a change a stolen
session must not make, such as turning two-factor sign-in on.
It defaults to verify with the user’s email as the
login, and answers false for a user without one: override it when users sign in with
something else.
Sourcefn store_locale(
&self,
cx: &Cx,
user: &Self::User,
locale: &Locale,
) -> impl Future<Output = Result<()>> + Send
fn store_locale( &self, cx: &Cx, user: &Self::User, locale: &Locale, ) -> impl Future<Output = Result<()>> + Send
Stores locale as user’s after they pick it from the shell’s language menu, so their
locale reads it on the next request, in another browser, and in the
mail a job sends them. It runs only when the pick differs from that locale, and never
while someone impersonates the user.
It defaults to storing nothing: the pick then lives in the browser’s cookie alone. A failure is logged, and the page still switches to the locale picked.
Sourcefn changed_credentials(
&self,
before: &dyn Any,
after: &dyn Any,
) -> Option<String>
fn changed_credentials( &self, before: &dyn Any, after: &dyn Any, ) -> Option<String>
The user_id of the user whose sign-in details a panel’s edit form
changed from before to after, two records of the resource’s model, or None when the
model is not this authenticator’s or the edit left the details alone.
The panel then ends that user’s sessions, pending sign-ins, reset links and pending email
change in the edit’s transaction, on every panel whose authenticator loads its type.
PasswordAuth answers for its account’s email and password hash; it
defaults to None.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".