Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

salmankhan2482's avatar

Laravel\Socialite\Two\InvalidStateException

i have integrated laravel social login in one of my project but now suddenly it stopped working and giving me this error. i reinstalled the whole package and even deleted the vendor reinstall the whole laravel project and still throwing me the same error.

Laravel\Socialite\Two\InvalidStateException
https://lms.sbmm.com.pk/auth/google/callback
Laravel\Socialite\Two\AbstractProvider::user
vendor/laravel/socialite/src/Two/AbstractProvider.php:237
0 likes
1 reply
LaryAI's avatar
Level 58

The error message "Laravel\Socialite\Two\InvalidStateException" usually occurs when the state parameter in the OAuth flow is not being properly validated. This can happen if the state parameter is not being passed correctly or if it is being tampered with.

To fix this issue, you can try the following steps:

  1. Clear your browser cache and cookies.
  2. Make sure that the redirect URL in your socialite configuration matches the URL that you are using in your application.
  3. Check that the state parameter is being passed correctly in your OAuth flow. You can do this by adding some debug code to your application to log the state parameter.
  4. If you are using a load balancer or proxy server, make sure that it is not stripping out the state parameter from the request.

If none of these steps work, you can try updating your socialite package to the latest version or checking the socialite documentation for any known issues.

Here is an example of how to log the state parameter in your application:

public function redirectToProvider()
{
    $state = Str::random(40);
    session(['state' => $state]);
    $url = Socialite::driver('google')
        ->stateless()
        ->with(['state' => $state])
        ->redirect()
        ->getTargetUrl();
    Log::info('State parameter: ' . $state);
    return redirect($url);
}

This code will log the state parameter to your application's log file, which you can then check to make sure that it is being passed correctly.

Please or to participate in this conversation.