Search in sources :

Example 51 with Verification

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()));
}
Also used : DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Test(org.junit.Test)

Example 52 with Verification

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()));
}
Also used : DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Test(org.junit.Test)

Example 53 with Verification

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()));
}
Also used : DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Test(org.junit.Test)

Example 54 with Verification

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));
}
Also used : DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)29 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)28 Algorithm (com.auth0.jwt.algorithms.Algorithm)14 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)11 Date (java.util.Date)11 Verification (com.auth0.jwt.interfaces.Verification)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 JWTVerifier (com.auth0.jwt.JWTVerifier)5 RSAPublicKey (java.security.interfaces.RSAPublicKey)5 Job (com.auth0.json.mgmt.jobs.Job)4 Claim (com.auth0.jwt.interfaces.Claim)4 Clock (com.auth0.jwt.interfaces.Clock)4 List (java.util.List)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 JWT (com.auth0.jwt.JWT)3 JWTVerifier (com.auth0.jwt.interfaces.JWTVerifier)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 FloodlightModuleException (net.floodlightcontroller.core.module.FloodlightModuleException)3