При авторизации на сайте через fb получаю ошибку:
Client error: `POST https://graph.facebook.com/v3.3/oauth/access_token` resulted in a `400 Bad Request` response: {"error":{"message":"Missing authorization code","type":"OAuthException","code":1
С чем она может быть связана?
Контроллер:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\SocialAccount;
use App\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;
class SocialController extends Controller
{
public function redirectToProvider($provider)
{
return Socialite::driver($provider)->redirect();
}
public function handleProviderCallback($provider)
{
$socialiteUser = Socialite::driver($provider)->user();
$user = $this->findOrCreateUser($provider, $socialiteUser);
auth()->login($user, true);
return redirect('/');
}
public function findOrCreateUser($provider, $socialiteUser)
{
if ($user = $this->findUserBySocialId($provider, $socialiteUser->getId())) {
return $user;
}
if ($user = $this->findUserByEmail($provider, $socialiteUser->getEmail())) {
$this->addSocialAccount($provider, $user, $socialiteUser);
return $user;
}
$user = User::create([
'name' => $socialiteUser->getName(),
'email' => $socialiteUser->getEmail(),
'password' => Hash::make(Str::random()),
]);
$this->addSocialAccount($provider, $user, $socialiteUser);
return $user;
}
public function findUserBySocialId($provider, $id)
{
$socialAccount = SocialAccount::where('provider', $provider)
->where('provider_id', $id)
->first();
return $socialAccount ? $socialAccount->user : false;
}
public function findUserByEmail($provider, $email)
{
return !$email ? null : User::where('email', $email)->first();
}
public function addSocialAccount($provider, $user, $socialiteUser)
{
SocialAccount::create([
'user_id' => $user->id,
'provider' => $provider,
'provider_id' => $socialiteUser->getId(),
'token' => $socialiteUser->token,
]);
}
}