module ProxyAuthentication
Based on Kentaro Imai’s code: kentaroimai.com/articles/1-controller-test-helpers-for-warden
Constants
- VERSION
Public Class Methods
setup() { |self| ... }
click to toggle source
# File lib/proxy_authentication.rb, line 21 def setup setup_warden include_helpers yield self if block_given? end
validate_with(&block)
click to toggle source
# File lib/proxy_authentication.rb, line 27 def validate_with &block @@validate_with_block = block end
Private Class Methods
authenticate!()
click to toggle source
# File lib/proxy_authentication.rb, line 53 def authenticate! rails_request = env['action_controller.instance'].request user = ProxyAuthentication::AuthenticationCipher.decode params['u'].to_s, rails_request user.present? ? success!(user) : fail end
define_warden_strategy()
click to toggle source
# File lib/proxy_authentication.rb, line 46 def define_warden_strategy Warden::Strategies.add(:proxy_authentication_via_token) do def valid? params['u'].present? && env['action_controller.instance'].present? end def authenticate! rails_request = env['action_controller.instance'].request user = ProxyAuthentication::AuthenticationCipher.decode params['u'].to_s, rails_request user.present? ? success!(user) : fail end end end
include_helpers()
click to toggle source
# File lib/proxy_authentication.rb, line 62 def include_helpers ActionController::Base.send :include, ::ProxyAuthentication::Helpers end
insert_warden_middleware()
click to toggle source
# File lib/proxy_authentication.rb, line 38 def insert_warden_middleware Rails.configuration.middleware.insert_before ActionDispatch::ParamsParser, Warden::Manager do |manager| manager.default_strategies :proxy_authentication_via_token manager.serialize_into_session { |user| ProxyAuthentication::AuthenticationCipher.encode user } manager.serialize_from_session { |hash| ProxyAuthentication::AuthenticationCipher.decode hash } end end
setup_warden()
click to toggle source
# File lib/proxy_authentication.rb, line 33 def setup_warden insert_warden_middleware define_warden_strategy end
valid?()
click to toggle source
# File lib/proxy_authentication.rb, line 49 def valid? params['u'].present? && env['action_controller.instance'].present? end