11package dev .findfirst .security .jwt ;
22
33import java .security .interfaces .RSAPrivateKey ;
4+ import java .security .interfaces .RSAPublicKey ;
45import java .util .Map ;
56
67import jakarta .annotation .PostConstruct ;
@@ -27,6 +28,8 @@ public class JwtService {
2728
2829 @ Value ("${jwt.private.key}" )
2930 private RSAPrivateKey priv ;
31+ @ Value ("${jwt.public.key}" )
32+ private RSAPublicKey pubKey ;
3033
3134 @ Value ("${findfirst.app.jwtCookieName}" )
3235 private String jwtCookie ;
@@ -37,7 +40,7 @@ public class JwtService {
3740
3841 @ PostConstruct
3942 private void init () {
40- jwtParser = Jwts .parserBuilder ().setSigningKey ( priv ).build ();
43+ jwtParser = Jwts .parser ().verifyWith ( pubKey ).build ();
4144 }
4245
4346 public String getJwtFromCookies (HttpServletRequest request ) {
@@ -47,7 +50,7 @@ public String getJwtFromCookies(HttpServletRequest request) {
4750
4851 public Jws <Claims > parseJwt (String jwt ) throws ExpiredJwtException , UnsupportedJwtException ,
4952 MalformedJwtException , SignatureException , IllegalArgumentException {
50- return jwtParser .parseClaimsJws (jwt );
53+ return jwtParser .parseSignedClaims (jwt );
5154 }
5255
5356 public String getUserNameFromJwtToken (String token ) {
0 commit comments