pub struct PasswordAuth<'a, R: RepositoryProvider> { /* private fields */ }Expand description
Namespaced authentication providers for clean API organization
These structs provide focused interfaces for specific authentication methods while maintaining access to the underlying Torii functionality. Password-based authentication provider
Provides methods for password registration, login, password changes, and password resets.
Implementations§
Source§impl<R: RepositoryProvider> PasswordAuth<'_, R>
Implementation of password-based authentication methods
impl<R: RepositoryProvider> PasswordAuth<'_, R>
Implementation of password-based authentication methods
Sourcepub async fn register_with_name(
&self,
email: &str,
password: &str,
name: Option<&str>,
) -> Result<User, ToriiError>
pub async fn register_with_name( &self, email: &str, password: &str, name: Option<&str>, ) -> Result<User, ToriiError>
Sourcepub async fn authenticate(
&self,
email: &str,
password: &str,
user_agent: Option<String>,
ip_address: Option<String>,
) -> Result<(User, Session), ToriiError>
pub async fn authenticate( &self, email: &str, password: &str, user_agent: Option<String>, ip_address: Option<String>, ) -> Result<(User, Session), ToriiError>
Authenticate a user with email and password
§Arguments
email: The email of the user to authenticatepassword: The password of the user to authenticateuser_agent: Optional user agent to associate with the sessionip_address: Optional IP address to associate with the session
§Returns
Returns the user and session if authentication is successful
Sourcepub async fn change_password(
&self,
user_id: &UserId,
old_password: &str,
new_password: &str,
) -> Result<(), ToriiError>
pub async fn change_password( &self, user_id: &UserId, old_password: &str, new_password: &str, ) -> Result<(), ToriiError>
Change a user’s password and invalidate all existing sessions
This method changes the user’s password after verifying the old password is correct. For security reasons, it also invalidates all existing sessions for the user, requiring them to log in again with the new password.
§Arguments
user_id: The ID of the user to change the password forold_password: The current password for verificationnew_password: The new password to set for the user
Sourcepub async fn reset_password_initiate(
&self,
email: &str,
reset_url_base: &str,
) -> Result<(), ToriiError>
pub async fn reset_password_initiate( &self, email: &str, reset_url_base: &str, ) -> Result<(), ToriiError>
Request a password reset for the given email address
This will generate a secure reset token and send a password reset email if mailer is configured. For security reasons, this method doesn’t reveal whether the email exists or not.
§Arguments
email: The email address to send the password reset toreset_url_base: The base URL for the password reset form (e.g., “https://yourapp.com/reset”)
§Returns
Always returns Ok() to prevent email enumeration attacks
Sourcepub async fn reset_password_initiate_with_expiration(
&self,
email: &str,
reset_url_base: &str,
expires_in: Duration,
) -> Result<(), ToriiError>
pub async fn reset_password_initiate_with_expiration( &self, email: &str, reset_url_base: &str, expires_in: Duration, ) -> Result<(), ToriiError>
Request a password reset with custom expiration time
§Arguments
email: The email address to send the password reset toreset_url_base: The base URL for the password reset formexpires_in: How long the reset token should be valid
Sourcepub async fn reset_password_verify_token(
&self,
token: &str,
) -> Result<bool, ToriiError>
pub async fn reset_password_verify_token( &self, token: &str, ) -> Result<bool, ToriiError>
Sourcepub async fn reset_password_complete(
&self,
token: &str,
new_password: &str,
) -> Result<User, ToriiError>
pub async fn reset_password_complete( &self, token: &str, new_password: &str, ) -> Result<User, ToriiError>
Complete the password reset process and invalidate all user sessions
This will:
- Verify and consume the reset token
- Update the user’s password
- Invalidate all existing sessions for security
- Send a password changed notification email if mailer is configured
§Arguments
token: The reset token received via emailnew_password: The new password to set
§Returns
Returns the user whose password was reset
Auto Trait Implementations§
impl<'a, R> Freeze for PasswordAuth<'a, R>
impl<'a, R> !RefUnwindSafe for PasswordAuth<'a, R>
impl<'a, R> Send for PasswordAuth<'a, R>
impl<'a, R> Sync for PasswordAuth<'a, R>
impl<'a, R> Unpin for PasswordAuth<'a, R>
impl<'a, R> !UnwindSafe for PasswordAuth<'a, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more