我正在尝试将 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
了两次。任何建议将不胜感激。