Laravel socialite 3.0 google return 403 - Forbidde

2019-07-17 03:58发布

问题:

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.

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');

回答1:

Google+ APIs Sign-in has been fully deprecated and will also be shut down on March 7, 2019.

Read Here: Google+ API Shutdown



回答2:

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);
}


回答3:

This error says that the server could understand the request from the client, but it refuses to proceed with further actions with the request. It is often displayed when the server is configured to deny the client’s request for some reason.

The causes behind 403 error page

If the URL you’ve entered is correct, then it can be any of the following three reasons.

1) No index page

2) Empty html directory

3) Poor permission configuration or ownership issues.

The above listed are the most common reasons of 403 forbidden error.

check that link for how to fix it