Laravel Socialite: InvalidStateException in AbstractProvider.php line 199:

For some reason I get this exception when I try to log in with Laravel Socialite with either Facebook or Google:

InvalidStateException in AbstractProvider.php line 199:

The exception are thrown from my SocialiteController, when it tries to get the user from the facebook driver.

public function callback(SocialAccountService $service, $provider)
    {
        try {
            var_dump(Socialite::driver('facebook')->user());

Here are the part of AbstractProvider.php that seem to throw the actual exception:

public function user()
{
  if ($this->hasInvalidState()) {
     throw new InvalidStateException;
}

I have been following this tutorial https://blog.damirmiladinov.com/laravel/laravel-5.2-socialite-twitter-login.html#.WFK0BfnhCUk. The login have worked fine until last week, for some reason.

I read other articles saying I should change config/session.php so domain is not null but my current domain (in my case localhost:8000 since I run local with XAMPP), and refresh Laravel cache etc. But it did not work.


I have discovered that my Laravel application cookies where missing, which caused the InvalidStateException exception.

I also noticed that the cookies were not recreated after each HTTP request. When I changed the domain value in Config/Session.php from my current one ("localhost") to null (the default value), then the cookies were recreated again.


尝试

session()->put('state', $request->input('state'));
$user = Socialite::driver('facebook')->user();
链接地址: http://www.djcxy.com/p/33120.html

上一篇: Laravel Socialite在托管类型后发生故障而被更改

下一篇: Laravel Socialite:AbstractProvider.php中的InvalidStateException行199: