Laravel 7 Socialite Google Login Shows Invalid Grant Error

Viewed 1146

I have used the Socialite library for google login.

When trying to fetch the user data after successful google login it shows an invalid grant message

$googleUser = Socialite::driver('google')->user();

Response

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

The same code working on my local machine and previous laravel versions.

Thanks in advance

2 Answers

I had the same problem and following code helped me:

$googleUser = Socialite::driver('google')
->with(['access_type' => 'offline'])
->user();

Here's more about this

Related