OAuth Token Refresh Issues

The Problem

Your OAuth-authenticated data source randomly disconnects, requiring manual re-authorization, despite refresh tokens being configured.

Symptoms

  • ❌ "Authentication expired" after 1 hour

  • ❌ Sync works, then fails days later with 401 errors

  • ❌ "Refresh token invalid" despite recent setup

  • ❌ Must re-authorize every week

  • ❌ Token refresh succeeds but still get 401 errors

Real-World Example

Google Drive connected via OAuth
Day 1: Syncs perfectly
Day 7: "401 Unauthorized - Invalid credentials"

Logs show:
✓ Access token expired (expected after 1 hour)
✗ Refresh token request failed: "invalid_grant"
✗ Stored refresh token: null (disappeared?)

User must: Disconnect and reconnect integration

Deep Technical Analysis

OAuth 2.0 Token Lifecycle

OAuth uses two tokens with different lifespans:

Access Token (short-lived):

Refresh Token (long-lived):

The Refresh Token Rotation Problem:

Storage Race Condition:

OAuth scopes determine token longevity:

Online vs Offline Access:

Incremental Authorization:

Consent Screen Re-prompts:

Refresh Token Revocation

Tokens can be revoked externally:

User-Initiated Revocation:

Admin-Initiated Revocation:

Automatic Revocation (security):

Token Storage Security vs Availability

Refresh tokens are sensitive credentials:

Storage Requirements:

The Encryption Key Rotation Problem:

Client ID and Secret Management

OAuth requires client credentials:

The Client Secret Problem:

Per-Customer OAuth Apps:

Token Expiry vs Actual Invalidity

Token expiry times aren't always accurate:

The Early Expiration Problem:

Preemptive Refresh:

Lazy vs Eager Refresh:


How to Solve

Request access_type=offline + handle refresh token rotation by updating stored token + implement preemptive refresh (10 min buffer) + gracefully handle revocation with reauth prompt. See OAuth Configurationarrow-up-right.

Last updated