Opaque Token vs JWT: Which Should Keycloak Issue?

Markaretta DofourMarkaretta Dofour12 min read

An opaque token is an access token whose value is a reference string with no claims your API can read, so the API has to send it to the authorization server’s introspection endpoint (RFC 7662) to learn whether it is active and who it belongs to. Keycloak issues its access tokens as signed JWTs (Keycloak OIDC layers). If you want opaque-style behavior from Keycloak, you can turn on lightweight access tokens and have your APIs introspect them, or put a gateway in front of your APIs that swaps a small outside token for a full JWT inside (the phantom token pattern).

Most explanations of opaque tokens describe the concept for one vendor’s product and stop there. This post keeps the definition short and then spends its time on the questions you hit when you run Keycloak: what it can actually issue, what introspection costs you in latency and load, how revocation works in practice, why tokens grow, and where the RFC 9068 JWT profile fits. It ends with a decision table you can use to pick one of three setups.

What is an opaque token?

OAuth 2.0 has always allowed both kinds of access token. RFC 6749 section 1.4 says of the access token string that it “is usually opaque to the client”, and that the token “may denote an identifier used to retrieve the authorization information or may self-contain the authorization information in a verifiable manner”. The first kind is what people call an opaque token or a reference token, and the second kind is a self-contained token, which in practice almost always means a JWT.

An opaque token looks like a long random string. Nothing in it tells the API who the user is, which client asked for it, which scopes it carries or when it expires. All of that lives on the authorization server, so the API has to ask. The standard way to ask is token introspection: the API posts the token to the introspection endpoint and gets back a JSON document whose active member is, in the words of RFC 7662 section 2.2, a “Boolean indicator of whether or not the presented token is currently active”, along with the claims the server chooses to share.

A JWT (RFC 7519) works the other way around. Its payload is a set of claims (issuer, subject, audience, expiry, roles and so on) that the authorization server signs, so any API that has the server’s public key can check the signature and read the claims without a network call. If you want the longer version, our post on what a JWT is walks through the structure and the checks.

How do opaque tokens and JWTs differ?

The two formats move the same information to different places, and that changes who pays for what.

Opaque (reference) token JWT (self-contained) token
What the API sees A random string Signed claims it can decode
How the API validates it Calls the introspection endpoint (RFC 7662) Checks the signature against the issuer’s public keys
Network call per request Yes, unless the result is cached No
Revocation Takes effect at the next introspection The token stays valid until it expires, unless the API introspects
Who can read the claims Only callers allowed to introspect Anyone holding the token, since the payload is only encoded
Size in the Authorization header Small and constant Grows with every claim you map

The privacy point in that table is often overlooked. In a JWT, “Each part contains a base64url-encoded value” (RFC 7519 section 3), and a signature protects the claims from tampering without hiding them. RFC 9068 section 6 notes that unencrypted tokens let clients “and potentially even end users” look inside the claims. A signed JWT that is not also encrypted, which is how Keycloak issues its access tokens, can therefore be decoded by anyone, so a browser, a mobile app or a log line that holds the token can read every claim in it. An opaque token keeps those claims on the server and shows them only to the clients you authorize to introspect.

Which access tokens does Keycloak issue?

Keycloak’s documentation says “Keycloak issued access tokens are JSON Web Tokens (JWT) digitally signed and encoded using JSON Web Signature (JWS)” (Keycloak OIDC layers), and your APIs validate them locally against the realm’s JWKS endpoint, as our guide to verifying a Keycloak-issued access token on the backend shows step by step. The closest Keycloak comes to an opaque token is the lightweight access token.

Lightweight access tokens arrived in Keycloak 24. The Keycloak 24 release notes describe an Always use lightweight access token flag in a client’s advanced settings and an Add to lightweight access token flag on some protocol mappers. With the flag on, the token “is still JWT signed by the realm key by default and still contains some very basic claims”, and Keycloak 25 trimmed it further: “Claims sub and auth_time are added by protocol mappers now” (Keycloak 25 release notes). The rest of the claims are still available: the Keycloak 23 notes say that most protocol mappers include an Add to token introspection switch, and they explain that access tokens “can omit lots of the claims, which would be still returned by the introspection endpoint” (Keycloak 23 release notes).

A lightweight access token is still a signed JWT, so it is not opaque in the strict sense. What it gives you is the same practical result: the token that travels over the wire carries almost nothing readable, and your API gets the user’s roles and other claims from the introspection endpoint. The Keycloak server admin guide puts it plainly in its section on token size: “Lightweight tokens do not carry roles over the wire” (Server Administration Guide).

Keycloak’s introspection endpoint is /realms/{realm}/protocol/openid-connect/token/introspect, and it “can only be invoked by confidential clients” (Keycloak OIDC layers). Each API that introspects therefore needs its own client with credentials in the realm.

What does introspection cost in latency and load?

Introspection adds one HTTP round trip to Keycloak for every request that is not served from a cache, and it moves load from your APIs onto Keycloak. A local JWT check is a signature verification in memory. An introspection call is a network request, TLS, client authentication and a lookup on the Keycloak side, and it happens on your hot path. If Keycloak is slow or unreachable, every API that introspects is slow or unreachable too, so introspection also makes Keycloak’s availability part of every API call.

Caching is the usual answer, and the RFC allows it. RFC 7662 section 4 says a protected resource “MAY cache the response of the introspection endpoint”, and warns that a more aggressive cache “will minimize network traffic and load on the introspection endpoint, but at the risk of stale information about the token”. In practice that means you cache by token for a short time, never longer than the token’s own expiry, and you accept that a revoked token keeps working until its cache entry runs out. A cache that lives only a few seconds still saves the repeated calls a busy client makes with the same token, while keeping the revocation delay short.

Plan Keycloak’s capacity with the introspection rate in mind. Keycloak’s own sizing guide gives CPU per request rate (for example, 1 vCPU for each 120 refresh token requests per second) and says “The used CPU scales linearly with the number of requests up to the tested limit”, so moving validation from your APIs into Keycloak shows up as extra requests per second on your Keycloak nodes, not as extra users.

How does revocation work in practice?

Revocation is the main reason teams want opaque tokens, so it helps to be precise about what each Keycloak mechanism does to an access token that is already out there.

  • The revocation endpoint. Keycloak implements RFC 7009 at /realms/{realm}/protocol/openid-connect/revoke, and its documentation says “Both refresh tokens and access tokens are supported by this endpoint” (Keycloak OIDC layers). A revoked access token is reported as inactive by introspection, but an API that only checks the JWT signature will not notice.
  • Logout and session removal. Ending a session stops its refresh token, and introspection of its tokens stops returning active: true. The admin guide is explicit that Sign out all active sessions “does not revoke outstanding access tokens” and that “Outstanding tokens must expire naturally” (Server Administration Guide), so locally validated JWTs keep working until they expire. Our post on how to revoke one Keycloak session without logging the user out everywhere covers the options for a single session.
  • The not-before revocation policy. Under Sessions, the Revocation action lets you click Set to now to reject tokens issued before that moment, and Push sends the policy “to any registered OIDC client with the Keycloak OIDC client adapter” (Server Administration Guide); the guide adds that pushing a revocation policy “does not work for other adapters” (Server Administration Guide). An API that validates JWTs with a generic library does not receive that push.
  • Short lifetimes. If your APIs validate JWTs locally, the access token lifespan is the longest a revoked or logged-out token can still be used. Keeping it short and letting clients use refresh tokens is the standard trade, and our posts on access tokens vs refresh tokens and JWT lifecycle management go through the settings.

In short, every Keycloak revocation path reaches an API immediately only if that API introspects. With local JWT validation, revocation reaches it when the token expires.

Why do Keycloak tokens grow, and does it matter?

A Keycloak access token carries whatever your protocol mappers and client scopes put into it. Realm roles, client roles for every client the user has roles in, group memberships and extra audiences all add claims, and a user with many roles and groups can end up with a token that is many times larger than a basic one. That token travels in the Authorization header of every request, and once it passes the header limit of Keycloak, your proxy or your API server, requests fail with HTTP 431. Our post on fixing Keycloak’s 431 “Request Header Fields Too Large” explains the limits and how to trim a token by turning off Full scope allowed, moving roles into dedicated client scopes and pruning mappers.

Size is also where lightweight tokens and opaque tokens help without any revocation argument. If your APIs need dozens of roles but your clients never read them, a lightweight token plus introspection keeps the header small and gives each API the full set of claims it is allowed to see.

Identity management as a service, on open source

Skycloak is a managed identity platform in the same category as Auth0 or Okta, built on real upstream Keycloak. You get SSO, MFA, SCIM and audit logs without running the servers, and you can export and self-host whenever you want.

Where do RFC 9068 JWT access tokens fit?

RFC 9068 is a profile that standardizes what a JWT access token should look like, so APIs can validate tokens from different servers the same way. It says the typ header value “SHOULD be” at+jwt (section 2.1), says the resource server “MUST verify” that value and reject tokens carrying any other (section 4), and marks these claims as REQUIRED: iss, exp, aud, sub, client_id, iat and jti (section 2.2). The at+jwt type matters because it lets an API reject an ID token presented as an access token, a mix-up our post on ID tokens vs access tokens covers.

RFC 9068 does not change the opaque versus JWT decision. It only describes how to do the JWT side well. Keycloak 26.2 added a client setting, Use “at+jwt” as access token header type under the client’s advanced settings, and the notes say “This setting is turned off by default” (Keycloak 26.2 release notes). Turn it on when your APIs or gateway check the typ header as RFC 9068 describes.

How does the phantom token pattern work with Keycloak?

The phantom token pattern, described by Curity, gives you opaque tokens outside your network and JWTs inside it. The client only ever holds a reference token. Your API gateway introspects it, gets the claims, and forwards the request to the API with a full JWT, or as Curity puts it, “The reverse proxy replaces the by-reference token with the by-value token in the actual request to the microservice.”

The phantom token pattern: the client sends a small token, the gateway introspects it with Keycloak and forwards a full JWT to the API

The client calls the gateway with a small token (1), the gateway introspects it with Keycloak (2) and gets back an active result with the full claims (3), then forwards the request to the API with a full JWT that the API checks locally (4).

With Keycloak, the outside token is a lightweight access token. The gateway introspects it with its own confidential client, which gives it both revocation status and claims in one call, and it caches the result briefly. For the inside token, Keycloak can return the full JWT from introspection when the request sends Accept: application/jwt and the client has Support JWT claim in Introspection Response turned on, but Keycloak’s documentation marks this as “deprecated now and will be removed in the future” and points to token exchange instead (Keycloak OIDC layers). For a setup you will run for years, plan the gateway around token exchange or around forwarding the introspected claims, rather than around that header. A full gateway configuration belongs in a separate how-to, so this post stops at the pattern.

Which setup should you choose?

Most teams end up in one of three setups. Start from what you need for revocation and claim privacy, then check whether you can afford the introspection traffic.

Setup How APIs validate Revocation reaches APIs Claims visible to the client Load on Keycloak Fits when
Plain JWT (Keycloak’s default) Local signature check against JWKS When the token expires All claims in the token Lowest: key fetches only Internal or first-party APIs where a few minutes of revocation delay is acceptable
Lightweight token plus introspection Each API introspects, with a short cache At the next introspection Almost none One call per uncached request Few APIs, large role sets, or claims you do not want in browsers and logs
Phantom token at the gateway Gateway introspects; APIs check a JWT locally At the gateway’s next introspection Almost none One call per uncached request, from the gateway only Public clients outside, many microservices inside, and a gateway you already run

If you are unsure, start with plain JWTs, short access token lifetimes and introspection on the few endpoints where revocation must be immediate, such as admin actions or payments. That hybrid is the cheapest to run and covers most risk, and you can move to lightweight tokens or a phantom gateway later without changing your clients’ login flow.

Frequently asked questions

Is an opaque token more secure than a JWT?

An opaque token is not stronger cryptographically, but it reveals nothing to whoever holds it and it can be revoked at the next introspection. A JWT is just as hard to forge when you validate it correctly, but its claims are readable and it stays valid until it expires unless your API introspects.

Can Keycloak issue opaque access tokens?

Keycloak’s access tokens are signed JWTs. Its lightweight access tokens, available since Keycloak 24, carry only basic claims and leave the rest to the introspection endpoint, which gives you the main benefits of an opaque token while the token remains a JWT.

Do I need introspection if my APIs validate JWTs locally?

You need it only where you want revocation to take effect before the token expires. Many teams introspect on a handful of sensitive endpoints and validate locally everywhere else.

What is the difference between a lightweight access token and an opaque token?

An opaque token is a reference string with no readable content. A Keycloak lightweight access token is still a signed JWT, but with most claims left out, so the API reads them from the introspection endpoint instead of from the token.

Does RFC 9068 make JWTs behave like opaque tokens?

No. RFC 9068 standardizes the format and required claims of JWT access tokens. It does not add revocation or hide claims, so the trade-offs in this post stay the same.

Next steps

Pick a setup from the decision table, then look at what your tokens carry today. Paste one of your Keycloak access tokens into our free JWT decoder to see every claim your APIs, and anyone who holds the token, can read. If the payload is larger or more revealing than you expected, lightweight tokens or a phantom gateway are worth testing. When you would rather run that realm on managed Keycloak than operate the cluster yourself, Skycloak’s managed Keycloak hosting is a good place to start.

Sources

Identity management as a service, on open source

Skycloak is a managed identity platform in the same category as Auth0 or Okta, built on real upstream Keycloak. You get SSO, MFA, SCIM and audit logs without running the servers, and you can export and self-host whenever you want.

Markaretta Dofour
Written by
Content Writer, Skycloak

Markaretta is Skycloak's content writer. She proposes topics, writes posts and pages for search and AI answers, and watches how they perform. She keeps to the answer first and never uses a number or quote without its source.

© 2026 Skycloak. All Rights Reserved. Design by Yasser SolimanKeycloak™ is a trademark of the Linux Foundation. Skycloak is not affiliated with the Keycloak project.