Skip to content

Commit

Permalink
[FIX] 카카오 소셜로그인 Redirect시 토큰을 쿼리파라미터로 전달하도록 수정 (#219)
Browse files Browse the repository at this point in the history
fix: redirect시 응답 본문 대신 쿼리파라미터로 토큰 반환

resolve #218
  • Loading branch information
Profile-exe authored Nov 27, 2024
1 parent 0de4641 commit 61e55f0
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -57,16 +56,18 @@ public ApiResponse<CustomBody<String>> logout(HttpServletRequest request) {

@Operation(summary = "카카오 소셜 로그인 (코드로 로그인)", description = "Redirect URL이 백엔드 주소로 설정될 때 사용합니다.")
@GetMapping("/login")
public ApiResponse<CustomBody<AuthToken>> 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이 프론트엔드 주소로 설정될 때 사용합니다.")
Expand Down

0 comments on commit 61e55f0

Please sign in to comment.