Author

Veerasundaravel Thirugnanasundaram <[email protected]>

veerasundaravel.wordpress.com/2011/01/27/facebook-registration-plugin-in-rails/

Synopsis

facebook_registration is a ruby library for displaying new Facebook Registration form and to parse to signed_request.

developers.facebook.com/docs/plugins/registration

Installation

sudo gem install facebook_registration

Using Gem in Rails

Once you installed the gem, you will need to configure your Facebook app in config/facebooker.yml.

You can copy facebooker.yml file which one is already available in this Root directory.

Initializing Registration Form

<%= init_fb_registration %>

Displaying Facebook Registration Form

<%= fb_registration_form("fields" =>"name,email,password", "redirect-uri"=>"http://localhost:3000/fb_registration", "width" =>830) %>

or 

<%= fb_registration_form("fields" =>"[{'name':'name'}, {'name':'email'}, {'name':'password'}, {'name':'username','description':'Username','type':'text'}, {'name':'like', 'description':'You like this Website', 'type':'checkbox', 'default':'checked'}]", "fb_only"=>false, "redirect-uri"=>"http://localhost:3000/fb_registration", "width" =>830) %>

For more form field specifications refer this url: 
  http://developers.facebook.com/docs/plugins/registration#named_fields 
  http://developers.facebook.com/docs/plugins/registration#custom_fields

Accessing profile informations

After displaying the form, you can register their details and they will be redirected to the url which one you have specified as redirect-uri. 

So in our case, you can parse the Facebook profile informations in the action fb_registration as follows:

FacebookRegistration::SignedRequest.parse(params["signed_request"])

it will return the output as follows:

{"expires"=>1295964000, "registration_metadata"=>{"fields"=>"[{'name':'name'}, {'name':'location'}, {'name':'email'}]"}, "algorithm"=>"HMAC-SHA256", "registration"=>{"name"=>"Veera Sundaravel", "location"=>{"name"=>"Chennai, Tamil Nadu", "id"=>000000000}, "email"=>"[email protected]"}, "user_id"=>"111111111", "oauth_token"=>"1212121212|2.9vzjKsatvaser_dStgereokRhg__.360220.1295964000-daff1|rsfsfasdfasdfasd", "user"=>{"country"=>"us", "locale"=>"en_US"}, "issued_at"=>1295956965}