-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: 로그아웃 구현 #57
feat: 로그아웃 구현 #57
Conversation
.sameSite("None") | ||
.httpOnly(true) | ||
.build(); | ||
response.setHeader(SET_COOKIE_HEADER, cookie.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기 쿠키 부분이 어떤 내용인지 이해가 잘 안갑니당..
제가 지금 쿠키 관련해서 전체적으로 이해가 잘 안되는데,, 제가 참고할 만한 자료가 있을까용.. |
링크 참고해보시면 좋을 거 같구요 refreshToken은 프론트에서 accessToken보다 긴 기간(일주일)을 가지고 있는 토큰이라, 탈취되면 보안상 위험해서 자바스크립트 코드나 관리자모드로 열어볼 수 없게 헤더에 대놓고 저장하거나 응답값으로 주는게 아니라 http통신할때만 서로 주고받을 수 있도록 httpOnly설정을 한 cookie에 저장해두고요! 로그인했을 때 제가 setCookie, httpOnly(true)로 refreshToken값을 넣어줬는데 로그아웃하면 refreshToken이 이제 쓸모가 없으니까 쿠키에 들어있는 refreshToken 정보를 무효처리 해줬어요! 둘다 해줘야하는건지는 모르겠는데 쿠키 "refreshToken" key값에 그냥 null을 넣어주고, 쿠키가 지속되는 시간 (maxAge)를 0으로 설정해서 그 시간이 지나면 쿠키 사라지게 했구요.! 그리고 어쨌든 저희 api를 통해서 로그인했으면 백엔드쪽에서 쿠키에 refreshToken값을 넣어준 상태일거라고 생각해서 tokenInterceptor에 private boolean isInvalidRefreshToken(Cookie[] cookies) {
if (Objects.isNull(cookies)) {
return true;
}
Cookie refreshToken = Arrays.stream(cookies)
.filter(cookie -> cookie.getName().equals("refreshToken"))
.findAny()
.get();
return Objects.isNull(refreshToken) || Objects.isNull(refreshToken.getValue()) || refreshToken.getValue().equals("") || refreshToken.getValue().isEmpty() || refreshToken.getMaxAge() == ZERO;
} 헤더에 쿠키가 존재하는지, 그 쿠키의 값이 null이 아니고 어떤 token값인지, maxAge가 0이 아닌지(만료되지 않았는지) 뭐 이런거 체크하는 과정 넣어줘서 컨트롤러테스트부분에 쿠키 하나씩 다 설정해준거예요 !! |
핫 이해했습니다..! 로그인때부터 구현되있었던 내용인데 제가 꼼꼼하게 못 봤었네요 ㅠㅠ 죄송해요 |
헉 아니에요!! 로그인부분은 저도 모르는거 그냥 구현해보고있는거라 저도 확신이 별로 없긴해요 ㅋㅋㅋ ㅠㅠ |
이슈
작업 내용
기타 사항
TestConfig.COOKIE_TOKEN
추가해주어야 요청 성공함체크리스트