Sha256: 82a7d113178ee85c0e46a4de077ce21b72b60d6e1c9253a2e73f84362b644f46

Contents?: true

Size: 682 Bytes

Versions: 16

Compression:

Stored size: 682 Bytes

Contents

# Provides a routing constraint that makes sure a user is authenticated
# before a route can be resolved.
#
# (used for autenticating sidekiq)

module Softwear
  module Auth
    class Routing
      def initialize(user_class, pred = nil)
        @user_class = user_class
        @pred = pred
      end

      def matches?(request)
        if user = @user_class.auth(request.session[:user_token])
          !@pred || @pred.call(user)
        else
          false
        end
      end
    end
  end
end

ActionDispatch::Routing::Mapper.class_eval do
  def authenticate(user_class, pred = nil, &block)
    constraints(::Softwear::Auth::Routing.new(user_class, pred), &block)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
softwear-lib-3.3.7 lib/softwear/auth/routing.rb
softwear-lib-3.3.6 lib/softwear/auth/routing.rb
softwear-lib-3.3.5 lib/softwear/auth/routing.rb
softwear-lib-3.1.5 lib/softwear/auth/routing.rb
softwear-lib-3.1.4 lib/softwear/auth/routing.rb
softwear-lib-3.1.3 lib/softwear/auth/routing.rb
softwear-lib-3.1.2 lib/softwear/auth/routing.rb
softwear-lib-3.1.1 lib/softwear/auth/routing.rb
softwear-lib-3.1.0 lib/softwear/auth/routing.rb
softwear-lib-3.0.0 lib/softwear/auth/routing.rb
softwear-lib-2.1.7 lib/softwear/auth/routing.rb
softwear-lib-2.1.6 lib/softwear/auth/routing.rb
softwear-lib-2.1.4 lib/softwear/auth/routing.rb
softwear-lib-2.1.3 lib/softwear/auth/routing.rb
softwear-lib-2.1.2 lib/softwear/auth/routing.rb
softwear-lib-2.1.1 lib/softwear/auth/routing.rb