Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public class KakaoController {
)
@ApiResponse(responseCode = "302", description = "카카오 로그인 페이지로 리디렉션됨")
@GetMapping("/login")
public void redirectToKakao(HttpServletResponse response) throws IOException {
String kakaoAuthUrl = kakaoService.getKakaoAuthUrl();
public void redirectToKakao(
@Parameter(description = "모바일 앱 여부") @RequestParam(value = "mobile", required = false, defaultValue = "false") boolean mobile,
HttpServletResponse response) throws IOException {
String kakaoAuthUrl = kakaoService.getKakaoAuthUrl(mobile);
response.sendRedirect(kakaoAuthUrl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,32 @@ public class KakaoService {
@Value("${kakao.redirectUri}")
private String redirectUri;

public String getKakaoAuthUrl() {
@Value("${kakao.mobileRedirectUri}")
private String mobileRedirectUri;

public String getKakaoAuthUrl(boolean mobile) {
String targetRedirectUri = mobile ? mobileRedirectUri : redirectUri;
return "https://kauth.kakao.com/oauth/authorize?response_type=code"
+ "&client_id=" + restApiKey
+ "&redirect_uri=" + redirectUri
+ "&redirect_uri=" + targetRedirectUri
+ "&scope=account_email,profile_nickname,profile_image";
}

public ResponseEntity<KakaoResponse.loginResponse> getUserInfo(String code) {
return getUserInfo(code, false);
}

public ResponseEntity<KakaoResponse.loginResponse> getUserInfo(String code, boolean mobile) {
try {
RestTemplate restTemplate = new RestTemplate();
String targetRedirectUri = mobile ? mobileRedirectUri : redirectUri;

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("grant_type", "authorization_code");
params.add("client_id", restApiKey);
params.add("redirect_uri", redirectUri);
params.add("redirect_uri", targetRedirectUri);
params.add("code", code);

HttpEntity<MultiValueMap<String, String>> tokenRequest = new HttpEntity<>(params, headers);
Expand Down
Loading