-
Notifications
You must be signed in to change notification settings - Fork 8
fix: 토큰 재발급 로직 수정 #289
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
fix: 토큰 재발급 로직 수정 #289
Changes from 4 commits
b23767c
c9b545f
abb3026
71a7689
9beb32c
699d9ab
0fb26cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
|
|
||
| import com.example.solidconnection.auth.dto.ReissueResponse; | ||
| import com.example.solidconnection.config.security.JwtProperties; | ||
| import com.example.solidconnection.custom.exception.CustomException; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
@@ -12,12 +13,14 @@ | |
| import java.util.Optional; | ||
|
|
||
| import static com.example.solidconnection.custom.exception.ErrorCode.REFRESH_TOKEN_EXPIRED; | ||
| import static com.example.solidconnection.util.JwtUtils.parseSubject; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class AuthService { | ||
|
|
||
| private final AuthTokenProvider authTokenProvider; | ||
| private final JwtProperties jwtProperties; | ||
|
|
||
| /* | ||
| * 로그아웃 한다. | ||
|
|
@@ -43,14 +46,15 @@ public void quit(SiteUser siteUser) { | |
| * - 리프레시 토큰이 만료되었거나, 존재하지 않는다면 예외 응답을 반환한다. | ||
| * - 리프레시 토큰이 존재한다면, 액세스 토큰을 재발급한다. | ||
| * */ | ||
| public ReissueResponse reissue(String subject) { | ||
| public ReissueResponse reissue(String accessToken) { | ||
| // 리프레시 토큰 만료 확인 | ||
| String subject = parseSubject(accessToken, jwtProperties.secret()); | ||
| Optional<String> optionalRefreshToken = authTokenProvider.findRefreshToken(subject); | ||
| if (optionalRefreshToken.isEmpty()) { | ||
| throw new CustomException(REFRESH_TOKEN_EXPIRED); | ||
| } | ||
| // 액세스 토큰 재발급 | ||
| String newAccessToken = authTokenProvider.generateAccessToken(subject); | ||
|
Comment on lines
-46
to
-53
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 컨트롤러에서 accessToken을 authService.reissue() 함수의 인자로 넘겨줬는데, 변경된 코드에서는 파라미터 이름을 accessToken 으로 바꿔 오해를 방지하고, |
||
| String newAccessToken = authTokenProvider.generateAccessToken(accessToken); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엑세스 토큰 재발급은
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅋㅎㅎㅎ... 이런 실수 방지하려면 Token 클래스가 정말 필요하겠네요.. |
||
| return new ReissueResponse(newAccessToken); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
궁금한 점이 생겼습니다..!
지금 만료된 엑세스 토큰으로 리프레시토큰을 찾아와서 새 엑세스토큰을 발급해주는 거로 이해를 했습니다!
(지금 방식이면 누군가 만료된 토큰을 탈취해도 계속 엑세스 토큰을 발급받는 거 아닌가란 생각이 들어서요!)
Uh oh!
There was an error while loading. Please reload this page.
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.
어... 맞습니다 저는 저 accessToken이라는 이름으로 되있는게 refreshToken이라 생각했네요.
reissue API로 전송하는건 refresh token인걸로 알고 있어서요.
저도 전체 코드 다시 한번 읽어보고 말씀드리겠습니다
Uh oh!
There was an error while loading. Please reload this page.
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을 POST 요청으로 받아,
Redis에 존재하는지 보고 존재한다면 새로운 accessToken 을 발급하도록 수정하면 될까요?
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.
이 방식이나 헤더로 받는 방식 두 개가 있을 거 같은데 전 둘 다 좋은 거 같아요!