我正在尝试将我的 Laravel 应用程序中的 Apple 登录与 Laravel/Socialite 集成。我已从开发者帐户创建了该应用程序并使用了所有正确的凭据。并使用私钥生成秘密密钥。 但我面临着问题
Client error:
POST https://appleid.apple.com/auth/token` 导致了 400 Bad Request
响应:{"error":"invalid_client"}`。
我已按照 本教程 使用私有身份验证密钥生成 client_secret_key。
我读了很多指南、论坛讨论和教程,但没有任何效果。
作曲家需要社交名流提供商/苹果
跟随链接:https://socialiteproviders.com/Apple/#installation-basic-usage
为您的网站 (
https://developer.apple.com/account/resources/identifiers/list/bundleId) 创建一个
App ID
,其中包含以下详细信息:
为您的网站 (
https://developer.apple.com/account/resources/identifiers/list/serviceId) 创建一个
Service ID
,其中包含以下详细信息:
为您的网站 (
https://developer.apple.com/account/resources/authkeys/list) 创建一个
Private Key
,其中包含以下详细信息:
key.txt
创建应用程序的客户端密钥:
sudo gem install jwt
首先,确保您已经安装了 Ruby,然后通过从命令行运行它来安装 JWT gem。
client_secret.rb
的文件来处理私钥:
require 'jwt'
key_file = 'key.txt'
team_id = ''
client_id = ''
key_id = ''
ecdsa_key = OpenSSL::PKey::EC.new IO.read key_file
headers = {
'kid' => key_id
}
claims = {
'iss' => team_id,
'iat' => Time.now.to_i,
'exp' => Time.now.to_i + 86400*180,
'aud' => 'https://appleid.apple.com',
'sub' => client_id,
}
token = JWT.encode claims, ecdsa_key, 'ES256', headers
puts token
Make Sure `composer require firebase/php-jwt` Installed
```
client_secret.php
<?php
require 'vendor/autoload.php';
use Firebase\JWT\JWT;
$teamId = 'TEAM ID';
$keyId = 'KEY ID';
$sub = 'com.avocado.client';
$aud = 'https://appleid.apple.com'; // it's a fixed URL value
$iat = strtotime('now');
$exp = strtotime('+60days');
$keyContent = file_get_contents('key.txt');
echo JWT::encode([
'iss' => $teamId,
'iat' => $iat,
'exp' => $exp,
'aud' => $aud,
'sub' => $sub,
], $keyContent, 'ES256', $keyId);
// Write the snippet in a method, return the value from that method
// You
?>
```
- Fill in the following fields:
- `team_id`: This can be found on the top-right corner when logged into
your Apple Developer account, right under your name.
- `client_id`: This is the identifier from the Service Id created in step
2 above, for example com.example.service
- `key_id`: This is the identifier of the private key created in step 3
above.
- Save the file and run it from the terminal. It will spit out a JWT which is
your client secret, which you will need to add to your `.env` file in the
next step.
```sh
ruby client_secret.rb
```
在您的
.env
文件中设置必要的环境变量:
APPLE_CLIENT_ID=app_Service_id
APPLE_CLIENT_SECRET=ggenerator_key_here APPLE_REDIRECT_URI=redirect_url_here ````