class Rack::Reqorder::Monitor::Helpers::AuthorizationHeader
taken from rails ActionController::HttpAuthentication::Token ^_^
Constants
- AUTHN_PAIR_DELIMITERS
- TOKEN_KEY
- TOKEN_REGEX
Public Class Methods
token_and_options(headers)
click to toggle source
# File lib/rack/reqorder/monitor/helpers.rb, line 51 def token_and_options(headers) authorization_request = headers['Authorization'] if authorization_request[TOKEN_REGEX] params = token_params_from authorization_request [params.shift[1], Hash[params].with_indifferent_access] end end
Private Class Methods
params_array_from(raw_params)
click to toggle source
Takes raw_params
and turns it into an array of parameters
# File lib/rack/reqorder/monitor/helpers.rb, line 67 def params_array_from(raw_params) raw_params.map { |param| param.split %r/=(.+)?/ } end
raw_params(auth)
click to toggle source
This method takes an authorization body and splits up the key-value pairs by the standardized :
, ;
, or \t
delimiters defined in AUTHN_PAIR_DELIMITERS
.
# File lib/rack/reqorder/monitor/helpers.rb, line 79 def raw_params(auth) _raw_params = auth.sub(TOKEN_REGEX, '').split(/\s*#{AUTHN_PAIR_DELIMITERS}\s*/) if !(_raw_params.first =~ %r{\A#{TOKEN_KEY}}) _raw_params[0] = "#{TOKEN_KEY}#{_raw_params.first}" end _raw_params end
rewrite_param_values(array_params)
click to toggle source
This removes the "
characters wrapping the value.
# File lib/rack/reqorder/monitor/helpers.rb, line 72 def rewrite_param_values(array_params) array_params.each { |param| (param[1] || "").gsub! %r/^"|"$/, '' } end
token_params_from(auth)
click to toggle source
# File lib/rack/reqorder/monitor/helpers.rb, line 62 def token_params_from(auth) rewrite_param_values params_array_from raw_params auth end