Sha256: 109ea9fccf8779912fb4c9f201a43d6e504097b0634b6530af136844567d7c62
Contents?: true
Size: 1015 Bytes
Versions: 3
Compression:
Stored size: 1015 Bytes
Contents
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') cookies = HTTP::CookieJar.new.parse(request.env['HTTP_COOKIE'], 'http://irrelevant') auth_cookie = cookies.find { |cookie| cookie.name == @configuration['cookie_name'] } return false unless auth_cookie.is_a?(HTTP::Cookie) auth_cookie.value 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
Version data entries
3 entries across 3 versions & 1 rubygems