Module: SimpleOAuth::Header::Params

Included in:
SimpleOAuth::Header
Defined in:
lib/simple_oauth/header/params.rb,
sig/simple_oauth/header/params.rbs

Overview

Normalization of the parameters that are signed

Instance Method Summary collapse

Instance Method Details

#attributesHeader::signed_attributes_hash

Extracts valid OAuth attributes from options (excludes realm per RFC 5849)

Returns:

  • (Header::signed_attributes_hash)


17
18
19
20
# File 'lib/simple_oauth/header/params.rb', line 17

def attributes
  validate_option_keys!
  options.slice(*ATTRIBUTE_KEYS).transform_keys { |key| :"#{OAUTH_PREFIX}#{key}" }
end

#expanded_paramsArray[untyped]

Expands parameters into one pair per value, for parameters with several values

Returns:

  • (Array[untyped])


72
73
74
75
76
# File 'lib/simple_oauth/header/params.rb', line 72

def expanded_params
  params.flat_map do |key, value|
    value.is_a?(Array) ? value.map { |element| [key, element] } : [[key, value]]
  end
end

#normalized_paramsString

Normalizes and sorts all request parameters for signing

Returns:

  • (String)


52
53
54
55
56
57
58
# File 'lib/simple_oauth/header/params.rb', line 52

def normalized_params
  signature_params
    .map { |key, value| [Header.escape(key), Header.escape(value)] }
    .sort
    .map { |pair| pair.join("=") }
    .join("&")
end

#signature_paramsArray[untyped]

Collects all parameters to include in signature

Returns:

  • (Array[untyped])


64
65
66
# File 'lib/simple_oauth/header/params.rb', line 64

def signature_params
  attributes.to_a + expanded_params + url_params
end

#url_paramsArray[untyped]

Extracts query parameters from the request URL

Returns:

  • (Array[untyped])


44
45
46
# File 'lib/simple_oauth/header/params.rb', line 44

def url_params
  Header.form_pairs(@uri.query)
end

#validate_option_keys!void

This method returns an undefined value.

Validates that no unknown keys are present in options



27
28
29
30
31
32
33
34
# File 'lib/simple_oauth/header/params.rb', line 27

def validate_option_keys!
  return if options[:ignore_extra_keys]

  extra_keys = options.keys - ATTRIBUTE_KEYS - IGNORED_KEYS
  return if extra_keys.empty?

  raise InvalidOptionsError, "Unknown option keys: #{extra_keys.map(&:inspect).join(", ")}"
end