Adamant Solutions

JWT "expired" (exp): why a fresh token is rejected

The exp claim is the time after which the token must not be accepted, as a number of seconds since 1970-01-01 UTC. A "token expired" error means the verifier's clock is past that time. Often the token really is old; sometimes the clocks or the units are wrong. Answer the questions to find which.

Find your cause

All the causes and fixes

exp is in milliseconds, not seconds

  • JWT numeric dates are seconds since the epoch. A token created with Date.now() (milliseconds) has an exp about 1000 times too large; a verifier that reads milliseconds will accept it while a standards-compliant one will not (or vice versa).
  • Divide by 1000 when creating: Math.floor(Date.now()/1000) + lifetimeSeconds.
  • Check the number of digits: 10 digits is seconds, 13 is milliseconds. Our timestamp converter tells them apart.

The client uses an expired token

  • Access tokens are meant to be short-lived (often 5 to 60 minutes). The client must refresh or re-authenticate when the token is close to expiry, not after the API rejects it.
  • Store the expiry time (from expires_in or the exp claim) with the token and refresh a little early.
  • On a 401 with an expired-token error, refresh once and retry the request once.

The lifetime is shorter than the use

  • If the work takes longer than the token lives, refresh in the middle, or request a longer lifetime where the security policy allows it.
  • Longer-lived tokens increase the damage when one leaks: prefer refreshing.

Clock skew between systems

  • Tokens are validated against the verifier's own clock. If it runs behind or ahead of the issuer, valid tokens look expired or not yet valid.
  • Synchronise all machines with NTP (containers and VMs inherit the host clock; laptops that sleep drift).
  • Compare the real time on both sides with the timestamp tool and the Date header of the issuer's response.

Add a small leeway (clock tolerance)

  • Even with NTP there can be a few seconds of difference. Most libraries support a leeway of 30-60 seconds when checking exp and nbf; use it, but do not make it large.

Not valid yet (nbf) or issued in the future (iat)

  • A token whose nbf or iat is later than the verifier's time is rejected as not yet valid: this is clock skew with the verifier behind the issuer.
  • Synchronise clocks and add a small leeway.

The token is not expired: look elsewhere

  • The message may come from another check: audience (aud), issuer (iss), signature or a cached "expired" result.
  • See JWT invalid signature and decode the token with the JWT inspector to compare iss and aud with what the API expects.
  • A gateway or cache may be holding an old validation result: clear it or check its TTL.

Frequently asked questions

How long should a JWT access token live?

There is no single rule: access tokens are commonly kept short (minutes to an hour) and renewed with refresh tokens. The right value depends on how much damage a leaked token can do.

Are exp values in seconds or milliseconds?

Seconds since 1970-01-01 UTC (RFC 7519 NumericDate). Milliseconds are a frequent bug.

Why is a brand-new token already expired?

Usually clock skew between the issuer and the verifier, or an exp computed in the wrong unit or time zone.

About this page

Nothing you select here is sent anywhere: the questions run in your browser. If you paste anything into the related tools, read their privacy notes and use test data. See the privacy notice.

Related: JWT inspector · Timestamp converter · JWT invalid signature · All error guides

Still stuck, or designing the flow for your API?

We configure and review OAuth2/OIDC and API gateways, including WSO2 Identity Server and API Manager. See the WSO2 services or the security review.

Message us on LinkedIn