Search code examples
laravellaravel-5google-oauthlaravel-socialite

Laravel socialite 3.0 google return 403 - Forbidden


I am using Laravel 5.6 and socialite 3.0. I have created google API from developer console and enable for Gmail API and google plus. please check screen shot.

enter image description here

Also, I have to make setup inside .env file.

Google callback return 403 error code

I have created class and method

public function redirect($provieder)
{
     return Socialite::driver($provieder)->redirect();
}

public function callback($provieder)
{           
    try{
        $user = Socialite::driver($provieder)->stateless()->user();
        if (isset($user)) {
            $social = $this->createUser($user,$provieder);
            return redirect()->route('profile.fill','location');
        }
        return redirect()->route('user.signup');
    }catch (Exception $e) {
        return redirect('auth/google');
    }
 }

I have create route file

Route::get('auth/{provider}', 'OAuth\SocialController@redirect');
Route::get('auth/{provider}/callback', 'OAuth\SocialController@callback');

Solution

  • You had to activate the Google+ API from the Google Developers Console.

    It was indeed an HTTP 403 Forbidden response.

    I learned a bit more about "ClientException"... it is thrown by Guzzle's HTTP client, and it contains a few useful properties, mainly request and response:

    try {
        $user = Socialite::driver('google')->user();
    }
    catch (GuzzleHttp\Exception\ClientException $e) {
         dd($e->response);
    }