pub struct AuthService<U, S, V, A, E>{
pub config: AuthConfig,
pub users: Arc<U>,
pub sessions: Arc<S>,
pub verifications: Arc<V>,
pub accounts: Arc<A>,
pub email: Arc<E>,
}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.
email: Arc<E>Email sender implementation.
Implementations§
Source§impl<U, S, V, A, E> AuthService<U, S, V, A, E>
impl<U, S, V, A, E> AuthService<U, S, V, A, E>
Sourcepub fn new(
config: AuthConfig,
users: U,
sessions: S,
verifications: V,
accounts: A,
email: E,
) -> Self
pub fn new( config: AuthConfig, users: U, sessions: S, verifications: V, accounts: A, email: E, ) -> Self
Create a new authentication service with the given configuration and backends.
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), AuthError>
pub async fn cleanup_expired(&self) -> Result<(u64, u64), AuthError>
Delete expired sessions and verification tokens. Returns (sessions_deleted, verifications_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.
The CSRF state and PKCE verifier are stored in the verifications table with the
identifier format oauth-state:{csrf_token}. This reuses existing infrastructure
rather than requiring a dedicated OAuth state table.