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 validate_api_key(&self, api_key: &str) -> Result<UserInfo>
pub async fn validate_api_key(&self, api_key: &str) -> Result<UserInfo>
Validate an API key and return user information.
Sourcepub async fn revoke_api_key(&self, api_key: &str) -> Result<()>
pub async fn revoke_api_key(&self, api_key: &str) -> Result<()>
Revoke an API key.
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 validate_username(&self, username: &str) -> Result<bool>
pub async fn validate_username(&self, username: &str) -> Result<bool>
Validate username format.
Sourcepub async fn validate_display_name(&self, display_name: &str) -> Result<bool>
pub async fn validate_display_name(&self, display_name: &str) -> Result<bool>
Validate display name format.
Sourcepub async fn validate_user_input(&self, input: &str) -> Result<bool>
pub async fn validate_user_input(&self, input: &str) -> Result<bool>
Validate user input.
Sourcepub async fn check_ip_rate_limit(&self, ip: &str) -> Result<bool>
pub async fn check_ip_rate_limit(&self, ip: &str) -> Result<bool>
Check IP rate limit.
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.
Sourcepub async fn generate_totp_secret(&self, user_id: &str) -> Result<String>
pub async fn generate_totp_secret(&self, user_id: &str) -> Result<String>
Generate TOTP secret for a user.
Sourcepub async fn generate_totp_qr_code(
&self,
user_id: &str,
app_name: &str,
secret: &str,
) -> Result<String>
pub async fn generate_totp_qr_code( &self, user_id: &str, app_name: &str, secret: &str, ) -> Result<String>
Generate TOTP QR code URL.
Sourcepub async fn generate_totp_code(&self, _secret: &str) -> Result<String>
pub async fn generate_totp_code(&self, _secret: &str) -> Result<String>
Generate current TOTP code.
Sourcepub async fn verify_totp_code(&self, user_id: &str, code: &str) -> Result<bool>
pub async fn verify_totp_code(&self, user_id: &str, code: &str) -> Result<bool>
Verify TOTP code.
Sourcepub async fn register_phone_number(
&self,
user_id: &str,
_phone_number: &str,
) -> Result<()>
pub async fn register_phone_number( &self, user_id: &str, _phone_number: &str, ) -> Result<()>
Register phone number for SMS MFA.
Sourcepub async fn initiate_sms_challenge(&self, user_id: &str) -> Result<String>
pub async fn initiate_sms_challenge(&self, user_id: &str) -> Result<String>
Initiate SMS challenge.
Sourcepub async fn generate_sms_code(&self, challenge_id: &str) -> Result<String>
pub async fn generate_sms_code(&self, challenge_id: &str) -> Result<String>
Generate SMS code.
Sourcepub async fn verify_sms_code(
&self,
challenge_id: &str,
code: &str,
) -> Result<bool>
pub async fn verify_sms_code( &self, challenge_id: &str, code: &str, ) -> Result<bool>
Verify SMS code.
Sourcepub async fn register_email(&self, user_id: &str, _email: &str) -> Result<()>
pub async fn register_email(&self, user_id: &str, _email: &str) -> Result<()>
Register email for email MFA.
Sourcepub async fn initiate_email_challenge(&self, user_id: &str) -> Result<String>
pub async fn initiate_email_challenge(&self, user_id: &str) -> Result<String>
Initiate email challenge.
Sourcepub async fn generate_email_code(&self, challenge_id: &str) -> Result<String>
pub async fn generate_email_code(&self, challenge_id: &str) -> Result<String>
Generate email code.
Sourcepub async fn verify_email_code(
&self,
challenge_id: &str,
code: &str,
) -> Result<bool>
pub async fn verify_email_code( &self, challenge_id: &str, code: &str, ) -> Result<bool>
Verify email code.
Sourcepub async fn generate_backup_codes(
&self,
user_id: &str,
count: usize,
) -> Result<Vec<String>>
pub async fn generate_backup_codes( &self, user_id: &str, count: usize, ) -> Result<Vec<String>>
Generate backup codes.
Sourcepub async fn verify_backup_code(
&self,
user_id: &str,
code: &str,
) -> Result<bool>
pub async fn verify_backup_code( &self, user_id: &str, code: &str, ) -> Result<bool>
Verify backup code.
Sourcepub async fn get_remaining_backup_codes(&self, user_id: &str) -> Result<usize>
pub async fn get_remaining_backup_codes(&self, user_id: &str) -> Result<usize>
Get remaining backup codes count.
Sourcepub async fn create_role(&self, role: Role) -> Result<()>
pub async fn create_role(&self, role: Role) -> Result<()>
Create a new role.
Sourcepub async fn assign_role(&self, user_id: &str, role_name: &str) -> Result<()>
pub async fn assign_role(&self, user_id: &str, role_name: &str) -> Result<()>
Assign a role to a user.
Sourcepub async fn set_role_inheritance(
&self,
child_role: &str,
parent_role: &str,
) -> Result<()>
pub async fn set_role_inheritance( &self, child_role: &str, parent_role: &str, ) -> Result<()>
Set role inheritance.
Sourcepub async fn grant_permission(
&self,
user_id: &str,
action: &str,
resource: &str,
) -> Result<()>
pub async fn grant_permission( &self, user_id: &str, action: &str, resource: &str, ) -> Result<()>
Grant permission to a user.
Sourcepub async fn revoke_permission(
&self,
user_id: &str,
action: &str,
resource: &str,
) -> Result<()>
pub async fn revoke_permission( &self, user_id: &str, action: &str, resource: &str, ) -> Result<()>
Revoke permission from a user.
Sourcepub async fn user_has_role(
&self,
user_id: &str,
role_name: &str,
) -> Result<bool>
pub async fn user_has_role( &self, user_id: &str, role_name: &str, ) -> Result<bool>
Check if user has a role.
Sourcepub async fn get_effective_permissions(
&self,
user_id: &str,
) -> Result<Vec<String>>
pub async fn get_effective_permissions( &self, user_id: &str, ) -> Result<Vec<String>>
Get effective permissions for a user.
Sourcepub async fn create_abac_policy(
&self,
name: &str,
_description: &str,
) -> Result<()>
pub async fn create_abac_policy( &self, name: &str, _description: &str, ) -> Result<()>
Create ABAC policy.
Sourcepub async fn map_user_attribute(
&self,
user_id: &str,
attribute: &str,
value: &str,
) -> Result<()>
pub async fn map_user_attribute( &self, user_id: &str, attribute: &str, value: &str, ) -> Result<()>
Map user attribute.
Sourcepub async fn get_user_attribute(
&self,
user_id: &str,
attribute: &str,
) -> Result<Option<String>>
pub async fn get_user_attribute( &self, user_id: &str, attribute: &str, ) -> Result<Option<String>>
Get user attribute.
Sourcepub async fn check_dynamic_permission(
&self,
user_id: &str,
action: &str,
resource: &str,
_context: HashMap<String, String>,
) -> Result<bool>
pub async fn check_dynamic_permission( &self, user_id: &str, action: &str, resource: &str, _context: HashMap<String, String>, ) -> Result<bool>
Check dynamic permission.
Sourcepub async fn create_resource(&self, resource: &str) -> Result<()>
pub async fn create_resource(&self, resource: &str) -> Result<()>
Create resource.
Sourcepub async fn delegate_permission(
&self,
delegator: &str,
delegate: &str,
permission: &str,
resource: &str,
duration: Duration,
) -> Result<()>
pub async fn delegate_permission( &self, delegator: &str, delegate: &str, permission: &str, resource: &str, duration: Duration, ) -> Result<()>
Delegate permission.
Sourcepub async fn get_active_delegations(&self, user_id: &str) -> Result<Vec<String>>
pub async fn get_active_delegations(&self, user_id: &str) -> Result<Vec<String>>
Get active delegations.