Class: Hitch::OauthRequestParameters
- Inherits:
-
Object
- Object
- Hitch::OauthRequestParameters
- Defined in:
- app/models/hitch/oauth_request_parameters.rb
Defined Under Namespace
Classes: Invalid
Constant Summary collapse
- FORM_MEDIA_TYPE =
"application/x-www-form-urlencoded"
Instance Method Summary collapse
-
#initialize(request, allowed:, form_only: false) ⇒ OauthRequestParameters
constructor
A new instance of OauthRequestParameters.
- #to_h ⇒ Object
Constructor Details
#initialize(request, allowed:, form_only: false) ⇒ OauthRequestParameters
Returns a new instance of OauthRequestParameters.
11 12 13 14 15 |
# File 'app/models/hitch/oauth_request_parameters.rb', line 11 def initialize(request, allowed:, form_only: false) @request = request @allowed = allowed.map(&:to_s).freeze @form_only = form_only end |
Instance Method Details
#to_h ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/hitch/oauth_request_parameters.rb', line 17 def to_h query = query_pairs reject_query_security_parameters!(query) if form_only pairs = (form_only ? [] : query) + form_pairs reject_nested_security_parameters!(pairs) allowed.to_h do |name| values = pairs.filter_map { |key, value| value if key == name } raise Invalid, "#{name} must not be repeated" if values.length > 1 raise Invalid, "#{name} must be a string" if values.any? { |value| !value.is_a?(String) } raise Invalid, "#{name} must not be blank" if values.one? && values.first.blank? [ name.to_sym, values.first&.dup&.freeze ] end.freeze rescue ArgumentError raise Invalid, "OAuth parameters are not valid form encoding" end |