본문 바로가기
Java/Spring with Error

[해결방법] io.jsonwebtoken.ExpiredJwtException

by HJ0216 2024. 8. 30.

io.jsonwebtoken.ExpiredJwtException

Environment
Language: Java 17
DB: MySQL, Redis

 

오류

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    // 1. Request Header에서 JWT 토큰 추출
    String accessToken = SecurityUtils.resolveToken(request);
 
    // 2. 토큰 유효성 검사
    // 토큰이 유효할 경우, 토큰에서 Authentication 객체를 가지고 와서 SecurityContext에 저장
    if (accessToken != null && jwtTokenProvider.isValidToken(accessToken)) {
        Authentication authentication = jwtTokenProvider.getAuthentication(accessToken);
        SecurityContextHolder.getContext().setAuthentication(authentication);
    }
 
    filterChain.doFilter(request, response);
    // 현재 필터가 요청을 처리한 후, 필터 체인의 다음 필터로 요청과 응답을 전달
}

accessToken이 예전 accessToken값을 들고와서, ExpiredJwtException 발생

 

 

원인

1
localhost:8080/api/v2/users/re-issue

Postman 요청 시, Authorization에서 Token이 입력되어있는지 확인

 

 

해결

Postman 요청 시, Authorization에서 Token 삭제

Body에 Argument 전달