The iOS Security Frameworks
iOS provides two primary frameworks for authentication. LocalAuthentication is used for on-device biometric checks (FaceID/TouchID). AuthenticationServices is used for federated identity providers, specifically 'Sign in with Apple.' As an Architect, you should aim to provide a 'Passwordless' experience to reduce friction while maintaining enterprise-grade security.
- Biometric Authentication (FaceID/TouchID)
Using the LocalAuthentication framework, you can request the system to verify the user's identity. The actual biometric data never leaves the device; the 'Secure Enclave' simply returns a boolean success or failure. You must add the NSFaceIDUsageDescription key to your Info.plist to use this feature.
- Sign in with Apple
If your app offers any third-party login (like Google or Facebook), Apple requires you to also offer Sign in with Apple. It provides a consistent UI and allows users to hide their real email address, sharing a unique, relay address with your Python backend instead.
- The Keychain for Token Storage
Once a user is authenticated, you should never store their session tokens in UserDefaults. Instead, use the Keychain Services. The Keychain is an encrypted database specifically designed for small bits of sensitive data like passwords, keys, and tokens. It persists even if the app is deleted and reinstalled.
Authentication Comparison
| Feature | LocalAuthentication (Biometric) | Sign in with Apple (Identity) |
|---|---|---|
| Purpose | Quick unlock / re-auth | Account creation / Login |
| Data Privacy | Stored in Secure Enclave | Managed by Apple ID |
| Network Required | No (Offline) | Yes (Online) |
| Setup | Info.plist description | Capability in Xcode |
| Flutter Bridge | Via local_auth plugin | Via sign_in_with_apple plugin |