Closed IceWizard98 closed 5 years ago
@IceWizard2809 what was your solution?
@IceWizard2809 what was your solution?
hi, @markhughes
i use @lcobucci library (https://github.com/lcobucci/jwt), it's very completed and u can use the following code
$signer = new Sha256();
$privateKey = new Key('file://' . KEYIOS);
$time = time();
$Issuer_ID = "YOURID";
$Key_ID = "YOURKEY";
$token = (new Builder())->issuedBy($Issuer_ID)// Configures the issuer (iss claim)
->permittedFor("appstoreconnect-v1")// Configures the audience (aud claim)
->identifiedBy('YOURIDENTIFIE', 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
$ch = curl_init();
$data = array(
'filter[frequency]' => 'DAILY',
'filter[reportSubType]' => 'SUMMARY',
'filter[reportType]' => 'SALES',
'filter[vendorNumber]' => '85942379',
//'filter[reportDate]' => '2019-08-25'
);
$params = '';
foreach ($data as $key => $value) {
$params .= $key . '=' . $value . '&';
}
//curl_setopt($ch, CURLOPT_URL, 'https://api.appstoreconnect.apple.com/v1/apps');
curl_setopt($ch, CURLOPT_URL, 'https://api.appstoreconnect.apple.com/v1/salesReports' . '?' . $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = "Authorization: Bearer $token";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$result = gzdecode($response);
curl_close($ch);
you can get all your personal var on apple website following their tutorial; to use this libary you need php7
@markhughes do you know how to fix that..? my token never has a signature which makes it fail jwt.io verificaion :/
This library didn’t seem to support it, sorry. I ended up using an alternative, but I don’t quite remember which one.... apologies!
A p8 file must be converted to PEM in order to be used by this lib, as it's not properly understood by openssl extension (AFAIK).
hi, i'm trying to authenticate with JWT for apple apis, but i can't finde a tutorial which can help me. But all related tutorial are using this libary, can some one help me with the code to log in and use Apple apis?
This is my code :
`$signer = new Sha256(); $privateKey = new Key('file://auth_file.p8'); $time = time();