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