login success
This commit is contained in:
@@ -12,8 +12,7 @@ public class WebClientConfig {
|
||||
public WebClient webClient() {
|
||||
return WebClient.builder()
|
||||
.defaultHeaders(httpHeaders -> {
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
httpHeaders.set("charset", "utf-8");
|
||||
httpHeaders.setContentType(MediaType.valueOf("application/x-www-form-urlencoded;charset=utf-8"));
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package site.ocr.prd.contorllers;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import site.ocr.prd.dto.LoginRequest;
|
||||
@@ -7,25 +8,36 @@ import site.ocr.prd.dto.LoginResponse;
|
||||
import site.ocr.prd.services.LoginService;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
|
||||
|
||||
@RestController
|
||||
public class LoginController {
|
||||
|
||||
@GetMapping("login/oauth-kakao")
|
||||
public LoginResponse kakaoLogin(HttpServletRequest query) {
|
||||
@GetMapping("login/oauth-kakao-token")
|
||||
public LoginResponse kakaoLoginRequest(HttpServletRequest query) {
|
||||
System.out.println("data ::: ");
|
||||
String accessToken = query.getParameter("code");
|
||||
System.out.println(accessToken);
|
||||
LoginRequest requestDTO = new LoginRequest();
|
||||
requestDTO.setGrantType("authorization_code");
|
||||
requestDTO.setClientId("a1d6afef2d4508a10a498b7069f67496");
|
||||
requestDTO.setRedirectUri("http://localhost:9001/login/oauth-kakao");
|
||||
requestDTO.setRedirectUri("http://localhost:9001/login/oauth-kakao-response");
|
||||
requestDTO.setCode(accessToken);
|
||||
LoginResponse response = new LoginService().loginService(requestDTO);
|
||||
System.out.println("response :: ");
|
||||
System.out.println(response);
|
||||
LoginResponse response = new LoginService(WebClient.builder()).loginService(requestDTO);
|
||||
return response;
|
||||
}
|
||||
|
||||
@PostMapping("login/oauth-kakao-response")
|
||||
public String kakaoLoginResponse( entity) {
|
||||
//TODO: process POST request
|
||||
System.out.println("response :: ");
|
||||
System.out.println(entity);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,19 +8,23 @@ import site.ocr.prd.dto.LoginResponse;
|
||||
|
||||
@Service
|
||||
public class LoginService {
|
||||
|
||||
private final WebClient webClient;
|
||||
|
||||
public LoginService(WebClient.Builder builder) {
|
||||
this.webClient = builder.build();
|
||||
}
|
||||
|
||||
public LoginResponse loginService(LoginRequest request) {
|
||||
|
||||
private final WebClient webClient;
|
||||
|
||||
LoginResponse response = new LoginResponse();
|
||||
System.out.println(request.toString());
|
||||
response = webClient.post()
|
||||
.uri("https://kauth.kakao.com/oauth/token")
|
||||
.uri("https://kauth.kakao.com/oauth/token/")
|
||||
.bodyValue(request)
|
||||
.retrieve()
|
||||
.bodyToMono(LoginResponse.class)
|
||||
.block();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user