Salesforce Auth Provide – Facebook

In this blog, I am going to explain how to configure Salesforce social sign on with Facebook.
Prerequisites:-
Custom Domain should be created and enabled for users.
Create a Facebook application:-

First, log into the Facebook Developer Site and create a new Facebook App. You can do this by clicking the “My Apps” menu at the top of the screen and then click on the “Add a New App” button. You should see something like the following:

Enter a “Display Name” (the name of your app), and choose a category for your app. Once you’ve done this, click the “Create App ID” button.
Next, click on Settings on the left side, and make note of the App ID and App Secret. You’ll need those later when you connect your Facebook Application to Salesforce. Click “Submit” to finish creating the new application. Your App Id and App Secret looks as shown below

Configure Facebook authentication provider in your Salesforce:-

Now we are going to configure your sales force login by using the facebook. To do this , go to setup ->Security Controls ->Auth Providers -> New –>Select Facebook as Provider Type as shown below

1.Enter a Name for the provision as Facebook or you can choose your any desired name wish to have
2.Enter Consumer Key and Consumer Secret from the App Id and App Secret which you got from the Facebook application.
3.Authorize Endpoint URL and Token Endpoint URL, User Info Endpoint URL are optional and leave it as of now.
4.click ‘Automatically create a registration handler template’.this is going to create a new Apex Class which will handle the user login by using facebook. If the User is not there in salesforce it’s going to create a new user or if exists it’s going to update the user
5.Select Execute Registration As any System admin User. Make sure user is having Manage users permission

Salesforce generated Registration handler looks as shown below. you can update the Registration handler with your own logic.

 

Map the Callback URL in Facebook

Now you have to go back the Facebook application which you created earlier, then associated your Callback URL in Facebook as shown below.Go back to your facebook application you just created in last steps. Click on Settings in left option bar. Click on Add Platform.

Select Platform as Web Platform. Update the Salesforce callback URL in Site URL as shown below

Testing Application:-

You can test your application by simply pasting Test-Only Initialization URL in browser it will redirect to the Facebook login page.

Adding the Facebook login to My Domain:-

To available Facebook login for all the user, you must need to add it to my domain in Salesforce as shown below.Go to Setup –> Domain Management –> My Domain.go to Authentication Configuration Click edit then Select Facebook as shown below.Save it

After adding it my domain you can able to login into Salesforce by directly using your facebook from your domain login page as shown below.

Now you can able to login into Salesforce by using Facebook. once you select the facebook login it will redirect to the Facebook for login. Up success login in facebook, you will be redirected to Salesforce homepage.