· Security

A token that expires every 60 days

The access token behind one of my workflows expires on September 17, and nothing I run can renew it. Why some OAuth tokens can only be renewed by a person at a browser, and what that kind of credential needs around it.

The access token that lets one of my workflows post to LinkedIn expires on Thursday, September 17. I know the date because I authorized the application on July 19 and LinkedIn access tokens last 60 days. Nothing I run can renew it. Somebody has to sit at a browser and authorize the application again, and that somebody is me, every 60 days for as long as the workflow exists.

I found this out the slow way. The workflow is the pipeline I have written about twice this summer. Every four hours it reads a set of news feeds, has a model choose and draft one item, and publishes a short post. In July I wrote that after I replaced a retired model ID, the pipeline published once and then "stopped at its final step for an unrelated reason." This is the reason.

The run on the night of July 17 published. By July 19 every run was failing at the last step, the one that calls LinkedIn, with an error from the workflow tool: refreshToken is required. Everything before that step was passing. The workflow has 32 steps and 31 of them were healthy, including every feed and both model calls. I give the count because a pipeline that has been broken three different ways in one week invites you to take the whole thing apart again, and here the error message had already named the one thing that was wrong.

The error makes sense once you know how the renewal is supposed to work. In OAuth 2.0 an application acts for a user by presenting an access token, and access tokens are meant to run out. The standard, RFC 6749, says that tokens "represent specific scopes and durations of access." So that an application can carry on after a token runs out without sending the user back to a consent screen, the standard provides a second credential, and defines it in one line: "Refresh tokens are credentials used to obtain access tokens." The sentence after that is the one I had never taken in: "Issuing a refresh token is optional at the discretion of the authorization server."

My workflow tool supports refresh tokens. When an access token expires, the tool presents the refresh token, receives a new access token and continues, with no person involved. That is what it tried to do on July 19. It had nothing to present, because LinkedIn had never issued one for my application.

LinkedIn documents this clearly, and I had not read it. On access tokens, the documentation says: "Currently, all access tokens are issued with a 60-day lifespan." On renewal: "Programmatic refresh tokens are available for a limited set of partners." The page for the feature opens by saying they are supported "for all approved Marketing Developer Platform (MDP) partners." An application that one person registered to post to his own feed is outside that set. For everyone outside it, the documented way to renew is to "go through the authorization process again," which means a browser and a signed-in member.

Renewing an access token with and without a refresh token
With a refresh token

The authorization server chose to issue one

On expiry the tool presents it and receives a new access token

No person is involved

Without a refresh token

LinkedIn issues them to a limited set of partners

On expiry the tool has nothing to present and the last step fails

I authorize the application again at a browser every 60 days

I authorized the application on July 19 and LinkedIn access tokens last 60 days, so this one expires on September 17.

So the credential in my workflow had an end date from the moment it was created. The date was no secret. The response that delivers the token includes an expires_in field holding the number of seconds the token has left, and LinkedIn's sample response shows 5,184,000, which is 60 days. I did not write the date down anywhere.

On July 19 I reconnected the credential by hand and the posts resumed. Sixty days from July 19 is September 17.

In February I wrote about the difference between a certificate that has expired and one that has been revoked. This token is the expired kind. Its end date was fixed on the day it was issued, and nothing has gone wrong with it. In July I said the same about a retired model ID. That makes three times this year I have written about a failure with a published date, and two of the failures were mine.

A 60-day credential is harder to live with than a yearly certificate, and the interval is why. A certificate that expires once a year gets a calendar entry and usually a ticket. A token that expires six times a year, where each renewal needs one particular person and a browser, tends to get neither, because no single lapse looks important enough to build a process around.

The failure is also quiet. When this token lapses, the feeds are still read, the model is still called, the draft is still written, and then the last step fails. Nobody is waiting for the post, so nobody complains when it does not appear. I described that problem in July and it applies here without changes.

Here is where I stand today. I have the date. In July I noted that this credential needed a warning ahead of its expiry, based on its age. I have not built that warning. This week the control is me reading my own notes, which is a control with a poor record.

What I would put around any credential of this kind:

Record the expiry when the token is issued. The token response tells you how long you have. Store the date next to the credential, in a system that can send an alert.

Alert early enough for a person to act. The renewal cannot be automated, so the warning has to arrive while the person who can do it has a free hour on a working day. A warning on the day of expiry only tells you why the thing is about to break.

Alert on the missing output as well. An expiry warning covers the failure you predicted. A check that says "this workflow has not published anything in a day" covers the ones you did not predict. Since the rebuild I described in August, every post leaves a row in a database table, so "no new row in 24 hours" is one query.

Keep a list of every credential that needs a person. Each one is a recurring task assigned to a named human. If that human is on vacation in the renewal week, the integration stops. In a company, the list belongs to whoever owns each integration, and the security team should want to see it. The pressure these credentials create runs toward shared logins and requests for longer-lived tokens, and both are worse than the chore.

Know what the renewal involves before the day comes. Which account signs in, from which browser, and what address the provider will redirect back to.

I do not think the 60-day limit is unreasonable. A token that can publish under my name should not live forever, and the provider's own documentation gives that as the reason: "To protect members' data, LinkedIn does not generate long-lived access tokens." The short life is a security control and it is doing its job. Knowing the date is my job.

One caveat. I run a second copy of this pipeline that is meant to post to a company page for one of my side businesses. It has never posted. Its credential holds no token at all, which is a different problem from an expired one, and renewing on Thursday will do nothing for it.

Views are my own.