What is the difference between an access token and a refresh token?

Dark navy cover card with the title 'What is the difference between an access token and a refresh token?' in white and a green accent bar

The difference in access token vs refresh token comes down to who receives each one. An access token is the short-lived credential your app sends to the API on every request. A refresh token is a longer-lived credential that your app sends only to the authorization server, to get a new access token when the old one expires.

Access token vs refresh token at a glance

An access token proves what the client may do right now, while a refresh token proves the client may keep asking for new access tokens. The OAuth 2.0 spec, RFC 6749, defines both, and the table below lines up the differences that change how you build a client.

Access token Refresh token
Purpose Call protected resources Get new access tokens
Sent to The API (resource server) Only the authorization server
How it's sent Authorization: Bearer header Form body of a POST to the token endpoint
Lifetime Short, often about an hour Longer, such as 24 hours or 90 days
Always issued? Yes, it's the point of the flow No, optional for the server
Error when bad 401 with invalid_token 400 with invalid_grant

What an access token does

An access token is the credential your app presents to reach a protected resource, for a specific scope and period. RFC 6749 says the string is usually opaque to the client, so your app should not depend on what is inside it.

The token can be a reference ID that the server looks up, or it can carry its own data plus a signature. RFC 9068 defines a standard JWT format for access tokens, which is why so many of them start with eyJ. Your app attaches it to each API call using the bearer scheme from RFC 6750:

GET /v1/orders HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIs...

What a refresh token does

A refresh token is the credential a client uses to obtain new access tokens without asking the user to sign in again. Per RFC 6749, it can also fetch tokens with the same or narrower scope, never a wider one.

Two rules matter in practice. First, refresh tokens are "never sent to resource servers"; only the authorization server sees them. Second, the token is bound to the client it was issued to, and confidential clients must authenticate when they use it. A stolen refresh token alone should not work for a different client.

A worked example: one token response, two error paths

Follow one session from sign-in to expiry. After sign-in, the token endpoint returns a JSON body like the example in RFC 6749:

{
  "access_token": "2YotnFZFEjr1zCsicMWpAA",
  "token_type": "example",
  "expires_in": 3600,
  "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA"
}

expires_in is the access token's lifetime in seconds, so 3600 means one hour. The response has no lifetime field for the refresh token.

When the hour is up, the API answers with HTTP 401 and invalid_token. RFC 6750 says the client may then request a new access token and retry, so your client sends the refresh token to the token endpoint:

POST /token HTTP/1.1
Host: auth.example.com
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA

If the refresh token itself is expired, revoked or belongs to another client, the token endpoint returns HTTP 400 with invalid_grant. Refreshing won't help now. Send the user back through sign-in.

The client logic:

  1. API returns 401 invalid_token: refresh, then retry the call once.
  2. Token endpoint returns 400 invalid_grant: stop refreshing and start a new sign-in.
  3. Refresh succeeds with a new refresh_token in the body: store it and throw the old one away.

A common bug is treating both errors alike. A client that retries the refresh on invalid_grant just loops.

Why not just use one long-lived access token?

Short access tokens limit the damage when one leaks, and the refresh token is what makes short lifetimes livable. RFC 9700, the current OAuth security best practice, says refresh tokens let servers issue access tokens with a short lifetime and reduced scope.

An access token travels to every API you call. A refresh token goes to one server. If an access token leaks, an attacker has it for minutes or an hour, not months.

Real defaults show the gap. One major identity platform gives access tokens a random lifetime between 60-90 minutes by default. Its refresh tokens default to 24 hours for single-page apps and 90 days for everything else.

How refresh token rotation catches theft

Refresh token rotation means the server issues a new refresh token on every refresh and invalidates the previous one. RFC 9700 requires public clients, such as browser and mobile apps, to get either rotation or sender-constrained refresh tokens.

Rotation works like a tripwire. If an attacker steals a refresh token and both parties use it, one of them will present a token that was already replaced. The server can't tell which party is the attacker, so it revokes the active refresh token. The real user has to sign in again, but the stolen refresh token stops working too.

The other option, sender-constrained tokens, cryptographically ties the refresh token to one client instance using mutual TLS or DPoP. Servers may also revoke refresh tokens after a password change or logout, and refresh tokens should expire after a period of inactivity. Clients can revoke tokens themselves through the endpoint defined in RFC 7009.

Where to store each token

The access token can live in memory, because losing it only costs one refresh. The refresh token needs the most protection your platform offers, since RFC 9700 calls it an attractive target that represents the full scope granted to the client.

My take: in a browser app, keep the refresh token out of JavaScript entirely. Put it in an HttpOnly cookie or behind a small backend that holds tokens for the browser. If it has to live in the browser, use an auth server that rotates it. The tradeoffs between storage options are covered in JWT in localStorage vs cookies, and the bigger session question is in JWT vs session cookies.

How to check an access token while debugging

When an access token is a JWT, you can read its exp and iat claims to see when it expires. Paste it into a JWT decoder, which shows the header, payload and the expiry with an expired or valid flag.

One limitation: decoding is not verifying. This decoder reads the token without checking the signature. It shows what a token claims and says nothing about whether to trust it. See JWT decode vs verify for why that matters. Opaque access tokens and most refresh tokens won't decode at all. That's expected. If exp looks right but the API still rejects it, why a JWT expires early walks through clock and unit bugs.

FAQ

Can I use a refresh token to call an API?

No. Under OAuth 2.0, refresh tokens are meant only for the authorization server and are never sent to resource servers. You exchange the refresh token at the token endpoint for a new access token, then call the API with that access token.

Does every OAuth server give you a refresh token?

No. Issuing a refresh token is optional and left to the authorization server. The current security best practice says the server must decide, based on a risk assessment, whether a given client gets one.

Is a refresh token a JWT?

It can be, but the spec describes it as a usually opaque string that points to authorization information on the server. Access tokens are more often JWTs, and there is a separate RFC that defines a JWT format for access tokens.

What happens when the refresh token expires?

The token endpoint rejects the refresh request with an invalid_grant error. The client then has to send the user through sign-in again to get a fresh authorization grant and a new pair of tokens.

Sources