Skip to content

Commit

Permalink
#5 refactor: 필요 없는 sout 삭제, ServiceResponse - get, set Lombok 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
peanut committed Nov 20, 2022
1 parent 3cf8319 commit bf9e091
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> name = (Map<String, String>) 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit bf9e091

Please sign in to comment.