为什么omniauth初始化两次?

时间:2013-05-15 14:47:21

标签: ruby-on-rails facebook omniauth

我正在尝试将facebook身份验证添加到我的网站。到目前为止,我已添加:

的Gemfile

gem 'omniauth-facebook', '1.4.0'

配置/初始化/ omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, 'XXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXX', {:provider_ignores_state => true}
end

配置/ routes.rb中

match '/auth/:provider/callback', :to => 'sessions#create', as: 'callback'

应用/控制器/ sessions_controller.rb

class SessionsController < ApplicationController
  def create
    render :text => request.env['omniauth.auth'].inspect
  end
end

我的问题是初始化似乎运行了两次。在rails服务器的日志中,我看到:

(facebook) Callback phase initiated.
(facebook) Callback phase initiated.
(facebook) Authentication failure! invalid_credentials: OAuth2::Error, : 
{"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100}}
(facebook) Authentication failure! invalid_credentials: OAuth2::Error, : 
{"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100}}

当我运行rake middleware时,我看到OmniAuth::Builder两次。任何建议都会非常感激。

1 个答案:

答案 0 :(得分:5)

正如Richlewis所指,如果你使用Devise和OmniAuth,你需要跳过额外的omniauth.rb初始化程序,只需在initializers / devise.rb中配置config.provider“KEY”,“SECRET”,然后继续你的实施。