Refresh Token Grant in OAuth 2.0

The Refresh Token Grant in OAuth 2.0

How apps quietly stay logged in for weeks or months without ever asking you to type your password again — and how that convenience is kept safe.

Think about a magazine subscription. You do not re-verify your identity and re-enter your payment details every single time a new issue arrives in your mailbox. You proved who you were once, and the publisher gave you a renewable subscription card that keeps working, issue after issue, until it eventually needs to be renewed or is cancelled. The Refresh Token Grant in OAuth 2.0 works on almost the same principle. It is the quiet mechanism that lets an app stay connected to your account for weeks or months, without repeatedly interrupting you to log in again every time your short-lived access token expires.

1The Problem: Short-Lived Tokens Are Deliberately Short

To understand why refresh tokens exist, it helps to remember why access tokens are made to expire so quickly in the first place.

Access tokens, the credentials an app presents to prove it has permission to act on your behalf, are intentionally designed to have a short lifespan, often as little as fifteen minutes to an hour. This is a deliberate security choice, not an oversight. If an access token is ever accidentally exposed, through a logging mistake or a network eavesdropper, a short lifespan limits how long that leaked token remains useful to an attacker.

Simple Analogy

Think of an access token like a self-erasing visitor sticker at an office building. It works perfectly while it lasts, but the ink fades to nothing after a couple of hours, so even if someone found a discarded sticker, it would already be useless. The problem this creates is obvious: if you are a legitimate, regular visitor, you do not want to walk back to the front desk and prove your identity again every single hour.

Without some additional mechanism, a short-lived access token would force the user to log in again, repeatedly, throughout the day, which would be exhausting and would push developers toward the unsafe temptation of simply making tokens last much longer instead. The Refresh Token Grant exists precisely to resolve this tension: it lets access tokens stay short and safe, while still giving the user a smooth, uninterrupted experience over long periods of time.

i
Not a Standalone Login Method

The Refresh Token Grant is never the very first way an app gets access. It always follows an earlier grant, most commonly the Authorization Code Grant, which is the one that originally produces the refresh token alongside the first access token.

2What Exactly Is a Refresh Token?

A refresh token looks similar to an access token on the surface — a long random string — but its purpose is completely different.

A refresh token is a special-purpose credential issued by the Authorization Server, alongside the access token, at the end of an initial login. Unlike the access token, a refresh token is never sent directly to a Resource Server to fetch actual data. Its one and only job is to be exchanged, later, for a brand-new access token, without requiring the user to log in and approve anything all over again.

Simple Analogy

If the access token is the self-erasing visitor sticker, the refresh token is the small plastic membership card the front desk keeps on file for you. You cannot use the membership card itself to walk through any secured doors. You can only show it at the front desk to get a fresh, working sticker printed, without needing to show your original identification documents again.

Access Token

Short-lived, used directly

Presented on every single API request. Expires quickly, typically within minutes to a couple of hours.

Refresh Token

Long-lived, used rarely

Presented only to the Token Endpoint, only when a new access token is needed. Can remain valid for days, weeks, or months.

Because a refresh token lives so much longer than an access token, it is, in a very real sense, more valuable and more dangerous if stolen. A stolen access token is only useful for a short window. A stolen refresh token could potentially be used to mint new access tokens over and over, for as long as it remains valid — which is exactly why, as later chapters will explain, refresh tokens are handled with significantly more caution than access tokens.

3Where Does the Refresh Token Come From?

The Refresh Token Grant does not stand alone. It is best understood as the second half of a longer story that begins with an earlier login.

A refresh token is not requested on its own out of thin air. It is issued as a side effect of an earlier, successful authorization flow, most commonly the Authorization Code Grant covered in an earlier tutorial. When a user first logs in and approves an application, the Authorization Server’s response to the initial token exchange typically includes not just an access token, but also a refresh token, provided the app requested the right permission (commonly signaled through a special scope, often named something like “offline_access”).

!
Not Every App Automatically Gets One

Some Authorization Servers only issue a refresh token if the Client explicitly asks for long-term, offline access, and some deliberately withhold refresh tokens from certain kinds of apps, such as browser-based single-page apps, because of the extra risk of storing a long-lived secret in a browser.

Once that first refresh token exists, the Refresh Token Grant becomes the recipe for everything that happens afterward: whenever the current access token is about to expire, or has already expired, the Client quietly uses the stored refresh token to request a new access token, without ever needing to redirect the user’s browser back through the login and consent screen again.

4The Flow, Step by Step

This chapter walks through what happens the moment an access token runs out, and how the app quietly recovers without bothering the user.

1

Client Notices the Access Token Has Expired

Either the Client tracks the token’s known expiration time in advance, or it simply tries a normal API call and receives an “expired token” error back from the Resource Server.

2

Client Retrieves Its Stored Refresh Token

The Client’s backend reads the refresh token it saved securely from the original login, without needing any input from the user at all.

3

Client Sends the Refresh Token to the Token Endpoint

This request goes directly and privately from the Client’s backend server to the Authorization Server’s Token Endpoint, exactly as the original code exchange did — the user’s browser is not involved.

4

Authorization Server Validates the Refresh Token

The server checks that the refresh token is genuine, has not expired, has not been revoked, and truly belongs to the Client presenting it.

5

A Fresh Access Token Is Issued

The Authorization Server responds with a brand-new access token, ready to be used immediately for the next API call, with the same or a narrower set of permissions as before.

6

Often, a New Refresh Token Is Issued Too

Many modern Authorization Servers also return a brand-new refresh token in the same response and immediately invalidate the old one, a safety pattern known as refresh token rotation, covered in detail shortly.

7

Client Resumes Normal Operation

The Client retries or continues its original API call using the fresh access token, and the user never sees any of this happen — no redirect, no login prompt, no interruption.

i
Completely Invisible to the User

Unlike the Authorization Code Grant, which always involves a visible browser redirect and a consent screen, the Refresh Token Grant happens entirely in the background, on a private server-to-server channel, with no browser involvement whatsoever.

5Seeing the Whole Flow as a Diagram

This diagram shows how the Refresh Token Grant fits in as a quiet, repeating loop that follows the original login.

sequenceDiagram
    participant C as Client (Backend)
    participant A as Authorization Server
    participant R as Resource Server

    Note over C,A: Earlier: user logged in once via Authorization Code Grant
    A->>C: Initial access token + refresh token issued

    C->>R: Call API with access token
    R->>C: Token expired

    C->>A: Send refresh token to Token Endpoint
    A->>A: Validate refresh token
    A->>C: New access token (and often a new refresh token)

    C->>R: Retry API call with new access token
    R->>C: Return protected data
        
FIG 1 — The refresh cycle repeats quietly, in the background, for as long as the refresh token remains valid.

Notice that the top of the diagram — the original login — only needs to happen once. Everything below that note can repeat silently, potentially dozens or hundreds of times over the life of a long user session, all without the user ever seeing a login screen again, as long as the refresh token keeps being renewed before it, too, eventually expires or is revoked.

6Refresh Token Rotation: A Key Safety Upgrade

Older systems reused the same refresh token indefinitely. Modern best practice replaces it with a fresh one on every use — here is why.

In the simplest possible design, a single refresh token could be issued once and reused forever, every time an access token needed renewing, until it eventually expired on its own. The trouble with that design is that if that one long-lived refresh token were ever stolen, an attacker could use it just as freely and for just as long as the legitimate app could, with no easy way for the system to tell the two apart.

Simple Analogy

Refresh token rotation is like a hotel key card system that reprints your card every time you use it at your room door, instantly deactivating the previous version of the card. If someone ever copies an old, already-replaced card, it simply will not work anymore — and, even more usefully, the front desk can notice that an old, dead card was just attempted and immediately suspect something is wrong.

With refresh token rotation, every single time a refresh token is used to obtain a new access token, the Authorization Server also issues a brand-new refresh token and immediately invalidates the one that was just used. This has two powerful benefits. First, a stolen but unused refresh token has a much smaller window of usefulness, since legitimate use will naturally rotate it away. Second, and just as importantly, if a stolen refresh token is ever actually used by an attacker, and the legitimate app later tries to use what is now an outdated, already-rotated token, the Authorization Server can detect this reuse of an invalidated token as a strong signal of theft and revoke the entire token family immediately.

!
Reuse Detection Is the Real Payoff

The security value of rotation comes specifically from detecting when an already-replaced refresh token gets used again — that single event is one of the clearest possible signs that a copy of the token has fallen into the wrong hands.

7Where Should a Refresh Token Be Stored?

Because a refresh token is so long-lived and powerful, where it is kept matters enormously.

Best

Trusted Backend Server

Stored in a secure database or server-side session, never sent to the browser at all. This is the safest possible location, available to traditional web applications.

Good, With Care

Secure, Restricted Cookie

A cookie marked so it cannot be read by page scripts and is only sent over encrypted connections, reducing exposure even though it technically lives in the browser.

Acceptable for Native Apps

Operating System Secure Storage

Mobile and desktop apps can use the device’s built-in secure credential storage, which is isolated from other apps and protected by the operating system.

Risky

Browser Script-Accessible Storage

Ordinary storage that any script running on the page can read is the least safe option, since a single unrelated security flaw elsewhere on the page could expose the token.

This is exactly why many Authorization Servers are cautious about handing a refresh token directly to a pure single-page browser application at all, since that kind of app has no truly private place to keep a long-lived secret. A common, safer pattern instead routes the refresh step through a small trusted backend the single-page app talks to, so the refresh token itself never has to touch the browser.

8Advantages and Trade-offs

Advantages

  • Access tokens can stay short-lived and safe, without sacrificing a smooth user experience.
  • Users are not repeatedly interrupted with login prompts throughout a long session.
  • Access can be individually and immediately cut off by revoking a single refresh token, without touching the user’s real password.
  • Rotation adds a built-in theft-detection mechanism at essentially no extra cost to legitimate users.
  • It works well across web apps, mobile apps, and desktop apps, as long as storage guidance is followed.

Disadvantages / Trade-offs

  • A refresh token is a more valuable target than an access token, simply because it lives so much longer.
  • Implementing rotation correctly, including reuse detection, adds meaningful backend complexity.
  • Some client types, particularly pure browser-based single-page apps, have no fully safe place to store a refresh token.
  • If a device is lost or a session is compromised, an unrevoked refresh token can allow silent, ongoing access until it is explicitly cut off.

9Best Practices and Common Mistakes

ANTI-PATTERN-01 Avoid
Problem

Issuing a single refresh token that is reused forever, with no rotation and no expiration at all.

Why It’s Harmful

A never-expiring, never-rotated refresh token becomes an extremely attractive, permanent target, and there is no way to detect or contain theft if it is ever copied.

Correct Approach

Rotate the refresh token on every use, set a reasonable maximum lifetime even for the whole rotating chain, and build in reuse detection to catch stolen tokens quickly.

ANTI-PATTERN-02 Avoid
Problem

Storing a refresh token in the same easily-readable location as other, less sensitive application data, such as plain browser storage accessible to any script.

Why It’s Harmful

This treats a long-lived, high-value credential with the same casualness as harmless, disposable settings, making it an easy target for any script-based vulnerability elsewhere on the page.

Correct Approach

Store refresh tokens using the strongest storage option available for the platform, such as a trusted backend, a restricted secure cookie, or the operating system’s secure credential storage.

ANTI-PATTERN-03 Avoid
Problem

Giving users no visible way to see or revoke long-lived sessions and connected devices.

Why It’s Harmful

Without visibility, a user who loses a device, or who simply wants to clean up old app access, has no practical way to shut down a lingering refresh token that could otherwise keep working indefinitely.

Correct Approach

Provide an account settings page listing active sessions or connected applications, each with a clear option to revoke access immediately.

10Real-World Examples You Have Probably Already Used

Staying Logged Into a Mobile App for Weeks

Opening a familiar mobile app days after your last visit and finding yourself still logged in, with no password prompt, is almost always the Refresh Token Grant quietly renewing your access in the background.

Background Sync Tools

A file-syncing or backup application that keeps working overnight, uploading new files without you sitting in front of it, relies on a stored refresh token to keep minting fresh access tokens as older ones expire.

“Remember Me” on Websites

A website that keeps you signed in across browser restarts, sometimes for a month or more, is typically using a securely stored refresh token behind the scenes rather than simply extending the life of the access token itself.

Connected Third-Party Integrations

A calendar-scheduling tool or an analytics dashboard that continues pulling in your data days after you connected it, without ever asking you to reconnect, depends on the refresh token it received during your original approval.

11How It Fits Alongside Other OAuth 2.0 Grant Types

Grant TypeRole in the Bigger PictureProduces a Refresh Token?
Authorization Code (+ PKCE)The original login step that typically produces the first refresh tokenOften, if requested and permitted
Device AuthorizationAn alternative original login step for input-constrained devicesOften, if requested and permitted
Refresh TokenThe quiet renewal step that follows either of the above, repeated as neededFrequently, when rotation is enabled
Client CredentialsServer-to-server access with no individual user; typically has no meaningful concept of a refresh tokenRarely, since new tokens can simply be requested again directly

This table highlights something worth remembering: the Refresh Token Grant is not a competing alternative to flows like the Authorization Code Grant. It is a companion that comes after them, extending the useful life of whatever access was originally granted, without needing to repeat the original login experience.

12Frequently Asked Questions

Q1Can a refresh token itself expire?

Yes. Most Authorization Servers set a maximum lifetime for refresh tokens, sometimes tied to a period of inactivity, after which the user must go through the full original login flow again.

Q2What happens to old access tokens once a new one is issued?

Older access tokens are simply left to expire naturally on their own short timers; the refresh process does not typically need to actively revoke them, since they will stop working on their own within minutes to hours regardless.

Q3Does refreshing a token ever require the user to do anything?

No, under normal conditions the entire refresh exchange happens silently between the Client’s backend and the Authorization Server. The user is only asked to log in again if the refresh token itself has expired, been revoked, or is rejected for some other reason.

Q4Why do some apps still log me out after a while, even with refresh tokens?

This is usually an intentional security policy, such as a maximum session length or periodic mandatory re-authentication, rather than a flaw in the refresh mechanism itself; many services balance convenience against risk by capping how long even a rotating refresh token chain can continue.

Q5Is a refresh token the same thing as a “remember me” cookie?

They serve a similar convenience goal but are technically different mechanisms; a refresh token is a formal part of the OAuth 2.0 token exchange used to mint new access tokens, while a “remember me” cookie is often a simpler, application-specific session mechanism, sometimes built on top of a refresh token behind the scenes.

13Summary and Key Takeaways

The Refresh Token Grant is the quiet, background partner that makes short-lived access tokens practical in everyday life. Rather than forcing a trade-off between security and convenience, it lets access tokens stay deliberately short and safe, while a separate, more carefully guarded refresh token silently renews access behind the scenes. Modern best practice strengthens this further with rotation, replacing the refresh token on every use and treating any reuse of an old one as a clear sign of theft. Understood this way, the Refresh Token Grant is not a separate login method at all — it is the mechanism that lets one good login keep paying off, safely, for a long time afterward.

Key Takeaways

  • Solves the short-token problem — lets access tokens stay short-lived and safe without interrupting the user constantly.
  • Always follows an earlier login — refresh tokens are issued alongside the first access token, not requested on their own.
  • Entirely invisible to the user — the whole exchange happens privately between the Client’s backend and the Authorization Server.
  • Rotation adds theft detection — issuing a new refresh token on every use, and flagging reuse of an old one, catches stolen tokens quickly.
  • Storage location matters enormously — a trusted backend or secure device storage is far safer than plain browser-accessible storage.
  • Revocable independently — a single refresh token can be cut off at any time without changing the user’s actual password.