lib/auth_trail/manager.rb in authtrail-0.1.0 vs lib/auth_trail/manager.rb in authtrail-0.1.1

- old
+ new

@@ -4,17 +4,14 @@ def after_set_user(user, auth, opts) # do not raise an exception for tracking AuthTrail.safely do request = ActionDispatch::Request.new(auth.env) - strategy = auth.env["omniauth.auth"]["provider"] if auth.env["omniauth.auth"] - strategy ||= auth.winning_strategy.class.name.split("::").last.underscore if auth.winning_strategy - strategy ||= "database_authenticatable" - identity = user.try(:email) + AuthTrail.track( - strategy: strategy, + strategy: detect_strategy(auth), scope: opts[:scope].to_s, identity: identity, success: true, request: request, user: user @@ -24,21 +21,32 @@ def before_failure(env, opts) AuthTrail.safely do if opts[:message] request = ActionDispatch::Request.new(env) - identity = request.params[opts[:scope]] && request.params[opts[:scope]][:email] rescue nil + scope = opts[:scope] + identity = request.params[scope] && request.params[scope][:email] rescue nil + AuthTrail.track( - strategy: "database_authenticatable", - scope: opts[:scope].to_s, + strategy: detect_strategy(env["warden"]), + scope: scope.to_s, identity: identity, success: false, request: request, failure_reason: opts[:message].to_s ) end end + end + + private + + def detect_strategy(auth) + strategy = auth.env["omniauth.auth"]["provider"] if auth.env["omniauth.auth"] + strategy ||= auth.winning_strategy.class.name.split("::").last.underscore if auth.winning_strategy + strategy ||= "database_authenticatable" + strategy end end end end