use of com.auth0.jwt.Claim in project java-jwt by auth0.
the class JWTVerifierTest method shouldSuccessfullyVerifyClaimWithPredicate.
@Test
public void shouldSuccessfullyVerifyClaimWithPredicate() {
String jwt = JWTCreator.init().withClaim("claimName", "claimValue").sign(Algorithm.HMAC256("secret"));
JWTVerifier verifier = JWTVerifier.init(Algorithm.HMAC256("secret")).withClaim("claimName", (claim, decodedJWT) -> "claimValue".equals(claim.asString())).build();
DecodedJWT decodedJWT = verifier.verify(jwt);
assertThat(decodedJWT, is(notNullValue()));
}
use of com.auth0.jwt.Claim in project java-jwt by auth0.
the class JsonNodeClaim method asMap.
@Override
public Map<String, Object> asMap() throws JWTDecodeException {
if (isMissing() || isNull() || !data.isObject()) {
return null;
}
try {
TypeReference<Map<String, Object>> mapType = new TypeReference<Map<String, Object>>() {
};
JsonParser thisParser = objectReader.treeAsTokens(data);
return thisParser.readValueAs(mapType);
} catch (IOException e) {
throw new JWTDecodeException("Couldn't map the Claim value to Map", e);
}
}
use of com.auth0.jwt.Claim in project wikidata-query-rdf by wikimedia.
the class TimeLimitedAccessTokenFactory method decide.
<T> T decide(String token, Supplier<T> good, Supplier<T> bad) {
if (token == null) {
return bad.get();
}
DecodedJWT decoded;
try {
decoded = verifier.verify(token);
} catch (JWTVerificationException e) {
return bad.get();
}
Claim claim = decoded.getClaim(USERNAME);
if (claim.isNull()) {
throw new IllegalStateException(("All valid jwt tokens must have a username claim"));
}
if (bannedUsernames.contains(claim.asString())) {
return bad.get();
}
return good.get();
}
use of com.auth0.jwt.Claim in project libresonic by Libresonic.
the class JWTSecurityServiceTest method addJWTToken.
@Test
public void addJWTToken() throws Exception {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriString);
String actualUri = service.addJWTToken(builder).build().toUriString();
String jwtToken = UriComponentsBuilder.fromUriString(actualUri).build().getQueryParams().getFirst(JWTSecurityService.JWT_PARAM_NAME);
DecodedJWT verify = verifier.verify(jwtToken);
Claim claim = verify.getClaim(JWTSecurityService.CLAIM_PATH);
assertEquals(expectedClaimString, claim.asString());
}
use of com.auth0.jwt.Claim in project data-transfer-project by google.
the class JWTTokenManager method getJobIdFromToken.
@Override
public UUID getJobIdFromToken(String token) {
try {
DecodedJWT jwt = verifier.verify(token);
// Token is verified, get claim
Claim claim = jwt.getClaim(JWTTokenManager.ID_CLAIM_KEY);
if (claim.isNull()) {
return null;
}
return claim.isNull() ? null : UUID.fromString(claim.asString());
} catch (JWTVerificationException exception) {
throw new RuntimeException("Error verifying token: " + token);
}
}
Aggregations