Lewati ke konten utama

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:

PlatformSecure Storage
AndroidDataStore (terenkripsi via Android Keystore/Tink)
iOSKeychain Services
Flutterflutter_secure_storage
RN CLIreact-native-keychain
RN Expoexpo-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​

  1. Access Token TTL: Simpan di memory + secure storage. Refresh sebelum expired.
  2. Refresh Token TTL: Simpan HANYA di secure storage.
  3. Token Rotation: Implement refresh token rotation untuk keamanan.
  4. Logout: Clear SEMUA token dan sensitive data dari storage.
  5. Biometric: Untuk app yang membutuhkan, gunakan biometric untuk mengakses token.