Created
October 3, 2019 06:13
-
-
Save kundan59/dab7012cfbb92a62a2cdf176de6dfa40 to your computer and use it in GitHub Desktop.
validate token example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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