From 61e55f081bfd3c67bbdb41a33b1d9a0895eb99f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=AA=85=EB=8D=95?= <68066437+Profile-exe@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:06:51 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20=EC=86=8C?= =?UTF-8?q?=EC=85=9C=EB=A1=9C=EA=B7=B8=EC=9D=B8=20Redirect=EC=8B=9C=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=EC=9D=84=20=EC=BF=BC=EB=A6=AC=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=EB=AF=B8=ED=84=B0=EB=A1=9C=20=EC=A0=84=EB=8B=AC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#219)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: redirect시 응답 본문 대신 쿼리파라미터로 토큰 반환 resolve #218 --- .../auth/controller/OAuthController.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/econo/buddybridge/auth/controller/OAuthController.java b/src/main/java/econo/buddybridge/auth/controller/OAuthController.java index cceb9a4..f41ee8b 100644 --- a/src/main/java/econo/buddybridge/auth/controller/OAuthController.java +++ b/src/main/java/econo/buddybridge/auth/controller/OAuthController.java @@ -15,11 +15,12 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import java.io.IOException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -28,8 +29,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.net.URI; - @Slf4j @RestController @RequiredArgsConstructor @@ -57,16 +56,18 @@ public ApiResponse> logout(HttpServletRequest request) { @Operation(summary = "카카오 소셜 로그인 (코드로 로그인)", description = "Redirect URL이 백엔드 주소로 설정될 때 사용합니다.") @GetMapping("/login") - public ApiResponse> login(@RequestParam("code") String code) { + public void login(@RequestParam("code") String code, HttpServletResponse response) throws IOException { KakaoLoginParams params = new KakaoLoginParams(code); AuthToken authToken = oAuthLoginService.loginWithToken(params); - // 프론트엔드 주소로 redirect - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.setLocation(URI.create(frontUrl)); + String redirectUrl = String.format("%s/?accessToken=%s&refreshToken=%s", + frontUrl, + authToken.accessToken(), + authToken.refreshToken() + ); - return ApiResponseGenerator.success(authToken, httpHeaders, HttpStatus.PERMANENT_REDIRECT); + response.sendRedirect(redirectUrl); } @Operation(summary = "카카오 소셜 로그인 (토큰으로 로그인)", description = "Redirect URL이 프론트엔드 주소로 설정될 때 사용합니다.")