我正在使用omniauth-facebook gem 来授权在我的rails 应用程序中使用facebook。
我已按照这些说明进行操作,但我面临的问题是有关无效凭据的错误:
(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']
is(服务器日志)的值。
#<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
路线.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
应用程序/模型/用户.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 获取数据。
有人可以帮我解决这个问题吗?