Skip to content

Commit

Permalink
[FIX] 애플 로그인 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaeAg committed Oct 3, 2024
1 parent 0d95783 commit af20053
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Date;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemReader;
import org.json.simple.JSONObject;
Expand All @@ -41,6 +42,7 @@
import org.websoso.WSSServer.exception.exception.CustomAppleLoginException;
import org.websoso.WSSServer.service.UserService;

@Slf4j
@Service
@RequiredArgsConstructor
public class AppleService {
Expand Down Expand Up @@ -149,15 +151,20 @@ private JSONObject parseIdToken(String idToken) {

private String createClientSecret() {
try {
log.info("1");
JWSHeader header = new JWSHeader.Builder(JWSAlgorithm.ES256).keyID(appleLoginKey).build();
log.info("2");
JWTClaimsSet claimsSet = buildJwtClaimsSet();
log.info("3");

SignedJWT jwt = new SignedJWT(header, claimsSet);
signJwt(jwt);
log.info("8");

return jwt.serialize();
} catch (Exception e) {
throw new CustomAppleLoginException(CLIENT_SECRET_CREATION_FAILED, "Failed to generate client secret");
String errorMessage = e.getMessage() + "\n" + e.getLocalizedMessage() + "\n" + e.getClass();
throw new CustomAppleLoginException(CLIENT_SECRET_CREATION_FAILED, errorMessage);
}
}

Expand All @@ -177,12 +184,17 @@ private JWTClaimsSet buildJwtClaimsSet() {
private void signJwt(SignedJWT jwt) {
try {
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(readPrivateKey(appleKeyPath));
log.info("4");
KeyFactory keyFactory = KeyFactory.getInstance("EC");
log.info("5");
ECPrivateKey ecPrivateKey = (ECPrivateKey) keyFactory.generatePrivate(spec);
log.info("6");
JWSSigner signer = new ECDSASigner(ecPrivateKey.getS());
jwt.sign(signer);
log.info("7");
} catch (Exception e) {
throw new CustomAppleLoginException(CLIENT_SECRET_CREATION_FAILED, "Failed to create client secret");
String errorMessage = e.getMessage() + "\n" + e.getLocalizedMessage() + "\n" + e.getClass();
throw new CustomAppleLoginException(CLIENT_SECRET_CREATION_FAILED, errorMessage);
}
}

Expand Down

0 comments on commit af20053

Please sign in to comment.