Skip to content

Commit

Permalink
#5 Feat : 애플 회원가입 / 로그인 controller 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
shinhn committed Jan 3, 2023
1 parent 91657c8 commit 299f9e9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yogit.server.applelogin.controller;

import com.yogit.server.applelogin.model.AppleLoginReq;
import com.yogit.server.applelogin.model.AppsResponse;
import com.yogit.server.applelogin.model.ServicesResponse;
import com.yogit.server.applelogin.model.TokenResponse;
Expand Down Expand Up @@ -37,6 +38,23 @@ public ApplicationResponse<TokenResponse> signUpApple(@RequestBody ServicesRespo
return null;
}
TokenResponse tokenResponse = appleService.requestCodeValidations(servicesResponse, null);
return ApplicationResponse.create("애플 회원가입에 성공했습니다.",tokenResponse);
}

/**
* Apple 로그인
*
* @return
*/
@PostMapping(value = "/sign-in/apple")
@ResponseBody
public ApplicationResponse<TokenResponse> signInApple(@RequestBody AppleLoginReq appleLoginReq) throws NoSuchAlgorithmException {

if (appleLoginReq == null) { // TODO 예외처리
System.out.println("요청 값이 없습니다.");
return null;
}
TokenResponse tokenResponse = appleService.requestCodeValidations(appleLoginReq.getServicesResponse(), appleLoginReq.getRefreshToken());
return ApplicationResponse.create("애플 로그인에 성공했습니다.",tokenResponse);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.yogit.server.applelogin.model;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class AppleLoginReq {

private ServicesResponse servicesResponse;

private String refreshToken; // 로그인 처리를 위한 token
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public class TokenResponse {
private String userType; // ex)apple
private Account account;
private Long userId;
private String userName;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.yogit.server.applelogin.service;

import com.yogit.server.applelogin.exception.InvalidRefreshTokenException;
import com.yogit.server.applelogin.exception.NotFoundRefreshTokenException;
import com.yogit.server.applelogin.model.Account;
import com.yogit.server.applelogin.model.ServicesResponse;
import com.yogit.server.applelogin.model.TokenResponse;
Expand All @@ -16,6 +14,7 @@
import net.minidev.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.security.NoSuchAlgorithmException;
import java.util.Map;

Expand Down Expand Up @@ -80,6 +79,7 @@ else if (client_secret != null && code == null && refresh_token != null) {

tokenResponse.setAccount(new Account(serviceResponse.getState(), code, serviceResponse.getId_token(), user, serviceResponse.getIdentifier(), serviceResponse.getHasRequirementInfo()));
tokenResponse.setUserType(UserType.APPLE.toString());

// userId 설정
if(refresh_token == null){
tokenResponse.setUserId(saveduser.getId());
Expand All @@ -88,6 +88,7 @@ else if (client_secret != null && code == null && refresh_token != null) {
User findUser = userRepository.findByAppleRefreshToken(refresh_token)
.orElseThrow(() -> new NotFoundUserException());
tokenResponse.setUserId(findUser.getId());
tokenResponse.setUserName(findUser.getName());
}


Expand Down

0 comments on commit 299f9e9

Please sign in to comment.