2013-05-15 61 views
3

我正在嘗試將Facebook身份驗證添加到我的網站。到目前爲止,我說:爲什麼omniauth初始化兩次?

的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 

的config/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 

我的問題是,初始化似乎兩次運行。在日誌中軌服務器我看到:

(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兩次。任何建議將不勝感激。

+0

不要以爲你使用設計也是你? – Richlewis

回答

4

由於Richlewis指的是,如果你使用的設計與OmniAuth你需要跳過額外omniauth.rb初始化,只是config.provider「KEY」,「祕密」初始化/ devise.rb內再進行與您的實施。

+1

使用devise將認證路徑從/ auth /:provider移動到/ users/auth /:provider。 – Will

+6

雖然我沒有omniauth.rb文件omniauth請求階段啓動兩次。開始在2014-02-12 10:05:42 +0530 GET,「/ users/auth/google_oauth2」for 127.0.0.1我,[2014-02-12T10:05:42.046501#4240]信息 - omniauth:(google_oauth2 )請求階段已啓動。 已啓動GET「/ users/auth/google_oauth2」for 127.0.0.1 at 2014-02-12 10:05:42 +0530 我,[2014-02-12T10:05:42.402859#4240]信息 - omniauth :(google_oauth2)請求階段已啓動。 – Sam

相關問題