Expand description
Comprehensive error types for the AuthFramework.
This module defines all error types used throughout the authentication framework, providing detailed error information for debugging, logging, and user feedback. All errors implement standard Rust error traits and provide contextual information to help diagnose issues.
§Error Categories
- Authentication Errors: Credential validation and method failures
- Authorization Errors: Permission and access control failures
- Token Errors: JWT creation, validation, and lifecycle issues
- Configuration Errors: Setup and configuration problems
- Storage Errors: Database and persistence layer issues
- Network Errors: External service communication failures
- Cryptographic Errors: Security operation failures
§Error Handling Patterns
The framework uses structured error handling with:
- Contextual error messages with relevant details
- Error chaining to preserve root cause information
- Categorized errors for appropriate response handling
- Security-safe error messages that don’t leak sensitive data
§Example Error Handling
use auth_framework::{AuthFramework, AuthError};
match auth_framework.authenticate("password", credential, metadata).await {
Ok(result) => handle_success(result),
Err(AuthError::InvalidCredential { credential_type, message }) => {
log::warn!("Invalid {} credential: {}", credential_type, message);
respond_with_auth_failure()
},
Err(AuthError::RateLimited { retry_after, .. }) => {
respond_with_rate_limit(retry_after)
},
Err(e) => {
log::error!("Authentication system error: {}", e);
respond_with_system_error()
}
}
§Security Considerations
Error messages are designed to:
- Provide useful debugging information for developers
- Avoid exposing sensitive information to potential attackers
- Enable proper security monitoring and alerting
- Support compliance requirements for audit logging
Enums§
- Auth
Error - Comprehensive error type covering all authentication and authorization failures.
- Device
Flow Error - Device flow specific errors
- MfaError
- MFA-specific errors
- OAuth
Provider Error - OAuth provider specific errors
- Permission
Error - Permission-specific errors
- Storage
Error - Storage-specific errors
- Token
Error - Token-specific errors
Type Aliases§
- Result
- Type alias for Results in the authentication framework.