module SoarAuthenticationToken class CascadeProvider def initialize(configuration) @configuration = configuration validate_configuration end def fetch(request) # TODO: refactor this functionality into modules - DON'T DUPLICATE! fetch_by_cookie(request) || fetch_by_auth_header(request) end private def fetch_by_cookie(request) return false unless request.env.has_key?('HTTP_COOKIE') return false unless request.cookies.has_key?(@configuration['cookie_name']) request.cookies[@configuration['cookie_name']] end def fetch_by_auth_header(request) return false unless request.env[@configuration['header_name']] request.env[@configuration['header_name']] end def validate_configuration raise "'cookie_name' must be configured" unless @configuration['header_name'] end end end