use of com.auth0.jwt.JWTVerifier in project singleton by vmware.
the class JwtTokenService method verifyToken.
public Map<String, Claim> verifyToken(String token) throws Exception {
JWTVerifier verifier = null;
verifier = JWT.require(Algorithm.HMAC256(authConfig.getJwtSecret())).build();
DecodedJWT decoded = null;
try {
decoded = verifier.verify(token);
} catch (Exception e) {
// TODO Auto-generated catch block
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
return decoded.getClaims();
}
use of com.auth0.jwt.JWTVerifier in project wandaxin-vehicle-manage by Jarrettluo.
the class AuthenticationInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws Exception {
// crossDomain(httpServletRequest, httpServletResponse);
// 从 http 请求头中取出 token
String token = httpServletRequest.getHeader("token");
// 如果不是映射到方法直接通过
if (!(object instanceof HandlerMethod)) {
return true;
}
HandlerMethod handlerMethod = (HandlerMethod) object;
Method method = handlerMethod.getMethod();
// 检查是否有passtoken注释,有则跳过认证
if (method.isAnnotationPresent(PassToken.class)) {
PassToken passToken = method.getAnnotation(PassToken.class);
if (passToken.required()) {
return true;
}
}
// 检查有没有需要用户权限的注解
if (method.isAnnotationPresent(UserLoginToken.class)) {
UserLoginToken userLoginToken = method.getAnnotation(UserLoginToken.class);
if (userLoginToken.required()) {
// 执行认证
if (token == null) {
throw new RuntimeException("无token,请重新登录");
}
// 获取 token 中的 user id
String userId;
try {
userId = JWT.decode(token).getAudience().get(0);
} catch (JWTDecodeException j) {
throw new RuntimeException("401");
}
UserDTO user = userService.findUserById(userId);
if (user == null) {
throw new RuntimeException("用户不存在,请重新登录");
}
// 验证 token
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(user.getPassword())).build();
try {
jwtVerifier.verify(token);
} catch (JWTVerificationException e) {
throw new RuntimeException("401");
}
return true;
}
}
return true;
}
use of com.auth0.jwt.JWTVerifier 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.JWTVerifier in project SpringBootSample by heowc.
the class SpringBootSecurityJwtApplicationTests method test_verifyJwtToken.
@Test
void test_verifyJwtToken() throws Exception {
try {
JWTVerifier verifier = JWT.require(Algorithm.HMAC256(TOKEN_KEY)).withIssuer("wonchul").acceptExpiresAt(// 만료일 -4일
DAY * 4).build();
DecodedJWT jwt = verifier.verify(JWT_TOKEN);
logger.info("=================== test_verifyJwtToken ===================");
logger.info("jwt token : " + jwt.getToken());
logger.info("jwt algorithm : " + jwt.getAlgorithm());
logger.info("jwt claims : " + jwt.getClaims());
logger.info("jwt issuer : " + jwt.getIssuer());
logger.info("jwt issuer date : " + jwt.getIssuedAt());
logger.info("jwt expires date : " + jwt.getExpiresAt());
logger.info("jwt signature : " + jwt.getSignature());
logger.info("jwt type : " + jwt.getType());
logger.info("jwt key id : " + jwt.getKeyId());
logger.info("jwt id : " + jwt.getId());
logger.info("jwt subject : " + jwt.getSubject());
logger.info("jwt content type : " + jwt.getContentType());
logger.info("jwt audience list : " + jwt.getAudience());
} catch (JWTVerificationException verificationEx) {
logger.info("Verify Error");
verificationEx.printStackTrace();
}
}
use of com.auth0.jwt.JWTVerifier in project LanternPowerMonitor by MarkBryanMilligan.
the class AppleSSO method getEmailFromIdToken.
public String getEmailFromIdToken(String _idToken) {
if (validatePublicKey()) {
try {
DecodedJWT jwt = JWT.decode(NullUtils.base64ToString(_idToken));
String kid = jwt.getHeaderClaim("kid").asString();
RSAPublicKey key = publicKeys.get(kid);
if (key != null) {
Algorithm algorithm = Algorithm.RSA256(key, null);
JWTVerifier verifier = JWT.require(algorithm).withIssuer("https://appleid.apple.com").withAudience(audience).build();
return verifier.verify(jwt).getClaim("email").asString().toLowerCase(Locale.ROOT);
}
} catch (Exception _e) {
LOG.error("Failed to verify Apple JWT token", _e);
}
}
return null;
}
Aggregations