mandar.gokhale
mandar.gokhale

Reputation: 1875

How to use Facebook registration plugin

Hi, I want to implement sign in with Facebook in my Rails web application. I red about it from https://developers.facebook.com/docs/plugins/registration/.

My problem is I am not getting how to get the users data from signed request into my database. Please help me.

Thanks in advance!

Upvotes: 3

Views: 1059

Answers (2)

Amit
Amit

Reputation: 174

this is the iframe code change the client_id and redirect_url with yours client id and redirect_url

<iframe src="https://www.facebook.com/plugins/registration?
             client_id=MY_CLIENT_ID&
             redirect_uri=MY_REDIRECT_URI&
             fields=name,email,first_name,last_name"
        scrolling="auto"
        frameborder="no"
        style="border:none"
        allowTransparency="true"
        width="100%"
        height="330">
</iframe>

it will automatically call the redirect_url provided here after clicking the register . in that method facebook will return you one variable "signed_request" that contains all the data for users. in the method you can decode the signed request . this is my code to decode the signed request

def decode_facebook_hash(signed_request)
  signature, str = signed_request.split('.')
  str += '=' * (4 - str.length.modulo(4))
  ActiveSupport::JSON.decode(Base64.decode64(str.gsub("-", "+").gsub("_", "/")))
end

Upvotes: 1

Simpleton
Simpleton

Reputation: 6415

You can use the OmniAuth gem.

A railscast tutorial is available here: http://railscasts.com/episodes/241-simple-omniauth

Upvotes: 0

Related Questions