Working with Mobile Authentication

1. Understanding Mobile Auth Challenges

ChallengeDetail
No browser cookiesUse tokens stored in OS secure storage
App lifecycleLong-lived refresh tokens needed
URL hijackingCustom schemes vulnerable; prefer App Links/Universal Links
Reverse engineeringSecrets in app are public — use PKCE not client secret

2. Implementing Deep Linking for OAuth

PlatformRecommended
iOSUniversal Links (HTTPS-verified)
AndroidApp Links (assetlinks.json)
FallbackCustom scheme only when verified links unavailable

3. Using Custom URL Schemes

Warning: Any app can register a custom scheme — vulnerable to interception. Always combine with PKCE.

4. Implementing App-to-App Authentication

MechanismDetail
iOSASWebAuthenticationSession + Universal Link
AndroidCustom Tabs + App Link
SSOSDK shares token via Keychain group / Account Manager

5. Working with System Webview

PlatformAPI
iOSASWebAuthenticationSession (RFC 8252)
AndroidCustom Tabs
CookiesShared with system browser → SSO
AvoidEmbedded WebView (no SSO, phishing risk)

6. Using In-App Browsers

Warning: RFC 8252 mandates external user agent (Custom Tabs / ASWebAuthenticationSession) for OAuth, not embedded WebView.

7. Implementing Secure Storage

PlatformAPI
iOSKeychain Services (kSecAttrAccessibleAfterFirstUnlock)
AndroidEncryptedSharedPreferences / Jetpack Security; backed by StrongBox/TEE
Cross-platformreact-native-keychain, expo-secure-store, flutter_secure_storage

8. Using Biometric Authentication

PlatformAPI
iOSLocalAuthentication (LAContext)
AndroidBiometricPrompt (androidx.biometric)
Key bindingKeychain/Keystore key requires biometric to use

9. Implementing Refresh Tokens in Mobile

PracticeDetail
StorageKeychain/Keystore, encrypted at rest
RotationReplace on every use
Reuse detectionRevoke family on duplicate use
DPoP / sender-constrainedBind to device-generated key

10. Handling Background Token Expiration

StrategyDetail
Refresh on resumeApp foreground → refresh if < 5min left
Background fetchiOS BGTaskScheduler / Android WorkManager
Push notificationWake app to refresh before expiry

11. Implementing Certificate Pinning

MethodDetail
Static pinSPKI hash in code/config
iOSATS + URLSessionDelegate challenge handler
AndroidNetworkSecurityConfig pin set
Backup pinRequired for rotation; otherwise app bricks
Remote updateSigned pin updates via OTA config