I am trying to get up a login and create user via omniauth-facebook gem, I am getting the hash back but it doesnt have all the data that I need and I running out of things to try, setup is below:
All I want to get is first_name, last_name, email and bio
Sessions Controller
def create
render text: request.env['omniauth.auth'].to_json
end
Route
get '/auth/:provider/callback', to: 'sessions#create'
omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, Rails.application.secrets.facebook_app_id,
Rails.application.secrets.facebook_app_secret,
:scope => 'email,public_profile', :info_fields =>
'name,email,first_name,last_name,bio'
provider :twitter, Rails.application.secrets.twitter_app_id,
Rails.application.secrets.twitter_app_secret
end
The returned hash:
{
"provider": "facebook",
"uid": "1**************",
"info": {
"name": "Philip Davies",
"image": "http://graph.facebook.com/1*************/picture?type=square"
},
"credentials": {
"token": "************",
"expires_at": 1488480906,
"expires": true
},
"extra": {
"raw_info": {
"name": "Philip Davies",
"id": "1***********"
}
}
}
I had this same issue and was unable to solve it but ended up finding a workaround via the Koala gem (https://github.com/arsduo/koala). I ended up using the facebook-omniauth gem to log in, saved that authentication token, and then used Koala to get the specific information from the user's Facebook profile.
My user.rb looks like this:
I know it's not the perfect solution, but it allowed me to do what I was trying to do, so maybe it will work for you as well. If you have any questions just let me know.