Laravel Socialite With Apple 返回“无效的 JWT 签名”

问题描述 投票:0回答:0

我尝试使用提供的令牌作为 API 获取当前用户数据,但我一直收到错误“无效的 JWT 签名”。我遵循了不同的教程,例如 bannisterdevpeel,但两者都给了我同样的错误。我正在使用 Laravel 9,社交名流包是 5.5。我可以知道有什么方法可以解决这个问题吗?

通过 Ruby 生成客户端密钥

require "jwt"

key_file = "key.txt"
team_id = "team_id"
client_id = "client_id"
key_id = "key_id"
validity_period = 180 # In days. Max 180 (6 months) according to Apple docs.

private_key = OpenSSL::PKey::EC.new IO.read key_file

token = JWT.encode(
 {
   iss: team_id,
   iat: Time.now.to_i,
   exp: Time.now.to_i + 86400 * validity_period,
   aud: "https://appleid.apple.com",
   sub: client_id
 },
 private_key,
  "ES256",
   header_fields=
   {
    kid: key_id 
   }
)
puts token

通过 PHP 生成客户端密码

// Generate client secret in php
use Firebase\JWT\JWT;

    public function createToken()
{
    $teamId = 'team_id';

    $keyId = 'key_id';

    $sub = env('APPLE_CLIENT_ID');

    $aud = 'https://appleid.apple.com'; // it's a fixed URL value

    $iat = strtotime('now');

    $exp = strtotime('+60days');

    $keyContent = file_get_contents(__DIR__ . '/../../../key.txt');

    

    echo JWT::encode([

        'iss' => $teamId,

        'iat' => $iat,

        'exp' => $exp,

        'aud' => $aud,

        'sub' => $sub,

    ], $keyContent, 'ES256', $keyId);

}

令牌访问

public function socialMediaLogin($request)
{
   $social = Socialite::driver($request->provider)->userFromToken($request->token);
   print_r($social);
}

php ios laravel laravel-socialite
© www.soinside.com 2019 - 2024. All rights reserved.