4

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

宝石文件

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

配置/路由.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了两次。任何建议将不胜感激。

4

1 回答 1

5

正如Richlewis所指的那样,如果您将 Devise 与 OmniAuth 一起使用,您需要跳过额外的omniauth.rb 初始化程序,只需在初始化程序/devise.rb 中配置 config.provider "KEY", "SECRET",然后继续您的实现。

于 2013-05-17T16:12:55.113 回答