offline access/authentication
-
I'm building a mobile app that needs to work in places with spotty or no connectivity (think field workers, transit, rural areas).
Can I use FusionAuth as my central identity provider while still letting users authenticate when the device is offline?
-
The cleanest way to do it is with asymmetric JWT verification plus a bounded offline grace period.** Here's the pattern.
FusionAuth signs JWTs with a private key it holds. The matching public key is published at the JWKS endpoint (
/.well-known/jwks.json). Your mobile app — or any resource server — can verify a token's signature locally, with zero network calls, as long as it has that public key. You can even bundle the public key with the application and avoid the retrieving it.That's the property that makes offline auth possible. You're not asking "is this token still good?" over the wire; you're asking "did FusionAuth sign this, and has it expired?" using math the device can do on its own.
See JWT signing configuration and the JWKS endpoint docs.
The Flow
1. First login (online, required). The user authenticates against FusionAuth via OAuth with the
offline_accessscope, or via the Login API withloginId+password+applicationId. You get back two things:- A short-lived access token (signed JWT, RS256, EdDSA, or ES256)
- A long-lived refresh token (opaque, default 30 days, configurable per tenant or application)
Refresh token details are in the refresh token settings docs.
2. Cache the JWKS on the device. Fetch
/.well-known/jwks.jsononce and store it. You'll match incoming tokens to the right key using thekidin the JWT header. For fully air-gapped scenarios, you can bundle the JWKS into the app at build time — see the air-gapping article.3. Online operation. The app uses the access token for API calls. When it expires, the app calls the Refresh a JWT API with the refresh token to mint a new access token.
4. Offline operation. The app validates the cached access token locally:
- Find the key in the JWKS where
kidmatches the JWT header - Verify the signature with that public key
- Check
exp,iss,aud, and any custom claims you care about
If the token is past
expbut the device is offline, allow a bounded grace period (e.g., 24 hours past expiration). After that, degrade functionality until the device reconnects and refreshes. For instance, you could allow read operations but nothing that changes data.5. On reconnect. Refresh immediately. If the refresh token has been revoked server-side, the call will fail and the user must re-authenticate.
Token lifetime tuning
This is where you make your security/availability tradeoff explicit. FusionAuth lets you tune both lifetimes per tenant or per application:
- Access token TTL (
ttl_seconds
set this short for online use (5–15 minutes is typical), but if you want longer offline windows without the grace-period workaround, you can extend it. Whatever you pick is the maximum revocation lag for compromised tokens. - Refresh token duration: default is ~30 days. Use a Sliding Window with Maximum Lifetime policy if you want active devices to keep working but inactive ones to expire automatically.
- One-Time Use refresh tokens: rotates the token value on every refresh. Strongly recommended — if a refresh token is stolen and used, the legitimate device's next refresh will fail and the theft is detected.
What FusionAuth gives you for revocation
Refresh tokens can be revoked automatically on password change, MFA enrollment, or any action that prevents login. You can also call the Revoke Refresh Tokens API directly. The catch: revocation only takes effect the next time the device tries to refresh. Already-issued access tokens remain valid until their
exp.Tradeoffs you're signing up for
Be honest with yourself about this approach. These aren't FusionAuth limitations, they're inherent to offline auth:
- Delayed revocation. A stolen device retains access until the access token expires and the offline grace period elapses. Shorter access token TTLs mean faster revocation but more refresh traffic and shorter offline windows. Pick where on that curve you want to sit.
- Clock trust. Offline
expchecks rely on the device clock, which the user controls. If that matters for your threat model, store a "last known server time" on each refresh and refuse to validate tokens if the clock has moved backward. - Stale claims. If a user's roles or permissions change, the old claims persist in the cached token until the next refresh. Acceptable for most apps, not for high-stakes authorization.
- Local credential storage. If you want users to "log in" while offline (PIN/biometric to unlock the cached session), you're storing something derivable from their credential on the device. Use the platform secure storage (iOS Keychain, Android Keystore) and a slow KDF like Argon2id for any password-derived material.
- Key rotation. If you bundle JWKS into the app, you have to ship app updates ahead of key rotations (or plan to create a bunch of keys ahead of time). If you fetch JWKS dynamically, you need a cache strategy and a fallback when the cache is stale and the network is down.
- MFA degrades offline. Push and SMS-based factors require connectivity. Offline auth typically falls back to device-bound factors (the refresh token + a local PIN/biometric), which is different than your online MFA flow. Decide whether that's acceptable.
Practical starting point
Here's an example of the configuration:
- Access token TTL: 15 minutes
- Refresh token: 30 days, sliding window, one-time use
- Offline grace period (app-enforced): 24 hours past
exp - JWKS: fetched on first launch, refreshed weekly when online, with a bundled fallback
- Mandatory online check-in: every 7 days (refuse to operate offline beyond this)
Tighten the numbers for higher-sensitivity apps, loosen them for field-work apps where availability matters more than instant revocation.
Some further reading for you:
The short version: FusionAuth gives you all the primitives:
- asymmetric signing
- JWKS
- configurable lifetimes
- refresh token revocation
The offline policy is yours to design, and the design is mostly about choosing how much revocation lag you can tolerate in exchange for how much offline runway your users need.
-
D dan has marked this topic as solved