-
jwt signWith deprecated 오류SOLUX-완숙이 2022. 1. 13. 14:48
String key; public JwtTokenProvider(@Value("${jwt.secret}") String secretKey) { key = Base64.getEncoder().encodeToString(secretKey.getBytes()); } public TokenInfoResponseDto generateToken(Authentication authentication) { ... //AccessToken 생성 Date accessTokenExpiresIn = new Date(now + ACCESS_TOKEN_EXPIRE_TIME); String accessToken = Jwts.builder() .setSubject(authentication.getName()) .claim(AUTHORITIES_KEY, authorities) .setExpiration(accessTokenExpiresIn) .signWith(SignatureAlgorithm.HS256, key) .compact(); }
이렇게 했더니 signWith이 deprecated 됐다고 했다.
Use Keys.hmacShaKeyFor(bytes) to obtain the Key and then invoke signWith(Key) or signWith(Key, SignatureAlgorithm). 이라는 설명이 떠서
private final Key key; public JwtTokenProvider(@Value("${jwt.secret}") String secretKey) { byte[] keyBytes = Decoders.BASE64.decode(secretKey); this.key = Keys.hmacShaKeyFor(keyBytes); } public TokenInfoResponseDto generateToken(Authentication authentication) { ... //AccessToken 생성 Date accessTokenExpiresIn = new Date(now + ACCESS_TOKEN_EXPIRE_TIME); String accessToken = Jwts.builder() .setSubject(authentication.getName()) .claim(AUTHORITIES_KEY, authorities) .setExpiration(accessTokenExpiresIn) .signWith(key, SignatureAlgorithm.HS256) .compact(); }
이렇게 변경했다.
'SOLUX-완숙이' 카테고리의 다른 글
spring security+jwt 회원가입, 로그인 #3 (0) 2022.01.17 JWT(Json Web Token) (0) 2022.01.17 spring security+jwt 회원가입, 로그인 #2 (0) 2022.01.12 회원가입 시 password를 암호화하여 저장하기 (0) 2022.01.12 spring security+jwt 회원가입, 로그인 #1 (0) 2022.01.12