Laravel 5.5社交登录无法正常工作

3

我最近尝试将 Laravel Socialite 与 Laravel 5.5 集成,但是遇到了如下错误:

GuzzleHttp \ Exception \ ClientException (400) 客户端错误: GET https://graph.facebook.com/v2.10/me?access_token=$my_token&appsecret_proof=my_proofsecret 的响应状态为 400 Bad Request :{"error":{"message":"Error validating access token: Session has expired on Tuesday, 03-Oct-17 05:00:00 PDT. The current (truncated...)}

现在我已经进行了一定的调试,基本上这个错误是由 FacebookProvider.php 中第89行代码造成的。

protected function getUserByToken($token)
{
    $meUrl = $this->graphUrl.'/'.$this->version.'/me?access_token='.$token.'&fields='.implode(',', $this->fields);

    if (! empty($this->clientSecret)) {
        $appSecretProof = hash_hmac('sha256', $token, $this->clientSecret);
        $meUrl .= '&appsecret_proof='.$appSecretProof;
    }

    $response = $this->getHttpClient()->get($meUrl, [
        'headers' => [
            'Accept' => 'application/json',
        ],
    ]);

    return json_decode($response->getBody(), true);
}

这是一行:

  $appSecretProof = hash_hmac('sha256', $token, $this->clientSecret);

如果我将整个if else代码块注释掉,似乎程序可以正常运行,但我无法找出问题所在。

如果您删除那行代码,您能否登录?您的令牌是否有效?因为当错误的令牌或凭据被传递时,这就是出现的错误。 - Mr. Pyramid
1
实际上我使用了不同的应用程序秘钥。哎呀。 - Syed Abdur Rehman Kazmi
现在它是否正常工作? - Mr. Pyramid
1
是的,现在它完美地工作了。是我自己的问题。 - Syed Abdur Rehman Kazmi
回答后我会给您点赞 :) - Mr. Pyramid
完成 - Syed Abdur Rehman Kazmi
2个回答

1

在从图形API获取令牌时,我实际上没有为我的应用程序选择access_token。我选择了默认的图形API令牌。Facebook实际上允许您生成特定于您的应用程序的访问令牌,因此您必须专门选择它。这是它的屏幕截图。

enter image description here


-2

$meUrl .= '&appsecret_proof='.$appSecretProof;

请删除此行和 & 符号


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接