use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldOverrideAcceptIssuedAtWhenIgnoreIssuedAtFlagPassedAndSkipTheVerification.
@Test
public void shouldOverrideAcceptIssuedAtWhenIgnoreIssuedAtFlagPassedAndSkipTheVerification() {
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0Nzc1OTJ9.0WJky9eLN7kuxLyZlmbcXRL3Wy8hLoNCEk5CCl2M4lo";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(Algorithm.HMAC256("secret")).acceptIssuedAt(1).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 shouldValidateExpiresAtWithLeeway.
// Expires At
@Test
public void shouldValidateExpiresAtWithLeeway() {
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0Nzc1OTJ9.isvT0Pqx0yjnZk53mUFSeYFJLDs-Ls9IsNAm86gIdZo";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(Algorithm.HMAC256("secret")).acceptExpiresAt(2);
DecodedJWT jwt = verification.build(mockOneSecondLater).verify(token);
assertThat(jwt, is(notNullValue()));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldValidateExpiresAtIfPresent.
@Test
public void shouldValidateExpiresAtIfPresent() {
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 shouldThrowOnFutureIssuedAt.
// Issued At with future date
@Test
public void shouldThrowOnFutureIssuedAt() {
IncorrectClaimException e = assertThrows(null, IncorrectClaimException.class, () -> {
String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE0Nzc1OTJ9.CWq-6pUXl1bFg81vqOUZbZrheO2kUBd2Xr3FUZmvudE";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(Algorithm.HMAC256("secret"));
DecodedJWT jwt = verification.build(mockOneSecondEarlier).verify(token);
assertThat(jwt, is(notNullValue()));
});
assertThat(e.getMessage(), is("The Token can't be used before 1970-01-18T02:26:32Z."));
assertThat(e.getClaimName(), is(RegisteredClaims.ISSUED_AT));
assertThat(e.getClaimValue().asLong(), is(1477592L));
}
Aggregations