Skip to content

Commit

Permalink
feat(#5) : Apple 계정 유저 정보 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
aeeazip committed Jul 2, 2023
1 parent 4cbe45a commit 7e4e22b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/trothly/trothcam/feign/AppleOAuthUserProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package trothly.trothcam.feign;

import io.jsonwebtoken.Claims;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import trothly.trothcam.dto.auth.apple.ApplePublicKeys;
import trothly.trothcam.exception.custom.InvalidTokenException;

import java.security.PublicKey;
import java.util.Map;

@Component
@RequiredArgsConstructor
public class AppleOAuthUserProvider {

private final AppleJwtParser appleJwtParser;
private final AppleClient appleClient;
private final PublicKeyGenerator publicKeyGenerator;
private final AppleClaimsValidator appleClaimsValidator;

public String getEmailFromToken(String identityToken) {
Map<String, String> headers = appleJwtParser.parseHeaders(identityToken);
ApplePublicKeys applePublicKeys = appleClient.getApplePublicKeys();

PublicKey publicKey = publicKeyGenerator.generatePublicKey(headers, applePublicKeys);

Claims claims = appleJwtParser.parsePublicKeyAndGetClaims(identityToken, publicKey);
validateClaims(claims);
return claims.get("email", String.class);
}

private void validateClaims(Claims claims) {
if (!appleClaimsValidator.isValid(claims)) {
throw new InvalidTokenException("Apple OAuth Claims 값이 올바르지 않습니다.");
}
}
}

0 comments on commit 7e4e22b

Please sign in to comment.