pub struct AuthFramework { /* private fields */ }Expand description
Main authentication framework.
Implementations§
Source§impl AuthFramework
impl AuthFramework
Sourcepub fn new(config: AuthConfig) -> Self
pub fn new(config: AuthConfig) -> Self
Create a new authentication framework.
Sourcepub fn register_method(
&mut self,
name: impl Into<String>,
method: Box<dyn AuthMethod>,
)
pub fn register_method( &mut self, name: impl Into<String>, method: Box<dyn AuthMethod>, )
Register an authentication method.
Sourcepub async fn initialize(&mut self) -> Result<()>
pub async fn initialize(&mut self) -> Result<()>
Initialize the authentication framework.
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.
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 metadata.
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>
Complete multi-factor authentication.
Sourcepub async fn validate_token(&self, token: &AuthToken) -> Result<bool>
pub async fn validate_token(&self, token: &AuthToken) -> Result<bool>
Validate a token.
Sourcepub async fn get_user_info(&self, token: &AuthToken) -> Result<UserInfo>
pub async fn get_user_info(&self, token: &AuthToken) -> Result<UserInfo>
Get user information from a token.
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>
Check if a token has a specific permission.
Sourcepub async fn refresh_token(&self, token: &AuthToken) -> Result<AuthToken>
pub async fn refresh_token(&self, token: &AuthToken) -> Result<AuthToken>
Refresh a token.
Sourcepub async fn revoke_token(&self, token: &AuthToken) -> Result<()>
pub async fn revoke_token(&self, token: &AuthToken) -> Result<()>
Revoke a token.
Sourcepub async fn create_api_key(
&self,
user_id: &str,
expires_in: Option<Duration>,
) -> Result<String>
pub async fn create_api_key( &self, user_id: &str, expires_in: Option<Duration>, ) -> Result<String>
Create a new API key for a user.
Sourcepub async fn create_session(
&self,
user_id: &str,
expires_in: Duration,
ip_address: Option<String>,
user_agent: Option<String>,
) -> Result<String>
pub async fn create_session( &self, user_id: &str, expires_in: Duration, ip_address: Option<String>, user_agent: Option<String>, ) -> Result<String>
Create a new session.
Sourcepub async fn get_session(&self, session_id: &str) -> Result<Option<SessionData>>
pub async fn get_session(&self, session_id: &str) -> Result<Option<SessionData>>
Get session information.
Sourcepub async fn delete_session(&self, session_id: &str) -> Result<()>
pub async fn delete_session(&self, session_id: &str) -> Result<()>
Delete a session.
Sourcepub async fn list_user_tokens(&self, user_id: &str) -> Result<Vec<AuthToken>>
pub async fn list_user_tokens(&self, user_id: &str) -> Result<Vec<AuthToken>>
Get all tokens for a user.
Sourcepub async fn cleanup_expired_data(&self) -> Result<()>
pub async fn cleanup_expired_data(&self) -> Result<()>
Clean up expired data.
Sourcepub async fn create_auth_token(
&self,
user_id: impl Into<String>,
scopes: Vec<String>,
method_name: impl Into<String>,
lifetime: Option<Duration>,
) -> Result<AuthToken>
pub async fn create_auth_token( &self, user_id: impl Into<String>, scopes: Vec<String>, method_name: impl Into<String>, lifetime: Option<Duration>, ) -> Result<AuthToken>
Create an authentication token directly (useful for testing and demos).
Note: In production, tokens should be created through the authenticate method.
Auto Trait Implementations§
impl Freeze for AuthFramework
impl !RefUnwindSafe for AuthFramework
impl Send for AuthFramework
impl Sync for AuthFramework
impl Unpin for AuthFramework
impl !UnwindSafe for AuthFramework
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
Mutably borrows from an owned value. Read more