JWT vs opaque tokens: self-contained or reference access tokens

JWTs are validated locally from a signature; opaque tokens need a lookup or introspection. Trade-offs in revocation, latency, size and privacy.

Short answer

Use JWT access tokens when many services or gateways must validate tokens without calling the issuer, and keep them short lived (5 to 15 minutes) because you cannot easily revoke them. Use opaque tokens when you need instant revocation, want to keep claims private from clients, or have a single backend that can look up a session cheaply. A common pattern is opaque to the outside world and JWT internally, with the gateway exchanging one for the other.

JWTOpaque token
What it isSigned JSON claims (RFC 7519, JWS RFC 7515)Random reference string, meaningless to holder
ValidationLocal: verify signature with JWKS, check iss, aud, expLookup in store or introspection (RFC 7662)
Network call per requestNo (JWKS cached)Yes, unless cached
RevocationHard: wait for exp or keep a jti deny listImmediate: delete the record
SizeOften 500 B to 2 KB+Typically 32 to 64 characters
Claims visible to clientYes, base64url is not encryptionNo
Key managementSigning keys, rotation, kid, alg pinningStore availability and secrecy
Typical lifetime5 to 15 minutesMinutes to hours, sliding allowed
StandardsRFC 9068 (JWT access token profile), RFC 8725 (BCP)RFC 7662 introspection, RFC 7009 revocation
Classic bugsalg none, alg confusion, missing aud checkStore outage, unauthenticated introspection

01How each works

A JWT is header.payload.signature, each part base64url encoded. The resource server fetches the issuer's public keys from its JWKS endpoint, picks the key by kid, verifies the signature with an algorithm it pins (for example RS256 or ES256), then checks iss, aud, exp, nbf and any scope claims. No call to the issuer is needed, which is the whole point and the whole problem: a valid signature stays valid until exp.

An opaque token is a high-entropy random string (at least 128 bits) that points at server-side state. The resource server either looks it up directly (a session store such as Redis) or calls the authorisation server's introspection endpoint, which returns active plus the claims. Delete the record and the token is dead on the next request.

02Validating the same request both ways

JWT: local verification with josetypescript
import { createRemoteJWKSet, jwtVerify } from "jose";

const JWKS = createRemoteJWKSet(new URL("https://auth.example.com/.well-known/jwks.json"));

export async function validateJwt(token: string) {
  const { payload } = await jwtVerify(token, JWKS, {
    issuer: "https://auth.example.com",
    audience: "https://api.example.com",
    algorithms: ["RS256"], // pin it: never trust the header's alg
    clockTolerance: 30,
  });
  return payload; // sub, scope, exp ... already checked
}
Opaque: introspection call and responsebash
# RFC 7662 introspection: the resource server authenticates itself
curl -s https://auth.example.com/oauth2/introspect \
  -u "orders-api:CLIENT_SECRET" \
  -d "token=4f1c9b0e7a2d4c6e8f0a1b3c5d7e9f11" \
  -d "token_type_hint=access_token"

# Response
{
  "active": true,
  "sub": "u-123",
  "client_id": "web-app",
  "scope": "orders:read",
  "aud": "https://api.example.com",
  "exp": 1763215200
}

For the opaque path, cache positive introspection results for less than the token's remaining lifetime (often 30 to 60 seconds) to cut latency, and accept that this cache is now your revocation delay.

03When to pick which

  • Many services, gateways or regions validating tokens: JWT, so the issuer is not on every request path.
  • Logout, account disable or stolen-token response must take effect now: opaque, or JWT plus a jti deny list.
  • Tokens go to browsers or third parties and claims are sensitive (email, internal IDs, entitlements): opaque, or encrypt with JWE.
  • Monolith with a session store already: opaque session ID in a __Host- cookie beats JWT in localStorage.
  • Edge gateway in front of microservices: accept opaque from clients, introspect once, mint a short internal JWT (the phantom token pattern).

04Common mistakes

  • Not pinning alg. Accepting whatever the header says enables none and RS256 to HS256 confusion, where the public key is used as an HMAC secret.
  • Skipping the aud check, so a token issued for one API is replayed against another.
  • Long-lived JWTs (hours or days) with no revocation path. Pair short access tokens with rotating refresh tokens instead.
  • Treating JWT payloads as secret. They are encoded, not encrypted.
  • Leaving the introspection endpoint unauthenticated, which gives anyone a token validity oracle.
  • Using opaque tokens with a single Redis and no failure plan: if the store is down, every request fails or, worse, someone adds a fail-open.
!Revocation lists erase the JWT advantage

Once every request checks a jti deny list you have reintroduced a lookup. Keep the list small (only revoked, unexpired tokens), distribute it to the edge, and keep lifetimes short so entries expire quickly.

05How to say it in an interview

“How to say it in the room

A JWT is self-contained: any service can verify it from the issuer's public keys without a network call, which scales well, but it is valid until it expires, so I keep it to minutes and pin the algorithm, issuer and audience. An opaque token is a pointer into server-side state: it costs a lookup or an introspection call per request, but revocation is instant and the client learns nothing from it. For public clients I like opaque at the edge and short internal JWTs behind the gateway.

Questions people ask

Q1Are JWTs more secure than opaque tokens?+

No. They make different trade-offs. JWTs remove a lookup but are hard to revoke and leak claims to whoever holds them. Opaque tokens revoke instantly but depend on a store or introspection endpoint being available.

Q2How do you revoke a JWT?+

You cannot make the signature invalid, so you either wait for exp, keep a deny list of jti values until each token expires, or rotate the signing key, which kills every token signed with it. Short lifetimes plus refresh token rotation is the usual answer.

Q3Should I store JWTs in localStorage?+

Avoid it for browser apps: any XSS can read localStorage. Prefer an HttpOnly, Secure, SameSite cookie, ideally holding an opaque session ID, or a backend-for-frontend that keeps tokens server side.

Q4What is token introspection?+

RFC 7662 defines an endpoint where a resource server posts a token and gets back whether it is active plus its metadata. It is how opaque OAuth access tokens are validated.

Q5Can an OAuth access token be either?+

Yes. OAuth 2.0 does not mandate a format. RFC 9068 standardises a JWT profile for access tokens, while many authorisation servers issue opaque tokens by default or let you choose per client.

Go deeper

Terms on this page