Every Dog has one Blog

Social Login Integration With All the Popular Social Networks in Ruby on Rails

I have seen lot of people writting pretty messy code to integrate social logins in rails or get confused to integrate multiple social logins in rails. In order to help them I have written a small application having integrations with Twitter + Facebook + Linkedin + Google + Github.

Here is the demo and here is the source code

I am using devise in this application. Few things to note in this:

  1. There are two models in this application a user model and an authorizations model and a user has_many authorizations.
  2. User can link to multiple social account from edit profile
  3. Once social accounts are linked, user can login from any connected social network.
  4. If user tries to create an account with a different social network while in loggedout state. System maps it to the same account if that email address exists in the database else it will create a new account.
  5. Twitter don’t provide email address of the user, nothing I can do about it.
  6. There are lot of other commented out gems in the Gemfile. Those are the gems that I use a lot in my various projects. I will strongly suggest you to checkout those gems.

How to replace and find keys to make this application work..

In the config directory there is a file ie social_keys.yml. You need to specify all the social keys there. Make sure have restarted the application after making any change in that file.

Here are the urls from where you can create an app and get the keys




Facebook Settings



Settings: Enter call back url as : under settings tab once you create an application



Settings: Go to API Access and enter redirect url as http://localhost:3000/users/auth/google_oauth2/callback



Settings:Application callback url should be http://localhost:3000/users/auth/github



No settings required by default.