Search code examples
phpfacebooklaravellaravel-5

Laravel 5 geting InvalidStateException in AbstractProvider.php


I am trying to use login with facebook in laravel 5 using Socialize.

Here is my route file code.

Route::get('fb', function ($facebook = "facebook")
{
    $provider = \Socialize::with($facebook);      
    if (Input::has('code'))
    {
        $user = $provider->user();
        return var_dump($user);
    } else {
        return $provider->scopes(['public_profile','user_friends'])->redirect();
    }
});

login is success and I get the code but time of get $provider->user() I get the error.

InvalidStateException in AbstractProvider.php line 161


Solution

  • I got temporary solution for that.

    public function user()
    {
        //if ($this->hasInvalidState()) {
        //    throw new InvalidStateException;
        //}
    
        $user = $this->mapUserToObject($this->getUserByToken(
            $token = $this->getAccessToken($this->getCode())
        ));
        return $user->setToken($token);
    }
    

    comment the $this->hasInvalidState() if condition in AbstractProvider.php file and it's work fine.