Skip to main content

Add Drupal 8 login with facebook button

A login with facebook, google or twitter (or any of the many social media out there) button is essential now because people are lazy. They don't want to fill up forms to sign up to a web service. One click login/sign up is the perfect solution.

Login with facebook is quite simple. All you have to do is install the module and create a facebook app. The social_apisocial_auth module should be installed along with social_auth_facebook. The best way to install and manage drupal modules is composer. 

Install composer like this as described here :

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Then go to your drupal site root or wherever your composer.json for the website is and run the following commands :

composer require drupal/social_api
composer require drupal/social_auth
composer require drupal/social_auth_facebook

Enable both the modules and go to the social_auth config (admin/config/social-api/social-auth) and click on the

 Facebook tab. This is what it would look like :

Login with facebook config

Substitute the values with the values from your facebook app. If you don't have an app, create one at this link https://developers.facebook.com/apps

After you create an app, you should get your app id and app secret by clicking on settings > basic. 

Facebook for developers configs

This is how settings will look: 

Facebook for developers settings

You should not only have an app, you should also add a product. In this case 'Facebook Login' is the product. This is how the product settings look like :

Facebook for developers login product settings

Now you should be able to login with facebook with the url 'http://yoursite.com/user/login/facebook'. To test on local machine, add your local url as well to the oauth redirect urls. 

Enjoy signing in with facebook. Read the facebook for developers blog for more info. Or login and comment here.

Share this post