oauth 0.5.7.pre.pre1 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a88cb9c5d6705a3a9af88054d4b67bd2fdf2686057bedb2022d1998f4e94d12f
4
- data.tar.gz: d37b3d22e48c4258f1ce25f154a9c1a0ab4252fb7cb804e79808dd36c0ddcc5f
3
+ metadata.gz: 0c08e223971fca8aa5c3d76ed37e5576c61519b505498104d585436088ce6629
4
+ data.tar.gz: 0ccc2c1e6a5da2173358c5d9ffd7c69d7e54f91a3c67606d8ae523e7d81f36f3
5
5
  SHA512:
6
- metadata.gz: 9c074fe3a9f43349f37deddbd1405f2d6eb53585d5188c81db30699b4d05b5ab546263d8e8471cad6742a861dcf23b14a94d54f3cede5f8891eeedd3a0e4b21c
7
- data.tar.gz: 2ad01843b191714dcc05e9aaed252d5d1edc59e224c3d46e9e0b361c92403a97bf52288c4d84fd530e22b44a7d112aa36adb3f4d62fa3a4a1561681a5e353f93
6
+ metadata.gz: 69762d403a1e19c3f4f89278e46115b70e86661b8db64916b00cb8cb7297f7c25e2bf84031965856783874306f3b1b57642aa5145fbbf71dcde618ef6470dc16
7
+ data.tar.gz: 9c4cd4916e04a79f8e969089c817e2d2942705a13159124442587d96ea6e812c92fed6388adc723b12d0f638cad4f947a797b933992a87d14bf82e98cbd204ad
data/CHANGELOG.md CHANGED
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
32
32
  * Fixed Unsafe String Comparison (#156, #209 by @pboling and @drosseau)
33
33
  * Fixed typos in Gemspec (#204, #203, #208 by @pboling)
34
34
  * Copyright Notice in LICENSE - added correct years (#217, #218 by @pboling)
35
+ * Fixed request proxy Class constant reference scopes - was missing `::` in many places (#225, #226 by @pboling)
35
36
 
36
37
  ### Removed
37
38
 
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Ruby OAuth
2
2
 
3
+ **NOTE**
4
+
5
+ This README, on branch `v0.5-maintenance`, targets 0.5.x series releases. For later releases please see the `msater` branch README.
6
+
3
7
  ## Status
4
8
 
5
9
  | Project | Ruby Oauth |
@@ -41,7 +45,15 @@ Or install it yourself as:
41
45
 
42
46
  Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.6, 2.7, and
43
47
  3.0. Ruby is limited to 2.0+ in the gemspec, and this may change while the gem is
44
- still at version 0.x.
48
+ still at version 0.x. The `master` branch currently targets 0.6.x releases.
49
+
50
+ | Ruby OAuth Version | Maintenance Branch | Officially Supported Rubies | Unofficially Supported Rubies |
51
+ |--------------------- | ------------------ | ------------------------------------------- | ----------------------------- |
52
+ | 0.7.x (hypothetical) | N/A | 2.7, 3.0, 3.1 | 2.6 |
53
+ | 0.6.x | `master` | 2.6, 2.7, 3.0 | 2.3, 2.4, 2.5 |
54
+ | 0.5.x | `v0.5-maintenance` | 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0 | |
55
+
56
+ NOTE: 0.5.7 is anticipated as last release of the 0.5.x series.
45
57
 
46
58
  ## Basics
47
59
 
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support"
2
4
  require "active_support/version"
3
5
  require "action_controller"
4
6
  require "uri"
5
7
 
6
- if
7
- Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
8
- then # rails 2.x
8
+ if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
9
+ # rails 2.x
9
10
  require "action_controller/request"
10
11
  unless ActionController::Request::HTTP_METHODS.include?("patch")
11
12
  ActionController::Request::HTTP_METHODS << "patch"
@@ -13,9 +14,8 @@ then # rails 2.x
13
14
  ActionController::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
14
15
  end
15
16
 
16
- elsif
17
- Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
18
- then # rails 3.x
17
+ elsif Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
18
+ # rails 3.x
19
19
  require "action_dispatch/http/request"
20
20
  unless ActionDispatch::Request::HTTP_METHODS.include?("patch")
21
21
  ActionDispatch::Request::HTTP_METHODS << "patch"
@@ -27,64 +27,63 @@ else # rails 4.x and later - already has patch
27
27
  require "action_dispatch/http/request"
28
28
  end
29
29
 
30
- module OAuth::RequestProxy
31
- class ActionControllerRequest < OAuth::RequestProxy::Base
32
- proxies(defined?(ActionDispatch::AbstractRequest) ? ActionDispatch::AbstractRequest : ActionDispatch::Request)
30
+ module OAuth
31
+ module RequestProxy
32
+ class ActionControllerRequest < OAuth::RequestProxy::Base
33
+ proxies(defined?(::ActionDispatch::AbstractRequest) ? ::ActionDispatch::AbstractRequest : ::ActionDispatch::Request)
33
34
 
34
- def method
35
- request.method.to_s.upcase
36
- end
35
+ def method
36
+ request.method.to_s.upcase
37
+ end
37
38
 
38
- def uri
39
- request.url
40
- end
39
+ def uri
40
+ request.url
41
+ end
41
42
 
42
- def parameters
43
- if options[:clobber_request]
44
- options[:parameters] || {}
45
- else
46
- params = request_params.merge(query_params).merge(header_params)
47
- params.stringify_keys! if params.respond_to?(:stringify_keys!)
48
- params.merge(options[:parameters] || {})
43
+ def parameters
44
+ if options[:clobber_request]
45
+ options[:parameters] || {}
46
+ else
47
+ params = request_params.merge(query_params).merge(header_params)
48
+ params.stringify_keys! if params.respond_to?(:stringify_keys!)
49
+ params.merge(options[:parameters] || {})
50
+ end
49
51
  end
50
- end
51
52
 
52
- # Override from OAuth::RequestProxy::Base to avoid roundtrip
53
- # conversion to Hash or Array and thus preserve the original
54
- # parameter names
55
- def parameters_for_signature
56
- params = []
57
- params << options[:parameters].to_query if options[:parameters]
53
+ # Override from OAuth::RequestProxy::Base to avoid roundtrip
54
+ # conversion to Hash or Array and thus preserve the original
55
+ # parameter names
56
+ def parameters_for_signature
57
+ params = []
58
+ params << options[:parameters].to_query if options[:parameters]
58
59
 
59
- unless options[:clobber_request]
60
- params << header_params.to_query
61
- params << request.query_string unless query_string_blank?
60
+ unless options[:clobber_request]
61
+ params << header_params.to_query
62
+ params << request.query_string unless query_string_blank?
62
63
 
63
- if raw_post_signature?
64
- params << request.raw_post
64
+ params << request.raw_post if raw_post_signature?
65
65
  end
66
- end
67
66
 
68
- params.
69
- join("&").split("&").
70
- reject { |s| s.match(/\A\s*\z/) }.
71
- map { |p| p.split("=").map{|esc| CGI.unescape(esc)} }.
72
- reject { |kv| kv[0] == "oauth_signature"}
73
- end
67
+ params.
68
+ join("&").split("&").
69
+ reject { |s| s.match(/\A\s*\z/) }.
70
+ map { |p| p.split("=").map { |esc| CGI.unescape(esc) } }.
71
+ reject { |kv| kv[0] == "oauth_signature" }
72
+ end
74
73
 
75
- def raw_post_signature?
76
- (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
77
- end
74
+ def raw_post_signature?
75
+ (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
76
+ end
78
77
 
79
- protected
78
+ protected
80
79
 
81
- def query_params
82
- request.query_parameters
83
- end
80
+ def query_params
81
+ request.query_parameters
82
+ end
84
83
 
85
- def request_params
86
- request.request_parameters
84
+ def request_params
85
+ request.request_parameters
86
+ end
87
87
  end
88
-
89
88
  end
90
89
  end
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/request_proxy/rack_request"
2
4
 
3
- module OAuth::RequestProxy
4
- class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
5
- proxies ActionDispatch::Request
5
+ module OAuth
6
+ module RequestProxy
7
+ class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
8
+ proxies ::ActionDispatch::Request
9
+ end
6
10
  end
7
11
  end
@@ -1,178 +1,182 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/request_proxy"
2
4
  require "oauth/helper"
3
5
 
4
- module OAuth::RequestProxy
5
- class Base
6
- include OAuth::Helper
6
+ module OAuth
7
+ module RequestProxy
8
+ class Base
9
+ include OAuth::Helper
7
10
 
8
- def self.proxies(klass)
9
- OAuth::RequestProxy.available_proxies[klass] = self
10
- end
11
+ def self.proxies(klass)
12
+ OAuth::RequestProxy.available_proxies[klass] = self
13
+ end
11
14
 
12
- attr_accessor :request, :options, :unsigned_parameters
15
+ attr_accessor :request, :options, :unsigned_parameters
13
16
 
14
- def initialize(request, options = {})
15
- @request = request
16
- @unsigned_parameters = (options[:unsigned_parameters] || []).map {|param| param.to_s}
17
- @options = options
18
- end
17
+ def initialize(request, options = {})
18
+ @request = request
19
+ @unsigned_parameters = (options[:unsigned_parameters] || []).map(&:to_s)
20
+ @options = options
21
+ end
19
22
 
20
- ## OAuth parameters
23
+ ## OAuth parameters
21
24
 
22
- def oauth_callback
23
- parameters["oauth_callback"]
24
- end
25
+ def oauth_callback
26
+ parameters["oauth_callback"]
27
+ end
25
28
 
26
- def oauth_consumer_key
27
- parameters["oauth_consumer_key"]
28
- end
29
+ def oauth_consumer_key
30
+ parameters["oauth_consumer_key"]
31
+ end
29
32
 
30
- def oauth_nonce
31
- parameters["oauth_nonce"]
32
- end
33
+ def oauth_nonce
34
+ parameters["oauth_nonce"]
35
+ end
33
36
 
34
- def oauth_signature
35
- # TODO can this be nil?
36
- [parameters["oauth_signature"]].flatten.first || ""
37
- end
37
+ def oauth_signature
38
+ # TODO: can this be nil?
39
+ [parameters["oauth_signature"]].flatten.first || ""
40
+ end
38
41
 
39
- def oauth_signature_method
40
- case parameters["oauth_signature_method"]
41
- when Array
42
- parameters["oauth_signature_method"].first
43
- else
44
- parameters["oauth_signature_method"]
42
+ def oauth_signature_method
43
+ case parameters["oauth_signature_method"]
44
+ when Array
45
+ parameters["oauth_signature_method"].first
46
+ else
47
+ parameters["oauth_signature_method"]
48
+ end
45
49
  end
46
- end
47
50
 
48
- def oauth_timestamp
49
- parameters["oauth_timestamp"]
50
- end
51
+ def oauth_timestamp
52
+ parameters["oauth_timestamp"]
53
+ end
51
54
 
52
- def oauth_token
53
- parameters["oauth_token"]
54
- end
55
+ def oauth_token
56
+ parameters["oauth_token"]
57
+ end
55
58
 
56
- def oauth_verifier
57
- parameters["oauth_verifier"]
58
- end
59
+ def oauth_verifier
60
+ parameters["oauth_verifier"]
61
+ end
59
62
 
60
- def oauth_version
61
- parameters["oauth_version"]
62
- end
63
+ def oauth_version
64
+ parameters["oauth_version"]
65
+ end
63
66
 
64
- # TODO deprecate these
65
- alias_method :consumer_key, :oauth_consumer_key
66
- alias_method :token, :oauth_token
67
- alias_method :nonce, :oauth_nonce
68
- alias_method :timestamp, :oauth_timestamp
69
- alias_method :signature, :oauth_signature
70
- alias_method :signature_method, :oauth_signature_method
67
+ # TODO: deprecate these
68
+ alias consumer_key oauth_consumer_key
69
+ alias token oauth_token
70
+ alias nonce oauth_nonce
71
+ alias timestamp oauth_timestamp
72
+ alias signature oauth_signature
73
+ alias signature_method oauth_signature_method
71
74
 
72
- ## Parameter accessors
75
+ ## Parameter accessors
73
76
 
74
- def parameters
75
- raise NotImplementedError, "Must be implemented by subclasses"
76
- end
77
+ def parameters
78
+ raise NotImplementedError, "Must be implemented by subclasses"
79
+ end
77
80
 
78
- def parameters_for_signature
79
- parameters.select { |k,v| not signature_and_unsigned_parameters.include?(k) }
80
- end
81
+ def parameters_for_signature
82
+ parameters.select { |k, _v| !signature_and_unsigned_parameters.include?(k) }
83
+ end
81
84
 
82
- def oauth_parameters
83
- parameters.select { |k,v| OAuth::PARAMETERS.include?(k) }.reject { |k,v| v == "" }
84
- end
85
+ def oauth_parameters
86
+ parameters.select { |k, _v| OAuth::PARAMETERS.include?(k) }.select { |_k, v| v != "" }
87
+ end
85
88
 
86
- def non_oauth_parameters
87
- parameters.reject { |k,v| OAuth::PARAMETERS.include?(k) }
88
- end
89
+ def non_oauth_parameters
90
+ parameters.select { |k, _v| !OAuth::PARAMETERS.include?(k) }
91
+ end
89
92
 
90
- def signature_and_unsigned_parameters
91
- unsigned_parameters+["oauth_signature"]
92
- end
93
+ def signature_and_unsigned_parameters
94
+ unsigned_parameters + ["oauth_signature"]
95
+ end
93
96
 
94
- # See 9.1.2 in specs
95
- def normalized_uri
96
- u = URI.parse(uri)
97
- "#{u.scheme.downcase}://#{u.host.downcase}#{(u.scheme.downcase == 'http' && u.port != 80) || (u.scheme.downcase == 'https' && u.port != 443) ? ":#{u.port}" : ""}#{(u.path && u.path != '') ? u.path : '/'}"
98
- end
97
+ # See 9.1.2 in specs
98
+ def normalized_uri
99
+ u = URI.parse(uri)
100
+ "#{u.scheme.downcase}://#{u.host.downcase}#{(u.scheme.casecmp("http").zero? && u.port != 80) || (u.scheme.casecmp("https").zero? && u.port != 443) ? ":#{u.port}" : ""}#{u.path && u.path != "" ? u.path : "/"}"
101
+ end
99
102
 
100
- # See 9.1.1. in specs Normalize Request Parameters
101
- def normalized_parameters
102
- normalize(parameters_for_signature)
103
- end
103
+ # See 9.1.1. in specs Normalize Request Parameters
104
+ def normalized_parameters
105
+ normalize(parameters_for_signature)
106
+ end
104
107
 
105
- def sign(options = {})
106
- OAuth::Signature.sign(self, options)
107
- end
108
+ def sign(options = {})
109
+ OAuth::Signature.sign(self, options)
110
+ end
108
111
 
109
- def sign!(options = {})
110
- parameters["oauth_signature"] = sign(options)
111
- @signed = true
112
- signature
113
- end
112
+ def sign!(options = {})
113
+ parameters["oauth_signature"] = sign(options)
114
+ @signed = true
115
+ signature
116
+ end
114
117
 
115
- # See 9.1 in specs
116
- def signature_base_string
117
- base = [method, normalized_uri, normalized_parameters]
118
- base.map { |v| escape(v) }.join("&")
119
- end
118
+ # See 9.1 in specs
119
+ def signature_base_string
120
+ base = [method, normalized_uri, normalized_parameters]
121
+ base.map { |v| escape(v) }.join("&")
122
+ end
120
123
 
121
- # Has this request been signed yet?
122
- def signed?
123
- @signed
124
- end
124
+ # Has this request been signed yet?
125
+ def signed?
126
+ @signed
127
+ end
128
+
129
+ # URI, including OAuth parameters
130
+ def signed_uri(with_oauth = true)
131
+ if signed?
132
+ params = if with_oauth
133
+ parameters
134
+ else
135
+ non_oauth_parameters
136
+ end
125
137
 
126
- # URI, including OAuth parameters
127
- def signed_uri(with_oauth = true)
128
- if signed?
129
- if with_oauth
130
- params = parameters
138
+ [uri, normalize(params)].join("?")
131
139
  else
132
- params = non_oauth_parameters
140
+ warn "This request has not yet been signed!"
133
141
  end
134
-
135
- [uri, normalize(params)] * "?"
136
- else
137
- STDERR.puts "This request has not yet been signed!"
138
142
  end
139
- end
140
143
 
141
- # Authorization header for OAuth
142
- def oauth_header(options = {})
143
- header_params_str = oauth_parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(", ")
144
+ # Authorization header for OAuth
145
+ def oauth_header(options = {})
146
+ header_params_str = oauth_parameters.map { |k, v| "#{k}=\"#{escape(v)}\"" }.join(", ")
144
147
 
145
- realm = "realm=\"#{options[:realm]}\", " if options[:realm]
146
- "OAuth #{realm}#{header_params_str}"
147
- end
148
+ realm = "realm=\"#{options[:realm]}\", " if options[:realm]
149
+ "OAuth #{realm}#{header_params_str}"
150
+ end
148
151
 
149
- def query_string_blank?
150
- if uri = request.env["REQUEST_URI"]
151
- uri.split("?", 2)[1].nil?
152
- else
153
- request.query_string.match(/\A\s*\z/)
152
+ def query_string_blank?
153
+ if (uri = request.env["REQUEST_URI"])
154
+ uri.split("?", 2)[1].nil?
155
+ else
156
+ request.query_string.match(/\A\s*\z/)
157
+ end
154
158
  end
155
- end
156
159
 
157
- protected
160
+ protected
158
161
 
159
- def header_params
160
- %w( X-HTTP_AUTHORIZATION Authorization HTTP_AUTHORIZATION ).each do |header|
161
- next unless request.env.include?(header)
162
+ def header_params
163
+ %w[X-HTTP_AUTHORIZATION Authorization HTTP_AUTHORIZATION].each do |header|
164
+ next unless request.env.include?(header)
162
165
 
163
- header = request.env[header]
164
- next unless header[0,6] == "OAuth "
166
+ header = request.env[header]
167
+ next unless header[0, 6] == "OAuth "
165
168
 
166
- # parse the header into a Hash
167
- oauth_params = OAuth::Helper.parse_header(header)
169
+ # parse the header into a Hash
170
+ oauth_params = OAuth::Helper.parse_header(header)
168
171
 
169
- # remove non-OAuth parameters
170
- oauth_params.reject! { |k,v| k !~ /^oauth_/ }
172
+ # remove non-OAuth parameters
173
+ oauth_params.select! { |k, _v| k =~ /^oauth_/ }
171
174
 
172
- return oauth_params
173
- end
175
+ return oauth_params
176
+ end
174
177
 
175
- return {}
178
+ {}
179
+ end
176
180
  end
177
181
  end
178
182
  end
@@ -1,55 +1,61 @@
1
- require "oauth/request_proxy/base"
1
+ # frozen_string_literal: true
2
+
3
+ require "oauth/request_proxy/base"
2
4
  require "curb"
3
5
  require "uri"
4
6
  require "cgi"
5
7
 
6
- module OAuth::RequestProxy::Curl
7
- class Easy < OAuth::RequestProxy::Base
8
- # Proxy for signing Curl::Easy requests
9
- # Usage example:
10
- # oauth_params = {:consumer => oauth_consumer, :token => access_token}
11
- # req = Curl::Easy.new(uri)
12
- # oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
13
- # req.headers.merge!({"Authorization" => oauth_helper.header})
14
- # req.http_get
15
- # response = req.body_str
16
- proxies ::Curl::Easy
17
-
18
- def method
19
- nil
20
- end
8
+ module OAuth
9
+ module RequestProxy
10
+ module Curl
11
+ class Easy < OAuth::RequestProxy::Base
12
+ # Proxy for signing Curl::Easy requests
13
+ # Usage example:
14
+ # oauth_params = {:consumer => oauth_consumer, :token => access_token}
15
+ # req = Curl::Easy.new(uri)
16
+ # oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
17
+ # req.headers.merge!({"Authorization" => oauth_helper.header})
18
+ # req.http_get
19
+ # response = req.body_str
20
+ proxies ::Curl::Easy
21
+
22
+ def method
23
+ nil
24
+ end
21
25
 
22
- def uri
23
- options[:uri].to_s
24
- end
26
+ def uri
27
+ options[:uri].to_s
28
+ end
25
29
 
26
- def parameters
27
- if options[:clobber_request]
28
- options[:parameters]
29
- else
30
- post_parameters.merge(query_parameters).merge(options[:parameters] || {})
31
- end
32
- end
30
+ def parameters
31
+ if options[:clobber_request]
32
+ options[:parameters]
33
+ else
34
+ post_parameters.merge(query_parameters).merge(options[:parameters] || {})
35
+ end
36
+ end
33
37
 
34
- private
38
+ private
35
39
 
36
- def query_parameters
37
- query = URI.parse(request.url).query
38
- return(query ? CGI.parse(query) : {})
39
- end
40
+ def query_parameters
41
+ query = URI.parse(request.url).query
42
+ (query ? CGI.parse(query) : {})
43
+ end
40
44
 
41
- def post_parameters
42
- post_body = {}
45
+ def post_parameters
46
+ post_body = {}
43
47
 
44
- # Post params are only used if posting form data
45
- if (request.headers["Content-Type"] && request.headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded"))
48
+ # Post params are only used if posting form data
49
+ if request.headers["Content-Type"] && request.headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")
46
50
 
47
- request.post_body.split("&").each do |str|
48
- param = str.split("=")
49
- post_body[param[0]] = param[1]
51
+ request.post_body.split("&").each do |str|
52
+ param = str.split("=")
53
+ post_body[param[0]] = param[1]
54
+ end
55
+ end
56
+ post_body
50
57
  end
51
58
  end
52
- post_body
53
59
  end
54
60
  end
55
61
  end
@@ -1,72 +1,76 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/request_proxy/base"
2
4
  # em-http also uses adddressable so there is no need to require uri.
3
5
  require "em-http"
4
6
  require "cgi"
5
7
 
6
- module OAuth::RequestProxy::EventMachine
7
- class HttpRequest < OAuth::RequestProxy::Base
8
-
9
- # A Proxy for use when you need to sign EventMachine::HttpClient instances.
10
- # It needs to be called once the client is construct but before data is sent.
11
- # Also see oauth/client/em-http
12
- proxies ::EventMachine::HttpClient
13
-
14
- # Request in this con
8
+ module OAuth
9
+ module RequestProxy
10
+ module EventMachine
11
+ class HttpRequest < OAuth::RequestProxy::Base
12
+ # A Proxy for use when you need to sign EventMachine::HttpClient instances.
13
+ # It needs to be called once the client is construct but before data is sent.
14
+ # Also see oauth/client/em-http
15
+ proxies ::EventMachine::HttpClient
15
16
 
16
- def method
17
- request.req[:method]
18
- end
17
+ # Request in this con
19
18
 
20
- def uri
21
- request.conn.normalize.to_s
22
- end
19
+ def method
20
+ request.req[:method]
21
+ end
23
22
 
24
- def parameters
25
- if options[:clobber_request]
26
- options[:parameters]
27
- else
28
- all_parameters
29
- end
30
- end
23
+ def uri
24
+ request.conn.normalize.to_s
25
+ end
31
26
 
32
- protected
27
+ def parameters
28
+ if options[:clobber_request]
29
+ options[:parameters]
30
+ else
31
+ all_parameters
32
+ end
33
+ end
33
34
 
34
- def all_parameters
35
- merged_parameters({}, post_parameters, query_parameters, options[:parameters])
36
- end
35
+ protected
37
36
 
38
- def query_parameters
39
- quer = request.req[:query]
40
- hash_quer = if quer.respond_to?(:merge)
41
- quer
42
- else
43
- CGI.parse(quer.to_s)
44
- end
45
- CGI.parse(request.conn.query.to_s).merge(hash_quer)
46
- end
37
+ def all_parameters
38
+ merged_parameters({}, post_parameters, query_parameters, options[:parameters])
39
+ end
47
40
 
48
- def post_parameters
49
- headers = request.req[:head] || {}
50
- form_encoded = headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")
51
- if ["POST", "PUT"].include?(method) && form_encoded
52
- CGI.parse(request.normalize_body(request.req[:body]).to_s)
53
- else
54
- {}
55
- end
56
- end
41
+ def query_parameters
42
+ quer = request.req[:query]
43
+ hash_quer = if quer.respond_to?(:merge)
44
+ quer
45
+ else
46
+ CGI.parse(quer.to_s)
47
+ end
48
+ CGI.parse(request.conn.query.to_s).merge(hash_quer)
49
+ end
57
50
 
58
- def merged_parameters(params, *extra_params)
59
- extra_params.compact.each do |params_pairs|
60
- params_pairs.each_pair do |key, value|
61
- if params.has_key?(key)
62
- params[key.to_s] += value
51
+ def post_parameters
52
+ headers = request.req[:head] || {}
53
+ form_encoded = headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")
54
+ if %w[POST PUT].include?(method) && form_encoded
55
+ CGI.parse(request.normalize_body(request.req[:body]).to_s)
63
56
  else
64
- params[key.to_s] = [value].flatten
57
+ {}
65
58
  end
66
59
  end
60
+
61
+ def merged_parameters(params, *extra_params)
62
+ extra_params.compact.each do |params_pairs|
63
+ params_pairs.each_pair do |key, value|
64
+ if params.key?(key)
65
+ params[key.to_s] += value
66
+ else
67
+ params[key.to_s] = [value].flatten
68
+ end
69
+ end
70
+ end
71
+ params
72
+ end
67
73
  end
68
- params
69
74
  end
70
-
71
75
  end
72
76
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "xmpp4r"
2
4
  require "oauth/request_proxy/base"
3
5
 
4
6
  module OAuth
5
7
  module RequestProxy
6
8
  class JabberRequest < OAuth::RequestProxy::Base
7
- proxies Jabber::Iq
8
- proxies Jabber::Presence
9
- proxies Jabber::Message
9
+ proxies ::Jabber::Iq
10
+ proxies ::Jabber::Presence
11
+ proxies ::Jabber::Message
10
12
 
11
13
  def parameters
12
14
  return @params if @params
@@ -16,9 +18,10 @@ module OAuth
16
18
  oauth = @request.get_elements("//oauth").first
17
19
  return @params unless oauth
18
20
 
19
- %w( oauth_token oauth_consumer_key oauth_signature_method oauth_signature
20
- oauth_timestamp oauth_nonce oauth_version ).each do |param|
21
- next unless element = oauth.first_element(param)
21
+ %w[ oauth_token oauth_consumer_key oauth_signature_method oauth_signature
22
+ oauth_timestamp oauth_nonce oauth_version ].each do |param|
23
+ next unless (element = oauth.first_element(param))
24
+
22
25
  @params[param] = element.text
23
26
  end
24
27
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/request_proxy/base"
2
4
 
3
5
  module OAuth
@@ -18,7 +20,7 @@ module OAuth
18
20
  # :consumer_secret => oauth_consumer_secret,
19
21
  # :token_secret => oauth_token_secret,
20
22
  class MockRequest < OAuth::RequestProxy::Base
21
- proxies Hash
23
+ proxies ::Hash
22
24
 
23
25
  def parameters
24
26
  @request["parameters"]
@@ -1,72 +1,81 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/request_proxy/base"
2
4
  require "net/http"
3
5
  require "uri"
4
6
  require "cgi"
5
7
 
6
- module OAuth::RequestProxy::Net
7
- module HTTP
8
- class HTTPRequest < OAuth::RequestProxy::Base
9
- proxies ::Net::HTTPGenericRequest
8
+ module OAuth
9
+ module RequestProxy
10
+ module Net
11
+ module HTTP
12
+ class HTTPRequest < OAuth::RequestProxy::Base
13
+ proxies ::Net::HTTPGenericRequest
10
14
 
11
- def method
12
- request.method
13
- end
15
+ def method
16
+ request.method
17
+ end
14
18
 
15
- def uri
16
- options[:uri].to_s
17
- end
19
+ def uri
20
+ options[:uri].to_s
21
+ end
18
22
 
19
- def parameters
20
- if options[:clobber_request]
21
- options[:parameters]
22
- else
23
- all_parameters
24
- end
25
- end
23
+ def parameters
24
+ if options[:clobber_request]
25
+ options[:parameters]
26
+ else
27
+ all_parameters
28
+ end
29
+ end
26
30
 
27
- def body
28
- request.body
29
- end
31
+ def body
32
+ request.body
33
+ end
30
34
 
31
- private
35
+ private
32
36
 
33
- def all_parameters
34
- request_params = CGI.parse(query_string)
35
- # request_params.each{|k,v| request_params[k] = [nil] if v == []}
37
+ def all_parameters
38
+ request_params = CGI.parse(query_string)
39
+ # request_params.each{|k,v| request_params[k] = [nil] if v == []}
36
40
 
37
- if options[:parameters]
38
- options[:parameters].each do |k,v|
39
- if request_params.has_key?(k) && v
40
- request_params[k] << v
41
- else
42
- request_params[k] = [v]
41
+ if options[:parameters]
42
+ options[:parameters].each do |k,v|
43
+ if request_params.has_key?(k) && v
44
+ request_params[k] << v
45
+ else
46
+ request_params[k] = [v]
47
+ end
48
+ end
43
49
  end
50
+ request_params
44
51
  end
45
- end
46
- request_params
47
- end
48
52
 
49
- def query_string
50
- params = [ query_params, auth_header_params ]
51
- params << post_params if (method.to_s.upcase == "POST" || method.to_s.upcase == "PUT") && form_url_encoded?
52
- params.compact.join("&")
53
- end
53
+ def query_string
54
+ params = [query_params, auth_header_params]
55
+ if (method.to_s.casecmp("POST").zero? || method.to_s.casecmp("PUT").zero?) && form_url_encoded?
56
+ params << post_params
57
+ end
58
+ params.compact.join("&")
59
+ end
54
60
 
55
- def form_url_encoded?
56
- request["Content-Type"] != nil && request["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")
57
- end
61
+ def form_url_encoded?
62
+ !request["Content-Type"].nil? && request["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")
63
+ end
58
64
 
59
- def query_params
60
- URI.parse(request.path).query
61
- end
65
+ def query_params
66
+ URI.parse(request.path).query
67
+ end
62
68
 
63
- def post_params
64
- request.body
65
- end
69
+ def post_params
70
+ request.body
71
+ end
66
72
 
67
- def auth_header_params
68
- return nil unless request["Authorization"] && request["Authorization"][0,5] == "OAuth"
69
- request["Authorization"]
73
+ def auth_header_params
74
+ return nil unless request["Authorization"] && request["Authorization"][0, 5] == "OAuth"
75
+
76
+ request["Authorization"]
77
+ end
78
+ end
70
79
  end
71
80
  end
72
81
  end
@@ -1,43 +1,47 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/request_proxy/base"
2
4
  require "uri"
3
5
  require "rack"
4
6
 
5
- module OAuth::RequestProxy
6
- class RackRequest < OAuth::RequestProxy::Base
7
- proxies Rack::Request
7
+ module OAuth
8
+ module RequestProxy
9
+ class RackRequest < OAuth::RequestProxy::Base
10
+ proxies ::Rack::Request
8
11
 
9
- def method
10
- request.env["rack.methodoverride.original_method"] || request.request_method
11
- end
12
+ def method
13
+ request.env["rack.methodoverride.original_method"] || request.request_method
14
+ end
12
15
 
13
- def uri
14
- request.url
15
- end
16
+ def uri
17
+ request.url
18
+ end
16
19
 
17
- def parameters
18
- if options[:clobber_request]
19
- options[:parameters] || {}
20
- else
21
- params = request_params.merge(query_params).merge(header_params)
22
- params.merge(options[:parameters] || {})
20
+ def parameters
21
+ if options[:clobber_request]
22
+ options[:parameters] || {}
23
+ else
24
+ params = request_params.merge(query_params).merge(header_params)
25
+ params.merge(options[:parameters] || {})
26
+ end
23
27
  end
24
- end
25
28
 
26
- def signature
27
- parameters["oauth_signature"]
28
- end
29
+ def signature
30
+ parameters["oauth_signature"]
31
+ end
29
32
 
30
- protected
33
+ protected
31
34
 
32
- def query_params
33
- request.GET
34
- end
35
+ def query_params
36
+ request.GET
37
+ end
35
38
 
36
- def request_params
37
- if request.content_type and request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
38
- request.POST
39
- else
40
- {}
39
+ def request_params
40
+ if request.content_type && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
41
+ request.POST
42
+ else
43
+ {}
44
+ end
41
45
  end
42
46
  end
43
47
  end
@@ -1,62 +1,65 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/request_proxy/base"
2
4
  require "rest-client"
3
5
  require "uri"
4
6
  require "cgi"
5
7
 
6
- module OAuth::RequestProxy::RestClient
7
- class Request < OAuth::RequestProxy::Base
8
- proxies RestClient::Request
9
-
10
- def method
11
- request.method.to_s.upcase
12
- end
8
+ module OAuth
9
+ module RequestProxy
10
+ module RestClient
11
+ class Request < OAuth::RequestProxy::Base
12
+ proxies ::RestClient::Request
13
13
 
14
- def uri
15
- request.url
16
- end
14
+ def method
15
+ request.method.to_s.upcase
16
+ end
17
17
 
18
- def parameters
19
- if options[:clobber_request]
20
- options[:parameters] || {}
21
- else
22
- post_parameters.merge(query_params).merge(options[:parameters] || {})
18
+ def uri
19
+ request.url
23
20
  end
24
- end
25
21
 
26
- protected
22
+ def parameters
23
+ if options[:clobber_request]
24
+ options[:parameters] || {}
25
+ else
26
+ post_parameters.merge(query_params).merge(options[:parameters] || {})
27
+ end
28
+ end
27
29
 
28
- def query_params
29
- query = URI.parse(request.url).query
30
- query ? CGI.parse(query) : {}
31
- end
30
+ protected
32
31
 
33
- def request_params
34
- end
35
-
36
- def post_parameters
37
- # Post params are only used if posting form data
38
- if method == "POST" || method == "PUT"
39
- OAuth::Helper.stringify_keys(query_string_to_hash(request.payload.to_s) || {})
40
- else
41
- {}
32
+ def query_params
33
+ query = URI.parse(request.url).query
34
+ query ? CGI.parse(query) : {}
42
35
  end
43
- end
44
-
45
- private
46
-
47
- def query_string_to_hash(query)
48
- keyvals = query.split("&").inject({}) do |result, q|
49
- k,v = q.split("=")
50
- if !v.nil?
51
- result.merge({k => v})
52
- elsif !result.key?(k)
53
- result.merge({k => true})
36
+
37
+ def request_params; end
38
+
39
+ def post_parameters
40
+ # Post params are only used if posting form data
41
+ if method == "POST" || method == "PUT"
42
+ OAuth::Helper.stringify_keys(query_string_to_hash(request.payload.to_s) || {})
54
43
  else
55
- result
44
+ {}
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def query_string_to_hash(query)
51
+ query.split("&").inject({}) do |result, q|
52
+ k, v = q.split("=")
53
+ if !v.nil?
54
+ result.merge({ k => v })
55
+ elsif !result.key?(k)
56
+ result.merge({ k => true })
57
+ else
58
+ result
59
+ end
56
60
  end
57
61
  end
58
- keyvals
59
62
  end
60
-
63
+ end
61
64
  end
62
- end
65
+ end
@@ -1,53 +1,59 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/request_proxy/base"
2
4
  require "typhoeus"
3
5
  require "typhoeus/request"
4
6
  require "uri"
5
7
  require "cgi"
6
8
 
7
- module OAuth::RequestProxy::Typhoeus
8
- class Request < OAuth::RequestProxy::Base
9
- # Proxy for signing Typhoeus::Request requests
10
- # Usage example:
11
- # oauth_params = {:consumer => oauth_consumer, :token => access_token}
12
- # req = Typhoeus::Request.new(uri, options)
13
- # oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
14
- # req.options[:headers].merge!({"Authorization" => oauth_helper.header})
15
- # hydra = Typhoeus::Hydra.new()
16
- # hydra.queue(req)
17
- # hydra.run
18
- # response = req.response
19
- proxies Typhoeus::Request
20
-
21
- def method
22
- request_method = request.options[:method].to_s.upcase
23
- request_method.empty? ? "GET" : request_method
24
- end
9
+ module OAuth
10
+ module RequestProxy
11
+ module Typhoeus
12
+ class Request < OAuth::RequestProxy::Base
13
+ # Proxy for signing Typhoeus::Request requests
14
+ # Usage example:
15
+ # oauth_params = {:consumer => oauth_consumer, :token => access_token}
16
+ # req = Typhoeus::Request.new(uri, options)
17
+ # oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
18
+ # req.options[:headers].merge!({"Authorization" => oauth_helper.header})
19
+ # hydra = Typhoeus::Hydra.new()
20
+ # hydra.queue(req)
21
+ # hydra.run
22
+ # response = req.response
23
+ proxies ::Typhoeus::Request
25
24
 
26
- def uri
27
- options[:uri].to_s
28
- end
25
+ def method
26
+ request_method = request.options[:method].to_s.upcase
27
+ request_method.empty? ? "GET" : request_method
28
+ end
29
29
 
30
- def parameters
31
- if options[:clobber_request]
32
- options[:parameters]
33
- else
34
- post_parameters.merge(query_parameters).merge(options[:parameters] || {})
35
- end
36
- end
30
+ def uri
31
+ options[:uri].to_s
32
+ end
37
33
 
38
- private
34
+ def parameters
35
+ if options[:clobber_request]
36
+ options[:parameters]
37
+ else
38
+ post_parameters.merge(query_parameters).merge(options[:parameters] || {})
39
+ end
40
+ end
39
41
 
40
- def query_parameters
41
- query = URI.parse(request.url).query
42
- query ? CGI.parse(query) : {}
43
- end
42
+ private
43
+
44
+ def query_parameters
45
+ query = URI.parse(request.url).query
46
+ query ? CGI.parse(query) : {}
47
+ end
44
48
 
45
- def post_parameters
46
- # Post params are only used if posting form data
47
- if method == "POST"
48
- OAuth::Helper.stringify_keys(request.options[:params] || {})
49
- else
50
- {}
49
+ def post_parameters
50
+ # Post params are only used if posting form data
51
+ if method == "POST"
52
+ OAuth::Helper.stringify_keys(request.options[:params] || {})
53
+ else
54
+ {}
55
+ end
56
+ end
51
57
  end
52
58
  end
53
59
  end
data/lib/oauth/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OAuth
2
- VERSION = "0.5.7-pre1"
2
+ VERSION = "0.5.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7.pre.pre1
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pelle Braendgaard
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2021-11-01 00:00:00.000000000 Z
19
+ date: 2021-11-02 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: actionpack
@@ -421,9 +421,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
421
421
  version: '2.0'
422
422
  required_rubygems_version: !ruby/object:Gem::Requirement
423
423
  requirements:
424
- - - ">"
424
+ - - ">="
425
425
  - !ruby/object:Gem::Version
426
- version: 1.3.1
426
+ version: '0'
427
427
  requirements: []
428
428
  rubygems_version: 3.0.3.1
429
429
  signing_key: