use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldAllowWithAnyOfAudienceVerificationToOverrideWithAudience.
@Test
public void shouldAllowWithAnyOfAudienceVerificationToOverrideWithAudience() {
// Token 'aud' = ["Mark", "David", "John"]
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiTWFyayIsIkRhdmlkIiwiSm9obiJdfQ.DX5xXiCaYvr54x_iL0LZsJhK7O6HhAdHeDYkgDeb0Rw";
Verification verification = JWTVerifier.init(Algorithm.HMAC256("secret")).withAudience("Mark", "Jim");
Exception exception = null;
try {
verification.build().verify(token);
} catch (Exception e) {
exception = e;
}
assertThat(exception, is(notNullValue()));
assertThat(exception, is(instanceOf(IncorrectClaimException.class)));
assertThat(exception.getMessage(), is("The Claim 'aud' value doesn't contain the required audience."));
DecodedJWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret")).withAnyOfAudience("Mark", "Jim").build().verify(token);
assertThat(jwt, is(notNullValue()));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldSkipIssuedAtVerificationWhenFlagIsPassed.
// Issued At with future date and ignore flag
@Test
public void shouldSkipIssuedAtVerificationWhenFlagIsPassed() {
String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE0Nzc1OTJ9.CWq-6pUXl1bFg81vqOUZbZrheO2kUBd2Xr3FUZmvudE";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(Algorithm.HMAC256("secret"));
verification.ignoreIssuedAt();
DecodedJWT jwt = verification.build(mockOneSecondEarlier).verify(token);
assertThat(jwt, is(notNullValue()));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldValidateNotBeforeIfPresent.
@Test
public void shouldValidateNotBeforeIfPresent() {
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0Nzc1OTJ9.isvT0Pqx0yjnZk53mUFSeYFJLDs-Ls9IsNAm86gIdZo";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(Algorithm.HMAC256("secret"));
DecodedJWT jwt = verification.build(mockNow).verify(token);
assertThat(jwt, is(notNullValue()));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldValidateNotBeforeWithLeeway.
// Not before
@Test
public void shouldValidateNotBeforeWithLeeway() {
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0Nzc1OTJ9.wq4ZmnSF2VOxcQBxPLfeh1J2Ozy1Tj5iUaERm3FKaw8";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(Algorithm.HMAC256("secret")).acceptNotBefore(2);
DecodedJWT jwt = verification.build(mockOneSecondEarlier).verify(token);
assertThat(jwt, is(notNullValue()));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldOverrideDefaultExpiresAtLeeway.
@Test
public void shouldOverrideDefaultExpiresAtLeeway() {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(algorithm);
JWTVerifier verifier = verification.acceptLeeway(1234L).acceptExpiresAt(9999L).build();
assertThat(verifier.expectedChecks, is(notNullValue()));
assertThat(verification.getLeewayFor(RegisteredClaims.ISSUED_AT), is(1234L));
assertThat(verification.getLeewayFor(RegisteredClaims.EXPIRES_AT), is(9999L));
assertThat(verification.getLeewayFor(RegisteredClaims.NOT_BEFORE), is(1234L));
}
Aggregations