Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

Compare JWT access tokens with opaque tokens checked by token introspection. How do you configure introspection in Spring Security, and what does it cost?

A JWT access token carries its claims and a signature, so the resource server validates it locally, fast, but cannot see a revocation before the token expires. An opaque token is a random string, so the resource server must ask the identity provider's introspection endpoint (RFC 7662) on each request, which makes revocation immediate but adds a network call. In Spring Security we set the introspection-uri, client-id and client-secret properties and enable opaqueToken() in the filter chain.

Why this question is asked

Choosing between JWTs and opaque tokens decides where the cost of security lands: in latency and load on every request, or in a window during which a revoked token still works. Interviewers ask it because many teams use JWTs by default without knowing what they give up, and because the configuration in Spring is short but the operating consequences are not. In this answer, we will recap both token types, see how introspection works, configure it in Spring Security, compare the costs, and look at caching as the middle ground.

1A Quick Recap of the Two Token Types

An access token is what a client sends in the Authorization header to call an API. The API, called the resource server, must answer two questions about it: is it still valid, and who and what does it allow?

A JWT answers both by itself. Its payload holds claims such as sub, the user, scope, the permissions, and exp, the expiry time, and its signature proves the identity provider wrote them. The resource server only needs the provider's public key, which it downloads once and caches.

An opaque token is just a long random string, for example 6f1b...e09a. It means nothing to the resource server. Only the identity provider knows which user and scopes stand behind it, so the resource server has to ask.

2How Token Introspection Works

RFC 7662 defines that question. The resource server sends the token to the provider's introspection endpoint in a POST request, authenticating itself as a client, and the provider answers with a small JSON document. The important field is active: true means the token is valid right now; false means it is expired, revoked or unknown, and the provider tells us nothing more.

Java
POST /oauth2/introspect
Authorization: Basic b3JkZXJzLWFwaTpzZWNyZXQ= # the resource server's own client credentials
Content-Type: application/x-www-form-urlencoded
token=6f1b...e09a
HTTP/1.1 200 OK
{"active":true,"sub":"user-42","scope":"orders.read","client_id":"web-app","exp":1762430400}
Step throughOne request with an opaque token
ClientResource serverIdentity provider
GET /orders with opaque token
POST /introspect token=...
active: true, sub, scope
build authentication from scope
200 orders

5 messages in order. Play them, or step through them one at a time.

Every request that is not cached costs one extra round trip to the provider.

3Configuring Introspection in Spring Security

Spring Boot sets up the introspector from three properties. The client id and secret are the resource server's own credentials at the provider, not the user's.

Java
spring:
security:
oauth2:
resourceserver:
opaquetoken:
introspection-uri: https://login.example.com/oauth2/introspect
client-id: orders-api
client-secret: ${ORDERS_API_INTROSPECTION_SECRET}
@Bean
SecurityFilterChain api(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(a -> a
.requestMatchers(HttpMethod.GET, "/orders/**").hasAuthority("SCOPE_orders.read")
.anyRequest().authenticated())
.oauth2ResourceServer(o -> o.opaqueToken(Customizer.withDefaults()));
return http.build();
}

Spring calls the endpoint for each bearer token, rejects the request with 401 when active is false, and turns the scope values into authorities with the SCOPE_ prefix, just as it does for JWTs. So authorization rules look the same for both token types. The secret comes from the environment or a secret store, never written into the file.

4What Each Choice Costs

The great strength of introspection is revocation. When a user logs out, an administrator disables an account, or a token leaks, the provider marks the token inactive and the very next introspection returns active: false. Nothing else is needed.

The price is a network call per request. If introspection takes 15 ms, every API call becomes 15 ms slower, and the provider must handle the sum of all API traffic, not just logins. If the provider is down, every API that introspects is down too.

A JWT is the mirror image. Validation is a signature check in memory, well under a millisecond, and APIs keep working through a short provider outage. But once issued, a JWT is valid until its exp. Revoking it early needs an extra mechanism such as a deny list of token ids, which brings back a lookup, so most teams simply keep JWT lifetimes short, for example 5 to 15 minutes.

JWT against opaque token with introspection
AspectJWT, validated locallyOpaque, introspected
Validation costsignature check in memorynetwork call to the provider
Revocationonly at expiry, unless extra checksimmediate
Provider outageAPIs keep working with cached keysAPIs fail
Claims visible to clientyes, payload is readableno, the string means nothing
Provider loadkey downloads onlyevery API request

5Caching as the Middle Ground

We can cache introspection results for a short time, keyed by a hash of the token. A cache of 30 seconds removes most calls for busy clients, but it also means a revoked token keeps working for up to 30 seconds. That is the trade in one number: the cache time is the revocation delay we accept. Spring does not cache by default, so we wrap the introspector ourselves.

Java
class CachingIntrospector implements OpaqueTokenIntrospector {
private final OpaqueTokenIntrospector delegate;
private final Cache<String, OAuth2AuthenticatedPrincipal> cache = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofSeconds(30)).maximumSize(100_000).build();
CachingIntrospector(OpaqueTokenIntrospector delegate) { this.delegate = delegate; }
@Override public OAuth2AuthenticatedPrincipal introspect(String token) {
return cache.get(sha256(token), k -> delegate.introspect(token)); // inactive tokens throw, so they are not cached
}
}

Notice that we never store the raw token as the key, and that we never cache a result past the token's own exp. Check your version for the introspector class to delegate to, since Spring Security has replaced its Nimbus-based introspector with a newer implementation.

6Follow-up questions

Can a resource server introspect a JWT?

Many providers allow it, and it gives immediate revocation for JWTs, but then we pay the network cost and lose the main benefit of JWTs. It can make sense for a few sensitive operations, such as changing a password, while ordinary reads validate locally.

Why does the resource server need its own client credentials for introspection?

Without them, anyone could send stolen tokens to the endpoint and learn who they belong to and what they allow. The provider only answers registered resource servers, and some providers only answer about tokens meant for that audience.

Which would you choose for a public API with heavy traffic?

Usually JWTs with short lifetimes, because local validation scales with the API rather than with the provider. If the security team needs immediate revocation, I would introspect at the gateway with a short cache and pass a JWT inward, so only one component pays the cost.

7Conclusion

In this answer, we compared the two token types. JWTs carry signed claims and are validated locally, which is fast and survives provider outages, but they stay valid until they expire. Opaque tokens must be introspected through the RFC 7662 endpoint, which Spring configures with introspection-uri, client-id, client-secret and opaqueToken(), and they can be revoked immediately at the cost of a network call per request. A short introspection cache sits in between, and its lifetime is exactly the revocation delay we accept.

What to say in the interviewAbout 80 seconds aloud

Open with

A JWT access token carries its own claims and a signature, so the resource server checks it locally with the provider's public key, in well under a millisecond, and keeps working if the provider is briefly down.

Then, if they want more

The catch is revocation: a JWT stays valid until exp, so we keep lifetimes short or add a deny list. An opaque token is just a random string, so the resource server calls the provider's introspection endpoint from RFC 7662, authenticating as its own client, and gets back active true or false plus the claims.

In Spring Boot I set spring.security.oauth2.resourceserver.opaquetoken.introspection-uri, client-id and client-secret, and enable oauth2ResourceServer with opaqueToken in the filter chain; scopes then become SCOPE_ authorities exactly as with JWTs. The benefit is immediate revocation, because the next check sees the token is inactive.

The cost is a network call on every request, more load on the provider, and an outage of the provider becoming an outage of the API.

If latency matters, I cache introspection results for a short time keyed by a token hash, accepting that the cache time is the revocation delay, or I introspect only at the gateway and pass JWTs to internal services.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Compare JWT access tokens with opaque tokens checked by token introspection. How do you...": https://scrivio-interview-library.netlify.app/spring-boot/oauth2-and-oidc/fa7f36757b/