-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/trothly/trothcam/feign/AppleOAuthUserProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 값이 올바르지 않습니다."); | ||
} | ||
} | ||
} |