Technical Architecture for Passwordless Systems

Technical Architecture for Passwordless Systems

Implementing passwordless authentication requires fundamental architectural changes. Traditional session management assumes password verification at login, but passkey systems need continuous credential presentation. The architecture must support multiple authentication methods simultaneously during transition periods while maintaining security properties for each method.

Platform differences create additional complexity. Apple's passkey implementation differs subtly from Google's, and both differ from password managers like 1Password or Bitwarden. Systems must handle these variations gracefully while providing consistent user experience. Cross-platform compatibility requires careful attention to WebAuthn specification details and extensive testing across devices.

class PasswordlessArchitecture:
    """Architecture for passwordless authentication systems"""
    
    def __init__(self):
        self.auth_methods = {}
        self.session_manager = SessionManager()
        
    def register_auth_method(self, method_type: str, handler):
        """Register authentication method handler"""
        
        self.auth_methods[method_type] = handler
    
    def authenticate_request(self, request: Dict) -> Optional[Dict]:
        """Handle multi-method authentication request"""
        
        auth_type = request.get('auth_type')
        
        if auth_type == 'passkey':
            return self._handle_passkey_auth(request)
        elif auth_type == 'password':
            return self._handle_password_auth(request)
        elif auth_type == 'magic_link':
            return self._handle_magic_link_auth(request)
        elif auth_type == 'biometric':
            return self._handle_biometric_auth(request)
        else:
            return None
    
    def _handle_passkey_auth(self, request: Dict) -> Optional[Dict]:
        """Handle passkey authentication"""
        
        assertion = request.get('assertion')
        
        # Verify assertion signature
        credential_id = assertion.get('credentialId')
        authenticator_data = base64.urlsafe_b64decode(
            assertion.get('authenticatorData') + '=='
        )
        client_data_json = base64.urlsafe_b64decode(
            assertion.get('clientDataJSON') + '=='
        )
        signature = base64.urlsafe_b64decode(
            assertion.get('signature') + '=='
        )
        
        # Verify signature with stored public key
        # Implementation depends on key type (ECDSA, RSA, etc.)
        
        # Create session with authentication context
        session = self.session_manager.create_session({
            'user_id': 'verified_user_id',
            'auth_method': 'passkey',
            'auth_strength': 'high',
            'device_bound': True,
            'credential_id': credential_id
        })
        
        return session
    
    def implement_account_recovery(self, user_id: str) -> Dict:
        """Implement passwordless account recovery"""
        
        recovery_methods = []
        
        # Check available recovery options
        user_data = self._get_user_data(user_id)
        
        if user_data.get('recovery_email'):
            recovery_methods.append({
                'method': 'email',
                'description': 'Send recovery link to em***@example.com',
                'available': True
            })
        
        if user_data.get('phone_number'):
            recovery_methods.append({
                'method': 'sms',
                'description': 'Send code to ***-***-1234',
                'available': True
            })
        
        if user_data.get('backup_passkeys', []):
            recovery_methods.append({
                'method': 'backup_passkey',
                'description': 'Use backup passkey from another device',
                'available': True
            })
        
        if user_data.get('social_recovery_enabled'):
            recovery_methods.append({
                'method': 'social_recovery',
                'description': 'Verify through trusted contacts',
                'available': len(user_data.get('trusted_contacts', [])) >= 3
            })
        
        return {
            'user_id': user_id,
            'recovery_methods': recovery_methods,
            'recommendation': self._recommend_recovery_method(recovery_methods)
        }
    
    def handle_platform_differences(self):
        """Handle platform-specific passkey implementations"""
        
        platform_configs = {
            'ios': {
                'min_version': '16.0',
                'features': {
                    'passkey_sync': True,
                    'conditional_ui': True,
                    'autofill_ui': True,
                    'cross_origin': False
                },
                'quirks': [
                    'Requires associated domains configuration',
                    'Syncs via iCloud Keychain only'
                ]
            },
            'android': {
                'min_version': '9.0',  # With Google Play Services
                'features': {
                    'passkey_sync': True,
                    'conditional_ui': True,
                    'autofill_ui': True,
                    'cross_origin': True
                },
                'quirks': [
                    'Requires Google Play Services',
                    'Different UI on different manufacturers'
                ]
            },
            'windows': {
                'min_version': '10.1903',
                'features': {
                    'passkey_sync': False,  # Local only by default
                    'conditional_ui': True,
                    'autofill_ui': False,
                    'cross_origin': True
                },
                'quirks': [
                    'Windows Hello required',
                    'Limited sync options'
                ]
            },
            'macos': {
                'min_version': '13.0',
                'features': {
                    'passkey_sync': True,
                    'conditional_ui': True,
                    'autofill_ui': True,
                    'cross_origin': False
                },
                'quirks': [
                    'Touch ID or authenticated Apple Watch required',
                    'Safari-first experience'
                ]
            }
        }
        
        return platform_configs

class BiometricAuthenticationEvolution:
    """Evolution of biometric authentication methods"""
    
    def __init__(self):
        self.biometric_methods = {
            'fingerprint': {
                'accuracy': 0.999,
                'spoofing_resistance': 'medium',
                'user_acceptance': 'high',
                'availability': 'widespread'
            },
            'face_recognition': {
                'accuracy': 0.9999,
                'spoofing_resistance': 'high',
                'user_acceptance': 'high',
                'availability': 'growing'
            },
            'iris_scan': {
                'accuracy': 0.99999,
                'spoofing_resistance': 'very high',
                'user_acceptance': 'medium',
                'availability': 'limited'
            },
            'voice_recognition': {
                'accuracy': 0.99,
                'spoofing_resistance': 'low',
                'user_acceptance': 'medium',
                'availability': 'widespread'
            },
            'behavioral_biometrics': {
                'accuracy': 0.95,
                'spoofing_resistance': 'high',
                'user_acceptance': 'high',
                'availability': 'emerging'
            }
        }
    
    def evaluate_biometric_combination(self, methods: List[str]) -> Dict:
        """Evaluate security of biometric combinations"""
        
        combined_accuracy = 1.0
        min_spoofing_resistance = 'very high'
        overall_acceptance = 'high'
        
        resistance_levels = ['low', 'medium', 'high', 'very high']
        
        for method in methods:
            if method in self.biometric_methods:
                bio = self.biometric_methods[method]
                
                # Combine accuracy (assume independent)
                combined_accuracy *= (1 - bio['accuracy'])
                
                # Take minimum spoofing resistance
                if resistance_levels.index(bio['spoofing_resistance']) < \
                   resistance_levels.index(min_spoofing_resistance):
                    min_spoofing_resistance = bio['spoofing_resistance']
                
                # Average acceptance
                if bio['user_acceptance'] != 'high':
                    overall_acceptance = 'medium'
        
        combined_accuracy = 1 - combined_accuracy
        
        return {
            'methods': methods,
            'combined_accuracy': combined_accuracy,
            'spoofing_resistance': min_spoofing_resistance,
            'user_acceptance': overall_acceptance,
            'security_score': self._calculate_bio_security_score(
                combined_accuracy, min_spoofing_resistance
            )
        }
    
    def _calculate_bio_security_score(self, accuracy: float, 
                                     spoofing_resistance: str) -> int:
        """Calculate biometric security score"""
        
        score = accuracy * 50  # Max 50 points for accuracy
        
        resistance_scores = {
            'low': 10,
            'medium': 25,
            'high': 40,
            'very high': 50
        }
        
        score += resistance_scores.get(spoofing_resistance, 0)
        
        return int(score)