pub struct AuthFramework { /* private fields */ }Expand description
Main authentication framework - now focused and modular
Implementations§
Source§impl AuthFramework
impl AuthFramework
Sourcepub fn new(config: AuthConfig) -> Result<Self>
pub fn new(config: AuthConfig) -> Result<Self>
Create a new authentication framework.
Returns a descriptive error if the configuration is invalid rather than panicking, so callers can decide how to handle startup failures.
Equivalent to AuthFramework::try_new.
§Example
use auth_framework::{AuthFramework, config::AuthConfig};
let fw = AuthFramework::new(AuthConfig::default())?;Sourcepub fn try_new(config: AuthConfig) -> Result<Self>
pub fn try_new(config: AuthConfig) -> Result<Self>
Create a new authentication framework, returning an error instead of panicking.
This is the preferred constructor for library callers and server startup code where configuration errors should be handled gracefully rather than aborting the process.
§Example
let fw = AuthFramework::try_new(AuthConfig::default())?;Sourcepub fn replace_storage(&mut self, storage: Arc<dyn AuthStorage>)
pub fn replace_storage(&mut self, storage: Arc<dyn AuthStorage>)
Replace the storage backend with a custom implementation.
This will swap the internal storage Arc and recreate dependent managers so they use the provided storage instance.
Sourcepub fn new_with_storage(
config: AuthConfig,
storage: Arc<dyn AuthStorage>,
) -> Result<Self>
pub fn new_with_storage( config: AuthConfig, storage: Arc<dyn AuthStorage>, ) -> Result<Self>
Sourcepub fn register_method(
&mut self,
name: impl Into<String>,
method: AuthMethodEnum,
)
pub fn register_method( &mut self, name: impl Into<String>, method: AuthMethodEnum, )
Sourcepub async fn initialize(&mut self) -> Result<()>
pub async fn initialize(&mut self) -> Result<()>
Sourcepub async fn authenticate(
&self,
method_name: &str,
credential: Credential,
) -> Result<AuthResult>
pub async fn authenticate( &self, method_name: &str, credential: Credential, ) -> Result<AuthResult>
Authenticate a user with the specified method.
Delegates to authenticate_with_metadata
with empty metadata.
§Example
let result = fw.authenticate("jwt", Credential::jwt(token)).await?;
match result {
AuthResult::Success(token) => println!("authenticated"),
AuthResult::MfaRequired(challenge) => println!("MFA needed"),
AuthResult::Failure(msg) => eprintln!("failed: {msg}"),
}Sourcepub async fn authenticate_with_metadata(
&self,
method_name: &str,
credential: Credential,
metadata: CredentialMetadata,
) -> Result<AuthResult>
pub async fn authenticate_with_metadata( &self, method_name: &str, credential: Credential, metadata: CredentialMetadata, ) -> Result<AuthResult>
Authenticate a user with the specified method and additional metadata.
Metadata can carry client IP, user-agent, and other contextual information for adaptive risk scoring and audit logging.
§Example
let mut meta = CredentialMetadata::new();
meta.client_ip = Some("203.0.113.1".to_string());
let result = fw.authenticate_with_metadata("jwt", credential, meta).await?;Sourcepub async fn complete_mfa(
&self,
challenge: MfaChallenge,
mfa_code: &str,
) -> Result<AuthToken>
pub async fn complete_mfa( &self, challenge: MfaChallenge, mfa_code: &str, ) -> Result<AuthToken>
Sourcepub async fn validate_token(&self, token: &AuthToken) -> Result<bool>
pub async fn validate_token(&self, token: &AuthToken) -> Result<bool>
Sourcepub async fn get_user_info(&self, token: &AuthToken) -> Result<UserInfo>
pub async fn get_user_info(&self, token: &AuthToken) -> Result<UserInfo>
Sourcepub async fn check_permission(
&self,
token: &AuthToken,
action: &str,
resource: &str,
) -> Result<bool>
pub async fn check_permission( &self, token: &AuthToken, action: &str, resource: &str, ) -> Result<bool>
Sourcepub fn token_manager(&self) -> &TokenManager
pub fn token_manager(&self) -> &TokenManager
Sourcepub fn mfa_manager(&self) -> &MfaManager
pub fn mfa_manager(&self) -> &MfaManager
Sourcepub fn session_manager(&self) -> &SessionManager
pub fn session_manager(&self) -> &SessionManager
Sourcepub fn user_manager(&self) -> &UserManager
pub fn user_manager(&self) -> &UserManager
Sourcepub async fn initiate_sms_challenge(&self, user_id: &str) -> Result<String>
pub async fn initiate_sms_challenge(&self, user_id: &str) -> Result<String>
Sourcepub async fn generate_sms_code(&self, challenge_id: &str) -> Result<String>
pub async fn generate_sms_code(&self, challenge_id: &str) -> Result<String>
Sourcepub async fn cleanup_expired_data(&self) -> Result<()>
pub async fn cleanup_expired_data(&self) -> Result<()>
Auto Trait Implementations§
impl Freeze for AuthFramework
impl !RefUnwindSafe for AuthFramework
impl Send for AuthFramework
impl Sync for AuthFramework
impl Unpin for AuthFramework
impl UnsafeUnpin for AuthFramework
impl !UnwindSafe for AuthFramework
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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