Facebook Login on Laravel 7
Laravel socialite is the easiest way to login to our website. Now I show you how to implement it on Facebook login by using the socialite package.
Step 1:
First, you should create your own Facebook App.
Click Create App.
Follow the below pictures of creating an app and take the required credentials
Step 2:
Download Socialite
Run this command on CMD.
composer require laravel/socialite
Step 3:
Now you should configure the app.php file. Open config/app.php file and put
Laravel\Socialite\SocialiteServiceProvider::class,
this under providers and put
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
this under aliases.
Step 4:
Now you should configure the config/services.php file.
'facebook' => [ 'client_id' => '3459825004069606', 'client_secret' => 'xxxxxxxxxxxxxxxxx', 'redirect' => 'https://test.com/callback/facebook', ],
Step 5:
Now add these two fields to your user’s table
provider, provider_id
as a string.
Step 6:
Now you should add the following routes in routes/web.php file.
Route::get('/auth/redirect/{provider}', 'SocialiteController@redirect'); Route::get('/callback/{provider}', 'SocialiteController@callback');
Step 7:
Create a controller by using CMD
php artisan make:controller SocialiteController
Step 8:
Put it in your Facebook href link. Now open the link and ready to log in.
{{ url('/auth/redirect/facebook') }}
Conclusion:
This is how we login into Facebook in Laravel development. The above code is created and tested by me. Please share your reviews in the comment section. See you on my next blog.
Comments