Skip to content
Advertisement

Laravel Socialite: InvalidStateException

I’m using Laravel Socialite to add a Facebook connect button on a website. Sometimes, I’ve got this error on callback:

exception 'LaravelSocialiteTwoInvalidStateException' 
in /example/vendor/laravel/socialite/src/Two/AbstractProvider.php:161

I don’t know what it mean and did not found anything yet about this error. The real problem is it seems to be a random exception (don’t understood why it happens). So what this error means and how to avoid it?

It seems it’s not the same problem as Laravel 5 geting InvalidStateException in AbstractProvider.php, cause in my case it’s random.

Advertisement

Answer

I ran into this issue last night and solve it with the following solution.

More information on my issue, I’ve got

InvalidStateException in AbstractProvider.php line 182

in the function handleProviderCallback() when it re-direct back from Facebook login. It seems to be the same as your issue.

Furthermore I found my issue occurs when I open my site without www. When I open my site with www.mysite.com – no problem. At first I think my issue is random until I’ve got the clue by Chris Townsend‘s reply to the question – Thank you very much.

The Solution

  1. Go to your www root, check the laravel file config/session.php
  2. Check session Session Cookie Domain The default configuration is 'domain' => null, I made a change to 'domain' => 'mysite.com'.
  3. After 'php artisan cache:clear' and 'composer dump-autoload', I can login with no issue from both www.mysite.com and mysite.com

Be sure to delete your cookies from browser when testing it after these modifications are done. Old cookies can still produce problems.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement