My Facebook login has suddenly stopped working using the Socialite package with Laravel 5.2. I have had it fully functional for a few days now and it just seems to of dropped off. I am fairly new to Laravel so please have some grace if it is something easy.
I get this error:
"The www.facebook.com page isn’t working. www.facebook.com redirected you too many times."
I have tried restarting the local server, running commands like php artisan config:clear
. Also tried installing with composer running version "laravel/socialite": "^2.0"
. I can't help but think it is something actually in the Facebook Developer Apps API config but everything looks okay!
I will provide my code just in case anyone who has the time to help and can spot any bugs. I used this link as a guide to go off http://ift.tt/2lzZZmY
.env
FACEBOOK_CLIENT_ID=xxxxxxxxx
FACEBOOK_CLIENT_SECRET=xxxxxxxx
FACEBOOK_CALLBACK_URL=http://localhost:8000/auth/facebook/
routes.php
Route::get('auth/facebook', 'Auth\FacebookController@redirectToProvider');
Route::get('auth/facebook/callback', 'Auth\FacebookController@handleProviderCallback');
FacebookController.php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\SocialAccountService;
use Socialite;
class FacebookController extends Controller
{
public function redirectToProvider()
{
//send off a request and to FB and get a token
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallback(SocialAccountService $service)
{
$user = $service->createOrGetUser(Socialite::driver('facebook')->user());
auth()->login($user);
return redirect()->to('account/{id}/myaccount');
}
}
SocialAccountService.php
namespace App;
use Laravel\Socialite\Contracts\User as ProviderUser;
class SocialAccountService
{
public function createOrGetUser(ProviderUser $providerUser)
{
$account = SocialAccount::whereProvider('facebook')
->whereProviderUserId($providerUser->getId())
->first();
if ($account) {
return $account->user;
} else {
$account = new SocialAccount([
'provider_user_id' => $providerUser->getId(),
'provider' => 'facebook'
]);
$user = User::whereEmail($providerUser->getEmail())->first();
if (!$user) {
$user = User::create([
'email' => $providerUser->getEmail(),
'name' => $providerUser->getName(),
]);
}
$account->user()->associate($user);
$account->save();
return $user;
}
}
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lzWYD8
via IFTTT
Aucun commentaire:
Enregistrer un commentaire