Rails Facebook login failed with omniauth-facebook - OmniAuth :: Strategies :: OAuth2 :: CallbackError

I am trying to connect to Facebook using omniauth-facebook in Rails 3.2.9; I followed the steps of Ryan Bates at http://railscasts.com/episodes/360-facebook-authentication , and at that very moment I have the same code.

If I try to log in without Javascript, it will work (I need to go to Facebook, I grant permissions and return my application), but if I try to use Javascript (for the Facebook popup), it first shows a popup for logging in, but then it does a redirect and gives me this error (without asking permission):

Started GET "/auth/facebook/callback" for 127.0.0.1 at 2012-11-16 15:16:03 -0600 (facebook) Callback phase initiated. (facebook) Authentication failure! invalid_credentials: OmniAuth::Strategies::OAuth2::CallbackError, OmniAuth::Strategies::OAuth2::CallbackError OmniAuth::Strategies::OAuth2::CallbackError (OmniAuth::Strategies::OAuth2::CallbackError) 

This is a very common mistake; I did research and tried all the solutions (mostly a few months ago), but none of them work. This is what I tried:

  • Facebook sandbox checking is disabled (and I waited an hour for distribution)
  • Checking the URL of the site http://localhost:3000/
  • Verifying the application and application ID
  • Lower the omniauth-facebook pearl to 1.4 and throw me this error: omniauth-facebook must pass either a code parameter or a signed request (via signed_request parameter or a fbsr_XXX cookie)
  • Upgrading to Rails 3.2.8

What else should I do? (I think the key is in Javascript, and now I have the same video code with CoffeeScript). Thanks in advance!

+8
ruby-on-rails facebook omniauth
source share
2 answers

I followed this Railscast just now and managed to get it working. You will notice that people discuss your issue in the comments . After the links there, I ended up this problem on Github and this https://stackoverflow.com/a/318618/

I recommend upgrading to 1.6.0 and 2.0.0 when it finally comes out. In the meantime, make sure that you are not making any of these errors:

  • Defining your application credentials in two different initializers, typically omniauth.rb and devise.rb . a source

  • There is a domain name mismatch between your current site and the site URL configured in your facebook application. a source

  • Exiting the facebook application in sandbox mode, so the domain name does not correspond to the production one. a source

  • Adding before_filter :authenticate to OmniauthCallbacksController or ApplicationController (since OmniauthCallbacksController inherits from ApplicationController). a source

  • Using omniauth-facebook in combination with Facebook client-side stream. a source

  • Pass with the state parameter.

+17
source share

Solution without downgrading (using 1.5.1 right now):

https://github.com/intridea/omniauth-oauth2/issues/32 β†’ Add this to your vendor declaration: provider: facebook, xxxxxxxxx, yyyyyyyyy, {: provider_ignores_state => true}

0
source share

All Articles