Hi all, I am back with Socialbeam Tutorials once again! After your overwhelming response for the project I thought to sit and write today about a very useful thing one would require for building Social Network “User Registrations via other Social Networks Authentication”
If you remember our my tutorial about Socialbeam I wrote about using Authlogic to integrate User Sign-In, Sign-Up, Sessions etc. Today we will see how to integrate OmniAuth for Users to join via their other Social Networks like Facebook,Twitter, LinkedIn or Google etc!
But before jumping into the tutorial I would like to throw some light on the Socialbeam development changes.
- I have moved to using Rails 3.2.13
- I am now using Ruby 1.9.3
- Please refer to the setup scripts in the github repo “socialbeam-dev” for latest changes and how to setup your box if you are out of sync!
Lets begin then!
What is OmniAuth ? OmniAuth is a flexible authentication system utilizing Rack middleware.OmniAuth gem Taken from their description
– OmniAuth is a library that standardizes multi-provider authentication for web applications. It was created to be powerful, flexible, and do as little as possible. Any developer can create strategies for OmniAuth that can authenticate users via disparate systems. OmniAuth strategies have been created for everything from Facebook to LDAP.In order to use OmniAuth in your applications, you will need to leverage one or more strategies.
Strategies in our terms refers to the Third Party Authentications like Facebook ,Twitter etc. So see a list of strategies supported you can refer here, the list is huge! I mean HUGE! https://github.com/intridea/omniauth/wiki/List-of-Strategies
Okay one more important thing to note is I will be using OmniAuth version 1.1.4 which is the latest on this current date October 3rd, 2013 , you will find a tons of tutorials on OmniAuth 0.3.x and the schema for 0.3.x is a little different, but even if you are using 0.3.x it shouldn’t be that hard to follow this up. Also I will be using Rails 3.x , if you are Rails 2.x guy don’t worry the steps are almost similar!
If you are new to User Registrations Framework on Socialbeam or in building your own Social Network I would recommend you to first read about Authlogic in my earlier tutorial about integrating Authlogic gem for normal User – Sessions management, as we would be integrating OmniAuth on top of Authlogic so Socialbeam would support both kind of registrations! Cool.
I have mentioned that I have made some major changes in Socialbeam so I would throw away my Gemfile at you once for your glance so that you can catch anything which might be different in your setup
gem 'rails', '3.2.13'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
#Easy deployment in Amazon EC2
gem "bcrypt-ruby", '~>3.0.1',:require => "bcrypt"
gem 'will_paginate', '~> 3.0'
group :development,:test do
#Unicorn App server
First off there needs to be some changes in our User Table definition reason being if I am using Social Network Authentications I donot need validations on password fields etc and Authlogic can rest in peace when OmniAuth does its work for Third Party Auhorizations.
Here is what the new User Schema should like
Step 1 : User Schema
class UsersTable < ActiveRecord::Migration def up create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "profile_name", :default => "beamer"
t.string "profile_id", :null => false
t.string "beamer_id", :null => false
t.integer "login_count", :default => 0
t.integer "failed_login_count", :default => 0
add_index "users", ["beamer_id"], :name => "index_users_on_beamer_id", :unique => true
add_index "users", ["first_name"], :name => "index_users_on_first_name"
add_index "users", ["profile_id"], :name => "index_users_on_profile_id", :unique => true
If you noted the difference from earlier version of the schema then you would see that I have removed :null=>false from many fields like passwords because of the mentioned reason earlier!