如何处理错误:
OmniAuth::Strategies::OAuth2::CallbackError
...generated by OmniAuth当用户进入Facebook登录时,但决定取消?
我见过一些关于这方面的线索,但没有一种解决方案对我有效。
我试着把这个:
OmniAuth.config.on_failure = UsersController.action(:oauth_failure)
...into omniauth.rb
初始化程序文件,但没有成功。
我使用的是omniauth-facebook gem和Rails 4.0.2。
任何帮助都非常感谢。
非常感谢!迈克尔。
我的gemfile.lock文件揭示了与无所不在的facebook创业板相关的以下宝石:
oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
omniauth (1.1.4)
hashie (>= 1.2, < 3)
rack
omniauth-facebook (1.5.1)
omniauth-oauth2 (~> 1.1.0)
omniauth-oauth2 (1.1.1)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
发布于 2014-04-17 09:24:34
我将omniauth-facebook
gem升级到1.0.6版本,现在它正在按预期工作。
对于其他遇到此问题并希望捕获此错误的人,以下是您需要的内容:
/config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'xxx', 'xxx', scope: "email,publish_stream,user_location,user_birthday"
end
/config/initializers/omniauth_failure_callback.rb
OmniAuth.config.on_failure = Proc.new do |env|
UsersController.action(:omniauth_failure).call(env)
end
/app/controllers/users_controller.rb
def omniauth_failure
flash[:danger] = "Unable to connect with Facebook at this time."
redirect_to root_url
end
https://stackoverflow.com/questions/23115984
复制相似问题