Repository navigation
Version 2.0 is a security release with breaking changes. Please read the migration notes below.
Security fixes
JWT.verifyin 1.x only checked the signature. It accepted expired tokens and tokens issued for other apps. The newJWT.verifyAppleandJWT.verifyalso checkexp,nbf,iat,iss,audand the nonce, and return aJWTVerificationResultwith the reason for a rejection.- ES256 signatures are now in the JWS format (64 bytes R || S). 1.x produced DER signatures, which strict verifiers reject.
- Verification never throws on malformed input.
- JWK
kty,alg,useandkidare checked. RSA keys need at least 2048 bits, EC keys the matching curve. The headeralgmust match the signing algorithm.noneand HMAC are rejected. - Strict base64url decoding, so a signature has exactly one valid form.
- Tokens longer than 16 KB are rejected before decoding (configurable).
New
JWT.verifyApplefor Sign in with Apple identity tokens.JWT.appleClientSecretfor the Sign in with Apple REST API.- ES384, ES512, RS384, RS512 and EC JWKs.
Keys.privateKey/Keys.publicKeyread PEM keys, with or without header and footer. Signing accepts a loadedPrivateKey.JWKSet,JWKObject.fromPublicKey, andexp,nbf,aud(String or array),sub,jtionJWTAuthPayload.- README examples for Gson, Jackson, a Sign in with Apple backend, APNs and issuing your own tokens.
Migrating from 1.x
- Requires Java 17.
- Remove the
Base64Encoder/Base64Decoderandcharsetarguments. Base64url and UTF-8 are built in. JWT.verify(jwt, jwk, decoder)is nowJWT.verifySignature(jwt, jwk). For Sign in with Apple useJWT.verifyApple.JWKObject.toRSAis nowtoPublicKey.toRSAStringwas removed.decodereturns null for anything that is not a signed token with three parts. It does not verify the token.- Payload claims are nullable.
implementation 'com.github.PhilJay:JWT:2.0.0'