{quot;error";:“invalid”u client";}-使用apple(JS+;PHP)登录
我试图用JavaScript+PHP编写一个“苹果登录”。我遵循了本教程:但aways返回“error”:“无效的\u客户端” 我在Lumen中使用Firebase\JWT对客户端进行编码\u secret:{quot;error";:“invalid”u client";}-使用apple(JS+;PHP)登录,php,authentication,Php,Authentication,我试图用JavaScript+PHP编写一个“苹果登录”。我遵循了本教程:但aways返回“error”:“无效的\u客户端” 我在Lumen中使用Firebase\JWT对客户端进行编码\u secret: $cert = file_get_contents( './AuthKey_84********.p8' ); $cert = openssl_pkey_get_private( $cert ); $payload = [
$cert = file_get_contents( './AuthKey_84********.p8' );
$cert = openssl_pkey_get_private( $cert );
$payload = [
'iss' => "U5********", // Emissor do token
'iat' => time(), // Hora que o token foi gerado
'exp' => time() + 86400 * 360, // Hora de expiração do token,
'aud' => 'https://appleid.apple.com',
'sub' => 'br.com.company.login', // Sujeito do token
];
$secretToken = JWT::encode($payload, $cert, 'ES256', '84********');
它返回了一个有效的承载令牌,但当我将在中使用时,返回无效的\u客户端
这是我获取身份验证代码的javascript:
AppleID.auth.init({
clientId: 'br.com.company.login',
scope: 'name email',
redirectURI: 'http://apple.epics.com.br/',
response_type: 'code',
usePopup: true,
});
const response = await AppleID.auth.signIn();
var data = {
idApple : response.authorization.code
};
最后一步,我使用PHP Curl获取access_令牌(错误在这里):
但是,无论我在这个CURL中使用什么有效负载,返回的总是相同的:{“error”:“invalid_client”}
谢谢 我试图用另一种方法生成JWT:但我遇到了同样的问题
// Envia os parametros via POST para a apple (bearer)
$params = [
'grant_type' => 'authorization_code',
'code' => $request->code,
'client_id' => $this->appleClientID,
'client_secret' => $secretToken,
];
// Valida o token e retorna o access_token
$ch = curl_init('https://appleid.apple.com/auth/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Accept: application/json",
"Content-Type: application/json",
"User-Agent: curl",
"Authorization: Bearer {$secretToken}"
]);
$response = curl_exec($ch);
$response = json_decode($response);