I am new to Laravel however and I am following the tutorial on http://www.codeanchor.net/blog/complete-laravel-socialite-tutorial/, to login a user through Facebook into my
It's little bit tricky for something that looks/should be easy, but anyway this is how i make things works for me.
you can find those instructions and more details in socialite docs
composer require laravel/socialite
in config/services.php add
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('FACEBOOK_CALLBACK_URL'),
],
in .env file add
FACEBOOK_CLIENT_ID=paste_client_id_here
FACEBOOK_CLIENT_SECRET=paste_client_secret_here
FACEBOOK_CALLBACK_URL=https://www.example.com/auth/facebook/callback
in routes/web.php add
Route::get('auth/facebook/', 'Auth\FacebookController@redirect')->name('auth.facebook');
Route::get('auth/facebook/callback', 'Auth\FacebookController@callback')->name('auth.facebook.callback');
in App\Http\Controllers\Auth add new controller FacebookController.php
redirect();
}
/**
* Create a new controller instance.
*
* @return void
*/
public function callback(Request $request)
{
try {
$facebookAccount = Socialite::driver('facebook')->user();
// your logic here...
return redirect()->route('your.route.name');
} catch (Exception $e) {
return redirect()->route('auth.facebook');
}
}
}
go to https://developers.facebook.com/apps and create new app (if you don't have one already)
and make sur your app settings are like below in those screen shots:
If you are developing in your local machine, you have to use tools like ngrok that provide a secure link to your localhost.
In the facebook login settings change https://www.example.com with the url provided by ngrok something like https://8b0215bc.ngrok.io.
It is the only way that worked for me while developing in my local machine.