0

我们正在使用 Warden 进行身份验证,并且我们有很多策略,很难追踪哪一个成功了。而是把线条像

Rails.logger.debug “通过 SSO 验证”如果用户

对于每个策略,我想在某处放置一个简单的行来记录策略消息。它在 Warden 的某个地方可用,因为它存储了成功的消息:

success!(username, message)

怎么做?放置这条线的最佳位置是什么?

我想我需要一个回调或类似的东西:

https://github.com/hassox/warden/wiki/Callbacks

4

1 回答 1

0

知道了:

Warden::Manager.after_authentication do |user,auth,opts|
  user = user.username if user.respond_to? :username
  message = auth.winning_strategy.message
  Rails.logger.info "User #{user} authenticated: #{auth.winning_strategy.message}"
end

在策略中:

success!(u, "with LDAP")

例如。这样可行。

于 2012-01-27T06:57:32.307 回答