use of com.auth0.jwt.Claim in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldGetBooleanValue.
@Test
public void shouldGetBooleanValue() {
JsonNode value = mapper.valueToTree(true);
Claim claim = claimFromNode(value);
assertThat(claim.asBoolean(), is(notNullValue()));
assertThat(claim.asBoolean(), is(true));
}
use of com.auth0.jwt.Claim in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldGetArrayValueOfCustomClass.
@Test
public void shouldGetArrayValueOfCustomClass() {
JsonNode value = mapper.valueToTree(new UserPojo[] { new UserPojo("George", 1), new UserPojo("Mark", 2) });
Claim claim = claimFromNode(value);
assertThat(claim.asArray(UserPojo.class), is(notNullValue()));
assertThat(claim.asArray(UserPojo.class), is(arrayContaining(new UserPojo("George", 1), new UserPojo("Mark", 2))));
}
use of com.auth0.jwt.Claim in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldReturnBaseClaimWhenParsingNullNode.
@Test
public void shouldReturnBaseClaimWhenParsingNullNode() {
JsonNode value = NullNode.getInstance();
Claim claim = claimFromNode(value);
assertThat(claim, is(notNullValue()));
assertThat(claim.isNull(), is(true));
assertThat(claim.isMissing(), is(false));
}
use of com.auth0.jwt.Claim 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()));
}
use of com.auth0.jwt.Claim 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()));
}
Aggregations