Skip to main content

Add Drupal 8 login with google 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 google project and enable api and services to get credentials (client secret and id). The social_apisocial_auth module should be installed along with social_auth_google. 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_google

Enable both the modules and go to the social_auth config (admin/config/social-api/social-auth) and click on the Google tab. This is what it would look like :

Login with google config

Substitute the values with the values from your google project that you created in google cloud platform. If you don't have a project, create one at this link https://console.cloud.google.com

After you create a project, you have to get your Client ID and Client Secret. Go to APIs and Services, and add credentials for oauth 2.0 : 

Google Oauth 2.0 Client ID and Secret

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

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

Share this post