Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Socialite: InvalidStateException (sometimes)

some of the users on my site are experiencing a Laravel\Socialite\Two\InvalidStateException. I've taken the steps outlined in the replies to Laravel Socialite: InvalidStateException and have not been able to resolve the issue. Only a small percentage of users seem to be experiencing this.

I have 2 fpm/nginx docker containers sitting behind an HAProxy load balancer.

like image 981
Webnet Avatar asked Jan 16 '18 15:01

Webnet


People also ask

What is stateless in Socialite?

Route::get('login/github', function() { return Socialite::driver('github')->stateless()->redirect(); }); Stateless just means there is no sessions stored. When they user completes their login, github redirects the user back to the callback you register with them earlier.


1 Answers

This seems to be an invalid state issue in socialite package that is already resolved in this post.

Some of your users are accessing your website with a different url (https://www.example.com or https://example.com) hence causing the mismatching "state" in the sessions.

If you are on Larvel 5.3 and above... add a SESSION_DOMAIN=http://example.com in 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' Hopefully this should resolve the issue.

like image 156
Syed Waqas Bukhary Avatar answered Sep 17 '22 23:09

Syed Waqas Bukhary