2013-08-20 32 views
2

在我的應用程序omniauth,有一個用戶使用谷歌的OAuth2驗證我將用戶重定向到:使用Omniauth,如何記錄所有身份驗證請求?

/users/auth/google_oauth2 

如果用戶批准該請求,然後#創建AuthenticationsController被調用。

With AuthenticationsController#create - 我可以添加事件跟蹤來記錄批准谷歌身份驗證的用戶數量。我沒有的是我發送的數字,以表示我沒有轉換率。

我該如何跟蹤連接請求的人數。

回答

0

一個令人討厭的解決方案是圍繞方法Strategy#request_call建立一個過濾器並在那裏進行跟蹤。

內的初始化:

OmniAuth::Strategy.class_eval do 
    def request_call_with_tracking 
    log :info, "Im running before the actual request_call" 
    Tracker.hit(name) #name will return the provider 
    request_call_without_tracking 
    end 
    alias_method_chain :request_call, :tracking 
end 
0

您可以通過使用OmniAuth安裝階段實現這一目標。您可以將:setup選項傳遞給OmniAuth提供程序,並在執行身份驗證之前執行一個proc程序。你可以在這個過程中添加事件跟蹤。

所以,如果你有一些跟蹤器類,你可以這樣做:

use OmniAuth::Builder do 
    provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], 
    :setup => lambda { |env| 
     Tracker.track 
    } 
end 

欲瞭解更多信息,請查閱Avdi Grimm's great blog post about the subject

相關問題