Skip to main content

AuthService

Struct AuthService 

Source
pub struct AuthService<U, S, V, A, O, E>{
    pub config: AuthConfig,
    pub users: Arc<U>,
    pub sessions: Arc<S>,
    pub verifications: Arc<V>,
    pub accounts: Arc<A>,
    pub oauth_states: Arc<O>,
    pub email: Arc<E>,
    pub events: Arc<EventEmitter>,
}
Expand description

Core authentication service. Generic over storage backends and email sender.

Fields§

§config: AuthConfig

Authentication configuration.

§users: Arc<U>

User storage backend.

§sessions: Arc<S>

Session storage backend.

§verifications: Arc<V>

Verification token storage backend.

§accounts: Arc<A>

OAuth account storage backend.

§oauth_states: Arc<O>

OAuth state storage backend.

§email: Arc<E>

Email sender implementation.

§events: Arc<EventEmitter>

Event emitter for auth lifecycle hooks.

Implementations§

Source§

impl<U, S, V, A, O, E> AuthService<U, S, V, A, O, E>

Source

pub fn new( config: AuthConfig, users: U, sessions: S, verifications: V, accounts: A, oauth_states: O, email: E, ) -> AuthService<U, S, V, A, O, E>

Create a new authentication service with the given configuration and backends.

Source

pub fn with_events(self, events: EventEmitter) -> AuthService<U, S, V, A, O, E>

Source

pub async fn signup( &self, input: NewUser, ip: Option<String>, user_agent: Option<String>, ) -> Result<SignupResult, AuthError>

Register a new user with email and password.

Source

pub async fn login( &self, email: &str, password: &str, ip: Option<String>, user_agent: Option<String>, ) -> Result<LoginResult, AuthError>

Authenticate a user with email and password.

Source

pub async fn logout(&self, session_id: i64) -> Result<(), AuthError>

Delete a single session by ID.

Source

pub async fn logout_all(&self, user_id: i64) -> Result<(), AuthError>

Delete all sessions for a user.

Source

pub async fn get_session( &self, raw_token: &str, ) -> Result<SessionResult, AuthError>

Retrieve a session and its associated user by raw token.

Source

pub async fn list_sessions( &self, user_id: i64, ) -> Result<Vec<Session>, AuthError>

List all active sessions for a user.

Source

pub async fn verify_email( &self, raw_token: &str, ip: Option<String>, user_agent: Option<String>, ) -> Result<VerifyEmailResult, AuthError>

Verify a user’s email address using a verification token.

Source

pub async fn request_password_reset( &self, email: &str, ) -> Result<RequestResetResult, AuthError>

Request a password reset token for a user by email.

Source

pub async fn reset_password( &self, raw_token: &str, new_password: &str, ) -> Result<ResetPasswordResult, AuthError>

Reset a user’s password using a reset token.

Source

pub async fn cleanup_expired(&self) -> Result<(u64, u64, u64), AuthError>

Delete expired sessions, verification tokens, and OAuth states. Returns (sessions_deleted, verifications_deleted, oauth_states_deleted).

Source

pub async fn oauth_callback( &self, info: OAuthUserInfo, tokens: OAuthTokens, ip: Option<String>, user_agent: Option<String>, ) -> Result<LoginResult, AuthError>

Handle OAuth callback - find or create user from OAuth info.

NOTE: OAuth state verification happens in the handler layer before calling this method. CSRF state and PKCE verifier are stored in the dedicated oauth_states table.

Source

pub async fn list_accounts( &self, user_id: i64, ) -> Result<Vec<PublicAccount>, AuthError>

List all OAuth accounts for a user, with sensitive fields removed.

Link an OAuth provider account to an existing authenticated user.

Unlink an OAuth provider account from a user.

Source

pub async fn refresh_oauth_token( &self, user_id: i64, account_id: i64, provider_config: &OAuthProviderConfig, ) -> Result<RefreshTokenResult, AuthError>

Refresh an OAuth access token for a specific account.

Auto Trait Implementations§

§

impl<U, S, V, A, O, E> Freeze for AuthService<U, S, V, A, O, E>

§

impl<U, S, V, A, O, E> !RefUnwindSafe for AuthService<U, S, V, A, O, E>

§

impl<U, S, V, A, O, E> Send for AuthService<U, S, V, A, O, E>

§

impl<U, S, V, A, O, E> Sync for AuthService<U, S, V, A, O, E>

§

impl<U, S, V, A, O, E> Unpin for AuthService<U, S, V, A, O, E>

§

impl<U, S, V, A, O, E> UnsafeUnpin for AuthService<U, S, V, A, O, E>

§

impl<U, S, V, A, O, E> !UnwindSafe for AuthService<U, S, V, A, O, E>

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,