Facebook Authentication in Ruby on Rails

Step 1: FaceBook Application Integration

Visit http://developers.facebook.com/apps and click the ‘Create New App’ and fill the required fields and select a category and subcategory, click Continue.

Step 2:

After that, note application’s id and secret and  click on ‘Website with Facebook Login’, here give a site URL i.e http://localhost:3000 and Save.

Step 3:Now in rails app open gem file and add the below gem.

gem ‘omniauth-facebook’  and type  $ bundle install  in console

Step 4:Create initializer i.e omniauth in/initializers/omniauth.rb & edit as below

OmniAuth.config.logger = Rails.logger

Replace ‘facebook app id’ with your app id, and ‘ facebook app secret’ with values that was i mentioned above.For solving Open SSL , issue we have to download a file i.e download this file and put in  rails application root folder.

Step 5:Next create a user model to save the data that retrieves from FaceBook i.e run the commands in console:

$rails g model user provider uid name oauth_token oauth_expires_at:datetime

$rake db:migrate

Step 6:Home controller and sessions  will allow user login & logout,So run the commands in the console.

$rails g controller home show

$rails g controller Sessions create destroy

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s