huedaya.com/blog
just bunch of .md files
Generate Apple Store Connect JWT with PHP

So to be able to use Apple Store Connect API, you need to generate the JWT Token, you can use this script. First clone this repo firebase/php-jwt, then create a file with this following content:

php
<?php

// Import composer 
require __DIR__ . '/vendor/autoload.php';

// Get the key from https://appstoreconnect.apple.com/access/integrations/api
use Firebase\JWT\JWT;

// Fill this
$appleKey = <<<EOD
-----BEGIN PRIVATE KEY-----
XXX
-----END PRIVATE KEY-----
EOD;
$appleKeyId = '2X9R4HXF34';
$appleIssuerId = '57246542-96fe-1a63-e053-0824d011072a';

// Prepare payload
$payloadBody = [
    'iss' => $appleIssuerId,
    'aud' => 'appstoreconnect-v1',
    'iat' => time(),
    'exp' => (time() + (60 * 5)), // 5 minutes
];
$payloadHeader = [
    "kid" => $appleKeyId,
    "typ" => "JWT"
];

// Genererate
$jwt = JWT::encode($payloadBody, $appleKey, 'ES256', $appleKeyId, $payloadHeader);

print_r($jwt);

Then simply call php name_file.php. To test the token you can use:

bash
curl -v -H 'Authorization: Bearer JWT_HERE' "https://api.appstoreconnect.apple.com/v1/apps"

That's it!

Last update: 2024-05-14 10:48:10 (1 week ago)