2

I'm trying to implement Facebook Authentication and I'm stuck. I exactly followed this guide

https://www.crondose.com/2016/12/guide-integrating-omniauth-rails-5-facebook-login-feature/

and get this error

I, [2017-11-07T00:55:47.114884 #12099] INFO -- omniauth: (facebook) Callback phase initiated. E, [2017-11-07T00:55:47.489634 #12099] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials: OAuth2::Error, :

Facebook API Version v2.10

I am using ruby 2.4.0 and Rails 5.1.4

Pardeep Dhingra
  • 3,916
  • 7
  • 30
  • 56
Takuya
  • 21
  • 3
  • can you tell me `omniauth-facebook` version? – Pardeep Dhingra Nov 06 '17 at 14:25
  • Thank you Pardeep! I did not specify the gem version. I just put "gem 'omniauth-facebook'" should i specify? – Takuya Nov 06 '17 at 23:10
  • You can find gem version in `Gemfile.lock` – Pardeep Dhingra Nov 07 '17 at 13:40
  • @Takuya config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], callback_url: "#{ENV["domain"]}/users/auth/facebook/callback", scope: 'email', token_params: { parse: :json } Try to use this code and note that token_params hash. I also faced this error and tried to debug this for few days. I could not find any valid cause of the bug but adding that last parameter fixed this. You can try this and let me know whether it fixed your issue or not. – Aakash Gupta Nov 09 '17 at 21:59

1 Answers1

0

You are likely getting this error because your App ID or App Secret are incorrect. Make sure your initializer has the correct Facebook API credentials:

# config/initializers/devise.rb
config.omniauth :facebook, <your App Id>, <your App Secret>,
  callback_url: "http://localhost:3000/users/auth/facebook/callback"

Another Tip: Facebook now requires you to specify the fields you want back from Facebook. In other words, if you want the Facebook user's email address, you need to specifically request it. In the past it was returned by default. You can request fields by using the scope parameter in the Devise configuration.

For example, to request the Facebook user's email and name, do this:

# config/initializers/devise.rb
config.omniauth :facebook, <your App Id>, <your App Secret>,
  callback_url: "http://localhost:3000/users/auth/facebook/callback",
  scope: 'email,name'
Tom Aranda
  • 5,919
  • 11
  • 35
  • 51
  • thank you Tom! The first one is the '''config.omniauth :facebook, , ,''' right? I am sure its correct. and second one I also tried and did not work as well,, other tip,,,? – Takuya Nov 06 '17 at 23:08
  • Just to clarify `` and `` should be the credentials you get from Facebook. It is going to be a random string of characters. `dkjfsdljfiowfjwejf43j` for example. – Tom Aranda Nov 06 '17 at 23:23