Skip to content

fix: 엑세스토큰 재발급 문제 해결 #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

beginner0107
Copy link
Owner

@beginner0107 beginner0107 commented Feb 13, 2024

🔥 Related Issue

close: #110

📝 Description

퇴근하고 프로젝트를 켜서 확인해보니, 엑세스 토큰이 만료되었을 때, 아예 accessToken과 refreshToken Cookie 값이 사라지는 문제점을 발견했습니다.

테스트 코드의 미작성으로 인한 문제점이라고도 볼 수 있어, 추후 작성해봐야 할 것 같습니다.

문제점은 GenericFilterBean이였습니다.

필터가 두번 실행되므로, 레디스에 저장된 refreshToken과 새로 발행한 refreshToken이 같지 않게 되면서,
쿠키를 모두 초기화시켜버린 것이였습니다.

서칭해서 찾은 정보로는 이런 문제점이 있었습니다.

  • https://targetcoders.com/%ED%95%84%ED%84%B0-%EC%A4%91%EB%B3%B5-%EC%A0%81%EC%9A%A9/
  • Jwt인증과 관련된 필터를 GenericFilterBean을 상속 받아서 구현하였고, @component로 빈으로 등록해주었습니다.
  • 이걸 다시 Security 설정 관련된 파일에서 주입받아 사용하고 있었는데,
  • 이 때 Spring Boot의 기능 때문에 필터가 두 번 등록되었습니다.
    image
  • Spring Boot는 Bean들 중에 Filter가 있으면 자동으로 Filter Chain에 등록하도록 동작한다고 합니다.
  • 그러면 addFilters를 제거하는 방식도 있지만 저는 OncePerRequestFilter를 상속받아 사용하기로 하였습니다.
  • 요청 당 한 번만 적용되는 것을 보장하기 때문에 적합한 해결 방법이라고 생각했습니다.

⭐️ Review

  • 이것 때문에 어제부터 한 5시간을 ...
  • 그래도 해결해서 다행이네요.

@beginner0107 beginner0107 added the 🐞 BugFix Something isn't working label Feb 13, 2024
@beginner0107 beginner0107 self-assigned this Feb 13, 2024
@beginner0107 beginner0107 marked this pull request as ready for review February 13, 2024 15:28
@beginner0107 beginner0107 merged commit d323e2f into develop Feb 13, 2024
@beginner0107 beginner0107 deleted the fix_#110_엑세스토큰_재발급_문제_해결 branch February 13, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 BugFix Something isn't working
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

엑세스토큰 재발급 안 되는 버그 수정
1 participant