Token & Credential Storage
❌ DILARANG
- Menyimpan token/credential di SharedPreferences / UserDefaults / AsyncStorage (plain text).
- Hardcode API key di source code.
- Menyimpan password user di device.
- Log token atau credential.
✅ WAJIB
Gunakan secure storage yang ter-enkripsi:
| Platform | Secure Storage |
|---|---|
| Android | DataStore (terenkripsi via Android Keystore/Tink) |
| iOS | Keychain Services |
| Flutter | flutter_secure_storage |
| RN CLI | react-native-keychain |
| RN Expo | expo-secure-store |
EncryptedSharedPreferences sudah deprecated
Google men-deprecate androidx.security:security-crypto (EncryptedSharedPreferences) tanpa pengganti resmi 1:1 — implementasinya bergantung langsung ke Android Keystore yang perilakunya tidak konsisten antar device. Rekomendasi saat ini: DataStore untuk persistensi + Tink/Security Crypto untuk enkripsi + Android Keystore untuk proteksi key. Project lama yang masih pakai EncryptedSharedPreferences boleh lanjut jalan, tapi rencanakan migrasi.
Token Management Flow
Rules
- Access Token TTL: Simpan di memory + secure storage. Refresh sebelum expired.
- Refresh Token TTL: Simpan HANYA di secure storage.
- Token Rotation: Implement refresh token rotation untuk keamanan.
- Logout: Clear SEMUA token dan sensitive data dari storage.
- Biometric: Untuk app yang membutuhkan, gunakan biometric untuk mengakses token.