pub struct AuthService { /* private fields */ }Expand description
Authentication service managing users and sessions.
Implementations§
Source§impl AuthService
impl AuthService
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new authentication service.
Uses environment variables as a fallback for admin credentials.
Sourcepub fn with_data_dir(data_dir: Option<PathBuf>) -> Self
pub fn with_data_dir(data_dir: Option<PathBuf>) -> Self
Create an authentication service with optional persistence to disk. Admin credentials are read from environment variables only.
Sourcepub fn with_data_dir_and_secrets(
data_dir: Option<PathBuf>,
secrets: Option<&dyn SecretsProvider>,
) -> Self
pub fn with_data_dir_and_secrets( data_dir: Option<PathBuf>, secrets: Option<&dyn SecretsProvider>, ) -> Self
Create an authentication service with persistence and a secrets provider. Admin credentials are resolved through the secrets provider chain (vault → external vault → env vars) instead of raw environment variables.
Sourcepub fn login(&self, username: &str, password: &str) -> AuthResponse
pub fn login(&self, username: &str, password: &str) -> AuthResponse
Authenticate user with username and password.
Sourcepub fn verify_mfa(&self, code: &str, temp_token: &str) -> AuthResponse
pub fn verify_mfa(&self, code: &str, temp_token: &str) -> AuthResponse
Verify MFA code and complete authentication.
Sourcepub fn validate_session(&self, token: &str) -> Option<UserInfo>
pub fn validate_session(&self, token: &str) -> Option<UserInfo>
Validate a session token and return user info.
Sourcepub fn list_users(&self) -> Vec<UserInfo>
pub fn list_users(&self) -> Vec<UserInfo>
List all users.
Sourcepub fn create_user(
&self,
username: &str,
email: &str,
password: &str,
role: &str,
) -> Result<UserInfo, String>
pub fn create_user( &self, username: &str, email: &str, password: &str, role: &str, ) -> Result<UserInfo, String>
Create a new user.
Sourcepub fn update_user(
&self,
username: &str,
email: Option<String>,
role: Option<String>,
password: Option<String>,
) -> Result<UserInfo, String>
pub fn update_user( &self, username: &str, email: Option<String>, role: Option<String>, password: Option<String>, ) -> Result<UserInfo, String>
Update an existing user.
Sourcepub fn enable_mfa(&self, username: &str) -> Result<String, String>
pub fn enable_mfa(&self, username: &str) -> Result<String, String>
Enable MFA for a user and return the generated secret. The secret should be stored by the user in their authenticator app.
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Clean up expired sessions.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AuthService
impl !RefUnwindSafe for AuthService
impl Send for AuthService
impl Sync for AuthService
impl Unpin for AuthService
impl UnsafeUnpin for AuthService
impl UnwindSafe for AuthService
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