use of com.auth0.jwt.interfaces.Verification in project jahia by Jahia.
the class JWTConfig method verifyToken.
@Override
public DecodedJWT verifyToken(String token) throws JWTVerificationException, RepositoryException {
Verification verification = signedVerification();
addConfigToVerification(verification);
// Reusable verifier instance
JWTVerifier verifier = verification.build();
return verifier.verify(token);
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTTest method shouldGetId.
@Test
public void shouldGetId() {
String token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxMjM0NTY3ODkwIn0.m3zgEfVUFOd-CvL3xG5BuOWLzb0zMQZCqiVNQQOPOvA";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWT.require(Algorithm.HMAC256("secret"));
DecodedJWT jwt = verification.build().verify(token);
assertThat(jwt, is(notNullValue()));
assertThat(jwt.getId(), is("1234567890"));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTTest method shouldGetIssuedAt.
@Test
public void shouldGetIssuedAt() {
long seconds = 1477592;
Clock clock = Clock.fixed(Instant.ofEpochSecond(seconds), ZoneId.of("UTC"));
String token = "eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE0Nzc1OTJ9.5o1CKlLFjKKcddZzoarQ37pq7qZqNPav3sdZ_bsZaD4";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWT.require(Algorithm.HMAC256("secret"));
DecodedJWT jwt = verification.build(clock).verify(token);
assertThat(jwt, is(notNullValue()));
assertThat(jwt.getIssuedAt(), is(equalTo(new Date(seconds * 1000))));
assertThat(jwt.getIssuedAtAsInstant(), is(equalTo(Instant.ofEpochSecond(seconds))));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldOverrideDefaultNotBeforeLeeway.
@Test
public void shouldOverrideDefaultNotBeforeLeeway() {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(algorithm);
JWTVerifier verifier = verification.acceptLeeway(1234L).acceptNotBefore(9999L).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(9999L));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldAllowWithAudienceVerificationToOverrideWithAnyOfAudience.
@Test
public void shouldAllowWithAudienceVerificationToOverrideWithAnyOfAudience() {
// Token 'aud' = ["Mark", "David", "John"]
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiTWFyayIsIkRhdmlkIiwiSm9obiJdfQ.DX5xXiCaYvr54x_iL0LZsJhK7O6HhAdHeDYkgDeb0Rw";
Verification verification = JWTVerifier.init(Algorithm.HMAC256("secret")).withAnyOfAudience("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")).withAudience("Mark").build().verify(token);
assertThat(jwt, is(notNullValue()));
}
Aggregations