Sha256: a21de7aa034f25d997ca3f798fcc5dcf97f3527de6c10e55db26bd6509e589a2

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

module AuthTrail
  module Manager
    class << self
      def after_set_user(user, auth, opts)
        request = ActionDispatch::Request.new(auth.env)

        AuthTrail.track(
          strategy: detect_strategy(auth),
          scope: opts[:scope].to_s,
          identity: AuthTrail.identity_method.call(request, opts, user),
          success: true,
          request: request,
          user: user
        )
      end

      def before_failure(env, opts)
        request = ActionDispatch::Request.new(env)

        AuthTrail.track(
          strategy: detect_strategy(env["warden"]),
          scope: opts[:scope].to_s,
          identity: AuthTrail.identity_method.call(request, opts, nil),
          success: false,
          request: request,
          failure_reason: opts[:message].to_s
        )
      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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
authtrail-0.6.0 lib/auth_trail/manager.rb
authtrail-0.5.0 lib/auth_trail/manager.rb
authtrail-0.4.3 lib/auth_trail/manager.rb
authtrail-0.4.2 lib/auth_trail/manager.rb
authtrail-0.4.1 lib/auth_trail/manager.rb
authtrail-0.4.0 lib/auth_trail/manager.rb
authtrail-0.3.1 lib/auth_trail/manager.rb
authtrail-0.3.0 lib/auth_trail/manager.rb