Posts

Part 6: The Interceptor Pattern - Mastering the Token Lifecycle

Image
 A Staff-level guide to using OkHttp Authenticator and Kotlin Mutex to prevent refresh storms and race conditions in high-scale apps. In  Part 5,  we ensured our app is running on a trustworthy device. But even on a “Strong Integrity” device, your networking layer can still be a source of chaos. If your app makes ten concurrent API calls the moment the user opens it — and their access token has just expired — you don’t want ten separate “refresh token” requests hitting your server. This is a classic  “Refresh Storm”  that leads to race conditions, invalidated sessions, and a frustrated user who is randomly logged out. ⚡  TL;DR The Problem:  Concurrent requests triggering redundant refresh calls (Race Conditions). The Tool:  OkHttp  Authenticator  (Reactive) for 401 handling. The Solution:  A Kotlin  Mutex  to synchronize the "Critical Section" of token renewal. The Impact:  Proper client-side concurrency control preve...

Part 5: Environment Trust - Play Integrity & Attestation

Image
 A Staff-level architecture guide to securing the runtime environment against rooting, hooking frameworks, and emulators. In  Part 1 , we designed the Stateless Blueprint. In  Part 4 , we secured the user’s identity with Passkeys. But there is a silent, systemic risk:  What if the environment itself is compromised? If your app is running on a rooted device with a hooking framework (like Frida or Xposed) or within a sophisticated emulator, even the best encryption and Passkeys can be undermined via memory injection or screen scraping. Today, we bridge the gap between “Who is the user?” and “Is the device trustworthy?” ⚡  TL;DR Compromised environments  allow attackers to bypass local security controls and manipulate runtime logic. Play Integrity API  provides a cryptographically signed verdict on app binary, device integrity, and licensing. Tiered Enforcement:  Align your security requirements with business risk — reserving high-value actions for “...