Skip to content

Commit

Permalink
#146 Feat: kakao 로그인 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-haeseung committed Aug 11, 2024
1 parent 2d366da commit f03cc74
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -29,6 +35,7 @@
import com.codiary.backend.global.web.dto.Member.FollowResponseDto;
import com.codiary.backend.global.web.dto.Member.MemberSumResponseDto;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

Expand Down Expand Up @@ -248,4 +255,36 @@ public ApiResponse<?> setProjects(@PathVariable(value = "projectName") String pr
memberCommandService.setProjects(member.getMemberId(), projectName);
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, memberCommandService.setProjects(member.getMemberId(), projectName));
}

@PostMapping("/login/kakao")
@Operation(summary = "카카오 로그인")
public ApiResponse<String> kakaoLogin() {
String url = "https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=__&redirect_uri=__";
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, "redirect:" + url.toString());
}

@GetMapping("/login/kakao")
@Operation(summary = "카카오 서버에서 요청하는 api")
public ApiResponse<String> kekaoToken(@RequestParam String code) {

HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");

MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
body.add("grant_type", "authorization_code");
body.add("client_id", "__");
body.add("redirect_uri", "__");
body.add("code", code);

HttpEntity<MultiValueMap<String, String>> kakaoTokenRequest = new HttpEntity<>(body, headers);
RestTemplate rt = new RestTemplate();
ResponseEntity<String> response = rt.exchange(
"https://kauth.kakao.com/oauth/token",
HttpMethod.POST,
kakaoTokenRequest,
String.class
);

return null;
}
}

0 comments on commit f03cc74

Please sign in to comment.