Ablaufdiagramm des Token-Refresh: App sendet Anfrage mit Access-Token an den Server, erhält die Fehlermeldung \"Token abgelaufen\", schickt daraufhin das Refresh-Token an den Anmeldedienst, bekommt ein neues Access-Token samt rotiertem Refresh-Token zurück und wiederholt damit die ursprüngliche Anfrage erfolgreich.

Token Refresh

Token refresh refers to the automatic renewal of an expired digital credential that an app uses to prove it is allowed to act on behalf of a logged-in user. This keeps you logged in without having to constantly re-enter your password.

When you log in to an online service, the service checks your password once. After that, your app receives back a long, random string of characters. This string is called a token, and it works like a wristband at a festival: whoever shows it is allowed in, without having to show identification again. For security reasons, though, such wristbands are only valid for a short time, often just a few minutes or hours. Token refresh is the process by which the app fetches a fresh wristband in the background, before or after the old one expires. You don’t notice any of this: you simply remain logged in.

Short validity as a safety net

Tokens are a popular target for attacks. Whoever steals a valid token can pose as you, without ever knowing your password. That’s precisely why tokens are deliberately made to expire quickly. A stolen token then becomes worthless after a short time, and the damage remains limited.

Without refresh, however, this short validity would be unbearable. You would have to log in again every fifteen minutes, in every app separately. Refresh resolves this conflict of goals: security through short lifespans, convenience through automatic renewal. This is the reason you don’t have to log in to your email program for months, even though new tokens are constantly flowing in the background.

A second advantage is control. The operator can refuse the renewal at any time, for example if a device has been reported stolen. At the next refresh attempt, the device gets kicked out. That’s exactly what happens when you click “Log out of all devices” in your account settings.

Two tokens with different jobs

When logging in, the app usually receives not one but two tokens. The first is called an access token and is sent along with every single request, for example when loading your messages. It is short-lived, often valid for only five to sixty minutes. The second is called a refresh token and has a single purpose: obtaining new access tokens.

The process is always the same. The app notices that the access token has expired, or the server responds with an error message. The app then sends the refresh token to a special address of the login service. It checks the token and sends back a fresh access token. The original request is then silently repeated, and you don’t notice anything.

Because the refresh token is valid for significantly longer, it is especially protected. It is never sent to regular servers, only to the login service. Many systems additionally work with rotation: with every refresh, the old refresh token becomes invalid and is replaced by a new one. If an already-used refresh token turns up again, that’s a strong sign of theft, and the service will, as a precaution, terminate all of that user’s sessions.

Where tokens are constantly renewed in everyday life

The mechanism becomes most visible when it fails. If an app suddenly asks you to log in again even though you haven’t changed anything, a refresh has usually failed. The message “Session expired” in online banking also belongs here. Banks deliberately set very short lifespans and often forgo a long-lived refresh altogether.

In the AI context, the term comes up especially with interfaces. Anyone who addresses a language model via a programming interface has to identify themselves with every request. Some providers work with a fixed API key for this, others with short-lived tokens plus refresh. For enterprise customers, the second approach is common, because it allows access to be controlled more finely and revoked more quickly.

A common misconception is to confuse token refresh with refreshing a web page. Both are colloquially called “refresh,” but they have nothing to do with each other. Nor does the term have anything to do with the tokens into which a language model breaks down text. Same word, two completely different meanings, which are nevertheless easy to tell apart in context.

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.