Question

I have a ruby on rails application that currently supports facebook authentication with devise / omniauth.

An iOS client is being built that needs to support facebook authentication also.

My question is, how do I use the access token server side to get the user's email outside of an omniauth callback?

My understanding is that omniauth provides some middleware that on a facebook callback writes an auth hash containing all information to request.env['omniauth.auth']

See: https://github.com/mkdynamic/omniauth-facebook

With an iOS client the flow is a little different, I think:

  1. The user signs into facebook on the client.
  2. The user agrees to give the app access.
  3. The client app posts access_token to the rails API.
  4. Rails app validates access token with facebook and retrieves users details.

It is step 4 that I'm not sure how to do.

Essentially once I have an access token how do I get an auth hash manually when I'm not in an omniauth callback?

Thanks for any help.

Was it helpful?

Solution 2

After much trial and error found the following way to get the user's email using the Koala gem:

@graph = Koala::Facebook::API.new(TOKEN, APP_SECRET)
@graph.get_object('me', :fields => ['email'])

OTHER TIPS

Try to use gem "Koala"

Example:

@graph = Koala::Facebook::API.new(oauth_access_token)
profile = @graph.get_object("me")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top