Question

we are using Warden for authentication and we have so many strategies it is difficult to track which one has been successful. Instead putting lines like

Rails.logger.debug "Authenticated with SSO" if user

to every strategy I would like to put one simple line somewhere to log the strategy message. It is available in the Warden somewhere because it stores the successful message:

success!(username, message)

How to do that? What is the best place to put this line in?

I guess I need a callback or something like that:

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

Was it helpful?

Solution

Got it:

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

And in the strategies:

success!(u, "with LDAP")

for example. That works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top