Search in sources :

Example 76 with JWTVerifier

use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.

the class JWTVerifierTest method shouldAddCustomLeewayToDateClaims.

@Test
public void shouldAddCustomLeewayToDateClaims() {
    Algorithm algorithm = mock(Algorithm.class);
    JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(algorithm);
    JWTVerifier verifier = verification.acceptLeeway(1234L).build();
    assertThat(verifier.expectedChecks, is(notNullValue()));
    assertThat(verification.getLeewayFor(RegisteredClaims.ISSUED_AT), is(1234L));
    assertThat(verification.getLeewayFor(RegisteredClaims.EXPIRES_AT), is(1234L));
    assertThat(verification.getLeewayFor(RegisteredClaims.NOT_BEFORE), is(1234L));
}
Also used : Algorithm(com.auth0.jwt.algorithms.Algorithm) Test(org.junit.Test)

Example 77 with JWTVerifier

use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.

the class JWTVerifierTest method shouldOverrideDefaultIssuedAtLeeway.

@Test
public void shouldOverrideDefaultIssuedAtLeeway() {
    Algorithm algorithm = mock(Algorithm.class);
    JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(algorithm);
    JWTVerifier verifier = verification.acceptLeeway(1234L).acceptIssuedAt(9999L).build();
    assertThat(verifier.expectedChecks, is(notNullValue()));
    assertThat(verification.getLeewayFor(RegisteredClaims.ISSUED_AT), is(9999L));
    assertThat(verification.getLeewayFor(RegisteredClaims.EXPIRES_AT), is(1234L));
    assertThat(verification.getLeewayFor(RegisteredClaims.NOT_BEFORE), is(1234L));
}
Also used : Algorithm(com.auth0.jwt.algorithms.Algorithm) Test(org.junit.Test)

Example 78 with JWTVerifier

use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.

the class ConcurrentVerifyTest method shouldPassECDSA384VerificationWithJOSESignature.

@Test
public void shouldPassECDSA384VerificationWithJOSESignature() throws Exception {
    String token = "eyJhbGciOiJFUzM4NCJ9.eyJpc3MiOiJhdXRoMCJ9.50UU5VKNdF1wfykY8jQBKpvuHZoe6IZBJm5NvoB8bR-hnRg6ti-CHbmvoRtlLfnHfwITa_8cJMy6TenMC2g63GQHytc8rYoXqbwtS4R0Ko_AXbLFUmfxnGnMC6v4MS_z";
    ECKey key = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_384, "EC");
    Algorithm algorithm = Algorithm.ECDSA384(key);
    JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
    concurrentVerify(verifier, token);
}
Also used : ECKey(java.security.interfaces.ECKey) Algorithm(com.auth0.jwt.algorithms.Algorithm) Test(org.junit.Test)

Example 79 with JWTVerifier

use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.

the class ConcurrentVerifyTest method shouldPassRSA384Verification.

@Test
public void shouldPassRSA384Verification() throws Exception {
    String token = "eyJhbGciOiJSUzM4NCIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.TZlWjXObwGSQOiu2oMq8kiKz0_BR7bbBddNL6G8eZ_GoR82BXOZDqNrQr7lb_M-78XGBguWLWNIdYhzgxOUL9EoCJlrqVm9s9vo6G8T1sj1op-4TbjXZ61TwIvrJee9BvPLdKUJ9_fp1Js5kl6yXkst40Th8Auc5as4n49MLkipjpEhKDKaENKHpSubs1ripSz8SCQZSofeTM_EWVwSw7cpiM8Fy8jOPvWG8Xz4-e3ODFowvHVsDcONX_4FTMNbeRqDuHq2ZhCJnEfzcSJdrve_5VD5fM1LperBVslTrOxIgClOJ3RmM7-WnaizJrWP3D6Z9OLxPxLhM6-jx6tcxEw";
    Algorithm algorithm = Algorithm.RSA384((RSAKey) readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA"));
    JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
    concurrentVerify(verifier, token);
}
Also used : Algorithm(com.auth0.jwt.algorithms.Algorithm) Test(org.junit.Test)

Example 80 with JWTVerifier

use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.

the class ConcurrentVerifyTest method shouldPassHMAC512Verification.

@Test
public void shouldPassHMAC512Verification() throws Exception {
    String token = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw";
    Algorithm algorithm = Algorithm.HMAC512("secret");
    JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
    concurrentVerify(verifier, token);
}
Also used : Algorithm(com.auth0.jwt.algorithms.Algorithm) Test(org.junit.Test)

Aggregations

JWTVerifier (com.auth0.jwt.JWTVerifier)115 Algorithm (com.auth0.jwt.algorithms.Algorithm)104 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)100 Test (org.junit.Test)42 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)30 IOException (java.io.IOException)23 JWTVerifier (com.auth0.jwt.interfaces.JWTVerifier)18 RSAPublicKey (java.security.interfaces.RSAPublicKey)15 JWTDecodeException (com.auth0.jwt.exceptions.JWTDecodeException)14 Claim (com.auth0.jwt.interfaces.Claim)10 Date (java.util.Date)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 HashMap (java.util.HashMap)8 ECKey (java.security.interfaces.ECKey)7 ServletException (javax.servlet.ServletException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 TokenExpiredException (com.auth0.jwt.exceptions.TokenExpiredException)5 RSAKeyProvider (com.auth0.jwt.interfaces.RSAKeyProvider)5 URL (java.net.URL)5 KeyFactory (java.security.KeyFactory)5