Skip to content

Commit

Permalink
#5 fix: 애플 로그인중 테스트를 위한 sout 모두 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaktmchl committed Nov 7, 2022
1 parent fd57b74 commit 1aa6713
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 69 deletions.
65 changes: 65 additions & 0 deletions .idea/libraries-with-intellij-classes.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class AppleController {

/**
* Sign in with Apple - JS Page (index.html)
*
*애플 로그인 index 페이지
* @param model
* @return
*/
Expand All @@ -37,17 +37,12 @@ public String appleLoginPage(ModelMap model) {
model.addAttribute("redirect_uri", metaInfo.get("REDIRECT_URI"));
model.addAttribute("nonce", metaInfo.get("NONCE"));

System.out.println(model.getAttribute("client_id"));
System.out.println(model.getAttribute("redirect_uri"));
System.out.println(model.getAttribute("nonce"));


return "index";
}

/**
* Apple login page Controller (SSL - https)
*
* publickey 요청 후 받은 데이터와 함계 redirect 페이지로 연결
* @param model
* @return
*/
Expand All @@ -63,60 +58,33 @@ public String appleLogin(ModelMap model) {
model.addAttribute("scope", "name email");
model.addAttribute("response_mode", "form_post");

System.out.println("==========================");
System.out.println(model.getAttribute("client_id"));
System.out.println(model.getAttribute("redirect_uri"));
System.out.println(model.getAttribute("nonce"));
System.out.println(model.getAttribute("response_type"));
System.out.println(model.getAttribute("scope"));
System.out.println(model.getAttribute("response_mode"));


return "redirect:https://appleid.apple.com/auth/authorize";
}

/**
* Apple Login 유저 정보를 받은 후 권한 생성
*
* privateKey 로 사용자 개인 정보와 refreshToken 발급받기
* @param serviceResponse
* @return
*/
@PostMapping(value = "/redirect")
@ResponseBody
public TokenResponse servicesRedirect(ServicesResponse serviceResponse) throws NoSuchAlgorithmException {

System.out.println("1-------------");
if (serviceResponse == null) {
return null;
}
System.out.println("2-------------");


System.out.println(serviceResponse);
System.out.println("3-------------");


String code = serviceResponse.getCode();
System.out.println(code);
System.out.println("4-------------");

String id_token = serviceResponse.getId_token();
System.out.println(id_token);
System.out.println("5-------------");

String client_secret = appleService.getAppleClientSecret(serviceResponse.getId_token());
System.out.println(client_secret);
System.out.println("6-------------");


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("================================");

System.out.println("7-------------");

return appleService.requestCodeValidations(client_secret, code, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,35 +146,20 @@ public String createClientSecret() {
SignedJWT jwt = new SignedJWT(header, claimsSet);

try {
// ECPrivateKey ecPrivateKey = new ECPrivateKeyImpl2(readPrivateKey());
// JWSSigner jwsSigner = new ECDSASigner(ecPrivateKey.getS());
//
// jwt.sign(jwsSigner);
System.out.println("=====새로운 시도 1=====");
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(readPrivateKey());
System.out.println("=====새로운 시도 5=====");


try{
KeyFactory kf = KeyFactory.getInstance("EC");
System.out.println("=====새로운 시도 6=====");
ECPrivateKey ecPrivateKey = (ECPrivateKey) kf.generatePrivate(spec);
System.out.println("=====새로운 시도 7=====");
System.out.println("=====새로운 시도 7.5====="+ecPrivateKey.getS());
JWSSigner jwsSigner = new ECDSASigner(ecPrivateKey.getS());
System.out.println("=====새로운 시도 8=====");
jwt.sign(jwsSigner);
System.out.println("=====새로운 시도 9=====");
}catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}catch (InvalidKeySpecException e){
e.printStackTrace();
}

}
// catch (InvalidKeyException e) {
// e.printStackTrace();
// }
catch (JOSEException e) {
e.printStackTrace();
}
Expand All @@ -191,20 +176,13 @@ private byte[] readPrivateKey() {

ClassPathResource resource = new ClassPathResource(KEY_PATH);


// Resource resource = new ClassPathResource(KEY_PATH);
byte[] content = null;
System.out.println("=====새로운 시도 2=====");
try (Reader keyReader = new InputStreamReader(resource.getInputStream());

PemReader pemReader = new PemReader(keyReader)) {
{
System.out.println("=====새로운 시도 3=====");
PemObject pemObject = pemReader.readPemObject();
System.out.println("=====새로운 시도 3.5=====");
content = pemObject.getContent();
System.out.println("=====새로운 시도 4=====");
System.out.println(content+"=====content=====");
}
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -261,15 +239,9 @@ public TokenResponse validateAnExistingRefreshToken(String client_secret, String
private TokenResponse getTokenResponse(Map<String, String> tokenRequest) {

try {
System.out.println("======tokenRequest"+tokenRequest);
String response = HttpClientUtils.doPost(AUTH_TOKEN_URL, tokenRequest);
System.out.println("======response"+response);

ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false); // null허용 설정 추가
System.out.println("======objectMapper"+objectMapper);

TokenResponse tokenResponse = objectMapper.readValue(response, TokenResponse.class);
System.out.println("======tokenResponse"+tokenResponse);

if (tokenRequest != null) {
return tokenResponse;
Expand Down Expand Up @@ -307,16 +279,10 @@ public JSONObject decodeFromIdToken(String id_token) {

try {
SignedJWT signedJWT = SignedJWT.parse(id_token);
System.out.println("=====payload1"+signedJWT );
ReadOnlyJWTClaimsSet getPayload = signedJWT.getJWTClaimsSet();
System.out.println("=====payload2"+getPayload);
ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
// objectMapper.enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT); // null 값 허용
// objectMapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
// Payload payload = objectMapper.readValue(getPayload.toJSONObject().toJSONString(), Payload.class);
JSONObject payload = objectMapper.readValue(getPayload.toJSONObject().toJSONString(), JSONObject.class);

System.out.println("=====payload3"+payload );
if (payload != null) {
return payload;
}
Expand Down

0 comments on commit 1aa6713

Please sign in to comment.