Laravel Socialite: InvalidStateException (sometimes)

some users of my site experience a Laravel\Socialite\Two\InvalidStateException . I took the measures outlined in the answers to Laravel Socialite: InvalidStateException and could not solve the problem. Only a small percentage of users seem to experience this.

I have 2 fpm / nginx docker containers located behind the HAProxy load balancer.

+7
php laravel-socialite
source share
2 answers

I bet the problem is due to load balancing. Here is my theory:

  • Sticky sessions : if your load balancer does not correctly configure a sticky session, some users can start a new session on server 1 and upon the next request it ends on server 2, which may throw Laravel\Socialite\Two\InvalidStateException

  • Request timeout : I'm not sure about this, but maybe for your session it’s not enough to complete the process that also throws Laravel\Socialite\Two\InvalidStateException

Perhaps if you change the laravel session store to a decentralized database instead of configuring the default text file, the exception will be resolved.

+3
source share

This seems like an unacceptable problem in the socialite package that has already been resolved in this post .

Some of your users access your site with a different URL ( https://www.example.com or https://example.com ), which causes a "state" mismatch in the sessions.

If you are on Larvel 5.3 or later ... add SESSION_DOMAIN=http://example.com to the .env file

For other versions, go to your config/session.php file and add your domain. 'domain' => 'www.example.com'

To apply changes immediately. Run 'php artisan cache:clear' and 'composer dump-autoload' We hope this should fix the problem.

+3
source share

All Articles