class ApiSignature::AuthHeader

Constants

AUTHN_PAIR_DELIMITERS
TOKEN_REGEX

Attributes

authorization[R]

Public Class Methods

new(authorization) click to toggle source
# File lib/api_signature/auth_header.rb, line 10
def initialize(authorization)
  @authorization = authorization.to_s
end

Public Instance Methods

credential() click to toggle source
# File lib/api_signature/auth_header.rb, line 14
def credential
  data[0]
end
options() click to toggle source
# File lib/api_signature/auth_header.rb, line 28
def options
  @options ||= (data[1] || {})
end
signature() click to toggle source
# File lib/api_signature/auth_header.rb, line 18
def signature
  options['Signature']
end
signed_headers() click to toggle source
# File lib/api_signature/auth_header.rb, line 22
def signed_headers
  return [] unless options['SignedHeaders']

  @signed_headers ||= options['SignedHeaders'].split(/;\s?/).map(&:strip)
end

Private Instance Methods

data() click to toggle source
# File lib/api_signature/auth_header.rb, line 34
def data
  @data ||= (parse_token_with_options || [])
end
params_array_from(raw_params) click to toggle source
# File lib/api_signature/auth_header.rb, line 53
def params_array_from(raw_params)
  raw_params.map { |param| param.split(/=(.+)?/) }
end
parse_token_with_options() click to toggle source
# File lib/api_signature/auth_header.rb, line 38
def parse_token_with_options
  return unless authorization[TOKEN_REGEX]

  params = token_params_from authorization
  [params.shift[1], Hash[params]]
end
raw_params(auth) click to toggle source
# File lib/api_signature/auth_header.rb, line 49
def raw_params(auth)
  auth.sub(TOKEN_REGEX, '').split(/\s*#{AUTHN_PAIR_DELIMITERS}\s*/)
end
rewrite_param_values(array_params) click to toggle source
# File lib/api_signature/auth_header.rb, line 57
def rewrite_param_values(array_params)
  array_params.each { |param| (param[1] || +'').gsub!(/^"|"$/, '') }
end
token_params_from(auth) click to toggle source
# File lib/api_signature/auth_header.rb, line 45
def token_params_from(auth)
  rewrite_param_values params_array_from raw_params(auth)
end