-
Notifications
You must be signed in to change notification settings - Fork 8
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
[BE] 기존 jwt 토큰 응답 방식을 쿠키로 변경하고 path 및 보안 설정 #131
Changes from all commits
4b7d2f2
8d56479
58b9ab0
0df9663
11d67fc
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 | ||||
---|---|---|---|---|---|---|
@@ -1,11 +1,12 @@ | ||||||
package kr.momo.controller.attendee; | ||||||
|
||||||
import jakarta.validation.Valid; | ||||||
import kr.momo.controller.MomoApiResponse; | ||||||
import kr.momo.service.attendee.AttendeeService; | ||||||
import kr.momo.service.attendee.dto.AttendeeLoginRequest; | ||||||
import kr.momo.service.attendee.dto.TokenResponse; | ||||||
import lombok.RequiredArgsConstructor; | ||||||
import org.springframework.http.HttpHeaders; | ||||||
import org.springframework.http.ResponseCookie; | ||||||
import org.springframework.http.ResponseEntity; | ||||||
import org.springframework.web.bind.annotation.PathVariable; | ||||||
import org.springframework.web.bind.annotation.PostMapping; | ||||||
import org.springframework.web.bind.annotation.RequestBody; | ||||||
|
@@ -15,12 +16,26 @@ | |||||
@RequiredArgsConstructor | ||||||
public class AttendeeController { | ||||||
|
||||||
private static final String ACCESS_TOKEN = "ACCESS_TOKEN"; | ||||||
|
||||||
private final AttendeeService attendeeService; | ||||||
|
||||||
@PostMapping("/api/v1/meetings/{uuid}/login") | ||||||
public MomoApiResponse<TokenResponse> login( | ||||||
@PathVariable String uuid, @RequestBody @Valid AttendeeLoginRequest request | ||||||
) { | ||||||
return new MomoApiResponse<>(attendeeService.login(uuid, request)); | ||||||
public ResponseEntity<Void> login(@PathVariable String uuid, @RequestBody @Valid AttendeeLoginRequest request) { | ||||||
String token = attendeeService.login(uuid, request); | ||||||
String path = String.format("/api/v1/meetings/%s/", uuid); | ||||||
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. 이 부분은 오타가 맞을까요?
Suggested change
|
||||||
|
||||||
return ResponseEntity.ok() | ||||||
.header(HttpHeaders.SET_COOKIE, createCookie(token, path)) | ||||||
.build(); | ||||||
} | ||||||
|
||||||
private String createCookie(String value, String path) { | ||||||
return ResponseCookie.from(ACCESS_TOKEN, value) | ||||||
.httpOnly(true) | ||||||
.secure(true) | ||||||
.path(path) | ||||||
.build() | ||||||
.toString(); | ||||||
} | ||||||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,9 +153,9 @@ void lock() { | |
String token = getToken(attendee, meeting); | ||
|
||
RestAssured.given().log().all() | ||
.cookie("ACCESS_TOKEN", token) | ||
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. Fixture 에 상수로 추가해줘도 될 것 같아요! 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. 좋네요 반영하겠습니다. |
||
.contentType(ContentType.JSON) | ||
.pathParam("uuid", meeting.getUuid()) | ||
.header("Authorization", "Bearer " + token) | ||
.when().patch("/api/v1/meetings/{uuid}/lock") | ||
.then().log().all() | ||
.statusCode(HttpStatus.OK.value()); | ||
|
@@ -170,9 +170,9 @@ void lockWithInvalidUUID() { | |
String token = getToken(attendee, meeting); | ||
|
||
RestAssured.given().log().all() | ||
.cookie("ACCESS_TOKEN", token) | ||
.contentType(ContentType.JSON) | ||
.pathParam("uuid", invalidUUID) | ||
.header("Authorization", "Bearer " + token) | ||
.when().patch("/api/v1/meetings/{uuid}/lock") | ||
.then().log().all() | ||
.statusCode(HttpStatus.NOT_FOUND.value()); | ||
|
@@ -186,9 +186,9 @@ void lockWithNoPermission() { | |
String token = getToken(attendee, meeting); | ||
|
||
RestAssured.given().log().all() | ||
.cookie("ACCESS_TOKEN", token) | ||
.contentType(ContentType.JSON) | ||
.pathParam("uuid", meeting.getUuid()) | ||
.header("Authorization", "Bearer " + token) | ||
.when().patch("/api/v1/meetings/{uuid}/lock") | ||
.then().log().all() | ||
.statusCode(HttpStatus.FORBIDDEN.value()); | ||
|
@@ -202,9 +202,9 @@ void unlock() { | |
String token = getToken(attendee, meeting); | ||
|
||
RestAssured.given().log().all() | ||
.cookie("ACCESS_TOKEN", token) | ||
.contentType(ContentType.JSON) | ||
.pathParam("uuid", meeting.getUuid()) | ||
.header("Authorization", "Bearer " + token) | ||
.when().patch("/api/v1/meetings/{uuid}/unlock") | ||
.then().log().all() | ||
.statusCode(HttpStatus.OK.value()); | ||
|
@@ -219,9 +219,9 @@ void unlockWithInvalidUUID() { | |
String token = getToken(attendee, meeting); | ||
|
||
RestAssured.given().log().all() | ||
.cookie("ACCESS_TOKEN", token) | ||
.contentType(ContentType.JSON) | ||
.pathParam("uuid", invalidUUID) | ||
.header("Authorization", "Bearer " + token) | ||
.when().patch("/api/v1/meetings/{uuid}/unlock") | ||
.then().log().all() | ||
.statusCode(HttpStatus.BAD_REQUEST.value()); | ||
|
@@ -235,9 +235,9 @@ void unlockWithNoPermission() { | |
String token = getToken(attendee, meeting); | ||
|
||
RestAssured.given().log().all() | ||
.cookie("ACCESS_TOKEN", token) | ||
.contentType(ContentType.JSON) | ||
.pathParam("uuid", meeting.getUuid()) | ||
.header("Authorization", "Bearer " + token) | ||
.when().patch("/api/v1/meetings/{uuid}/unlock") | ||
.then().log().all() | ||
.statusCode(HttpStatus.FORBIDDEN.value()); | ||
|
@@ -252,6 +252,6 @@ private String getToken(Attendee attendee, Meeting meeting) { | |
.when().post("/api/v1/meetings/{uuid}/login", meeting.getUuid()) | ||
.then().log().all() | ||
.statusCode(HttpStatus.OK.value()) | ||
.extract().jsonPath().getString("data.token"); | ||
.extract().cookie("ACCESS_TOKEN"); | ||
} | ||
} |
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.
궁금해서 SET-COOKIE 에 들어갈 key-value 이름 컨벤션도 찾아봤는데 역시나 이상없네요 👍