PasswordAuth

Struct PasswordAuth 

Source
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

Source

pub async fn register( &self, email: &str, password: &str, ) -> Result<User, ToriiError>

Register a user with a password

§Arguments
  • email: The email of the user to register
  • password: The password of the user to register
§Returns

Returns the registered user

Source

pub async fn register_with_name( &self, email: &str, password: &str, name: Option<&str>, ) -> Result<User, ToriiError>

Register a user with a password and optional name

§Arguments
  • email: The email of the user to register
  • password: The password of the user to register
  • name: Optional name for the user
§Returns

Returns the registered user

Source

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 authenticate
  • password: The password of the user to authenticate
  • user_agent: Optional user agent to associate with the session
  • ip_address: Optional IP address to associate with the session
§Returns

Returns the user and session if authentication is successful

Source

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 for
  • old_password: The current password for verification
  • new_password: The new password to set for the user
Source

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 to
  • reset_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

Source

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 to
  • reset_url_base: The base URL for the password reset form
  • expires_in: How long the reset token should be valid
Source

pub async fn reset_password_verify_token( &self, token: &str, ) -> Result<bool, ToriiError>

Verify a password reset token without consuming it

This is useful for frontend validation before showing the password reset form.

§Arguments
  • token: The reset token to verify
§Returns

Returns true if the token is valid and not expired

Source

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:

  1. Verify and consume the reset token
  2. Update the user’s password
  3. Invalidate all existing sessions for security
  4. Send a password changed notification email if mailer is configured
§Arguments
  • token: The reset token received via email
  • new_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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,