User Authentication via Facebook Connect Android

Currently, on our website, we allow users to enter / register their Facebook credentials using graph api . We are creating a mobile application, and we want to also support the login on Facebook. I know about the Android SDK and how to get the access token, my question is:

  • As soon as I have a facebook access token, how can I authenticate the user using our backend system.

One idea is to pass the access_token to my server server and request the facebook user id (I don't want to pass the facebook id because someone might just fool the request). Now, using the facebook id, I can associate it with our user id and register the user.

  • Will this method work, or is there another solution
+3
source share
1 answer

The approach described above works well. Here is the summary:

  • Facebook connects through the iPhone app.
  • Get fb access token on phone
  • Send fb access token to your Rails server
  • The controller you are using will check the fb parameter and request user information

    An example of how a controller might look like

  if params[:fb_access_token]
    @graph = Koala::Facebook::GraphAPI.new(params[:fb_access_token])
    @me = @graph.get_object("me")  
    if profile = Profile.find_by_facebook_uid(@me["id"])
      user = profile.user
      render :text => user.access_token
    else
      render :text => "unregistered", :status => 401 and return
    end
  else
+3
source

All Articles