Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication using Facebook via Rails API

Users of my Rails app can authenticate in one of these 2 manners:

  • Using their Facebook account
  • Using our own authentication

I'm using Facebook SDK on Android and devise and omniauth on Rails.

How do I authenticate against my Rails app on Android so I can then fetch the information I need from the server?

NB: I've noticed this question is getting a fair amount of views recently. Please don't follow the advice given in this thread too closely -- the web moves fast and it dates from 3 years ago!

like image 832
F. P. Avatar asked May 25 '12 10:05

F. P.


1 Answers

This can be done using the fb_graph gem (not fbgraph!).

You can just add it to your gemfile and do

user = FbGraph::User.me(token).fetch

where token is the oauth token you got by using, for example, the Facebook SDK on Android. user.email will be the user's email address (if you set up the necessary permissions).

You can use this URL for testing:

https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=https://www.facebook.com/connect/login_success.html&response_type=token
like image 65
F. P. Avatar answered Oct 24 '22 21:10

F. P.