Skip to content

Instantly share code, notes, and snippets.

@kundan59
Created October 3, 2019 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kundan59/dab7012cfbb92a62a2cdf176de6dfa40 to your computer and use it in GitHub Desktop.
Save kundan59/dab7012cfbb92a62a2cdf176de6dfa40 to your computer and use it in GitHub Desktop.
validate token example
public Boolean validateToken(final String token) {
try {
if (!StringUtils.isEmpty(token)) {
Algorithm algorithm = Algorithm.HMAC256(JWT_TOKEN_KEY);
JWTVerifier verifier = JWT.require(algorithm)
.withIssuer("admin")
.build();
DecodedJWT jwt = verifier.verify(token);
return jwt.getClaim("userId") != null;
} else {
return false;
}
} catch (JWTVerificationException e) {
LOGGER.error("PROBLEM", e);
throw new RuntimeException("Something bad happened. Please try again later");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment