Package com.auth0.jwt
Class JWTVerifier
- java.lang.Object
-
- com.auth0.jwt.JWTVerifier
-
- All Implemented Interfaces:
JWTVerifier
public final class JWTVerifier extends java.lang.Object implements JWTVerifier
The JWTVerifier class holds the verify method to assert that a given Token has not only a proper JWT format, but also it's signature matches.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJWTVerifier.BaseVerificationThe Verification class holds the Claims required by a JWT to be valid.
-
Constructor Summary
Constructors Constructor Description JWTVerifier(Algorithm algorithm, java.util.Map<java.lang.String,java.lang.Object> claims, Clock clock)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidassertDateIsFuture(java.util.Date date, long leeway, java.util.Date today)private voidassertDateIsPast(java.util.Date date, long leeway, java.util.Date today)private voidassertValidAudienceClaim(java.util.List<java.lang.String> audience, java.util.List<java.lang.String> value)private voidassertValidClaim(Claim claim, java.lang.String claimName, java.lang.Object value)private voidassertValidDateClaim(java.util.Date date, long leeway, boolean shouldBeFuture)private voidassertValidIssuerClaim(java.lang.String issuer, java.util.List<java.lang.String> value)private voidassertValidStringClaim(java.lang.String claimName, java.lang.String value, java.lang.String expectedValue)(package private) static Verificationinit(Algorithm algorithm)Initialize a JWTVerifier instance using the given Algorithm.DecodedJWTverify(DecodedJWT jwt)Perform the verification against the given decoded JWT, using any previous configured options.DecodedJWTverify(java.lang.String token)Perform the verification against the given Token, using any previous configured options.private voidverifyAlgorithm(DecodedJWT jwt, Algorithm expectedAlgorithm)private voidverifyClaims(DecodedJWT jwt, java.util.Map<java.lang.String,java.lang.Object> claims)
-
-
-
Method Detail
-
init
static Verification init(Algorithm algorithm) throws java.lang.IllegalArgumentException
Initialize a JWTVerifier instance using the given Algorithm.- Parameters:
algorithm- the Algorithm to use on the JWT verification.- Returns:
- a JWTVerifier.Verification instance to configure.
- Throws:
java.lang.IllegalArgumentException- if the provided algorithm is null.
-
verify
public DecodedJWT verify(java.lang.String token) throws JWTVerificationException
Perform the verification against the given Token, using any previous configured options.- Specified by:
verifyin interfaceJWTVerifier- Parameters:
token- to verify.- Returns:
- a verified and decoded JWT.
- Throws:
AlgorithmMismatchException- if the algorithm stated in the token's header it's not equal to the one defined in theJWTVerifier.SignatureVerificationException- if the signature is invalid.TokenExpiredException- if the token has expired.InvalidClaimException- if a claim contained a different value than the expected one.JWTVerificationException- if any of the verification steps fail
-
verify
public DecodedJWT verify(DecodedJWT jwt) throws JWTVerificationException
Perform the verification against the given decoded JWT, using any previous configured options.- Specified by:
verifyin interfaceJWTVerifier- Parameters:
jwt- to verify.- Returns:
- a verified and decoded JWT.
- Throws:
AlgorithmMismatchException- if the algorithm stated in the token's header it's not equal to the one defined in theJWTVerifier.SignatureVerificationException- if the signature is invalid.TokenExpiredException- if the token has expired.InvalidClaimException- if a claim contained a different value than the expected one.JWTVerificationException- if any of the verification steps fail
-
verifyAlgorithm
private void verifyAlgorithm(DecodedJWT jwt, Algorithm expectedAlgorithm) throws AlgorithmMismatchException
- Throws:
AlgorithmMismatchException
-
verifyClaims
private void verifyClaims(DecodedJWT jwt, java.util.Map<java.lang.String,java.lang.Object> claims) throws TokenExpiredException, InvalidClaimException
-
assertValidClaim
private void assertValidClaim(Claim claim, java.lang.String claimName, java.lang.Object value)
-
assertValidStringClaim
private void assertValidStringClaim(java.lang.String claimName, java.lang.String value, java.lang.String expectedValue)
-
assertValidDateClaim
private void assertValidDateClaim(java.util.Date date, long leeway, boolean shouldBeFuture)
-
assertDateIsFuture
private void assertDateIsFuture(java.util.Date date, long leeway, java.util.Date today)
-
assertDateIsPast
private void assertDateIsPast(java.util.Date date, long leeway, java.util.Date today)
-
assertValidAudienceClaim
private void assertValidAudienceClaim(java.util.List<java.lang.String> audience, java.util.List<java.lang.String> value)
-
assertValidIssuerClaim
private void assertValidIssuerClaim(java.lang.String issuer, java.util.List<java.lang.String> value)
-
-