For one of the client we was looking for such solution. Client want to get his daily sale report.
Here the hardest part was to get the connection working with applestore api, and there is not much info available for php based solution.
We solved it using https://github.com/lcobucci/jwt
First we install the library
$composer require lcobucci/jwt
And use sample code, you have to modify based on your need and also replace those keys from apple site.
use Curl\Curl; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Ecdsa\Sha256; $signer = new Sha256(); $privateKey = new Key('file://AuthKey_XYZ.p8'); $time = time(); $Issuer_ID = "FROM_APPLE_PAGE"; $Key_ID = "FROM_APPLE_PAGE"; $token = (new Builder())->issuedBy($Issuer_ID)// Configures the issuer (iss claim) ->permittedFor("appstoreconnect-v1")// Configures the audience (aud claim) ->identifiedBy('XXYYZZ', true)// Configures the id (jti claim), replicating as a header item ->withHeader('kid', $Key_ID) ->withHeader('type', 'JWT') ->withHeader('alg', 'ES256') ->issuedAt($time)// Configures the time that the token was issue (iat claim) ->expiresAt($time + 1200)// Configures the expiration time of the token (exp claim) ->withClaim('uid', 1)// Configures a new claim, called "uid" ->getToken($signer, $privateKey); // Retrieves the generated token $token->getHeaders(); // Retrieves the token headers $token->getClaims(); // Retrieves the token claims