Why OAuth token rotation breaks integrations and how to handle it
Nango engineers share lessons from managing auth for over 1,000 APIs, highlighting risks of token rotation, inconsistent expiry data, and silent failures.
In May 2025, a critical bug in Nango’s codebase caused the loss of hundreds of user connections across multiple third-party APIs. The incident occurred when a faulty conditional statement prevented refreshed credentials from saving to the database, leading to the discard of valid tokens. This event exposed the fragility of OAuth implementations at scale and forced the team to rethink how they manage authentication for over 1,000 integrated APIs.
What happened
The root cause was a merged pull request containing an if condition that never executed. For nearly two hours, scheduled jobs refreshed access and refresh tokens but failed to persist the new credentials. While many providers allow the use of old refresh tokens to recover from such errors, several major platforms do not. Providers like Airtable and Atlassian invalidate the old refresh token immediately upon issuing a new one. Salesforce and Slack behave similarly when token rotation is enabled.
Because the new tokens were lost and the old ones invalidated, there was no programmatic way to restore these connections. Customers had to ask their end users to manually re-authorize every affected account. This incident highlighted that while OAuth is a standard protocol, provider implementations vary significantly. Many of these differences are undocumented and only become apparent during production failures. Since then, Nango has expanded its support from roughly 400 APIs to more than 1,000, applying hard-learned operational lessons to each new integration.
How it works
Token rotation is designed to enhance security by limiting the lifespan of refresh tokens, but it introduces significant operational risk. If a bug interrupts the rotation process, the connection can be permanently broken. Nango now treats refresh tokens as critical financial assets rather than disposable cache entries. New tokens are persisted before any other operations occur, and the persistence path includes dedicated regression tests. Any anomalies in platform-level refreshes trigger immediate alerts for the on-call team.
Different providers enforce rotation rules with varying degrees of strictness. Airtable, for instance, revokes entire app authorizations if a stale token is used or if a refresh request is duplicated outside a short grace period. It also invalidates old access tokens instantly upon successful refresh, which can break long-running jobs. In contrast, Xero allows retries with the previous refresh token for up to 30 minutes if a failure occurs. To manage these discrepancies, Nango serializes refresh requests per connection using distributed locks and implements per-provider expiration buffers to avoid rejecting early refresh attempts.
Key details
- Token rotation bugs can permanently destroy connections if providers invalidate old refresh tokens immediately, requiring manual user re-authorization.
- Access token expiry data is unreliable because the OAuth 2.0 spec makes the
expires_infield optional, leading to silent breakage with providers like Zendesk and Salesforce. - Auth failures often return HTTP 200 status codes with error messages in the body, as seen with Zoho CRM, Workday, and LastPass, complicating automated error detection.
- Providers frequently make breaking changes to authentication flows without clear announcements, such as Figma moving credentials to Basic Authorization headers.
- Some APIs require workarounds like mock servers or custom parsing because their documentation is inaccurate or their structure deviates from standard REST patterns.
- Nango maintains a public provider registry in a single YAML file to track these specific behavioral nuances across its supported integrations.
Why it matters
For engineers building software that integrates with third-party services, assuming uniform OAuth behavior is a dangerous mistake. The inconsistency in how providers handle token expiry, rotation, and error reporting means that generic client libraries often fail in subtle ways. Silent failures, where an API returns a success status code despite an authentication error, can lead to data corruption or empty responses that are difficult to debug. Understanding these provider-specific quirks is essential for building resilient integration layers that do not degrade user experience during routine maintenance or minor outages.
Furthermore, the lack of standardized testing environments and accurate documentation forces development teams to build complex workarounds. When providers change authentication endpoints or requirements without treating them as breaking API changes, existing integrations break unexpectedly. This increases the maintenance burden on engineering teams, who must constantly monitor for changes and update their configurations. Recognizing that auth logic is as critical as business logic helps prioritize robust error handling, retry mechanisms, and comprehensive monitoring for external dependencies.
What you can do
- Treat refresh tokens as critical state that must be persisted atomically before any network calls complete, ensuring no token is lost during rotation.
- Implement per-provider configuration for token expiration buffers and retry windows to accommodate strict providers like Exact Online and Airtable.
- Build heuristics to detect auth failures in non-standard responses, such as checking response bodies for error strings when HTTP status codes are 200.
- Serialize token refresh requests per connection using distributed locks to prevent race conditions and duplicate requests that might trigger revocation.
- Monitor provider documentation and changelogs actively, as auth changes are often announced via email or support forums rather than formal API versioning.
- Use introspection endpoints where available to verify token validity, but implement fallbacks for when these endpoints fail or return unsupported errors.



