MIGRATION_GUIDE.md
The version 4 release contains several improvements:
java.time.Instant when creating or verifying JWTs with Numeric Date claim values.null claim values both when creating and validation JWTs.This guide captures the changes you should be aware of when planning and upgrading to version 4.
Classes or methods removed:
impl package has been removed as an export in module-info.java. This package contains implementation-specific code that may change at any point.Algorithm#ECDSA256K(ECDSAKeyProvider keyProvider) and Algorithm#ECDSA256K(ECPublicKey publicKey, ECPrivateKey privateKey) methods have been removed.com.auth0.jwt.interfaces.Clock has been removed. Instead, an implementation of java.time.Clock can be passed to the BaseVerification for testing purposes.com.auth0.jwt.impl.NullClaim has been removed. Claim#isNull can be used to determine if a claim's value is null.com.auth0.jwt.impl.PublicClaims was removed, and replaced by com.auth0.jwt.RegisteredClaims and com.auth0.jwt.HeaderParams.com.auth0.jwt.interfaces.Verification#withAnyOfAudience no longer provides a default implementation.null as the value no longer removes the claim if it was previously added to the builder. It now adds the claim with a null value.null for the value of a claim expectation would remove that expectation from the validation. In version 4, passing null does not remove that expectation, but instead validates that the claim has the literal value null.IncorrectClaimException (subclass of InvalidClaimException) will now be thrown instead of an InvalidClaimException.MissingClaimException (subclass of InvalidClaimException) will now be thrown instead of an InvalidClaimException.withClaimPresence(String claimName) now validates that the claim is present in the JWT, and a claim with a null value is considered present. Previously, a claim with a value of null would be considered as missing and fail the validation.Date (or Instant). Instead, the expected Date or Instant will be compared to the claim's value only considering seconds (because JWT date/time claims are represented as seconds since the epoch).com.auth0.jwt.interfaces.Claim#isNull() now returns true only if the claim is present and its value is null. Previously, it returned true if the claim was present and its value was null, or if the claim was not present in the JWT. To check if the claim is present or not in the JWT, use isMissing().IncorrectClaimException addedThis class extends InvalidClaimException and represents that when validating a JWT, an expected claim exists in the JWT but does not match the expected value.
MissingClaimException addedThis class extends InvalidClaimException and represents that when validating a JWT, an expected claim is missing from the JWT.
HeaderParams addedThis class contains constants representing common header parameter names.
RegisteredClaims addedThis class contains constants representing the registered claim names.
JWTCreator new methodsJWTCreator.Builder#withExpiresAt(Instant expiresAt) - adds the exp claim to the JWT from a java.time.Instant.JWTCreator.Builder#withNotBefore(Instant notBefore) - adds the nbf claim to the JWT from a java.time.Instant.JWTCreator.Builder#withIssuedAt(Instant issuedAt) - adds the iat claim to the JWT from a java.time.Instant.JWTCreator.Builder#withClaim(String claimName, Instant value) - adds a claim to the JWT from a java.time.Instant.JWTCreator.Builder#withNullClaim(String claimName) - adds a claim to the JWT with the literal value null.DecodedJWT new methodsInstant getExpiresAtAsInstant() - Returns a JWT's exp claim as a java.time.Instant.Instant getNotBeforeAsInstant() - Returns a JWT's nbf claim as a java.time.Instant.Instant getIssuedAtAsInstant() - Returns a JWT's iat claim as a java.time.Instant.Claim new methodsInstant asInstant() - Gets a claim as a java.time.Instant.boolean isMissing() - Returns whether the claim is present or not.Verification new methodsVerification withClaim(String name, Instant value) - Adds an expectation that a claim with the provided name has a value equal to the provided java.time.Instant.Verification withClaim(String name, BiPredicate<Claim, DecodedJWT> predicate) - Allows for a claim to be validated with the supplied predicate.Verification withNullClaim(String name) - Adds an expectation that a claim with the provided name has a value equal to the literal null.