Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR -- omniauth: (facebook) Authentication failure

I'm getting the following error using the latest Omniauth Facebook gem:

ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials: OAuth2::Error, :

My credentials are correct and i seem to hit facebook ok but the callback errors out.

Any ideas?

like image 654
Gregg Horton Avatar asked Mar 09 '23 11:03

Gregg Horton


2 Answers

The problem I had was that my app was using an older version of the facebook API. Omniauth-facebook uses a default API version, in my case 2.4 but my App needed a newer version because that is what it said in my Facebook Developer Console. In my case, all I had to do was to update the omniauth-facebook gem to version 4.0.

If you wish you can set the Facebook API version that you want to use instead of using the default like this (omniauth-facebook docs):

use OmniAuth::Builder do
  provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'],
    client_options: {
      site: 'https://graph.facebook.com/v3.0',  # this is the example API version
      authorize_url: "https://www.facebook.com/v3.0/dialog/oauth"
    }
end

You can check which API verison your app is using by going to your facebook developer console. enter image description here

You can read more about the omniauth-facebook gem API here: http://www.rubydoc.info/gems/omniauth-facebook/4.0.0#API_Version

like image 120
Alexander Luna Avatar answered Mar 15 '23 10:03

Alexander Luna


I had the same problem but specifying version didn't help me. I end up passing token_params: { parse: :json } something like below which resolved my issue :

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, Figaro.env.fb_appid, Figaro.env.fb_sec,
           { scope: 'email',  token_params: { parse: :json } }
end

I have found the reference #174 comment

like image 37
Manishh Avatar answered Mar 15 '23 11:03

Manishh