토큰받기 성공, 사용자정보조회 시작
This commit is contained in:
@@ -6,8 +6,9 @@ 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.LoginRequestDto;
|
||||
import site.ocr.prd.dto.LoginResponseDto;
|
||||
import site.ocr.prd.dto.LoginReqDTO;
|
||||
import site.ocr.prd.dto.LoginResDTO;
|
||||
import site.ocr.prd.dto.UserInfoInqyReqDTO;
|
||||
import site.ocr.prd.services.LoginService;
|
||||
|
||||
|
||||
@@ -18,22 +19,45 @@ public class LoginController {
|
||||
//service 선언
|
||||
private LoginService loginService = new LoginService(WebClient.builder());
|
||||
|
||||
@GetMapping("/oauth/oauth-kakao-authorize") //kakao에서 get으로 요청 보냄
|
||||
/**
|
||||
* 프론트에서 카카오로 로그인 요청 후 카카오에서 리다이렉트 해준 인가코드로 토큰 발급 및 사용자정보 조회
|
||||
* @param redirectRespn 카카오에서 리다이렉트해준 인가코드
|
||||
*/
|
||||
@GetMapping("/oauth/oauth-kakao-authorize") //kakao에서 get으로 리다이렉트 해줌
|
||||
public void kakaoLoginRequestDto(HttpServletRequest redirectRespn) {
|
||||
String accessToken = redirectRespn.getParameter("code");
|
||||
System.out.println(accessToken);
|
||||
LoginRequestDto requestDTO = new LoginRequestDto();
|
||||
requestDTO.setGrant_type("authorization_code");
|
||||
requestDTO.setClient_id("a1d6afef2d4508a10a498b7069f67496");
|
||||
requestDTO.setRedirect_uri("http://localhost:9001/oauth/oauth-kakao-authorize");
|
||||
requestDTO.setCode(accessToken);
|
||||
String code = redirectRespn.getParameter("code");
|
||||
System.out.println("인가코드 :: " + code);
|
||||
|
||||
/**
|
||||
* 카카오에 토큰값 요청
|
||||
* requestDTO
|
||||
* @param grant_type
|
||||
* @param client_id 카카오콘솔의 app key
|
||||
* @param code 인가코드
|
||||
*/
|
||||
LoginReqDTO loginRequest = new LoginReqDTO();
|
||||
loginRequest.setGrant_type("authorization_code");
|
||||
loginRequest.setClient_id("a1d6afef2d4508a10a498b7069f67496");
|
||||
loginRequest.setRedirect_uri("http://localhost:9001/oauth/oauth-kakao-authorize");
|
||||
loginRequest.setCode(code);
|
||||
|
||||
/**
|
||||
* 카카오로부터 받은 토큰값
|
||||
* @param access_token 사용자정보 조회용 토큰
|
||||
* @param expires_in 토큰 유효시간(초)
|
||||
* @param refresh_token 사용자 리프레시 토큰
|
||||
*/
|
||||
LoginResDTO loginResult = loginService.getToken(loginRequest);
|
||||
System.out.println("결과 :: " + loginResult.toString());
|
||||
|
||||
UserInfoInqyReqDTO userInfoInqyRequest = new UserInfoInqyReqDTO();
|
||||
userInfoInqyRequest.setAccess_token(loginResult.getAccess_token());
|
||||
|
||||
|
||||
LoginResponseDto result = loginService.getToken(requestDTO);
|
||||
System.out.println("결과 :: " + result.toString());
|
||||
}
|
||||
|
||||
@GetMapping("login/oauth-kakao-token")
|
||||
public String kakaoLoginResponseDto(@RequestBody LoginResponseDto response) {
|
||||
public String kakaoLoginResponseDto(@RequestBody LoginResDTO response) {
|
||||
//TODO: process POST request
|
||||
System.out.println("response :: ");
|
||||
System.out.println(response.getAccess_token());
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Getter
|
||||
@Setter
|
||||
public class LoginRequestDto {
|
||||
public class LoginReqDTO {
|
||||
|
||||
@JsonProperty("grant_type")
|
||||
String grant_type; //authorization_code
|
||||
17
prd/src/main/java/site/ocr/prd/dto/UserInfoInqyReqDTO.java
Normal file
17
prd/src/main/java/site/ocr/prd/dto/UserInfoInqyReqDTO.java
Normal file
@@ -0,0 +1,17 @@
|
||||
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 UserInfoInqyReqDTO {
|
||||
|
||||
@JsonProperty("access_token")
|
||||
String access_token;
|
||||
|
||||
}
|
||||
24
prd/src/main/java/site/ocr/prd/dto/UserInfoInqyResDTO.java
Normal file
24
prd/src/main/java/site/ocr/prd/dto/UserInfoInqyResDTO.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package site.ocr.prd.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserInfoInqyResDTO {
|
||||
|
||||
class Request {
|
||||
@JsonProperty("id")
|
||||
String id;
|
||||
|
||||
@JsonProperty("properties")
|
||||
|
||||
}
|
||||
|
||||
class Properties {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user