omniauth-facebook and fb_graph not working together - ruby-on-rails

I am developing a rails 3.2 application and am authenticating using omniauth-facebook. This part has been giving me no problems. I get the request.env['omniauth.hash'] successfully and I extract the Oauth token as such.
auth_hash = request.env['omniauth.hash']
token = auth_hash['credentials']['token']
Afterwards I try to hit Facebook's Open Graph using fb_graph as such:
user = FbGraph::User.me(token)
However when I do this, my user is not loaded. I just get a blank user and it seems like facebook is not accepting my token as a valid token for some reason. Am I doing something wrong? Is the token I have not the one I need to make Facebook Open Graph requests? Help is much appreciated!

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

Related

Devise with Facebook Omniauth - How to authenticate using API?

I have an application running Rails 4, Devise and Omniauth (Facebook). Everything works fine.
Now I want to create an IOS app to access this database. I planned to do this using JSON requests to fetch and post data to Rails RESTfull resources that I have.
Before I start writing the IOS app, I tried to test retrieving data from the web app, using cURL on command line (JSON requests), but Devise always reject me saying that I have to authenticate first.
How should I do this? How to authenticate, using JSON requests, using Facebook username/password and access the data from the Rails app?
Or am I thinking all wrong and I should do this in a different way?
You must create Facebook APP
You have to use Facebook SDK for login in Facebook
In the app using SDK you have to make login in the facebook
After a successful login facebook return "access token" for api requests.
"access token" you must send on the server with ruby on rails.
You have to use gem "koala" or other for access to facebook api using this "access token".'
6.1 As first step you must get user information from facebook. (you will have facebook UID, and may be email.)
6.2 Then you must find current user in your DB and login using Devise method sign_in
Also you have to seen this gem
https://github.com/lynndylanhurley/devise_token_auth

Facebook login on iPhone. Authenticate with Rails Backend (Devise+Omniauth)

I am trying to implement a facebook user authentication in my iOS6 App through my Rails Backend running with Devise using omniauth. I am looking for a step by step guide how to setup my API and Devise + Authentication.
I only have a only have a rough knowledge about how to do that.
(on App) check if the user signs in on his facebook on iPhone
iPhone is authenticated client sided on Facebook. FB passes me his mobile auth token
I send my auth token or auth hash to my rails backend via API RESTful SSL.
Rails receives the Token and checks if it is valid. ( What command uses the least traffic against FB Graph API? with Koala Gem)
If valid. Check if the user already exists. If not, create a new user.
Create a new session.
Is this correct?
Are there any good examples?
Thank you very much.
I'm not familiar with the iPhone piece, but your approach after that is generally accurate. The only exception is that you would typically use provider + uid to find or create a user, rather than a token. That might be what you meant by your #5, but it wasn't clear to me.
Beyond that, there is a good (paid) Railscast on the subject of Omniauth + Devise, which would probably be worth the price for you:
http://railscasts.com/episodes/235-devise-and-omniauth-revised
It covers how you can receive and handle the auth hash, and it gives you a nice starting point for what your methods will look like.
if you don't access to pro episodes i have some links to help.
http://jessewolgamott.com/blog/2012/01/19/the-one-with-a-json-api-login-using-devise/
you can also look into it
http://net.tutsplus.com/tutorials/ruby/how-to-use-omniauth-to-authenticate-your-users/
Nice and easy to code
http://blog.joshsoftware.com/2010/12/16/multiple-applications-with-devise-omniauth-and-single-sign-on/
I hope these will work for you :)
http://www.orhancanceylan.com/rails-twitter-and-facebook-authentications-with-omniauth-and-devise/

Persistent server side Facebook authentication

I am trying to pull a public feed from the graph onto my site. I'm currently doing this with the Koala gem for Ruby on Rails.
My problem is that I can not figure out if it is possible to silently maintain authentication so as not to interrupt service. I do not want my user to be authenticated, just myself using a server side connection.
Can this be done? What am I missing?
I assume you have a Facebook app set up. To get a public page's posts, you will need to use your app access token. Note that this is different from the app id and secret specified in your app configuration on Facebook's developer site. Koala's OAuth class provides a method to get it.
Here's how to do it:
oauth = Koala::Facebook::OAuth.new Facebook::APP_ID, Facebook::SECRET
app_access_token = oauth.get_app_access_token
graph = Koala::Facebook::API.new app_access_token
graph.get_connections("depechemode", "posts")
(I'm a Depeche Mode fan.)
Do you mean, you want to pull a public page's feed and display it on your website, without your website's users needing to login to facebook? Please provide more detail.

How to update users facebook profile status from my rails web application

in my rails web application I am implementing Facebook connectivity. I want that whenever user updates his/her status on my site his/her facebook status should also be updated. Is there any working rails application for this?
Please help.Thank you.
Have a look at the Koala gem which acts as a client to the Facebook graph API and does exactly what you need.
fb_graph as well also accomplishes what the koala gem does .
Though to update on a user to user basis you'll need to have some sort of login system in place. In that case I'd look at Devise using omniauth to accomplish this.
I use devise + omniauth for authentication and getting the right access token.
I use Koala for updating + reading information.

OmniAuth to extract full profile data from LinkedIn

I'm loving the ease of OmniAuth, but I'm having a hard time connecting the dots on making additional api calls after I receive the token back.
I'll use LinkedIn as an example, but it's not LinkedIn that's the issue, more so my lack of understanding on how to make subsequent calls after I have authenticated.
I can make the request to LinkedIn and authenticate just fine.
Then I get the hash back and it's completely populated.
Now I would like to call LinkedIn back and get my complete profile data or maybe a list of contacts. How do I do this? Will I need the oauth gem after all?
I'd prefer to avoid app specific gems because I will have to make the same requests to twitter and facebook.
Omniauth is designed for authentification only.
Marcel Falliere is right. Omniauth is just for authentication.
You can have a look at this plugin, it could solve your problem.
https://github.com/pengwynn/linkedin
I think I just found out the answer to it.
after completion of oauth process with service provider(fb, twitter) omniauth saves the user. here it passes a hash to the user object and the content of hash are here https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema these credentials part can be used to request further request( infact u will have to save these in your user object).

Resources