Veerasundaravel Thirugnanasundaram <[email protected]>


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


sudo gem install facebook_registration

Using Gem in Rails

In previous versions, we must specify our FB app keys in a YAML file. But in this version we can directly specify the APP-ID, Secret key etc within the app whenever needed like below:

Initializing Registration Form

<%= init_fb_registration('YOUR-FACEBOOK-APP-ID') %>

Displaying Facebook Registration Form

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


<%= 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, "onvalidate"=>"validate_async") %>

Available parameters:

redirect-uri: The URI that will process the signed_request. It must be prefixed by your Site URL. fields: Comma separated list of Named Fields, or JSON of Custom Fields. fb_only: Optional. (boolean) Only allow users to register by linking their Facebook profile. Use this if you do not have your own registration system. Default: false. width: Optional. (int) The width of the iframe in pixels. If the width is < 520 the plugin will render in a small layout. onvalidate: Javascript function for client side validate of form inputs. And moreā€¦

For more form field specifications refer these urls:

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"], 'YOUR-FACEBOOK-SECRET-KEY')

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}