我一直在我的应用程序中实现社会名流,并让Facebook登录在本地正常工作。但是,当在生产环境中尝试代码时,登录时应用程序错误。
这是我的回调代码
public function show()
{
return Socialite::driver('facebook')->redirect();
}
public function create()
{
if (!Auth()->user()) {
try {
$driver = Socialite::driver('facebook')->fields([
'name',
'first_name',
'last_name',
'email',
'gender',
'verified'
]);
$user = $driver->user();
$this->findOrCreateUser($user);
} catch (\Exception $e) {
log::error('facebook failed ' . $e);
return redirect()->route('homepage');
}
}
return Redirect::to(env('APP_URL'));
}
public function findOrCreateUser(\Laravel\Socialite\Contracts\User $user)
{
try {
$authUser = User::where('provider_id', $user->id)->first();
if ($authUser) {
Auth()->loginUsingId($authUser->id);
} else {
$usercreate = new User;
$usercreate->firstName = $user->getName();
$usercreate->email = $user->getEmail();
$usercreate->provider ='facebook';
$usercreate->provider_id = $user->getId();
$usercreate->avatar_url = 'update';
$usercreate->cover_url = 'update';
$usercreate->save();
$finaluser = User::where('provider_id', '=', $user->id)->first();
Auth::loginUsingId($finaluser->id);
}
} catch (\Exception $e) {
log::error('facebook failed ' . $e);
return redirect('auth/facebook');
}
}
这是登录时尝试在Facebook页面上单击“继续”时遇到的错误。该错误被捕获,然后将我重定向到主页,但没有创建或登录用户。
facebook failed GuzzleHttp\Exception\ClientException: Client error: `POST https://graph.facebook.com/v3.0/oauth/access_token` resulted in a `400 Bad Request` response:
{"error":{"message":"Error validating client secret.","type":"OAuthException","code":1,"fbtrace_id":"E4+c6Prdnz+"}}
in /home/forge/www.fishamax.co.uk/releases/20181219133426/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113