-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 토큰 반환 시 cookie가 아닌 body 사용하도록 변경 (#206)
* feat: 발급한 토큰을 header가 아닌 body로 반환하도록 수정 * refactor: 사용안하는 클래스와 메서드 제거 * test: 바뀐 API 스펙에 맞게 명세 수정
- Loading branch information
1 parent
5822571
commit d2c5876
Showing
13 changed files
with
123 additions
and
95 deletions.
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
28 changes: 0 additions & 28 deletions
28
backend/src/main/java/com/zzang/chongdae/auth/controller/CookieProducer.java
This file was deleted.
Oops, something went wrong.
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
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/zzang/chongdae/auth/service/dto/LoginResponse.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,8 @@ | ||
package com.zzang.chongdae.auth.service.dto; | ||
|
||
public record LoginResponse(String accessToken, String refreshToken) { | ||
|
||
public LoginResponse(TokenDto tokenDto) { | ||
this(tokenDto.accessToken(), tokenDto.refreshToken()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/zzang/chongdae/auth/service/dto/RefreshResponse.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,8 @@ | ||
package com.zzang.chongdae.auth.service.dto; | ||
|
||
public record RefreshResponse(String accessToken, String refreshToken) { | ||
|
||
public RefreshResponse(TokenDto tokenDto) { | ||
this(tokenDto.accessToken(), tokenDto.refreshToken()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/zzang/chongdae/auth/service/dto/SignupMemberResponseItem.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,10 @@ | ||
package com.zzang.chongdae.auth.service.dto; | ||
|
||
import com.zzang.chongdae.member.repository.entity.MemberEntity; | ||
|
||
public record SignupMemberResponseItem(Long id, String nickname) { | ||
|
||
public SignupMemberResponseItem(MemberEntity member) { | ||
this(member.getId(), member.getNickname()); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/zzang/chongdae/auth/service/dto/SignupTokenResponseItem.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,8 @@ | ||
package com.zzang.chongdae.auth.service.dto; | ||
|
||
public record SignupTokenResponseItem(String accessToken, String refreshToken) { | ||
|
||
public SignupTokenResponseItem(TokenDto tokenDto) { | ||
this(tokenDto.accessToken(), tokenDto.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
36 changes: 21 additions & 15 deletions
36
backend/src/test/java/com/zzang/chongdae/global/helper/CookieProvider.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 |
---|---|---|
@@ -1,29 +1,35 @@ | ||
package com.zzang.chongdae.global.helper; | ||
|
||
import com.zzang.chongdae.auth.service.dto.LoginRequest; | ||
import io.restassured.RestAssured; | ||
import com.zzang.chongdae.auth.service.dto.TokenDto; | ||
import io.restassured.http.Cookie; | ||
import io.restassured.http.Cookies; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
@Component | ||
public class CookieProvider { | ||
|
||
private final TestTokenProvider tokenProvider; | ||
|
||
@Autowired | ||
public CookieProvider(TestTokenProvider tokenProvider) { | ||
this.tokenProvider = tokenProvider; | ||
} | ||
|
||
public Cookies createCookies() { | ||
return RestAssured.given().log().all() | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(new LoginRequest("dora1234")) | ||
.when().post("/auth/login") | ||
.then().log().all() | ||
.extract().detailedCookies(); | ||
TokenDto tokenDto = tokenProvider.createTokens(); | ||
return createCookiesFromTokenDto(tokenDto); | ||
} | ||
|
||
public Cookies createCookiesWithCi(String ci) { | ||
return RestAssured.given().log().all() | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(new LoginRequest(ci)) | ||
.when().post("/auth/login") | ||
.then().log().all() | ||
.extract().detailedCookies(); | ||
TokenDto tokenDto = tokenProvider.createTokensWithCi(ci); | ||
return createCookiesFromTokenDto(tokenDto); | ||
} | ||
|
||
private Cookies createCookiesFromTokenDto(TokenDto tokenDto) { | ||
Cookie accessToken = new Cookie.Builder("access_token", tokenDto.accessToken()).build(); | ||
Cookie refreshToken = new Cookie.Builder("refresh_token", tokenDto.refreshToken()).build(); | ||
return new Cookies(accessToken, refreshToken); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/src/test/java/com/zzang/chongdae/global/helper/TestTokenProvider.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,29 @@ | ||
package com.zzang.chongdae.global.helper; | ||
|
||
import com.zzang.chongdae.auth.service.dto.LoginRequest; | ||
import com.zzang.chongdae.auth.service.dto.TokenDto; | ||
import io.restassured.RestAssured; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class TestTokenProvider { | ||
|
||
public TokenDto createTokens() { // TODO: 로그인 API 호출 대신 토큰 생성 로직으로 대체하기 | ||
return RestAssured.given().log().all() | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(new LoginRequest("dora1234")) | ||
.when().post("/auth/login") | ||
.then().log().all() | ||
.extract().response().as(TokenDto.class); | ||
} | ||
|
||
public TokenDto createTokensWithCi(String ci) { | ||
return RestAssured.given().log().all() | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(new LoginRequest(ci)) | ||
.when().post("/auth/login") | ||
.then().log().all() | ||
.extract().response().as(TokenDto.class); | ||
} | ||
} |