Omniauth facebook authentication failure Invalid application Id

832 views Asked by At

I am using omniauth-facebook gem to authorize using facebook in my rails application.

I have followed these instructions but the problem I am facing is error about invalid credentials:

(facebook) Authentication failure! invalid_credentials: OAuth2::Error, : 
{"error":{"message":"Error validating application. Invalid application ID.","type":"OAuthException","code":101}}

What is weird about this is that I am getting user info even though I get this error from facebook api.

the value of request.env['omniauth.auth'] is(server log).

#<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=true 
expires_at=1421256863 token="some_long_value"> extra=#<OmniAuth::AuthHash 
raw_info=#<OmniAuth::AuthHash education=[#<OmniAuth::AuthHash school=
#<OmniAuth::AuthHash id="174179219354091" name="Udacity"> type="College">]
email="[email protected]" favorite_athletes=[#<OmniAuth::AuthHash id="51926382304"  
name="Derrick Rose">, #<OmniAuth::AuthHash id="344128252278047" name="Sachin   
Tendulkar">,.... so on

routes.rb

devise_for :users, :controllers => {:omniauth_callbacks => "omniauth_callbacks"}

config/initializers/omniauth.rb

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do 
  provider :facebook, 'key', 'secret', {:provider_ignores_state => true}
  # key and secret are correctly added in above line
end

app/model/user.rb

devise :omniauthable, :omniauth_providers => [:facebook]

app/controller/omniauth_callback_controller.rb

class OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def facebook
    omniauth = request.env['omniauth.auth']
    # Other code to create authentication and other logic
    puts "===>>> Omniauth is #{omniauth}"
  end

  def failure
    res = request.env['omniauth.auth']
    puts "======>>>>>> Authentication failed #{res}"
    redirect_to root_path
  end  
end   

Every time response goes to failure method but not to facebook method.

What I don't understand is when I am getting invalid credentials error from api then how come I get all the data from facebook. I doubt I have something wrong on my end while handling the callback from facebook. Can anyone point where the problem can be?

I am pretty sure I am using correct application id and key I am getting data from facebook in the response.

Can anybody help me with this issue?

0

There are 0 answers