-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
wabi/src/main/kotlin/com/wap/wabi/auth/admin/entity/AdminRefreshToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.wap.wabi.auth.admin.entity; | ||
|
||
import jakarta.persistence.*; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
@Entity | ||
public class AdminRefreshToken { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private String adminName; | ||
private String refreshToken; | ||
private int reissueCount = 0; | ||
|
||
public AdminRefreshToken() { | ||
} | ||
|
||
public AdminRefreshToken(builder builder) { | ||
this.adminName = builder.adminName; | ||
this.refreshToken = builder.refreshToken; | ||
} | ||
|
||
public void updateRefreshToken(String refreshToken) { | ||
this.refreshToken = refreshToken; | ||
} | ||
|
||
public boolean validateRefreshToken(String refreshToken) { | ||
return this.refreshToken.equals(refreshToken); | ||
} | ||
|
||
public void increaseReissueCount() { | ||
reissueCount++; | ||
} | ||
|
||
public static class builder { | ||
private String adminName; | ||
private String refreshToken; | ||
|
||
public builder adminName(String adminName) { | ||
this.adminName = adminName; | ||
return this; | ||
} | ||
|
||
public builder refreshToken(String refreshToken) { | ||
this.refreshToken = refreshToken; | ||
return this; | ||
} | ||
|
||
public AdminRefreshToken build() { | ||
return new AdminRefreshToken(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
wabi/src/main/kotlin/com/wap/wabi/auth/admin/repository/AdminRefreshTokenRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.wap.wabi.auth.admin.repository; | ||
|
||
import com.wap.wabi.auth.admin.entity.AdminRefreshToken; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface AdminRefreshTokenRepository extends JpaRepository<AdminRefreshToken, Long> { | ||
Optional<AdminRefreshToken> findAdminRefreshTokenByAdminNameAndReissueCountLessThan(String name, long count); | ||
|
||
Optional<AdminRefreshToken> findAdminRefreshTokenByAdminName(String name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
로그인 시에는 토큰을 응답 바디로 반환하는데, 새로 발급되는 액세스 토큰을 헤더에 담아서 반환하는 이유가 있을까요?
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.
만료 시에 액세스 토큰을 헤더로 반환해서 자동로그인을 이어갈 수 있도록 하는 의도였습니다.
로그인 마다 액세스 토큰만 바디로 반환하는 게 아닌, 리프레시 토큰도 반환되어 이와 같은 과정이 필요했습니다.
어떻게 생각하시나요?
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.
저는 프론트 입장에서 새로운 액세스 토큰이 헤더로 오든 바디로 오든 결국 해당값을 꺼내어 사용해야 한다는 점에서 큰 차이가 없을 것이라고 생각해요. 그렇다면 일관성있게 바디로 반환하는게 좋지 않을까 하는 생각입니다.
추가적으로, 리프레시 토큰을 통해 액세스토큰을 발급받을때 리프레시 토큰도 새로 갱신해야 한다고 생각하는데 어떻게 생각하시나요?
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.
제가 잘 몰라서 그런데 리프레시 토큰은 만료 기간이 길고 액세스 토큰을 만료 기간을 짧게 만들고
먼저 엑세스 토큰을 통해 api 요청을 할 때, 만료가 되면 리프레시 토큰을 보내서 api 요청을 진행하는 것이 이 방식의 과정 아닌가요??
그러면 리프레시 토큰을 통해 api 요청을 진행할 때, 리프레시 토큰이 만료가 안됐다면 새로운 엑세스 토큰을 반환받아야 하는 것이 맞다고 생각했었어요.
그래서 헤더를 통해 받은 것이었습니다 (api 요청 body에 넣을 순 없으므로)
이 리프레시 토큰마저 만료되면 로그인을 다시 해야하는 것이라고 생각했습니다.
리프레시 토큰을 통해 액세스 토큰을 발급받을 때 리프레시 토큰을 갱신하는 방향으로 수정하겠습니다
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.
사실 저도 리프레시 토큰을 잘 아는건 아니라서 그냥 생각해봤을때, 리프레시 토큰이 자주 바뀌는게 보다 안정성 있지 않을까 생각했어요. 아래 볼르그 글을 참고해보니 관점의 차이가 좀 있었던것 같습니다.
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년 정도 되는 긴 기간으로 잡네요. 기존 방식이 더 권장되는 방향인것 같습니다.
만약, 이미 수정하셨다면 안정성은 확실히 더 올라갈 것으로 예상되어 좋은것 같고 아니라면 그대로 진행해도 될것 같네요 👍
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.
알겠습니다!