-
Notifications
You must be signed in to change notification settings - Fork 6
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: refresh token을 도입한다 #818
Open
drunkenhw
wants to merge
7
commits into
develop
Choose a base branch
from
feat/815
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cf8d9e4
feat: refresh token 저장 기능 추가
drunkenhw 6c81c25
feat: refresh token 발급 및 access token 재발급 기능 추가
drunkenhw f44fa29
feat: refresh token 발급 및 access token 재발급 api 추가
drunkenhw 2925286
chore: flyway script 추가
drunkenhw 5a47f9a
feat: 쿠키 설정 추가
drunkenhw 1814339
chore: stop congestion calculating
drunkenhw d4167fd
fix: refresh token 기간 변경
drunkenhw 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
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
39 changes: 39 additions & 0 deletions
39
...ain/java/com/carffeine/carffeine/auth/controller/support/RefreshTokenCookieGenerator.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,39 @@ | ||
package com.carffeine.carffeine.auth.controller.support; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseCookie; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.Duration; | ||
|
||
@Component | ||
public class RefreshTokenCookieGenerator { | ||
|
||
private static final String REFRESH_TOKEN = "refreshToken"; | ||
private static final String VALID_COOKIE_PATH = "/"; | ||
private static final String LOGOUT_COOKIE_VALUE = ""; | ||
private static final int LOGOUT_COOKIE_AGE = 0; | ||
|
||
@Value("${jwt.refresh-token-expiration-period}") | ||
private long expireLength; | ||
|
||
public ResponseCookie createCookie(String refreshToken) { | ||
return ResponseCookie.from(REFRESH_TOKEN, refreshToken) | ||
.maxAge(Duration.ofMillis(expireLength)) | ||
.path(VALID_COOKIE_PATH) | ||
.sameSite("None") | ||
.secure(true) | ||
.httpOnly(true) | ||
.build(); | ||
} | ||
|
||
public ResponseCookie createLogoutCookie() { | ||
return ResponseCookie.from(REFRESH_TOKEN, LOGOUT_COOKIE_VALUE) | ||
.maxAge(LOGOUT_COOKIE_AGE) | ||
.sameSite("None") | ||
.secure(true) | ||
.httpOnly(true) | ||
.build(); | ||
} | ||
|
||
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. 개행 삭제해주세요 |
||
} |
31 changes: 31 additions & 0 deletions
31
backend/src/main/java/com/carffeine/carffeine/auth/domain/RefreshToken.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,31 @@ | ||
package com.carffeine.carffeine.auth.domain; | ||
|
||
import com.carffeine.carffeine.common.domain.BaseEntity; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Getter | ||
@Builder | ||
@EqualsAndHashCode(of = "id", callSuper = false) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
public class RefreshToken extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private Long memberId; | ||
|
||
private String tokenId; | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/com/carffeine/carffeine/auth/domain/RefreshTokenRepository.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.carffeine.carffeine.auth.domain; | ||
|
||
import org.springframework.data.repository.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface RefreshTokenRepository extends Repository<RefreshToken, Long> { | ||
|
||
RefreshToken save(RefreshToken refreshToken); | ||
|
||
Optional<RefreshToken> findByTokenId(String refreshToken); | ||
|
||
void deleteByMemberId(Long loginMember); | ||
} |
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
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/com/carffeine/carffeine/auth/service/dto/Tokens.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,7 @@ | ||
package com.carffeine.carffeine.auth.service.dto; | ||
|
||
public record Tokens( | ||
String accessToken, | ||
String refreshToken | ||
) { | ||
} |
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 |
---|---|---|
|
@@ -4,10 +4,12 @@ | |
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import javax.servlet.Filter; | ||
|
||
@Profile("!test") | ||
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. 이 부분이 잘 이해가 안가는데요 Profile을 이와 같이 설정한 이유가 무엇인가요?? |
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
|
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.
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.
sameSite None 아주 좋네요 👍
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.
어우 정말 오랜만이네요 반가워요