사용자정보 가져오기 성공
This commit is contained in:
2
prd/.gitignore
vendored
2
prd/.gitignore
vendored
@@ -34,4 +34,4 @@ out/
|
|||||||
/.nb-gradle/
|
/.nb-gradle/
|
||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/*
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import site.ocr.prd.dto.LoginReqDTO;
|
import site.ocr.prd.dto.LoginReqDTO;
|
||||||
import site.ocr.prd.dto.LoginResDTO;
|
import site.ocr.prd.dto.LoginResDTO;
|
||||||
import site.ocr.prd.dto.UserInfoInqyReqDTO;
|
import site.ocr.prd.dto.UserInfoInqyReqDTO;
|
||||||
|
import site.ocr.prd.dto.UserInfoInqyResDTO;
|
||||||
import site.ocr.prd.services.LoginService;
|
import site.ocr.prd.services.LoginService;
|
||||||
|
|
||||||
|
|
||||||
@@ -53,6 +54,10 @@ public class LoginController {
|
|||||||
UserInfoInqyReqDTO userInfoInqyRequest = new UserInfoInqyReqDTO();
|
UserInfoInqyReqDTO userInfoInqyRequest = new UserInfoInqyReqDTO();
|
||||||
userInfoInqyRequest.setAccess_token(loginResult.getAccess_token());
|
userInfoInqyRequest.setAccess_token(loginResult.getAccess_token());
|
||||||
|
|
||||||
|
UserInfoInqyResDTO userInfoInqyResponse = loginService.getUserInfo(userInfoInqyRequest);
|
||||||
|
System.out.println("사용자정보 :: " + userInfoInqyResponse.toString());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,13 @@ public class LoginReqDTO {
|
|||||||
|
|
||||||
@JsonProperty("grant_type")
|
@JsonProperty("grant_type")
|
||||||
String grant_type; //authorization_code
|
String grant_type; //authorization_code
|
||||||
|
|
||||||
@JsonProperty("client_id")
|
@JsonProperty("client_id")
|
||||||
String client_id; //앱 REST API 키
|
String client_id; //앱 REST API 키
|
||||||
|
|
||||||
@JsonProperty("redirect_uri")
|
@JsonProperty("redirect_uri")
|
||||||
String redirect_uri; //인가코드가 리다이렉트된 uri
|
String redirect_uri; //인가코드가 리다이렉트된 uri
|
||||||
|
|
||||||
@JsonProperty("code")
|
@JsonProperty("code")
|
||||||
String code; //인가코드 요청으로 얻은 인가코드
|
String code; //인가코드 요청으로 얻은 인가코드
|
||||||
}
|
}
|
||||||
@@ -9,19 +9,25 @@ import lombok.ToString;
|
|||||||
@ToString
|
@ToString
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class LoginResponseDto {
|
public class LoginResDTO {
|
||||||
|
|
||||||
@JsonProperty("token_type")
|
@JsonProperty("token_type")
|
||||||
String token_type; //토큰타입, bearer 고정
|
String token_type; //토큰타입, bearer 고정
|
||||||
|
|
||||||
@JsonProperty("access_token")
|
@JsonProperty("access_token")
|
||||||
String access_token; //사용자 엑세스 토큰 값
|
String access_token; //사용자 엑세스 토큰 값
|
||||||
|
|
||||||
@JsonProperty("id_token")
|
@JsonProperty("id_token")
|
||||||
String id_token; //ID 토큰값, openID connect가 활성화된 경우만 발급
|
String id_token; //ID 토큰값, openID connect가 활성화된 경우만 발급
|
||||||
|
|
||||||
@JsonProperty("expires_in")
|
@JsonProperty("expires_in")
|
||||||
Integer expires_in; //엑세스토큰과 id토큰의 만료시간(초))
|
Integer expires_in; //엑세스토큰과 id토큰의 만료시간(초))
|
||||||
|
|
||||||
@JsonProperty("refresh_token")
|
@JsonProperty("refresh_token")
|
||||||
String refresh_token; //사용자 리프레시 토큰 값
|
String refresh_token; //사용자 리프레시 토큰 값
|
||||||
|
|
||||||
@JsonProperty("refresh_token_expires_in")
|
@JsonProperty("refresh_token_expires_in")
|
||||||
Integer refresh_token_expires_in; //리프레시 토큰 만료 시간(초)
|
Integer refresh_token_expires_in; //리프레시 토큰 만료 시간(초)
|
||||||
|
|
||||||
String scope; //인증된 사용자의 정보조회 범위, 여러개일 경우 공백으로 구분
|
String scope; //인증된 사용자의 정보조회 범위, 여러개일 경우 공백으로 구분
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,6 @@ import lombok.ToString;
|
|||||||
@Setter
|
@Setter
|
||||||
public class UserInfoInqyReqDTO {
|
public class UserInfoInqyReqDTO {
|
||||||
|
|
||||||
class Request {
|
|
||||||
@JsonProperty("access_token")
|
@JsonProperty("access_token")
|
||||||
String access_token;
|
String access_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Properties {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package site.ocr.prd.dto;
|
package site.ocr.prd.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
@@ -10,28 +8,10 @@ import lombok.ToString;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class UserInfoInqyResDTO {
|
public class UserInfoInqyResDTO {
|
||||||
|
|
||||||
class Response {
|
|
||||||
@JsonProperty("id")
|
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
@JsonProperty("properties")
|
|
||||||
KakaoAccount account;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class KakaoAccount {
|
|
||||||
PropertiesKeys keys;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class PropertiesKeys {
|
|
||||||
String profile;
|
|
||||||
String name;
|
String name;
|
||||||
String email;
|
String email;
|
||||||
String age_range;
|
String age_range;
|
||||||
String birthday;
|
String birthday;
|
||||||
String gender;
|
String gender;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
package site.ocr.prd.services;
|
package site.ocr.prd.services;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.reactive.function.BodyInserters;
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import site.ocr.prd.dto.LoginReqDTO;
|
import site.ocr.prd.dto.LoginReqDTO;
|
||||||
import site.ocr.prd.dto.LoginResDTO;
|
import site.ocr.prd.dto.LoginResDTO;
|
||||||
|
import site.ocr.prd.dto.UserInfoInqyReqDTO;
|
||||||
|
import site.ocr.prd.dto.UserInfoInqyResDTO;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class LoginService {
|
public class LoginService {
|
||||||
@@ -34,5 +40,30 @@ public class LoginService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserInfoInqyResDTO getUserInfo(UserInfoInqyReqDTO request) {
|
||||||
|
|
||||||
|
// 응답 DTO
|
||||||
|
UserInfoInqyResDTO result = new UserInfoInqyResDTO();
|
||||||
|
|
||||||
|
JsonNode root = webClient.get()
|
||||||
|
.uri("https://kapi.kakao.com/v2/user/me")
|
||||||
|
.header(HttpHeaders.AUTHORIZATION, "Bearer " + request.getAccess_token())
|
||||||
|
.retrieve()
|
||||||
|
.bodyToMono(JsonNode.class)
|
||||||
|
.block();
|
||||||
|
|
||||||
|
//사용자ID
|
||||||
|
String id = root.path("id").asText();
|
||||||
|
String name = root.path("name").asText();
|
||||||
|
String email = root.path("email").asText();
|
||||||
|
//jsonnode :: {"id":4438121341,"connected_at":"2025-09-09T03:53:23Z"}
|
||||||
|
System.out.println("jsonnode :: " + root.toString());
|
||||||
|
result.setId(id);
|
||||||
|
result.setName(name);
|
||||||
|
result.setEmail(email);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user