-
카테고리
-
세부 분야
백엔드
-
해결 여부
해결됨
jjwt 0.12 이상으로 하시는 분들에게..
24.03.28 14:42 작성 조회수 126
0
jjwt가 버전업 되면서 강사님이 업데이트 해주신 코드들도 jwt valid할 때 안되는 경우가 발생하더라고요... 그래서 찾아본결과
다음과 같이 작성하시면 원활하게 동작을 합니다. 참고하세요.
private boolean isJwtValid(String jwt) {
byte[] secretKeyBytes = Base64.getEncoder().encode(env.getProperty("token.secret").getBytes());
SecretKey signingKey = new SecretKeySpec(secretKeyBytes, SignatureAlgorithm.HS512.getJcaName());
boolean returnValue = true;
String subject = null;
try {
JwtParser jwtParser = Jwts.parser().
verifyWith(signingKey).build();
Jws<Claims> claimsJws = jwtParser.parseSignedClaims(jwt);
Claims payload = claimsJws.getPayload();
subject = payload.getSubject();
}catch (Exception ex){
returnValue = false;
}
if(subject == null || subject.isEmpty()){
returnValue = false;
}
return returnValue;
}
답변을 작성해보세요.
0
답변 1