SSOGEN / Learn / Java JWT library comparison: JJWT, Nimbus JOSE + JWT and java-jwt

Learn

Java JWT library comparison: JJWT, Nimbus JOSE + JWT and java-jwt

A Java JWT library signs, parses and verifies tokens. JJWT, Nimbus JOSE + JWT and java-jwt all do it, and none checks issuer or audience until you configure it.

Three steel inspection gauges and a machined disc, labelled JJWT, Nimbus JOSE + JWT and java-jwt with each exception
One token with the wrong aud, refused by all three libraries, each with its own exception.

Which Java JWT library should you use? Choose by the job. All three libraries below verify an RS256 token against a JWKS, and in our run each refused all six bad tokens once the checks were switched on. JJWT, Nimbus JOSE + JWT and java-jwt differ in algorithms, key handling, encryption and style.

If you need Look first at Why, from its own documentation
A fluent API to build and parse tokens on Java 8 or later JJWT 0.13.0 README: fluent interfaces, JWS and JWE, “all Java 8+ JDKs and Android”
Every standard JWS and JWE algorithm, JWK handling and a managed JWKS source Nimbus JOSE + JWT 10.10 Site: all standard signature and encryption algorithms; JWK set retrieval with caching, outage and retry handling
Signing and verification with HS, RS, PS and ES algorithms, and keys from a JWKS through a companion library java-jwt 4.6.2 README: HS, RS, PS and ES at 256, 384 and 512 bits; JWKS through jwks-rsa-java

Five checks every JWT validator must make

A library verifies a signature. Your configuration decides which claims count. RFC 8725, the JWT best current practices, asks for algorithm, issuer and audience checks.

  • Signature.When a token arrives, then verify it with the issuer’s public key, picked by the kid header from the issuer’s JWKS.
  • Algorithm.When the header names an alg, then accept only the one you expect, never none (RFC 8725, section 3.1). Skipped, a forged token can choose its own algorithm.
  • Issuer.When iss is read, then it must equal the issuer you trust (section 3.8). Skipped, a token from another issuer passes.
  • Audience.When aud is read, then it must contain your API’s identifier (section 3.9). Skipped, a token issued for another API passes.
  • Expiry.When exp is read, then refuse the token after that time, allowing only the clock skew you choose.

A sixth step, checking that the scope covers the call, belongs to your own code. To read the claims of a token you already hold, paste it into the JWT decoder, which runs in your browser.

The three libraries side by side

Each cell comes from the project’s own documentation or its Maven Central listing, read on 2026-11-17.

JJWT Nimbus JOSE + JWT java-jwt
Latest on Maven Central 0.13.0 (2025-08-20) 10.10 (2026-09-17) 4.6.2 (2026-10-13)
Signature algorithms HS, RS, ES, PS, EdDSA; PS and some others need Java 11 or a JCA provider All standard JWS algorithms HS, RS, PS, ES at 256, 384 and 512 bits; PS needs a provider on Java 8; ES256K dropped
Encryption (JWE) Yes, all standard JWE algorithms Yes, all standard JWE algorithms The README documents signing and verification
Keys from a JWKS Parses a JWK Set with Jwks.setParser(); you fetch the document and choose the key in a Locator JWKSourceBuilder retrieves a JWK set with caching, outage and retry handling Separate jwks-rsa-java 0.24.2; cache, rate limit and re-fetch when a kid is not cached
Clock skew clockSkewSeconds setMaxClockSkew on the claims verifier acceptLeeway
Runtime Java 8 or later, Android Java and Android Java LTS 8, 11, 17 and 21, server-side JVM
Maven coordinates io.jsonwebtoken:jjwt-api, plus jjwt-impl and jjwt-jackson com.nimbusds:nimbus-jose-jwt com.auth0:java-jwt, plus com.auth0:jwks-rsa
Source github.com/jwtk/jjwt connect2id.com and Bitbucket github.com/auth0/java-jwt

The same token checked by all three libraries

We generated a throwaway 2048-bit RSA key and served its JWKS from 127.0.0.1. The issuer, audience and key address follow the example in the SSOGEN OpenID Connect guide; the hosts are fictional. Snippets compiled with --release 17 and ran on OpenJDK 21.0.12 on 2026-11-17, with Jackson 2.22.4. Imports are omitted.

JJWT 0.13.0 (imports omitted)
JwkSet keySet = Jwks.setParser().build().parse(httpGet(jwksUrl)); // httpGet: your own HTTP call
Locator<Key> locator = new LocatorAdapter<Key>() {
@Override protected Key locate(JwsHeader header) {
return keySet.getKeys().stream()
.filter(k -> header.getKeyId() != null && header.getKeyId().equals(k.getId()))
.findFirst().map(Jwk::toKey).orElse(null);
}
};
Claims claims = Jwts.parser().keyLocator(locator)
.requireIssuer("https://sso.acme.example")
.requireAudience("https://reports.acme.example/api")
.build().parseSignedClaims(token).getPayload();
Nimbus JOSE + JWT 10.10 (imports omitted)
JWKSource<SecurityContext> keys = JWKSourceBuilder.create(new URL(jwksUrl)).build();
DefaultJWTProcessor<SecurityContext> processor = new DefaultJWTProcessor<>();
processor.setJWSKeySelector(new JWSVerificationKeySelector<>(JWSAlgorithm.RS256, keys));
processor.setJWTClaimsSetVerifier(new DefaultJWTClaimsVerifier<>(
"https://reports.acme.example/api", // aud
new JWTClaimsSet.Builder().issuer("https://sso.acme.example").build(), // iss
Set.of("exp", "sub"))); // required claims
JWTClaimsSet claims = processor.process(token, null);
java-jwt 4.6.2 with jwks-rsa 0.24.2 (imports omitted)
JwkProvider jwks = new UrlJwkProvider(new URL(jwksUrl));
RSAKeyProvider keys = new RSAKeyProvider() {
public RSAPublicKey getPublicKeyById(String kid) {
try { return (RSAPublicKey) jwks.get(kid).getPublicKey(); }
catch (Exception e) { throw new RuntimeException(e); }
}
public RSAPrivateKey getPrivateKey() { return null; }
public String getPrivateKeyId() { return null; }
};
DecodedJWT jwt = JWT.require(Algorithm.RSA256(keys))
.withIssuer("https://sso.acme.example")
.withAudience("https://reports.acme.example/api")
.build().verify(token);

We then ran one valid token and six bad ones through each snippet. Every bad token was signed with the real key where the attack allows it, so only the named defect differs.

Test token, decoded (a service application token)
alg
RS256
kid
key-1
iss
https://sso.acme.example
aud
https://reports.acme.example/api
sub
acme-nightly-report
scope
reports.read
exp
issue time plus 300 seconds
Token JJWT Nimbus java-jwt
Valid Accepted Accepted Accepted
alg is none Refused Refused Refused
HS256, public key as secret Refused Refused Refused
Wrong iss Refused Refused Refused
Wrong aud Refused Refused Refused
Expired one hour ago Refused Refused Refused
kid not in the JWKS Refused Refused Refused

The exception differs by library, which matters when you map failures to HTTP 401 and log lines.

Bad token JJWT Nimbus java-jwt
alg is none UnsupportedJwtException: unsecured JWSs are disallowed by default BadJOSEException: unsecured JWTs are rejected AlgorithmMismatchException
HS256, public key as secret UnsupportedJwtException: an RSA key may not verify HS256 BadJOSEException: another algorithm expected, or no matching key AlgorithmMismatchException
Wrong iss IncorrectClaimException BadJWTException: iss claim value rejected IncorrectClaimException
Wrong aud IncorrectClaimException BadJWTException: aud claim rejected IncorrectClaimException
Expired ExpiredJwtException ExpiredJWTException TokenExpiredException
kid not in the JWKS UnsupportedJwtException: unable to locate the verification key BadJOSEException: no matching key SigningKeyNotFoundException from jwks-rsa, wrapped by our key provider

Then we deleted the issuer and audience lines from each snippet and sent the same tokens again. All three libraries accepted the wrong-iss token and the wrong-aud token. The other four stayed refused.

Where the keys come from

An issuer publishes its public keys as a JWKS. Your API reads the kid in the token header, takes the key with that kid and verifies the signature. When the issuer rotates keys, a new kid appears in the set, and a verifier that meets a kid it does not hold should fetch the JWKS again, then refuse.

Verifying a bearer token with the issuer's JWKS

  • ClientSends the request
  • Your Java APILibrary plus your checks
  • Issuersso.acme.example
  1. Client to Your Java API1Request with Authorization: Bearer token
  2. Your Java API2Read alg and kid from the headerRefuse any alg you did not expect.
  3. Your Java API to Issuer3GET /oauth2/jwksOnly when the cache has no key with this kid.
  4. Issuer to Your Java API4JWKS: public keys only
  5. Your Java API5Verify signature, then iss, aud and exp
  6. Your Java API to Client6200 with data, or 401
With JJWT your Locator fetches the set; Nimbus and jwks-rsa fetch and cache it for you.

SSOGEN publishes its signing keys as a JWKS that applications fetch themselves, as described for the OpenID Connect provider. To read a key set from any issuer, use the JWKS tool.

How Spring’s resource server validates tokens

Spring Security’s resource server builds its decoder with NimbusJwtDecoder. The Spring Security 7.1.2 reference describes these properties:

application.yml of the API (resource server)
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://sso.acme.example
audiences: https://reports.acme.example/api
  • issuer-uri. Validates the iss claim and lets Spring discover the issuer’s public keys.
  • audiences. Validates the aud claim, who the token was sent to.
  • jwk-set-uri. Optional; names the key set directly, so the server does not contact the issuer at startup.
  • Algorithm. By default NimbusJwtDecoder trusts only RS256.

Client login is a separate setup, covered in Spring Boot OAuth2 and OpenID Connect sign-in.

The three libraries are also dependencies like any other; OWASP Dependency-Check matches them to published CVEs during the build. Fix first any reported CVE that is in the CISA KEV catalog, because attackers are already exploiting it.

Questions Java developers ask

Which Java library should I use to validate a JWT?

Pick the library that matches your key source and algorithms. JJWT suits a fluent API on Java 8 or later. Nimbus JOSE + JWT covers every standard JWS and JWE algorithm with a managed JWKS source. java-jwt covers HS, RS, PS and ES signing and verification, with keys from jwks-rsa. All three passed the same six bad-token tests.

How do I verify a JWT with a JWKS in Java?

Select the key by the token’s kid, then verify. In JJWT, parse the set with Jwks.setParser() and return the matching key from a Locator. In Nimbus, build a JWKSource from the JWKS URL. In java-jwt, use a KeyProvider backed by jwks-rsa. Pin the expected algorithm in every case.

Do these libraries check aud and iss for me?

Only when you configure them. Without the issuer and audience lines, all three accepted tokens with a wrong iss and a wrong aud in our run. They did check the signature and exp by default. Add requireIssuer and requireAudience in JJWT, the claims verifier in Nimbus, or withIssuer and withAudience in java-jwt.

Can I encrypt a JWT, not only sign it?

Yes, with JJWT or Nimbus. Both document encrypted tokens (JWE) with all standard JWE algorithms. The java-jwt README documents signing and verification only. A signed token is readable by anyone who holds it; encrypt the token only when its claims must stay private from the client.

When sign-in belongs outside the application code

If the task is sign-in for a Tomcat or Spring Boot web application, not token checks in an API, the SSOGEN Java agent takes sign-in off the application code.

Sources, all read 2026-11-17:

Test results are from our own run on 2026-11-17.

Updated