pub struct AuthService<U, S, V, A, O, E>where
U: UserStore,
S: SessionStore,
V: VerificationStore,
A: AccountStore,
O: OAuthStateStore,
E: EmailSender,{
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: AuthConfigAuthentication 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>where
U: UserStore,
S: SessionStore,
V: VerificationStore,
A: AccountStore,
O: OAuthStateStore,
E: EmailSender,
impl<U, S, V, A, O, E> AuthService<U, S, V, A, O, E>where
U: UserStore,
S: SessionStore,
V: VerificationStore,
A: AccountStore,
O: OAuthStateStore,
E: EmailSender,
Sourcepub fn new(
config: AuthConfig,
users: U,
sessions: S,
verifications: V,
accounts: A,
oauth_states: O,
email: E,
) -> AuthService<U, S, V, A, O, E>
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.
pub fn with_events(self, events: EventEmitter) -> AuthService<U, S, V, A, O, E>
Sourcepub async fn signup(
&self,
input: NewUser,
ip: Option<String>,
user_agent: Option<String>,
) -> Result<SignupResult, AuthError>
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.
Sourcepub async fn login(
&self,
email: &str,
password: &str,
ip: Option<String>,
user_agent: Option<String>,
) -> Result<LoginResult, AuthError>
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.
Sourcepub async fn logout(&self, session_id: i64) -> Result<(), AuthError>
pub async fn logout(&self, session_id: i64) -> Result<(), AuthError>
Delete a single session by ID.
Sourcepub async fn logout_all(&self, user_id: i64) -> Result<(), AuthError>
pub async fn logout_all(&self, user_id: i64) -> Result<(), AuthError>
Delete all sessions for a user.
Sourcepub async fn get_session(
&self,
raw_token: &str,
) -> Result<SessionResult, AuthError>
pub async fn get_session( &self, raw_token: &str, ) -> Result<SessionResult, AuthError>
Retrieve a session and its associated user by raw token.
Sourcepub async fn list_sessions(
&self,
user_id: i64,
) -> Result<Vec<Session>, AuthError>
pub async fn list_sessions( &self, user_id: i64, ) -> Result<Vec<Session>, AuthError>
List all active sessions for a user.
Sourcepub async fn verify_email(
&self,
raw_token: &str,
ip: Option<String>,
user_agent: Option<String>,
) -> Result<VerifyEmailResult, AuthError>
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.
Sourcepub async fn request_password_reset(
&self,
email: &str,
) -> Result<RequestResetResult, AuthError>
pub async fn request_password_reset( &self, email: &str, ) -> Result<RequestResetResult, AuthError>
Request a password reset token for a user by email.
Sourcepub async fn reset_password(
&self,
raw_token: &str,
new_password: &str,
) -> Result<ResetPasswordResult, AuthError>
pub async fn reset_password( &self, raw_token: &str, new_password: &str, ) -> Result<ResetPasswordResult, AuthError>
Reset a user’s password using a reset token.
Sourcepub async fn cleanup_expired(&self) -> Result<(u64, u64, u64), AuthError>
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).
Sourcepub async fn oauth_callback(
&self,
info: OAuthUserInfo,
tokens: OAuthTokens,
ip: Option<String>,
user_agent: Option<String>,
) -> Result<LoginResult, AuthError>
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.
Sourcepub async fn list_accounts(
&self,
user_id: i64,
) -> Result<Vec<PublicAccount>, AuthError>
pub async fn list_accounts( &self, user_id: i64, ) -> Result<Vec<PublicAccount>, AuthError>
List all OAuth accounts for a user, with sensitive fields removed.
Sourcepub async fn link_account(
&self,
user_id: i64,
info: OAuthUserInfo,
tokens: OAuthTokens,
) -> Result<LinkAccountResult, AuthError>
pub async fn link_account( &self, user_id: i64, info: OAuthUserInfo, tokens: OAuthTokens, ) -> Result<LinkAccountResult, AuthError>
Link an OAuth provider account to an existing authenticated user.
Sourcepub async fn unlink_account(
&self,
user_id: i64,
account_id: i64,
) -> Result<UnlinkAccountResult, AuthError>
pub async fn unlink_account( &self, user_id: i64, account_id: i64, ) -> Result<UnlinkAccountResult, AuthError>
Unlink an OAuth provider account from a user.
Sourcepub async fn refresh_oauth_token(
&self,
user_id: i64,
account_id: i64,
provider_config: &OAuthProviderConfig,
) -> Result<RefreshTokenResult, AuthError>
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> 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