Skip to content
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: RefreshToken 추가 #51

Merged
merged 2 commits into from
Dec 8, 2024
Merged

feat: RefreshToken 추가 #51

merged 2 commits into from
Dec 8, 2024

Conversation

Zepelown
Copy link
Member

@Zepelown Zepelown commented Dec 6, 2024

📌 관련 이슈

✨ PR 세부 내용

기능

  • 기존 AccessToken 만 사용하는 구조에서 RefreshToken를 추가한다.
  • Swagger 상에서 Refresh-Token Header를 넣을 수 있다.
    image

설정

  • AccessToken의 유효 시간은 10분이다.
  • AccessToken이 만료가 되면 RefreshToken을 사용하여 새로운 AccessToken을 받는다.
  • RefreshToken이 만료가 되면 로그인을 통해 사용자는 새로운 RefreshToken을 받을 수 있다.
  • RefreshToken은 Header의 이름은 "Refresh-Token"이다.

주의사항

application.properties를 변경했기 때문에 Merge가 완료된 뒤에 Deploy 로직을 변경해야 한다.

⌛ 소요 시간

@Zepelown Zepelown requested a review from Due-IT December 6, 2024 19:47
Copy link
Contributor

@Due-IT Due-IT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생 많으셨습니다 👍

기능상 문제는 없을것으로 보여 merge에 동의하나, 가능하다면 제가 말씀드린 부분을 한 번더 확인해주시면 감사하겠습니다😊

Comment on lines +80 to +82
// 새 액세스 토큰을 응답 헤더에 추가
response.setHeader("New-Access-Token", newAccessToken)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로그인 시에는 토큰을 응답 바디로 반환하는데, 새로 발급되는 액세스 토큰을 헤더에 담아서 반환하는 이유가 있을까요?

Copy link
Member Author

@Zepelown Zepelown Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

만료 시에 액세스 토큰을 헤더로 반환해서 자동로그인을 이어갈 수 있도록 하는 의도였습니다.
로그인 마다 액세스 토큰만 바디로 반환하는 게 아닌, 리프레시 토큰도 반환되어 이와 같은 과정이 필요했습니다.

어떻게 생각하시나요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 프론트 입장에서 새로운 액세스 토큰이 헤더로 오든 바디로 오든 결국 해당값을 꺼내어 사용해야 한다는 점에서 큰 차이가 없을 것이라고 생각해요. 그렇다면 일관성있게 바디로 반환하는게 좋지 않을까 하는 생각입니다.

추가적으로, 리프레시 토큰을 통해 액세스토큰을 발급받을때 리프레시 토큰도 새로 갱신해야 한다고 생각하는데 어떻게 생각하시나요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 잘 몰라서 그런데 리프레시 토큰은 만료 기간이 길고 액세스 토큰을 만료 기간을 짧게 만들고
먼저 엑세스 토큰을 통해 api 요청을 할 때, 만료가 되면 리프레시 토큰을 보내서 api 요청을 진행하는 것이 이 방식의 과정 아닌가요??
그러면 리프레시 토큰을 통해 api 요청을 진행할 때, 리프레시 토큰이 만료가 안됐다면 새로운 엑세스 토큰을 반환받아야 하는 것이 맞다고 생각했었어요.
그래서 헤더를 통해 받은 것이었습니다 (api 요청 body에 넣을 순 없으므로)
이 리프레시 토큰마저 만료되면 로그인을 다시 해야하는 것이라고 생각했습니다.

리프레시 토큰을 통해 액세스 토큰을 발급받을 때 리프레시 토큰을 갱신하는 방향으로 수정하겠습니다

Copy link
Contributor

@Due-IT Due-IT Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사실 저도 리프레시 토큰을 잘 아는건 아니라서 그냥 생각해봤을때, 리프레시 토큰이 자주 바뀌는게 보다 안정성 있지 않을까 생각했어요. 아래 볼르그 글을 참고해보니 관점의 차이가 좀 있었던것 같습니다.

https://velog.io/@chuu1019/Access-Token%EA%B3%BC-Refresh-Token%EC%9D%B4%EB%9E%80-%EB%AC%B4%EC%97%87%EC%9D%B4%EA%B3%A0-%EC%99%9C-%ED%95%84%EC%9A%94%ED%95%A0%EA%B9%8C

저는 리프레시 토큰이 탈취된다면 해당 기간동안 언제든 액세스토큰을 발급 받을 수 있기에 잦은 갱신이 필요하다 생각했지만,
위 언급한 블로그의 내용에서는 리프레시 토큰을 주고 받을 일이 많지 않기 때문에 애초에 통신과정에 탈취당할 가능성이 적어 만료기간을 1년 정도 되는 긴 기간으로 잡네요. 기존 방식이 더 권장되는 방향인것 같습니다.

만약, 이미 수정하셨다면 안정성은 확실히 더 올라갈 것으로 예상되어 좋은것 같고 아니라면 그대로 진행해도 될것 같네요 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

알겠습니다!

@Zepelown Zepelown merged commit 22bd899 into develop Dec 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] JWT Refresh 토큰 추가
2 participants