Java and Spring Level 3 This level · 52 of 56
Hard java spring

User logs out but their JWT has not expired?

The 30 second answer

A self-contained JWT stays valid until its exp claim. Resource servers verify the signature locally and do not know about logout, so a stolen token still works. Mitigations are short-lived access tokens plus refresh tokens revoked on logout, a denylist of jti until expiry, opaque tokens with introspection, or a per-user token version check. Deleting the token only on the client is not revocation.

Could you say this in an interview?

A self-contained JWT stays **valid until exp** — resource servers verify the signature locally and don't know about logout, so a stolen token still works. Mitigations: short access-token lifetime + refresh tokens that are revoked on logout (RFC 7009), a denylist of jti checked until exp (reintroduces state, use Redis with TTL), opaque tokens + introspection (RFC 7662), or token-version/"issued-after" check per user. Client-side deletion alone is not revocation.

Alternate interview scenarios

"OAuth or JWT: what is the difference, how does token expiration work, and how do refresh token flows work?"

They are not alternatives. OAuth 2.0 is an authorization framework: it defines roles, grants and how a client obtains an access token from an authorization server. JWT is a token format: a signed set of claims. An OAuth access token may be a JWT or an opaque string. Expiration uses the exp claim: a resource server rejects the token after that time, usually allowing a small clock skew, and also checks issuer, audience and signature. Because a JWT cannot be recalled before exp, I keep access tokens short-lived. When one expires, the client sends its refresh token to the token endpoint and receives a new access token, so the user does not log in again. The OAuth security best current practice says refresh tokens for public clients must be sender-constrained or rotated: each refresh returns a new refresh token, and reuse of an old one signals theft, so the server can revoke the whole family. Logout then means revoking the refresh token, while the short access-token lifetime bounds the rest.

Sources (5)
  1. RFC 7519 JWT (exp, jti)rfc-editor.org
  2. RFC 7009 Token Revocationrfc-editor.org
  3. RFC 7662 Token Introspectionrfc-editor.org
  4. RFC 6749: OAuth 2.0 (access tokens, refresh tokens, refreshing an access token)rfc-editor.org
  5. RFC 9700: OAuth 2.0 Security Best Current Practice (refresh token protection)rfc-editor.org
Previous
Next