pub struct Internal<'a, D, A> { /* private fields */ }Implementations§
Source§impl<'a, D: Adapter, A> Internal<'a, D, A>
impl<'a, D: Adapter, A> Internal<'a, D, A>
pub async fn find_user_by_email( &self, email: &str, ) -> Result<Option<UserView>, AuthError>
pub async fn find_user_by_id( &self, id: &Id, ) -> Result<Option<UserView>, AuthError>
Sourcepub async fn create_user(
&self,
user: NewUser,
account: Option<NewAccount>,
) -> Result<UserView, AuthError>
pub async fn create_user( &self, user: NewUser, account: Option<NewAccount>, ) -> Result<UserView, AuthError>
Creates a user (and optionally its first account) in one transaction.
Answers USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL (422) when the email is taken.
pub async fn link_account( &self, user_id: &Id, account: NewAccount, ) -> Result<Account, AuthError>
pub async fn find_account( &self, provider_id: &str, account_id: &str, ) -> Result<Option<Account>, AuthError>
pub async fn credential_account( &self, user_id: &Id, ) -> Result<Option<Account>, AuthError>
Sourcepub fn validate_new_password(&self, password: &str) -> Result<(), AuthError>
pub fn validate_new_password(&self, password: &str) -> Result<(), AuthError>
Checks a new password against the configured length limits and policy.
Sourcepub async fn set_password(
&self,
user_id: &Id,
password: &str,
) -> Result<(), AuthError>
pub async fn set_password( &self, user_id: &Id, password: &str, ) -> Result<(), AuthError>
Validates, hashes and stores a password, creating the credential account if needed.
Sourcepub async fn create_session(
&self,
user_id: &Id,
remember_me: bool,
) -> Result<SessionView, AuthError>
pub async fn create_session( &self, user_id: &Id, remember_me: bool, ) -> Result<SessionView, AuthError>
Creates a session and sets its cookies, running no sign-in gate at all. This is the
low-level primitive: sign a user in with sign_in, and finish a
challenged sign-in with complete_sign_in. Finishing one
with this would skip every other plugin’s gates, so a banned user would get a session.
Sourcepub async fn find_session_by_token(
&self,
token: &str,
) -> Result<Option<SessionView>, AuthError>
pub async fn find_session_by_token( &self, token: &str, ) -> Result<Option<SessionView>, AuthError>
The unexpired session token belongs to, with its user, without refreshing it.
For plugins that hold session tokens of their own, such as one per signed-in account.
Sourcepub async fn ephemeral_session(
&self,
user_id: &Id,
) -> Result<Option<SessionView>, AuthError>
pub async fn ephemeral_session( &self, user_id: &Id, ) -> Result<Option<SessionView>, AuthError>
The request-only session a resolver’s Resolved::User
gets for this user, after the session gates. None when the user doesn’t exist; the
gate’s error when one refuses the user (a banned user, with the admin plugin). For
plugins that act for a user without a session, such as an API key’s owner.
Makes token the request’s session: sets the session cookie (for the configured
lifetime, or for the browser session when remember_me is false) and drops the
cookie cache, which belonged to the previous session.
Sourcepub async fn sign_in(
&self,
user: UserView,
method: impl Into<Cow<'static, str>>,
remember_me: bool,
) -> Result<SignInResult, AuthError>
pub async fn sign_in( &self, user: UserView, method: impl Into<Cow<'static, str>>, remember_me: bool, ) -> Result<SignInResult, AuthError>
Runs every sign-in gate in registration order, then creates the session. The first gate that denies or challenges ends the sign-in without a session.
Sourcepub async fn complete_sign_in(
&self,
challenger: &str,
user: UserView,
method: impl Into<Cow<'static, str>>,
remember_me: bool,
) -> Result<SignInResult, AuthError>
pub async fn complete_sign_in( &self, challenger: &str, user: UserView, method: impl Into<Cow<'static, str>>, remember_me: bool, ) -> Result<SignInResult, AuthError>
Finishes a sign-in that a gate of plugin challenger answered with
Gate::Challenge, once the user has met the challenge (e.g. a correct TOTP code).
Pass the plugin’s own id (TwoFactor::ID, or "app" for a gate the app registered)
and the method the sign-in started with.
Runs every gate except challenger’s, in registration order, whether they come before
or after it, then creates the session. A remaining gate can still deny, which returns
its error with no session. It can also challenge, which returns
SignInResult::Challenge with no session; answer with its body. That gate’s plugin
finishes the sign-in with its own complete_sign_in, which runs challenger’s gates
again, so two gates that both challenge the same user keep challenging each other.
A 500 when no gate belongs to challenger: a wrong id would run the challenger’s
own gate again and challenge forever.
Sourcepub async fn claim_unverified_user(
&self,
user: UserView,
) -> Result<UserView, AuthError>
pub async fn claim_unverified_user( &self, user: UserView, ) -> Result<UserView, AuthError>
Makes the person who just proved control of an email the only owner of its unverified
user: deletes every account (password and OAuth links) and session the user collected
before the proof, then marks the email verified and emits UserClaimed, on which
plugins drop credentials of their own (passkeys). Email-primary sign-ins (magic links,
email codes) call this when they land on a user whose email isn’t verified, so whoever
registered that address first keeps no access. A verified user comes back unchanged.
pub async fn revoke_session( &self, user_id: &Id, session_id: &Id, ) -> Result<bool, AuthError>
Sourcepub async fn revoke_user_sessions(
&self,
user_id: &Id,
keep: Option<&Id>,
) -> Result<u64, AuthError>
pub async fn revoke_user_sessions( &self, user_id: &Id, keep: Option<&Id>, ) -> Result<u64, AuthError>
Deletes every session of a user, except keep when given.
Sourcepub async fn create_verification(
&self,
identifier: &str,
ttl: Duration,
data: Option<String>,
) -> Result<String, AuthError>
pub async fn create_verification( &self, identifier: &str, ttl: Duration, data: Option<String>, ) -> Result<String, AuthError>
Stores a single-use value and returns it. Only its hash is kept.
Sourcepub async fn store_verification_value(
&self,
identifier: &str,
value: &str,
ttl: Duration,
data: Option<String>,
) -> Result<(), AuthError>
pub async fn store_verification_value( &self, identifier: &str, value: &str, ttl: Duration, data: Option<String>, ) -> Result<(), AuthError>
Stores a caller-chosen value (e.g. a 6-digit OTP) under identifier, replacing older ones.
Sourcepub async fn consume_verification_value(
&self,
identifier: &str,
value: &str,
) -> Result<Option<Verification>, AuthError>
pub async fn consume_verification_value( &self, identifier: &str, value: &str, ) -> Result<Option<Verification>, AuthError>
Consumes a value stored with store_verification_value.
Sourcepub async fn find_verification(
&self,
token: &str,
) -> Result<Option<Verification>, AuthError>
pub async fn find_verification( &self, token: &str, ) -> Result<Option<Verification>, AuthError>
The unexpired verification for token, without consuming it.
Sourcepub async fn consume_verification(
&self,
token: &str,
) -> Result<Option<Verification>, AuthError>
pub async fn consume_verification( &self, token: &str, ) -> Result<Option<Verification>, AuthError>
Finds and deletes the verification for token. None if unknown or expired.
Sourcepub fn can_send_email(&self) -> bool
pub fn can_send_email(&self) -> bool
Whether a mailer is configured, so send_email can succeed.
pub async fn send_email(&self, email: AuthEmail) -> Result<(), AuthError>
Sourcepub async fn send_email_in_background(
&self,
email: AuthEmail,
) -> Result<(), AuthError>
pub async fn send_email_in_background( &self, email: AuthEmail, ) -> Result<(), AuthError>
Sends email without waiting for the mailer, so the route answers in the same time
whether or not it sent anything. Use it where sending depends on whether an account
exists. A failed send is logged (tracing::error!), not returned.
Sourcepub async fn simulate_verification(&self) -> Result<(), AuthError>
pub async fn simulate_verification(&self) -> Result<(), AuthError>
The database work of creating and looking up a verification token, for the branch of a route that sends nothing, so both branches take about as long.