-
Notifications
You must be signed in to change notification settings - Fork 1
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: accessToken 재발급 #155
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
038b9ed
feat: logout 구현
Choi-JJunho c2709da
feat: accessToken 재발급 구현
Choi-JJunho 6402566
fix: 응답 수정 및 테스트 수정
Choi-JJunho 2d778a7
Merge branch 'develop' of https://github.com/BCSDLab/KOIN_API_V2 into…
Choi-JJunho 52499bc
refactor: 사용자 인증 요구사항 제거
Choi-JJunho f03034f
refactor: 리프레시토큰 userId 구분
Choi-JJunho 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
13 changes: 13 additions & 0 deletions
13
src/main/java/in/koreatech/koin/domain/user/dto/UserTokenRefreshRequest.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,13 @@ | ||
package in.koreatech.koin.domain.user.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
@JsonNaming(value = SnakeCaseStrategy.class) | ||
public record UserTokenRefreshRequest( | ||
@JsonProperty("refresh_token") @NotNull(message = "refresh_token을 입력해주세요.") String refreshToken | ||
) { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/in/koreatech/koin/domain/user/dto/UserTokenRefreshResponse.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,13 @@ | ||
package in.koreatech.koin.domain.user.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record UserTokenRefreshResponse( | ||
@JsonProperty("token") String accessToken, | ||
@JsonProperty("refresh_token") String refreshToken | ||
) { | ||
|
||
public static UserTokenRefreshResponse of(String accessToken, String refreshToken) { | ||
return new UserTokenRefreshResponse(accessToken, 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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import io.restassured.http.ContentType; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
|
@@ -126,4 +127,66 @@ void userLogoutSuccess() { | |
|
||
Assertions.assertThat(token).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("사용자가 로그인 이후 refreshToken을 재발급한다") | ||
void userRefreshToken() { | ||
User user = User.builder() | ||
.password("1234") | ||
.nickname("주노") | ||
.name("최준호") | ||
.phoneNumber("010-1234-5678") | ||
.userType(UserType.USER) | ||
.email("[email protected]") | ||
.isAuthed(true) | ||
.isDeleted(false) | ||
.build(); | ||
|
||
userRepository.save(user); | ||
|
||
ExtractableResponse<Response> response = RestAssured | ||
.given() | ||
.log().all() | ||
.body(""" | ||
{ | ||
"email": "[email protected]", | ||
"password": "1234" | ||
} | ||
""") | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.log().all() | ||
.post("/user/login") | ||
.then() | ||
.log().all() | ||
.statusCode(HttpStatus.CREATED.value()) | ||
.extract(); | ||
|
||
RestAssured | ||
.given() | ||
.log().all() | ||
.header("Authorization", "BEARER " + response.jsonPath().getString("token")) | ||
.body( | ||
Map.of("refresh_token", response.jsonPath().getString("refresh_token")) | ||
) | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.log().all() | ||
.post("/user/refresh") | ||
.then() | ||
.log().all() | ||
.statusCode(HttpStatus.OK.value()) | ||
.extract(); | ||
|
||
UserToken token = tokenRepository.findById(user.getId()).get(); | ||
|
||
assertSoftly( | ||
softly -> { | ||
softly.assertThat(response.jsonPath().getString("token")).isNotNull(); | ||
softly.assertThat(response.jsonPath().getString("refresh_token")).isNotNull(); | ||
softly.assertThat(response.jsonPath().getString("refresh_token")) | ||
.isEqualTo(token.getRefreshToken()); | ||
} | ||
); | ||
} | ||
} |
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.
R
인증 헤더 필요 유무에 대한 의견 부탁드립니다~!
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.
현재 상황에 대해 저는 2번 방법이 좋을 것 같습니다!
refresh token만 검증하면 관리나 검증 로직이 간편하기 때문입니다.
탈취의 경우는 액세스 토큰의 만료 시간을 줄이거나 로그아웃하는 방법이 있기 때문에 괜찮을 것 같다고 생각합니다..!