수정중
This commit is contained in:
@@ -3,8 +3,8 @@ 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;
|
||||
import site.ocr.prd.dto.LoginResponse;
|
||||
import site.ocr.prd.dto.LoginRequestDto;
|
||||
import site.ocr.prd.dto.LoginResponseDto;
|
||||
import site.ocr.prd.services.LoginService;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -15,28 +15,31 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@RestController
|
||||
public class LoginController {
|
||||
|
||||
//service 선언
|
||||
private LoginService loginService = new LoginService(WebClient.builder());
|
||||
|
||||
@GetMapping("login/oauth-kakao-token")
|
||||
public LoginResponse kakaoLoginRequest(HttpServletRequest query) {
|
||||
System.out.println("data ::: ");
|
||||
String accessToken = query.getParameter("code");
|
||||
@GetMapping("login/oauth-kakao-authorize") //kakao에서 get으로 요청 보냄
|
||||
public void kakaoLoginRequestDto(HttpServletRequest request) {
|
||||
String accessToken = request.getParameter("code");
|
||||
System.out.println(accessToken);
|
||||
LoginRequest requestDTO = new LoginRequest();
|
||||
LoginRequestDto requestDTO = new LoginRequestDto();
|
||||
requestDTO.setGrantType("authorization_code");
|
||||
requestDTO.setClientId("a1d6afef2d4508a10a498b7069f67496");
|
||||
requestDTO.setRedirectUri("http://localhost:9001/login/oauth-kakao-response");
|
||||
requestDTO.setRedirectUri("http://localhost:9001/login/oauth-kakao-authorize");
|
||||
requestDTO.setCode(accessToken);
|
||||
LoginResponse response = new LoginService(WebClient.builder()).loginService(requestDTO);
|
||||
return response;
|
||||
|
||||
loginService.getToken(requestDTO);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("login/oauth-kakao-response")
|
||||
public String kakaoLoginResponse( entity) {
|
||||
@PostMapping("login/oauth-kakao-token")
|
||||
public String kakaoLoginResponseDto(@RequestBody LoginResponseDto response) {
|
||||
//TODO: process POST request
|
||||
System.out.println("response :: ");
|
||||
System.out.println(entity);
|
||||
System.out.println(response.getAccessToken());
|
||||
|
||||
return entity;
|
||||
return response.getAccessToken();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package site.ocr.prd.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -7,10 +9,13 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Getter
|
||||
@Setter
|
||||
public class LoginRequest {
|
||||
public class LoginRequestDto {
|
||||
|
||||
@JsonProperty("grant_type")
|
||||
String grantType; //authorization_code
|
||||
@JsonProperty("client_id")
|
||||
String clientId; //앱 REST API 키
|
||||
@JsonProperty("redirect_uri")
|
||||
String redirectUri; //인가코드가 리다이렉트된 uri
|
||||
String code; //인가코드 요청으로 얻은 인가코드
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package site.ocr.prd.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Getter
|
||||
@Setter
|
||||
public class LoginResponse {
|
||||
|
||||
String grantType; //authorization_code
|
||||
String clientId; //앱 REST API 키
|
||||
String redirectUri; //인가코드가 리다이렉트된 uri
|
||||
String code; //인가코드 요청으로 얻은 인가코드
|
||||
}
|
||||
27
prd/src/main/java/site/ocr/prd/dto/LoginResponseDto.java
Normal file
27
prd/src/main/java/site/ocr/prd/dto/LoginResponseDto.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package site.ocr.prd.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Getter
|
||||
@Setter
|
||||
public class LoginResponseDto {
|
||||
|
||||
@JsonProperty("token_type")
|
||||
String tokenType; //토큰타입, bearer 고정
|
||||
@JsonProperty("access_token")
|
||||
String accessToken; //사용자 엑세스 토큰 값
|
||||
@JsonProperty("id_token")
|
||||
String idToken; //ID 토큰값, openID connect가 활성화된 경우만 발급
|
||||
@JsonProperty("expires_in")
|
||||
Integer expiresIn; //엑세스토큰과 id토큰의 만료시간(초))
|
||||
@JsonProperty("refresh_token")
|
||||
String refreshToken; //사용자 리프레시 토큰 값
|
||||
@JsonProperty("refresh_token_expires_in")
|
||||
Integer refreshTokenExpiresIn; //리프레시 토큰 만료 시간(초)
|
||||
String scope; //인증된 사용자의 정보조회 범위, 여러개일 경우 공백으로 구분
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package site.ocr.prd.services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import site.ocr.prd.dto.LoginRequest;
|
||||
import site.ocr.prd.dto.LoginResponse;
|
||||
import site.ocr.prd.dto.LoginRequestDto;
|
||||
import site.ocr.prd.dto.LoginResponseDto;
|
||||
|
||||
@Service
|
||||
public class LoginService {
|
||||
@@ -15,17 +16,18 @@ public class LoginService {
|
||||
this.webClient = builder.build();
|
||||
}
|
||||
|
||||
public LoginResponse loginService(LoginRequest request) {
|
||||
public String getToken(LoginRequestDto request) {
|
||||
|
||||
LoginResponse response = new LoginResponse();
|
||||
System.out.println(request.toString());
|
||||
response = webClient.post()
|
||||
System.out.println("요청 ::: " + request.toString());
|
||||
String result = webClient.post()
|
||||
.uri("https://kauth.kakao.com/oauth/token/")
|
||||
.bodyValue(request)
|
||||
.retrieve()
|
||||
.bodyToMono(LoginResponse.class)
|
||||
//.bodyToMono(LoginResponseDto.class)
|
||||
.bodyToMono(String.class)
|
||||
.block();
|
||||
return response;
|
||||
System.out.println("성공여부 ::: " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user