In May 2025, we merged a PR at Nango that had a crucial bug: an if circumstance that never fired prevented refreshed credentials from being saved to the database. We caught the bug and reverted it in fair under two hours.
In those two hours, our scheduled jobs had refreshed and abandoned admission and refresh tokens for hundreds of connections. For most APIs, that was recoverable: the old refresh token motionless worked, so the next scheduled refresh repaired the connection.
Then we learned how many providers rotate refresh tokens.

Many providers, including Airtable and Atlassian, invalidate the old refresh token the instant a replacement is issued. Salesforce and Slack can do the identical whenever rotation is enabled for the OAuth app.
There was no way to get those tokens back. For all affected connection, our customers had to ask their users to go through the consent display again.
OAuth is a standard, but OAuth providers are not interchangeable. Each API’s auth behaves a small differently, and several of those differences are undocumented and lone exterior in production.
For context, Nango is an open-source project that lets web applications and agents merge alongside third-party APIs. Our customers embed it in their products. Their users nexus third-party accounts, and Nango keeps those connections working.
Since then, we’ve grown from supporting concerning 400 APIs to 1,000+ APIs. The event changed how we run auth, but it was lone the archetypal of multiple lessons.
Lesson 1: Token rotation makes average bugs irreversible
Refresh token rotation is a safety win, but a bug in the rotation way can permanently demolish a association and power the person to reauthorize. That’s what made our event so expensive.
We now treat refresh tokens akin money, not cache. The new token gets persisted before item alternatively can fail. The persistence way has its own regression tests, and any platform-level refresh anomalies immediately leaf the on-call team.
Providers enforce refresh-token rotation differently
Take Airtable: a refresh petition alongside a old token or the incorrect client credentials can come back a 400 or 401, but Airtable doesn’t halt there. It revokes the user’s complete authority for your app, and the lone way rear is for the person to reconnect. Sending the identical refresh petition twice can additionally logic revocation. Airtable documents a abbreviated grace duration for copy refreshes, but retrying the old token following that duration revokes the authorization.
Airtable additionally invalidates the old admission token the instant a refresh succeeds, so a long-running job motionless using an old token can neglect mid-run.
Xero handles it better: if a refresh fails or the reply never arrives, you can retry alongside the former refresh token for up to 30 minutes.
Issues akin these pushed us to serialize refreshes per association rearward a distributed lock.

*This is lone the achievement path. Failure paths don’t fit in one diagram.
Even refreshing first can be wrong. For example, Exact Online’s admission tokens final for 10 minutes, and its token endpoint rejects any refresh attempt made additional than 30 seconds before expiry. Our “refresh 15 minutes early” regulation meant all refresh cut exterior that opening and was rejected. We had to add assistance for per-provider expiration buffers.
Lesson 2: You can’t reliably cognize whenever admission tokens expire
The authoritative OAuth 2.0 spec (RFC 6749) makes expires_in optional for admission tokens. For us, this has been a recurring origin of silent breakage.
Zendesk, for example, rolled out expiring admission tokens for OAuth clients, including existing ones. Its token reply includes expires_in only if you petition it. Without that parameter, the admission token motionless expires under the default policy, but the reply doesn’t say when. We discovered this lone following the rotating refresh token lapsed and connections started dying.
Salesforce’s token reply includes no expiry. The documented way to inspect it is a distinct self-examination endpoint, which we call before deciding whether to refresh an admission token.
POST /services/oauth2/introspect HTTP/1.1 Host: yourInstance.my.salesforce.com Authorization: Basic <base64 of client_id:client_secret> Content-Type: application/x-www-form-urlencoded token=<access_token>&token_type_hint=access_token
Sample response:
{ "active": true, "scope": "id api refresh_token", "exp": 1549921091, "iat": 1549917491, "token_type": "Bearer", "client_id": "xxxxxxxxxxxxxxxxxxxx" }
But in June 2024, the self-examination endpoint started intermittently returning unsupported_token_type for several tokens. When self-examination failed, we refreshed anyway. The replacement admission token could be introspected normally, although we never learned why the first token failed.
Refresh token lifetimes are fair as inconsistent
- NetSuite’s OAuth refresh tokens expire after 7 days, requiring complete re-consent, which is why many teams use its token-based authentication instead.
- Google’s refresh tokens live indefinitely, apart from under documented conditions, including the app being in “Testing” status, six months without use, or a person exceeding 100 live refresh tokens for your client.
We now refresh old credentials on a cron, so tokens get exercised before inactivity kills them.
Auth failures don’t continually appearance akin failures
You’d anticipate an auth nonaccomplishment to come back a 401. It frequently doesn’t:
- Zoho CRM’s token endpoint returns HTTP 200 alongside the error in the body.
- Workday and Dayforce come back no error at all whenever a approval guideline is missing; the API fair returns bare data.
- One SOAP-based API we assistance returns HTTP 200 for everything, including incorrect passwords.
- LastPass does the same, alongside the nonaccomplishment as plain content in the body. Our credential inspect for it exactly searches the reply for the cord “Authorization Error”.
We ended up construction per-provider heuristics: at the period of this analysis, 276 of the approximately 935 providers in our register declared an authenticated endpoint that Nango can call to inspect whether credentials motionless work.
Lesson 3: Providers create breaking changes to their API auth
16% of commits to our provider config are fixes. There’s no dependable nourish for provider auth changes; we frequently study concerning them from a unsuccessful stream or a client report.
Figma announced by email that credentials had to move from the petition build to a Basic Authorization header and that the OAuth presenter was changing. We shipped the update, but anyone who missed the email power not detect the alter until refreshes commencement failing.
Shopify changed how offline tokens are issued, so apps began receiving expiring tokens anywhere they earlier didn’t. We shipped a config change to maintain the old behavior.
Lesson 4: Sometimes you build about the provider, not alongside it
Supporting a new API assumes two things: you can get credentials to test with, and you can discover exact docs for how its auth works. At our scale, the two assumptions neglect frequently adequate that going about the provider is routine:
- Salesforce Data Cloud is separately provisioned, and none of our test orgs included it. Its auth requires two chained token exchanges against distinct hosts. We built a imitate server from the documented responses so we could execute and test the stream without live credentials.
- LastPass’s API isn’t really REST: nearly all procedure hits the identical URL, alongside the act passed in the petition body. That bankrupt an assumption in our proxy that all integration would define idiosyncratic endpoints, so we added assistance for APIs alongside lone a basis URL.
- A community associate established the resolution to a recurring Asana OAuth error (client_id is missing or invalid) in Asana’s assistance forum and added it to our docs. It wasn’t covered in Asana’s own docs.
- Read.ai’s documented authority URL pointed at their inner developer-testing page. The genuine endpoint came from querying their OpenID finding endpoint directly.
If you build an API, ten requests
API clients would neglect small frequently if providers did these ten things:
- Return expires_in. Always, in seconds.
- If you rotate refresh tokens, regard a short, bounded grace duration for the former token, akin Xero’s 30 minutes. This absorbs copy refreshes at the disbursal of weaker replay finding during that window.
- Return additional particular errors than fair invalid_grant. Revocation, guideline failure, expired token: say which one it was in the error body.
- Treat auth changes as breaking API changes. Version them, province them, and don’t use them retroactively to existing clients.
- Document your revocation triggers. Password resets, per-user token caps, and inactivity windows.
- Offer several way to test against your API without a revenue call (even for paid apps).
- Keep your auth records community and accurate.
- Make 200 average success. If your API returns 200 OK alongside an error in the body, no generic client can inform it’s damaged without special-casing your responses.
- Prefer accepted behavior whenever the specification leaves area for interpretation.
- If REST is your contemporary API, create it the origin of truth. Don’t depart essential functionality lone in SOAP or WSDL files.
Our provider register is community in a sole YAML file if you desire to inspect the details.