socialite: Google login - InvalidStateException

  • Socialite Version: ^4.1,
  • Laravel Version: 5.8
  • PHP Version: 7. 2.18
  • Database Driver & Version:

Description:

Specifically for Google (Facebook works) I get an InvalidStateException .

However if I comment out profile in $scopes array in file /vendor/laravel/socialite/src/Two/GoogleProvider.php

so it looks like:

protected $scopes = [
        'openid',
        //'profile',
        'email',
    ];

Then login works, however then I don’t have access to name which I really need.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 25 (1 by maintainers)

Most upvoted comments

I just tried with stateless()

public function redirectToGoogle(){

        return Socialite::driver('google')->stateless()->redirect();
    }

 public function googleLogin(Request $request)

    {

        try {

                $user = Socialite::driver('google')->stateless()->user();} 
catch (\Exception $e) {

          dd($e);

        }

I got the user detail along with profile data

Same here… It works well on localhost, without SESSION_DOMAIN, without stateless(), and any other possible suggestion I found. but Live in production, I end up with the same Laravel\Socialite\Two\InvalidStateException vendor/laravel/socialite/src/Two/AbstractProvider.php:210

Hi,

I don’t believe I am using an older token as this happens whenever I check and has been happening from the very beginning, though I do not really know how I would check which token is being used (whether old or not).

If I add stateless() in handleProviderCallback like so: $user = Socialite::driver($provider)->stateless()->user();

then I get the following error, does that maybe tell you anything useful?

Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `400 Bad Request` response: { "error": "invalid_request", "error_description": "Missing required parameter: code" }