-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from AI-SIP/develop
실기기 테스트 버전
- Loading branch information
Showing
4 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/aisip/OnO/backend/Auth/AppleTokenVerifier.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,38 @@ | ||
package com.aisip.OnO.backend.Auth; | ||
|
||
import com.auth0.jwk.Jwk; | ||
import com.auth0.jwk.JwkProvider; | ||
import com.auth0.jwk.UrlJwkProvider; | ||
import com.auth0.jwt.JWT; | ||
import com.auth0.jwt.JWTVerifier; | ||
import com.auth0.jwt.algorithms.Algorithm; | ||
import com.auth0.jwt.interfaces.DecodedJWT; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.security.GeneralSecurityException; | ||
import java.security.interfaces.RSAPublicKey; | ||
|
||
@Component | ||
public class AppleTokenVerifier { | ||
|
||
private static final String APPLE_ISSUER = "https://appleid.apple.com"; | ||
private static final String APPLE_KEYS_URL = "https://appleid.apple.com/auth/keys"; | ||
|
||
public DecodedJWT verifyToken(String idTokenString) throws GeneralSecurityException, IOException { | ||
try { | ||
JwkProvider provider = new UrlJwkProvider(new URL(APPLE_KEYS_URL)); | ||
DecodedJWT jwt = JWT.decode(idTokenString); | ||
Jwk jwk = provider.get(jwt.getKeyId()); | ||
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) jwk.getPublicKey(), null); | ||
JWTVerifier verifier = JWT.require(algorithm) | ||
.withIssuer(APPLE_ISSUER) | ||
.build(); | ||
|
||
return verifier.verify(idTokenString); | ||
} catch (Exception e) { | ||
throw new GeneralSecurityException("Invalid ID token."); | ||
} | ||
} | ||
} |
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
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