Hello!
Im using this liblary to generate ES256 JWT for Apple to connect with them, but the problem is that generated token is invalid.
So in summary :
- I got from them : AuthKey_XXXXXXXXXX.p8 ( as u can see its in p8 format )
- PHP of my server is 8.1. which means that I'm using this liblary in version : 4.1
What I did and it didn't work
- trying to convert .p8, to .pem and generate public key from .pem one, and use this in code below
My Code (PHP 8.1)
require 'vendor/autoload.php';
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Validation\NoConstraintsGiven;
use Lcobucci\JWT\Signer\Key\InMemory;
$privateKey = InMemory::file(__DIR__ . '/AuthKey_XXXXXXX.pem');
$publicKey = InMemory::file(__DIR__ . '/AuthKey_XXXXXXX.pub');
$config = Configuration::forAsymmetricSigner(Lcobucci\JWT\Signer\Ecdsa\Sha256::create(), $privateKey, $publicKey );
$now = new DateTimeImmutable();
$token = $config->builder()
->issuedBy('XXXXXXXXX')
->withHeader('alg', 'ES256')
->withHeader('kid', 'XXXXXXXXX')
->withHeader('typ', 'JWT')
->permittedFor('appstoreconnect-v1')
->withClaim('scope', array("GET /v1/apps?filter[platform]=IOS"))
->issuedAt($now)
->expiresAt($now->modify('+1 hour'))
->getToken($config->signer(), $config->signingKey());
$final_token = $token->toString();
// And final connecting with Apple because token is generated :
$url = 'https://api.appstoreconnect.apple.com/v1/apps/';
$ch = curl_init();
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Bearer '.$final_token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$head = curl_exec($ch);
print_r($head);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
What I need :
- generate valid ES256 JWT which will allows me to connect with Apple, based on .p8 file which I have
Thanks, Jake
Question