Mobile sales integration fails to refresh Salesforce REST API tokens

Our mobile sales team is experiencing constant logouts from the Salesforce mobile app during field visits. The OAuth refresh token process appears to be failing intermittently, causing major disruptions to our sales operations.

The issue started after we updated our OAuth refresh token scope configurations last week. Users are being forced to re-authenticate multiple times per day, which is unacceptable when they’re meeting clients. I’ve checked our session timeout settings in Setup, and they’re set to 2 hours with refresh token valid for 90 days.

Here’s the error we’re seeing in the mobile app logs:


HTTP 401: invalid_grant
refresh_token expired or revoked
OAuth token refresh failed at 2025-03-14T08:45:12Z

I suspect the mobile app isn’t storing the refresh tokens properly between sessions, or there’s a mismatch in our OAuth scope configuration. Has anyone dealt with mobile token storage issues in Summer '25? Our field sales productivity has dropped significantly, and we need a reliable solution fast.

Let me provide a comprehensive solution addressing all three key areas: OAuth refresh token scope, session timeout settings, and mobile app token storage.

OAuth Refresh Token Scope Configuration: Navigate to your Connected App settings and verify the OAuth scopes include both ‘refresh_token’ and ‘offline_access’. The offline_access scope is critical for mobile apps to maintain authentication across app restarts and device sleep cycles.

Refresh Token Policy Fix: Your current 1-day expiration is causing the constant logouts. Here’s the recommended configuration:


Setup > Connected Apps > Your Mobile App
OAuth Policies > Refresh Token Policy:
- Set to "Refresh token valid for 90 days"
- Enable "Rotate refresh token on use"

This gives mobile users sufficient validity while maintaining security through token rotation.

Session Timeout Alignment: Go to Setup > Session Settings and configure:

  • Session timeout: 4 hours (longer than current 2 hours for field work)
  • Disable timeout warning: Unchecked (gives users warning before expiration)
  • Force logout on session timeout: Unchecked for mobile profiles

For mobile-specific profiles, create a custom session setting that’s more lenient than desktop users.

Mobile App Token Storage: If you’re using Salesforce Mobile SDK, the token storage should be handled automatically via platform-specific secure storage (iOS Keychain/Android Keystore). However, verify these implementation points:

  1. Token Refresh Logic: Ensure your app implements proactive token refresh before expiration:

// Check token expiry 5 minutes before actual expiry
if (tokenExpiryTime - currentTime < 300000) {
  refreshOAuthToken();
}
  1. Background Refresh: Enable background token refresh in your mobile app configuration to handle refreshes even when app is backgrounded.

  2. Error Handling: Implement proper retry logic for failed refresh attempts with exponential backoff.

IP Restriction Configuration: For mobile users, you have two options:

  • Option A: Disable IP restrictions entirely for the mobile Connected App
  • Option B: Implement “Relax IP restrictions” for mobile user profiles (Setup > Profiles > Session Settings)

I recommend Option B as it provides better security while accommodating mobile users.

Verification Steps:

  1. Update Connected App refresh token policy to 90 days
  2. Add ‘offline_access’ to OAuth scopes if missing
  3. Extend session timeout to 4 hours for mobile profiles
  4. Enable IP relaxation for field sales profiles
  5. Test with a pilot group of field users for 48 hours
  6. Monitor OAuth token refresh events in Event Monitoring

Monitoring and Validation: Enable Event Monitoring for OAuth tokens and watch for these events:

  • LoginAs events (indicates forced re-authentication)
  • OAuth Token Refresh events (should show successful refreshes)
  • Session hijacking events (validates security isn’t compromised)

After implementing these changes, your mobile users should maintain persistent authentication throughout their workday without forced logouts. The combination of extended refresh token validity, proper scope configuration, and relaxed IP restrictions for mobile profiles will resolve the field sales disruption while maintaining reasonable security controls.


This draft is based on general Salesforce knowledge. It has not been verified against your specific version and environment. Practitioners: verify the steps and share your experience below.

I’ve seen this exact issue with mobile implementations. The 401 invalid_grant error typically means your refresh token is being invalidated prematurely. First thing to check: are you using the ‘refresh_token offline_access’ scope in your Connected App? Without offline_access, tokens won’t persist across app restarts. Also verify your Connected App’s refresh token policy isn’t set to ‘Refresh token is valid until revoked’ with IP restrictions that might conflict with mobile IPs.

Check your mobile app’s token storage implementation. If you’re using standard iOS Keychain or Android Keystore, tokens should persist. However, if your app clears cache aggressively or users have battery optimization enabled, the secure storage might get wiped. I’ve also seen cases where background app refresh being disabled causes the token refresh to fail silently. What mobile platform are you on, and are you using the Salesforce Mobile SDK or a custom implementation?

“Confirmed this resolves the token expiration loop — adding ‘offline_access’ scope to our Connected App alongside extending refresh token policy beyond 1 day eliminated the mobile logouts entirely.”

We’re using the Salesforce Mobile SDK for both iOS and Android. The Connected App does have ‘refresh_token offline_access’ in the scope, but I just noticed the refresh token policy is set to expire after 1 day instead of the standard setting. Could that be causing the premature expirations? Also, our IP relaxation settings might be too restrictive for mobile users who are constantly changing locations. I’ll test with a longer refresh token validity period and relaxed IP restrictions.

That 1-day refresh token expiration is definitely your culprit. For mobile field users, you should set it to at least 30-90 days or ‘until revoked’. The constant location changes combined with short token validity creates a perfect storm. Also, make sure your session timeout settings align with your refresh token policy. If session timeout is 2 hours but refresh tokens expire daily, users working longer shifts will hit authentication walls. I’d recommend testing with ‘Refresh token is valid until revoked’ for mobile users first, then implement proper token rotation if security requires shorter validity.

Before you extend token validity to ‘until revoked’, consider the security implications. Mobile devices are more prone to loss or theft. A better approach is to use 30-day refresh tokens with proper token rotation and implement device fingerprinting. Also enable OAuth token audit trails in Event Monitoring so you can track token usage patterns and identify suspicious refresh attempts.

I want to add one more critical point about IP restrictions with mobile users. If your Connected App has IP restrictions enabled, mobile field users will constantly fail authentication as they move between cell towers and WiFi networks. For mobile deployments, you should either disable IP restrictions entirely or use a whitelist approach with VPN requirements instead.