Last active
September 7, 2020 15:59
-
-
Save ArnauMrJeff/180d80f348eeb46f4dcea469f9029055 to your computer and use it in GitHub Desktop.
Apple ID Sign In: GetClaims
This file contains hidden or 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
import io.jsonwebtoken.Claims; | |
import io.jsonwebtoken.JwsHeader; | |
import io.jsonwebtoken.Jwts; | |
import io.jsonwebtoken.SignatureAlgorithm; | |
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; | |
import org.bouncycastle.openssl.PEMParser; | |
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; | |
import java.security.KeyFactory; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.PrivateKey; | |
import java.security.PublicKey; | |
import java.security.spec.InvalidKeySpecException; | |
import java.security.spec.RSAPublicKeySpec; | |
import java.util.Base64; | |
private Claims getClaims(String keyIdentifier, String idToken) throws InvalidKeySpecException, NoSuchAlgorithmException{ | |
var publicKey = createPublicKeyApple(keyIdentifier); | |
try { | |
return Jwts.parser().setSigningKey(publicKey).parseClaimsJws(idToken).getBody(); | |
} catch(Exception e) { | |
LOG.info("Exception JWT Signature" + e.getMessage()); | |
throw new AppleKeysException("Not a right public key"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment