DEV Community

Cover image for Tokens expire quietly
Jonas Nguyen
Jonas Nguyen

Posted on Originally published at jonasnguyen.com

Tokens expire quietly

Connecting an account is the part everyone tests. You sign in, you post, it works, you ship. The failure comes later — 30 or 60 days later — when nobody is watching.

How I found it

Threads gives an app a long-lived token that lasts 60 days. While planning something unrelated, I noticed nothing in Clienzo ever refreshed it. The first customers had connected Threads in early September, which meant their connections would stop working in early November. No error, no warning — scheduled posts would simply start failing.

Later, approving Pinterest, I found the same thing there with 30-day tokens. Those connections were already dead.

The fix

A daily job now goes through every connection:

  • if a token has 30 days or less left and is at least a day old, it is refreshed;
  • if the network says the token is no longer valid, the connection is marked expired and the owner gets a notification to reconnect;
  • any other error is left alone and tried again the next day, so a network having a bad day cannot disconnect anyone.

Each network gets its own small refresher, so adding one is a few lines, not a new job. Tumblr's tokens, which last well under an hour, are refreshed just before publishing instead, with a lock so two posts going out at once do not both try to refresh the same token.

The lesson

Every integration has a clock on it. When I add a network now, "how long does the token last, and what refreshes it" is a question I answer on day one, not day 59.

Next in this series: the four days no email left Clienzo, and how I found out.


Originally published on jonasnguyen.com, where I write about building Clienzo and the next startups.

Top comments (1)

Collapse
 
onelifevibe profile image
OneLifeVibe •

The quiet failure is what stuck with me. A connection that works on day one and then silently stops in early November is much harder to catch than a loud error at sign in. I liked the restraint in the fix too, especially retrying other errors the next day instead of disconnecting someone over a bad network day, and treating the token lifetime as a day one question for each new network.