[英]JWT Token generated always results in 401 when submitted to Apple servers
I am using the following code in PHP to generate a JWT token to use with the App Store Server API:我在 PHP 中使用以下代码生成一个 JWT 令牌以与 App Store 服务器 API 一起使用:
$keyId = 'provided by apple';
$priv_key = <<<EOD
-----BEGIN PRIVATE KEY-----
provided by apple
-----END PRIVATE KEY-----
EOD;
$pem_private_key = file_get_contents('AuthKey.pem');
$private_key = openssl_pkey_get_private($pem_private_key);
$public_key_pem = openssl_pkey_get_details($private_key)['key'];
$public_key = openssl_pkey_get_public($public_key_pem);
$headers = [
"kid"=> $keyId,
"typ" => 'JWT'
];
$payload = [
"iss" => "provided by apple",
"iat" => time(),
"exp" => time() + (60 * 60 * 24 * 7),
"aud" => "appstoreconnect-v1",
"bid" => "com.bundle.my"
];
$jwt = JWT::encode($payload, $priv_key, 'ES256', $keyId, $headers);
This results in a JWT token.这会产生 JWT 令牌。 However when I try to use it with the Apple Store API, I always get 401 Unauthorized;
但是,当我尝试将它与 Apple Store API 一起使用时,我总是得到 401 Unauthorized; Unauthenticated.
未经验证。
What am I doing wrong?我究竟做错了什么?
The problem was the expiration time as Apple only allows an expiration of max 20 mins.问题是到期时间,因为 Apple 只允许最多 20 分钟的到期时间。
Changed to time() + 1200.更改为时间 () + 1200。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.