Skip to content

Instantly share code, notes, and snippets.

@ArnauMrJeff
Last active September 7, 2020 15:59
Show Gist options
  • Save ArnauMrJeff/180d80f348eeb46f4dcea469f9029055 to your computer and use it in GitHub Desktop.
Save ArnauMrJeff/180d80f348eeb46f4dcea469f9029055 to your computer and use it in GitHub Desktop.
Apple ID Sign In: GetClaims
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