# Control Center UI - Leptos Authentication System
A comprehensive authentication system built with Leptos and WebAssembly for cloud infrastructure management.
## 🔐 Features Overview
### Core Authentication
- **Email/Password Login** with comprehensive validation
- **JWT Token Management** with automatic refresh
- **Secure Token Storage** with AES-256-GCM encryption in localStorage
- **401 Response Interceptor** for automatic logout and token refresh
### Multi-Factor Authentication (MFA)
- **TOTP-based MFA** with QR code generation
- **Backup Codes** for account recovery
- **Mobile App Integration** (Google Authenticator, Authy, etc.)
### Biometric Authentication
- **WebAuthn/FIDO2 Support** for passwordless authentication
- **Platform Authenticators** (Touch ID, Face ID, Windows Hello)
- **Cross-Platform Security Keys** (USB, NFC, Bluetooth)
- **Credential Management** with device naming and removal
### Advanced Security Features
- **Device Trust Management** with fingerprinting
- **Session Timeout Warnings** with countdown timers
- **Password Reset Flow** with email verification
- **SSO Integration** (OAuth2, SAML, OpenID Connect)
- **Session Management** with active session monitoring
### Route Protection
- **Auth Guards** for protected routes
- **Permission-based Access Control** with role validation
- **Conditional Rendering** based on authentication state
- **Automatic Redirects** for unauthorized access
## 📁 Architecture Overview
```
src/
├── auth/ # Authentication core
│ ├── mod.rs # Type definitions and exports
│ ├── token_manager.rs # JWT token handling with auto-refresh
│ ├── storage.rs # Encrypted token storage
│ ├── webauthn.rs # WebAuthn/FIDO2 implementation
│ ├── crypto.rs # Cryptographic utilities
│ └── http_interceptor.rs # HTTP request/response interceptor
├── components/auth/ # Authentication components
│ ├── mod.rs # Component exports
│ ├── login_form.rs # Email/password login form
│ ├── mfa_setup.rs # TOTP MFA configuration
│ ├── password_reset.rs # Password reset flow
│ ├── auth_guard.rs # Route protection components
│ ├── session_timeout.rs # Session management modal
│ ├── sso_buttons.rs # SSO provider buttons
│ ├── device_trust.rs # Device trust management
│ ├── biometric_auth.rs # WebAuthn biometric auth
│ ├── logout_button.rs # Logout functionality
│ └── user_profile.rs # User profile management
├── utils/ # Utility modules
└── lib.rs # Main application entry
```
## 🚀 Implemented Components
All authentication components have been successfully implemented:
### ✅ Core Authentication Infrastructure
- **Secure Token Storage** (`src/auth/storage.rs`) - AES-256-GCM encrypted localStorage with session-based keys
- **JWT Token Manager** (`src/auth/token_manager.rs`) - Automatic token refresh, expiry monitoring, context management
- **Crypto Utilities** (`src/auth/crypto.rs`) - Secure random generation, hashing, HMAC, device fingerprinting
- **HTTP Interceptor** (`src/auth/http_interceptor.rs`) - 401 handling, automatic logout, request/response middleware
### ✅ Authentication Components
- **Login Form** (`src/components/auth/login_form.rs`) - Email/password validation, remember me, SSO integration
- **MFA Setup** (`src/components/auth/mfa_setup.rs`) - TOTP with QR codes, backup codes, verification flow
- **Password Reset** (`src/components/auth/password_reset.rs`) - Email verification, secure token flow, validation
- **Session Timeout** (`src/components/auth/session_timeout.rs`) - Countdown modal, automatic logout, session extension
### ✅ Advanced Security Features
- **Device Trust** (`src/components/auth/device_trust.rs`) - Device fingerprinting, trust management, auto-generated names
- **Biometric Auth** (`src/components/auth/biometric_auth.rs`) - WebAuthn/FIDO2 integration, credential management
- **SSO Buttons** (`src/components/auth/sso_buttons.rs`) - OAuth2/SAML/OIDC providers with branded icons
- **User Profile** (`src/components/auth/user_profile.rs`) - Comprehensive profile management with tabbed interface
### ✅ Route Protection System
- **Auth Guard** (`src/components/auth/auth_guard.rs`) - Protected routes, permission guards, role-based access
- **Logout Button** (`src/components/auth/logout_button.rs`) - Secure logout with server notification and cleanup
### ✅ WebAuthn Integration
- **WebAuthn Manager** (`src/auth/webauthn.rs`) - Complete FIDO2 implementation with browser compatibility
- **Biometric Registration** - Platform and cross-platform authenticator support
- **Credential Management** - Device naming, usage tracking, removal capabilities
## 🔒 Security Implementation
### Token Security
- **AES-256-GCM Encryption**: All tokens encrypted before storage
- **Session-based Keys**: Encryption keys unique per browser session
- **Automatic Rotation**: Keys regenerated on each application load
- **Secure Cleanup**: Complete token removal on logout
### Device Trust
- **Hardware Fingerprinting**: Based on browser, platform, screen, timezone
- **Trust Duration**: Configurable trust periods (7, 30, 90, 365 days)
- **Trust Tokens**: Separate tokens for device trust validation
- **Remote Revocation**: Server-side device trust management
### Session Management
- **Configurable Timeouts**: Adjustable session timeout periods
- **Activity Monitoring**: Tracks user activity for session extension
- **Concurrent Sessions**: Multiple session tracking and management
- **Graceful Logout**: Clean session termination with server notification
### WebAuthn Security
- **Hardware Security**: Leverages hardware security modules
- **Biometric Verification**: Touch ID, Face ID, Windows Hello support
- **Security Key Support**: USB, NFC, Bluetooth FIDO2 keys
- **Attestation Validation**: Hardware authenticity verification
## 📱 Component Usage Examples
### Basic Authentication Flow
```rust
use leptos::*;
use control_center_ui::auth::provide_auth_context;
use control_center_ui::components::auth::*;
#[component]
fn App() -> impl IntoView {
provide_meta_context();
// Initialize auth context with API base URL
provide_auth_context("http://localhost:8080".to_string()).unwrap();
view! {