Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devise token auth + Save Facebook auth_hash info in database #326

Closed
gustavoguimaraes opened this issue Aug 5, 2015 · 7 comments
Closed

Comments

@gustavoguimaraes
Copy link

I am using Devise auth token gem and ng-token auth for authenticating my single page app. Besides registering with email there is the option to sign-up via Facebook. It works.

My problem is that as for my Fb request scope I set to get the user_friends, email and public_info, however when I get the request I don't see the auth_hash request.env['omniauth.auth']. This is described in the omniauth-facebook gem documentation.

Basically I want to save what FB gives back about the user in my database. How would you do it?

https://stackoverflow.com/questions/31833159/devise-token-auth-save-facebook-info

@tjb
Copy link

tjb commented Aug 6, 2015

👍 I am having the same issue

@gustavoguimaraes
Copy link
Author

According to the devise wiki on omniauth, it expects the response to have request.env['omniauth.auth'] which I can't find.

Instead I have in my response request.env['action_dispatch.request.unsigned_session_cookie'] which does not give me all the info that is supposed to be in auth_hash scope I set more on auth_hash info here https://github.com/mkdynamic/omniauth-facebook#auth-hash.

If you want to see the response, you can override the OmniauthCallbackController as described here and in the omniauth_success action, use a debugger. request.env['omniauth.auth'] returns nil. @lynndylanhurley Do you know why? Any guidance for anyone trying to solve this? Thanks you very much for creating these amazing libraries!

@tjb
Copy link

tjb commented Aug 6, 2015

@gustavoguimaraes I could only find information in the auth_hash but when I change the scope it will not return new data. It seems as though the scope values are not getting passed correctly.

@gustavoguimaraes
Copy link
Author

@tylerbobella totally.

Within request.env['action_dispatch.request.unsigned_session_cookie']

I see
... {"provider"=>"facebook", "uid"=>"******", "info"=>{"name"=>"John Doe", "image"=>"http://graph.facebook.com/99999/picture"}, .....

but no other info from public_profile or scopes values

@consti
Copy link

consti commented Aug 19, 2015

@gustavoguimaraes I'm running into the same problem – I'm especially missing the email attribute in the info hash. Did you find a solution?

@consti
Copy link

consti commented Aug 19, 2015

@gustavoguimaraes I was able to resolve this issue by adding the desired fields to the provider hash:

# /config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider(
    :facebook,
    ENV['FACEBOOK_KEY'],
    ENV['FACEBOOK_SECRET'],
    scope: 'email',
    info_fields: 'email,first_name,last_name')
end

Now omniauth-facebook actually requests (and receives) email, first_name, last_name and passes it forward to the DeviseTokenAuth::OmniauthCallbacksController (make sure to define your own if you want to use first_name,last_name etc.).

@booleanbetrayal
Copy link
Collaborator

Closing this issue since it's somewhat out of scope for this gem and a configuration example for omniauth-facebook has been provided. Can re-open if need be though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants