Omniauth facebook身份验证失败无效的应用程序ID

时间:2014-11-15 22:21:26

标签: ruby-on-rails ruby devise omniauth omniauth-facebook

我正在使用 omniauth-facebook gem授权在我的rails应用程序中使用facebook。

我已按照these说明操作,但我遇到的问题是有关无效凭据的错误:

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

有什么奇怪的是,即使我从facebook api收到此错误,我也会收到用户信息。

request.env['omniauth.auth']的值 是(服务器日志)。

#<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="ashish@gmail.com" 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"}

配置/初始化/ 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

应用/模型/ user.rb

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

应用/控制器/ 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   

每次响应都转到failure方法而不是facebook方法。

我不明白的是当我从api收到无效的凭据错误时,我怎么才能从facebook获取所有数据。在处理来自facebook的回调时,我怀疑自己有什么问题。 任何人都可以指出问题所在吗?

我很确定我正在使用正确的应用程序ID和密钥我在回复中从facebook获取数据。

有人可以帮我解决这个问题吗?

0 个答案:

没有答案