Laravel 5.5 socialite not working

Viewed 514

I recently tried to integrate laravel socialite with laravel 5.5 but i was getting an error :

GuzzleHttp \ Exception \ ClientException (400) Client error: GET https://graph.facebook.com/v2.10/me? access_token=$my_token&appsecret_proof=my_proofsecret resulted in a 400 Bad Request response: {"error":{"message":"Error validating access token: Session has expired on Tuesday, 03-Oct-17 05:00:00 PDT. The current (truncated...)

Now i have debugged it to some extent and basically this is the line creating the error in FacebookProvider.php line number 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);
}

this is the line :

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

If i comment it out this whole if else block it seems to work fine, cant figure out whats wrong.

2 Answers

I was actually not selecting the access_token's for my application while getting it from the graph API. I selected the default graph api token. Facebook actually lets you generate access token specific to your App so you have to selection it specifically.. Here is a screenshot of it.

enter image description here

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

please remove this line and & sign

Related