From bf9e091159fb6663ec77fed0714e19e9f2a3e18c Mon Sep 17 00:00:00 2001 From: peanut Date: Sun, 20 Nov 2022 18:31:24 +0900 Subject: [PATCH] =?UTF-8?q?#5=20refactor:=20=ED=95=84=EC=9A=94=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20sout=20=EC=82=AD=EC=A0=9C,=20ServiceResponse=20-=20?= =?UTF-8?q?get,=20set=20Lombok=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AppleController.java | 38 ++++--------------- .../applelogin/model/ServicesResponse.java | 37 +----------------- .../applelogin/service/AppleServiceImpl.java | 11 +----- .../user/dto/request/CreateUserAppleReq.java | 5 --- 4 files changed, 10 insertions(+), 81 deletions(-) diff --git a/server/src/main/java/com/yogit/server/applelogin/controller/AppleController.java b/server/src/main/java/com/yogit/server/applelogin/controller/AppleController.java index 0bd568d..62553e9 100644 --- a/server/src/main/java/com/yogit/server/applelogin/controller/AppleController.java +++ b/server/src/main/java/com/yogit/server/applelogin/controller/AppleController.java @@ -22,49 +22,21 @@ public class AppleController { @Autowired AppleService appleService; - /** - * Apple Login 유저 정보를 받은 후 권한 생성 - * privateKey 로 사용자 개인 정보와 refreshToken 발급받기 - * @param serviceResponse - * @return - */ -// @PostMapping(value = "/redirect") -// @ResponseBody -// public TokenResponse servicesRedirect(@RequestBody ServicesResponse serviceResponse) throws NoSuchAlgorithmException { -// -// if (serviceResponse == null) { -// return null; -// } -// -// String code = serviceResponse.getCode(); -// String id_token = serviceResponse.getId_token(); -// String client_secret = appleService.getAppleClientSecret(serviceResponse.getId_token()); -// -// logger.debug("================================"); -// logger.debug("id_token ‣ " + serviceResponse.getId_token()); -// logger.debug("payload ‣ " + appleService.getPayload(serviceResponse.getId_token())); -// logger.debug("client_secret ‣ " + client_secret); -// logger.debug("================================"); -// -// return appleService.requestCodeValidations(client_secret, code, null); -// } - /** * Apple 회원가입 * privateKey 로 사용자 개인 정보와 refreshToken 발급받기 - * @param serviceResponse * @return */ @PostMapping(value = "/sign-up/apple") @ResponseBody - public TokenResponse signUpApple(@RequestBody ServicesResponse serviceResponse) throws NoSuchAlgorithmException { + public TokenResponse signUpApple(@RequestBody ServicesResponse servicesResponse) throws NoSuchAlgorithmException { - if (serviceResponse == null) { // TODO 예외처리 + if (servicesResponse == null) { // TODO 예외처리 System.out.println("요청 값이 없습니다."); return null; } - return appleService.requestCodeValidations(serviceResponse, null); + return appleService.requestCodeValidations(servicesResponse, null); } /** @@ -73,6 +45,10 @@ public TokenResponse signUpApple(@RequestBody ServicesResponse serviceResponse) * @param client_secret * @param refresh_token * @return + * refresh_token은 만료되지 않기 때문에 + * 권한이 필요한 요청일 경우 굳이 매번 애플 ID 서버로부터 refresh_token을 통해 access_token을 발급 받기보다는 + * 유저의 refresh_token을 따로 DB나 기타 저장소에 저장해두고 캐싱해두고 조회해서 검증하는편이 성능면에서 낫다고 함.. + * 우리도 db에 refresh token을 따로 저장해서 사용하므로 이 메소드는 필요 없지 않을까.. */ // @PostMapping(value = "/refresh") // @ResponseBody diff --git a/server/src/main/java/com/yogit/server/applelogin/model/ServicesResponse.java b/server/src/main/java/com/yogit/server/applelogin/model/ServicesResponse.java index 3b7fbcb..4108fe8 100644 --- a/server/src/main/java/com/yogit/server/applelogin/model/ServicesResponse.java +++ b/server/src/main/java/com/yogit/server/applelogin/model/ServicesResponse.java @@ -2,48 +2,15 @@ import lombok.Data; +import lombok.NoArgsConstructor; import net.minidev.json.JSONObject; @Data +@NoArgsConstructor public class ServicesResponse { private String state; private String code; private String id_token; private JSONObject user; - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getId_token() { - return id_token; - } - - public void setId_token(String id_token) { - this.id_token = id_token; - } - -// public String getUser() { -// return user; -// } -// -// public void setUser(String user) { -// this.user = user; -// } - - public ServicesResponse() { - } } diff --git a/server/src/main/java/com/yogit/server/applelogin/service/AppleServiceImpl.java b/server/src/main/java/com/yogit/server/applelogin/service/AppleServiceImpl.java index 06beec4..8824dbf 100644 --- a/server/src/main/java/com/yogit/server/applelogin/service/AppleServiceImpl.java +++ b/server/src/main/java/com/yogit/server/applelogin/service/AppleServiceImpl.java @@ -57,28 +57,19 @@ public TokenResponse requestCodeValidations(ServicesResponse serviceResponse, St // 이메일 추출 String email = user.getAsString("email"); - System.out.println("email : " + email); // 이름 추출 - //JSONObject name = (JSONObject)user.get("name"); Map name = (Map) user.get("name"); String lastName = name.get("lastName"); String firstName = name.get("firstName"); String fullName = lastName + firstName; - System.out.println("fullName : " + fullName); // 만약 처음 인증하는 유저여서 refresh 토큰 없으면 client_secret, authorization_code로 검증 if (client_secret != null && code != null && refresh_token == null) { tokenResponse = appleUtils.validateAuthorizationGrantCode(client_secret, code); - // 유저 엔티티 생성 + // 유저 생성 CreateUserAppleReq createUserAppleReq = new CreateUserAppleReq(email, tokenResponse.getRefresh_token(),fullName); - System.out.println("========req======="); - System.out.println("name : " + createUserAppleReq.getName()); - System.out.println("loginId : " + createUserAppleReq.getLoginId()); - System.out.println("refresh_token : " + createUserAppleReq.getRefresh_token()); - System.out.println("================="); - userService.createUserApple(createUserAppleReq); tokenResponse.setName(fullName); diff --git a/server/src/main/java/com/yogit/server/user/dto/request/CreateUserAppleReq.java b/server/src/main/java/com/yogit/server/user/dto/request/CreateUserAppleReq.java index c5bd9de..e43c918 100644 --- a/server/src/main/java/com/yogit/server/user/dto/request/CreateUserAppleReq.java +++ b/server/src/main/java/com/yogit/server/user/dto/request/CreateUserAppleReq.java @@ -16,11 +16,6 @@ public class CreateUserAppleReq { public static User toEntityUserApple(CreateUserAppleReq createUserAppleReq){ User user = new User(createUserAppleReq.loginId, createUserAppleReq.refresh_token, createUserAppleReq.name); - - System.out.println(user.getLoginId()); - System.out.println(user.getRefresh_token()); - System.out.println(user.getName()); - return user; } }