MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

How to Add Sign-in with Facebook feature in Laravel.

In this tutorial, we’re going learn how to add authentication via Facebook to a Laravel app. In Short, How to add Sign-in with Facebook feature in our Laravel Project. For that, we use Laravel Socialite Package which is officially provided by Laravel (you can check Documentation here.)

Socialite supports Facebook, Twitter, LinkedIn, Google, GitHub and Bitbucket.

Note :- For using Socialite Package, you must have Laravel 5.4 or an Upper version of Laravel in your project. (Recommended 5.5 and above.)

I’m using Laravel 5.8 (version) in my project. So Follow the below Steps to add Sign-in with Facebook Functionality in your existing Laravel Project.

Step 1 :- Install Socialite using composer by below Command.

composer require laravel/socialite

Step 2 :- Go to config/services.php and add a new Package as below.

‘Facebook’ => [
‘client_id’ => ‘FACEBOOK_CLIENT_ID’,
‘client_secret’ => ‘FACEBOOK_CLIENT_SECRET’,
‘redirect’ => ‘http://your-callback-url’,
],

We’ll obtain client_id, client_secret and redirect URL in next Step.

Since we added a new package, make sure to add to the service providers array in config/app.php (In providers array)

‘providers’ => [
// Other service providers…

Laravel\Socialite\SocialiteServiceProvider::class,
],

Add an alias in config/app.php, so it is easier to reference later.

‘Socialite’ => Laravel\Socialite\Facades\Socialite::class,

Step 3 :- Now, Create your app on Facebook.

( i ) Create a Project :- Go to https://developers.facebook.com/ and click on My Apps and then Create App as shown below.

Facebook for Developers top menu with My Apps highlighted
Facebook for Developers My Apps dropdown with Create App highlighted

After Clicking on Create App a pop-up appears like this (See below Image) :-

Facebook Create a New App ID dialog with Display Name and Contact Email fields

In Which Fill the Display Name (Your App Name) and click on Create App ID. A Security check pop-up appears just pass it, and you are redirected to the App Dashboard.

Now Click on Facebook Login Set-up and then click on WWW(web) see Below image

Facebook app dashboard Add a Product page with Facebook Login Set Up highlighted

After that Click on Settings in the left side, Fill Redirect_URL and then click on Save Changes. See the below image for help. :-

Redirect URL is like your_web_URL/login/facebook/callback

Facebook Login settings showing Client OAuth Settings and Valid OAuth Redirect URIs field

After that click on Settings–>Basic below Dashboard where you can find Your_App_ID and Your_App_Secret. See the Below Image.

Facebook app Settings Basic page showing App ID and App Secret fields

just copy and paste it in the config/services.php as mentioned in Step 2.

Step 4 :- Handle the route. Go to routes/web.php. See the below code.

Route::get(‘login/facebook’, ‘Auth\LoginController@redirectToProvider’);
Route::get(‘login/facebook/callback’, ‘Auth\LoginController@handleProviderCallback’);

Step 5 :- Now go to loginController and paste the below code.

use Socialite;

public function redirectToProvider()
{
return Socialite::driver(‘facebook’)->stateless()->redirect();
}


public function handleProviderCallback()
{
$user = Socialite::driver(‘facebook’)->user();
// $user->token; (return as your need)
}

Step 6 :- Now, we make Sign-in with Facebook button. Just copy and paste the below code in your login page.

Note :- You can use fa-fa icon of facebook instead of facebook.svg or download it by searching on google by Keyword facebook SVG icon download.

Thats All. ???

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

How to Sign-in or login from PHP 7 using LinkedIn API?

In this blog, I am going to explain How to Login from PHP using LinkedIn API. So, before you go to XAMPP folder’s htdocs and create a…

Read More

Single Sign-On Implementations: Practical Comparison and Evaluation Guide

This guide expands a short 2015 link list of SSO tools into a practical DevOps reference. You will learn how SSO flows work, how to compare implementations, and how to validate integrations with real commands.

Read More

Complete Tutorial: JWT (JSON Web Token) & OIDC (OpenID Connect)

1. 🔎 What is JWT? Definition Structure 2. 🔎 What is OIDC? Definition Key OIDC Tokens 3. ❓ Why do we need them? JWT OIDC 4. ⚙️…

Read More

Laravel: oauth_access_tokens clean up process

using Laravel Passport—the oauth_access_tokens table balloons when tokens aren’t expiring, not being revoked on logout, or not being purged. Here’s a practical, safe cleanup + prevention plan…

Read More

Keyclock: A Identity & SSO tools

Keycloak: Identity & SSO Tool (IAM in one box) What it is Keycloak is an open-source Identity and Access Management (IAM) platform that provides Single Sign-On (SSO),…

Read More

Laravel: Complete Guide of Laravel Passport

Here’s a comprehensive, up-to-date step-by-step tutorial for setting up and using Laravel Passport (OAuth2 API authentication) with clear explanations, working code samples, and troubleshooting tips—suitable for local…

Read More