oauth 0.5.3 → 0.5.7.pre.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +454 -0
  3. data/CODE_OF_CONDUCT.md +84 -0
  4. data/LICENSE +18 -17
  5. data/README.md +211 -0
  6. data/TODO +0 -0
  7. data/bin/oauth +2 -2
  8. data/lib/oauth/cli/authorize_command.rb +0 -0
  9. data/lib/oauth/cli/base_command.rb +2 -2
  10. data/lib/oauth/cli/help_command.rb +0 -0
  11. data/lib/oauth/cli/query_command.rb +0 -0
  12. data/lib/oauth/cli/sign_command.rb +0 -0
  13. data/lib/oauth/cli/version_command.rb +0 -0
  14. data/lib/oauth/cli.rb +18 -18
  15. data/lib/oauth/client/action_controller_request.rb +7 -6
  16. data/lib/oauth/client/em_http.rb +99 -99
  17. data/lib/oauth/client/helper.rb +29 -23
  18. data/lib/oauth/client/net_http.rb +5 -5
  19. data/lib/oauth/client.rb +0 -0
  20. data/lib/oauth/consumer.rb +88 -44
  21. data/lib/oauth/errors/error.rb +0 -0
  22. data/lib/oauth/errors/problem.rb +0 -0
  23. data/lib/oauth/errors/unauthorized.rb +3 -1
  24. data/lib/oauth/errors.rb +3 -3
  25. data/lib/oauth/helper.rb +12 -8
  26. data/lib/oauth/oauth.rb +0 -0
  27. data/lib/oauth/oauth_test_helper.rb +4 -4
  28. data/lib/oauth/request_proxy/action_controller_request.rb +15 -11
  29. data/lib/oauth/request_proxy/action_dispatch_request.rb +7 -0
  30. data/lib/oauth/request_proxy/base.rb +16 -16
  31. data/lib/oauth/request_proxy/curb_request.rb +5 -5
  32. data/lib/oauth/request_proxy/em_http_request.rb +18 -12
  33. data/lib/oauth/request_proxy/jabber_request.rb +3 -3
  34. data/lib/oauth/request_proxy/mock_request.rb +1 -1
  35. data/lib/oauth/request_proxy/net_http.rb +9 -9
  36. data/lib/oauth/request_proxy/rack_request.rb +4 -4
  37. data/lib/oauth/request_proxy/rest_client_request.rb +7 -7
  38. data/lib/oauth/request_proxy/typhoeus_request.rb +7 -7
  39. data/lib/oauth/request_proxy.rb +0 -0
  40. data/lib/oauth/server.rb +2 -2
  41. data/lib/oauth/signature/base.rb +8 -6
  42. data/lib/oauth/signature/hmac/sha1.rb +4 -4
  43. data/lib/oauth/signature/hmac/sha256.rb +17 -0
  44. data/lib/oauth/signature/plaintext.rb +2 -2
  45. data/lib/oauth/signature/rsa/sha1.rb +3 -3
  46. data/lib/oauth/signature.rb +0 -0
  47. data/lib/oauth/token.rb +5 -5
  48. data/lib/oauth/tokens/access_token.rb +3 -3
  49. data/lib/oauth/tokens/consumer_token.rb +0 -0
  50. data/lib/oauth/tokens/request_token.rb +10 -3
  51. data/lib/oauth/tokens/server_token.rb +0 -0
  52. data/lib/oauth/tokens/token.rb +0 -0
  53. data/lib/oauth/version.rb +1 -1
  54. data/lib/oauth.rb +8 -7
  55. metadata +182 -64
  56. data/README.rdoc +0 -85
  57. data/lib/oauth/core_ext.rb +0 -53
@@ -1,5 +1,5 @@
1
- require 'oauth/helper'
2
- require 'oauth/request_proxy/net_http'
1
+ require "oauth/helper"
2
+ require "oauth/request_proxy/net_http"
3
3
 
4
4
  class Net::HTTPGenericRequest
5
5
  include OAuth::Helper
@@ -58,7 +58,7 @@ private
58
58
  { :request_uri => oauth_full_request_uri(http,options),
59
59
  :consumer => consumer,
60
60
  :token => token,
61
- :scheme => 'header',
61
+ :scheme => "header",
62
62
  :signature_method => nil,
63
63
  :nonce => nil,
64
64
  :timestamp => nil }.merge(options)
@@ -71,7 +71,7 @@ private
71
71
 
72
72
  if options[:request_endpoint] && options[:site]
73
73
  is_https = options[:site].match(%r(^https://))
74
- uri.host = options[:site].gsub(%r(^https?://), '')
74
+ uri.host = options[:site].gsub(%r(^https?://), "")
75
75
  uri.port ||= is_https ? 443 : 80
76
76
  end
77
77
 
@@ -89,7 +89,7 @@ private
89
89
  end
90
90
 
91
91
  def set_oauth_header
92
- self['Authorization'] = @oauth_helper.header
92
+ self["Authorization"] = @oauth_helper.header
93
93
  end
94
94
 
95
95
  # FIXME: if you're using a POST body and query string parameters, this method
data/lib/oauth/client.rb CHANGED
File without changes
@@ -1,34 +1,45 @@
1
- require 'net/http'
2
- require 'net/https'
3
- require 'oauth/oauth'
4
- require 'oauth/client/net_http'
5
- require 'oauth/errors'
6
- require 'cgi'
1
+ require "net/http"
2
+ require "net/https"
3
+ require "oauth/oauth"
4
+ require "oauth/client/net_http"
5
+ require "oauth/errors"
6
+ require "cgi"
7
7
 
8
8
  module OAuth
9
9
  class Consumer
10
10
  # determine the certificate authority path to verify SSL certs
11
- CA_FILES = %W(#{ENV['SSL_CERT_FILE']} /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /usr/share/curl/curl-ca-bundle.crt)
12
- CA_FILES.each do |ca_file|
13
- if File.exist?(ca_file)
14
- CA_FILE = ca_file
15
- break
11
+ if ENV["SSL_CERT_FILE"]
12
+ if File.exist?(ENV["SSL_CERT_FILE"])
13
+ CA_FILE = ENV["SSL_CERT_FILE"]
14
+ else
15
+ raise "The SSL CERT provided does not exist."
16
+ end
17
+ end
18
+
19
+ if !defined?(CA_FILE)
20
+ CA_FILES = %W(/etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /usr/share/curl/curl-ca-bundle.crt)
21
+ CA_FILES.each do |ca_file|
22
+ if File.exist?(ca_file)
23
+ CA_FILE = ca_file
24
+ break
25
+ end
16
26
  end
17
27
  end
18
28
  CA_FILE = nil unless defined?(CA_FILE)
19
29
 
20
30
  @@default_options = {
21
31
  # Signature method used by server. Defaults to HMAC-SHA1
22
- :signature_method => 'HMAC-SHA1',
32
+ :signature_method => "HMAC-SHA1",
23
33
 
24
34
  # default paths on site. These are the same as the defaults set up by the generators
25
- :request_token_path => '/oauth/request_token',
26
- :authorize_path => '/oauth/authorize',
27
- :access_token_path => '/oauth/access_token',
35
+ :request_token_path => "/oauth/request_token",
36
+ :authenticate_path => "/oauth/authenticate",
37
+ :authorize_path => "/oauth/authorize",
38
+ :access_token_path => "/oauth/access_token",
28
39
 
29
40
  :proxy => nil,
30
41
  # How do we send the oauth values to the server see
31
- # http://oauth.net/core/1.0/#consumer_req_param for more info
42
+ # https://oauth.net/core/1.0/#consumer_req_param for more info
32
43
  #
33
44
  # Possible values:
34
45
  #
@@ -146,11 +157,14 @@ module OAuth
146
157
  request_options[:oauth_callback] ||= OAuth::OUT_OF_BAND unless request_options[:exclude_callback]
147
158
 
148
159
  if block_given?
149
- response = token_request(http_method,
150
- (request_token_url? ? request_token_url : request_token_path),
151
- nil,
152
- request_options,
153
- *arguments, &block)
160
+ response = token_request(
161
+ http_method,
162
+ (request_token_url? ? request_token_url : request_token_path),
163
+ nil,
164
+ request_options,
165
+ *arguments,
166
+ &block
167
+ )
154
168
  else
155
169
  response = token_request(http_method, (request_token_url? ? request_token_url : request_token_path), nil, request_options, *arguments)
156
170
  end
@@ -179,7 +193,7 @@ module OAuth
179
193
  return nil if block_given? and yield(req) == :done
180
194
  rsp = http.request(req)
181
195
  # check for an error reported by the Problem Reporting extension
182
- # (http://wiki.oauth.net/ProblemReporting)
196
+ # (https://wiki.oauth.net/ProblemReporting)
183
197
  # note: a 200 may actually be an error; check for an oauth_problem key to be sure
184
198
  if !(headers = rsp.to_hash["www-authenticate"]).nil? &&
185
199
  (h = headers.select { |hdr| hdr =~ /^OAuth / }).any? &&
@@ -228,9 +242,18 @@ module OAuth
228
242
  end
229
243
  end
230
244
  when (300..399)
231
- # this is a redirect
232
- uri = URI.parse(response['location'])
233
- response.error! if uri.path == path # careful of those infinite redirects
245
+ # Parse redirect to follow
246
+ uri = URI.parse(response["location"])
247
+ our_uri = URI.parse(site)
248
+
249
+ # Guard against infinite redirects
250
+ response.error! if uri.path == path && our_uri.host == uri.host
251
+
252
+ if uri.path == path && our_uri.host != uri.host
253
+ options[:site] = "#{uri.scheme}://#{uri.host}"
254
+ @http = create_http
255
+ end
256
+
234
257
  self.token_request(http_method, uri.path, token, request_options, arguments)
235
258
  when (400..499)
236
259
  raise OAuth::Unauthorized, response
@@ -266,6 +289,10 @@ module OAuth
266
289
  @options[:request_token_path]
267
290
  end
268
291
 
292
+ def authenticate_path
293
+ @options[:authenticate_path]
294
+ end
295
+
269
296
  def authorize_path
270
297
  @options[:authorize_path]
271
298
  end
@@ -283,6 +310,14 @@ module OAuth
283
310
  @options.has_key?(:request_token_url)
284
311
  end
285
312
 
313
+ def authenticate_url
314
+ @options[:authenticate_url] || site + authenticate_path
315
+ end
316
+
317
+ def authenticate_url?
318
+ @options.has_key?(:authenticate_url)
319
+ end
320
+
286
321
  def authorize_url
287
322
  @options[:authorize_url] || site + authorize_path
288
323
  end
@@ -308,18 +343,22 @@ module OAuth
308
343
  # Instantiates the http object
309
344
  def create_http(_url = nil)
310
345
 
311
-
312
346
  if !request_endpoint.nil?
313
347
  _url = request_endpoint
314
348
  end
315
349
 
316
-
317
- if _url.nil? || _url[0] =~ /^\//
318
- our_uri = URI.parse(site)
319
- else
320
- our_uri = URI.parse(_url)
321
- end
322
-
350
+ our_uri = if _url.nil? || _url[0] =~ /^\//
351
+ URI.parse(site)
352
+ else
353
+ your_uri = URI.parse(_url)
354
+ if your_uri.host.nil?
355
+ # If the _url is a path, missing the leading slash, then it won't have a host,
356
+ # and our_uri *must* have a host, so we parse site instead.
357
+ URI.parse(site)
358
+ else
359
+ your_uri
360
+ end
361
+ end
323
362
 
324
363
  if proxy.nil?
325
364
  http_object = Net::HTTP.new(our_uri.host, our_uri.port)
@@ -328,19 +367,24 @@ module OAuth
328
367
  http_object = Net::HTTP.new(our_uri.host, our_uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
329
368
  end
330
369
 
331
- http_object.use_ssl = (our_uri.scheme == 'https')
370
+ http_object.use_ssl = (our_uri.scheme == "https")
332
371
 
333
- if @options[:ca_file] || CA_FILE
334
- http_object.ca_file = @options[:ca_file] || CA_FILE
372
+ if @options[:no_verify]
373
+ http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
374
+ else
375
+ ca_file = @options[:ca_file] || CA_FILE
376
+ if ca_file
377
+ http_object.ca_file = ca_file
378
+ end
335
379
  http_object.verify_mode = OpenSSL::SSL::VERIFY_PEER
336
380
  http_object.verify_depth = 5
337
- else
338
- http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
339
381
  end
340
382
 
341
- http_object.read_timeout = http_object.open_timeout = @options[:timeout] || 30
383
+ http_object.read_timeout = http_object.open_timeout = @options[:timeout] || 60
342
384
  http_object.open_timeout = @options[:open_timeout] if @options[:open_timeout]
343
385
  http_object.ssl_version = @options[:ssl_version] if @options[:ssl_version]
386
+ http_object.cert = @options[:ssl_client_cert] if @options[:ssl_client_cert]
387
+ http_object.key = @options[:ssl_client_key] if @options[:ssl_client_key]
344
388
  http_object.set_debug_output(debug_output) if debug_output
345
389
 
346
390
  http_object
@@ -358,20 +402,20 @@ module OAuth
358
402
  # only add if the site host matches the current http object's host
359
403
  # (in case we've specified a full url for token requests)
360
404
  uri = URI.parse(site)
361
- path = uri.path + path if uri.path && uri.path != '/' && uri.host == http.address
405
+ path = uri.path + path if uri.path && uri.path != "/" && uri.host == http.address
362
406
 
363
407
  headers = arguments.first.is_a?(Hash) ? arguments.shift : {}
364
408
 
365
409
  case http_method
366
410
  when :post
367
411
  request = Net::HTTP::Post.new(path,headers)
368
- request["Content-Length"] = '0' # Default to 0
412
+ request["Content-Length"] = "0" # Default to 0
369
413
  when :put
370
414
  request = Net::HTTP::Put.new(path,headers)
371
- request["Content-Length"] = '0' # Default to 0
415
+ request["Content-Length"] = "0" # Default to 0
372
416
  when :patch
373
417
  request = Net::HTTP::Patch.new(path,headers)
374
- request["Content-Length"] = '0' # Default to 0
418
+ request["Content-Length"] = "0" # Default to 0
375
419
  when :get
376
420
  request = Net::HTTP::Get.new(path,headers)
377
421
  when :delete
@@ -384,7 +428,7 @@ module OAuth
384
428
 
385
429
  if data.is_a?(Hash)
386
430
  request.body = OAuth::Helper.normalize(data)
387
- request.content_type = 'application/x-www-form-urlencoded'
431
+ request.content_type = "application/x-www-form-urlencoded"
388
432
  elsif data
389
433
  if data.respond_to?(:read)
390
434
  request.body_stream = data
File without changes
File without changes
@@ -6,7 +6,9 @@ module OAuth
6
6
  end
7
7
 
8
8
  def to_s
9
- [request.code, request.message] * " "
9
+ return "401 Unauthorized" if request.nil?
10
+
11
+ "#{request.code} #{request.message}"
10
12
  end
11
13
  end
12
14
  end
data/lib/oauth/errors.rb CHANGED
@@ -1,3 +1,3 @@
1
- require 'oauth/errors/error'
2
- require 'oauth/errors/unauthorized'
3
- require 'oauth/errors/problem'
1
+ require "oauth/errors/error"
2
+ require "oauth/errors/unauthorized"
3
+ require "oauth/errors/problem"
data/lib/oauth/helper.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'openssl'
2
- require 'base64'
1
+ require "openssl"
2
+ require "base64"
3
3
 
4
4
  module OAuth
5
5
  module Helper
@@ -15,17 +15,17 @@ module OAuth
15
15
  end
16
16
 
17
17
  def _escape(string)
18
- URI.escape(string, OAuth::RESERVED_CHARACTERS)
18
+ URI::DEFAULT_PARSER.escape(string, OAuth::RESERVED_CHARACTERS)
19
19
  end
20
20
 
21
21
  def unescape(value)
22
- URI.unescape(value.gsub('+', '%2B'))
22
+ URI::DEFAULT_PARSER.unescape(value.gsub("+", "%2B"))
23
23
  end
24
24
 
25
25
  # Generate a random key of up to +size+ bytes. The value returned is Base64 encoded with non-word
26
26
  # characters removed.
27
27
  def generate_key(size=32)
28
- Base64.encode64(OpenSSL::Random.random_bytes(size)).gsub(/\W/, '')
28
+ Base64.encode64(OpenSSL::Random.random_bytes(size)).gsub(/\W/, "")
29
29
  end
30
30
 
31
31
  alias_method :generate_nonce, :generate_key
@@ -47,8 +47,12 @@ module OAuth
47
47
  # make sure the array has an element so we don't lose the key
48
48
  values << nil if values.empty?
49
49
  # multiple values were provided for a single key
50
- values.sort.collect do |v|
51
- [escape(k),escape(v)] * "="
50
+ if values[0].is_a?(Hash)
51
+ normalize_nested_query(values, k)
52
+ else
53
+ values.sort.collect do |v|
54
+ [escape(k),escape(v)] * "="
55
+ end
52
56
  end
53
57
  elsif values.is_a?(Hash)
54
58
  normalize_nested_query(values, k)
@@ -58,7 +62,7 @@ module OAuth
58
62
  end * "&"
59
63
  end
60
64
 
61
- #Returns a string representation of the Hash like in URL query string
65
+ # Returns a string representation of the Hash like in URL query string
62
66
  # build_nested_query({:level_1 => {:level_2 => ['value_1','value_2']}}, 'prefix'))
63
67
  # #=> ["prefix%5Blevel_1%5D%5Blevel_2%5D%5B%5D=value_1", "prefix%5Blevel_1%5D%5Blevel_2%5D%5B%5D=value_2"]
64
68
  def normalize_nested_query(value, prefix = nil)
data/lib/oauth/oauth.rb CHANGED
File without changes
@@ -1,5 +1,5 @@
1
- require 'action_controller'
2
- require 'action_controller/test_process'
1
+ require "action_controller"
2
+ require "action_controller/test_process"
3
3
 
4
4
  module OAuth
5
5
  module OAuthTestHelper
@@ -8,7 +8,7 @@ module OAuth
8
8
  incoming.request_uri = request.path
9
9
  incoming.host = request.uri.host
10
10
  incoming.env["SERVER_PORT"] = request.uri.port
11
- incoming.env['REQUEST_METHOD'] = request.http_method
11
+ incoming.env["REQUEST_METHOD"] = request.http_method
12
12
  incoming
13
13
  end
14
14
 
@@ -18,7 +18,7 @@ module OAuth
18
18
  incoming.host = request.uri.host
19
19
  incoming.env["HTTP_AUTHORIZATION"] = request.to_auth_string
20
20
  incoming.env["SERVER_PORT"] = request.uri.port
21
- incoming.env['REQUEST_METHOD'] = request.http_method
21
+ incoming.env["REQUEST_METHOD"] = request.http_method
22
22
  incoming
23
23
  end
24
24
  end
@@ -1,12 +1,12 @@
1
- require 'active_support'
1
+ require "active_support"
2
2
  require "active_support/version"
3
- require 'action_controller'
4
- require 'uri'
3
+ require "action_controller"
4
+ require "uri"
5
5
 
6
6
  if
7
7
  Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
8
8
  then # rails 2.x
9
- require 'action_controller/request'
9
+ require "action_controller/request"
10
10
  unless ActionController::Request::HTTP_METHODS.include?("patch")
11
11
  ActionController::Request::HTTP_METHODS << "patch"
12
12
  ActionController::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch
@@ -16,15 +16,15 @@ then # rails 2.x
16
16
  elsif
17
17
  Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
18
18
  then # rails 3.x
19
- require 'action_dispatch/http/request'
19
+ require "action_dispatch/http/request"
20
20
  unless ActionDispatch::Request::HTTP_METHODS.include?("patch")
21
21
  ActionDispatch::Request::HTTP_METHODS << "patch"
22
22
  ActionDispatch::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch
23
23
  ActionDispatch::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
24
24
  end
25
25
 
26
- else # rails 4.x - already has patch
27
- require 'action_dispatch/http/request'
26
+ else # rails 4.x and later - already has patch
27
+ require "action_dispatch/http/request"
28
28
  end
29
29
 
30
30
  module OAuth::RequestProxy
@@ -60,16 +60,20 @@ module OAuth::RequestProxy
60
60
  params << header_params.to_query
61
61
  params << request.query_string unless query_string_blank?
62
62
 
63
- if request.post? && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
63
+ if raw_post_signature?
64
64
  params << request.raw_post
65
65
  end
66
66
  end
67
67
 
68
68
  params.
69
- join('&').split('&').
69
+ join("&").split("&").
70
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'}
71
+ map { |p| p.split("=").map{|esc| CGI.unescape(esc)} }.
72
+ reject { |kv| kv[0] == "oauth_signature"}
73
+ end
74
+
75
+ def raw_post_signature?
76
+ (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
73
77
  end
74
78
 
75
79
  protected
@@ -0,0 +1,7 @@
1
+ require "oauth/request_proxy/rack_request"
2
+
3
+ module OAuth::RequestProxy
4
+ class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
5
+ proxies ActionDispatch::Request
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
- require 'oauth/request_proxy'
2
- require 'oauth/helper'
1
+ require "oauth/request_proxy"
2
+ require "oauth/helper"
3
3
 
4
4
  module OAuth::RequestProxy
5
5
  class Base
@@ -20,41 +20,41 @@ module OAuth::RequestProxy
20
20
  ## OAuth parameters
21
21
 
22
22
  def oauth_callback
23
- parameters['oauth_callback']
23
+ parameters["oauth_callback"]
24
24
  end
25
25
 
26
26
  def oauth_consumer_key
27
- parameters['oauth_consumer_key']
27
+ parameters["oauth_consumer_key"]
28
28
  end
29
29
 
30
30
  def oauth_nonce
31
- parameters['oauth_nonce']
31
+ parameters["oauth_nonce"]
32
32
  end
33
33
 
34
34
  def oauth_signature
35
35
  # TODO can this be nil?
36
- [parameters['oauth_signature']].flatten.first || ""
36
+ [parameters["oauth_signature"]].flatten.first || ""
37
37
  end
38
38
 
39
39
  def oauth_signature_method
40
- case parameters['oauth_signature_method']
40
+ case parameters["oauth_signature_method"]
41
41
  when Array
42
- parameters['oauth_signature_method'].first
42
+ parameters["oauth_signature_method"].first
43
43
  else
44
- parameters['oauth_signature_method']
44
+ parameters["oauth_signature_method"]
45
45
  end
46
46
  end
47
47
 
48
48
  def oauth_timestamp
49
- parameters['oauth_timestamp']
49
+ parameters["oauth_timestamp"]
50
50
  end
51
51
 
52
52
  def oauth_token
53
- parameters['oauth_token']
53
+ parameters["oauth_token"]
54
54
  end
55
55
 
56
56
  def oauth_verifier
57
- parameters['oauth_verifier']
57
+ parameters["oauth_verifier"]
58
58
  end
59
59
 
60
60
  def oauth_version
@@ -140,15 +140,15 @@ module OAuth::RequestProxy
140
140
 
141
141
  # Authorization header for OAuth
142
142
  def oauth_header(options = {})
143
- header_params_str = oauth_parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')
143
+ header_params_str = oauth_parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(", ")
144
144
 
145
145
  realm = "realm=\"#{options[:realm]}\", " if options[:realm]
146
146
  "OAuth #{realm}#{header_params_str}"
147
147
  end
148
148
 
149
149
  def query_string_blank?
150
- if uri = request.env['REQUEST_URI']
151
- uri.split('?', 2)[1].nil?
150
+ if uri = request.env["REQUEST_URI"]
151
+ uri.split("?", 2)[1].nil?
152
152
  else
153
153
  request.query_string.match(/\A\s*\z/)
154
154
  end
@@ -161,7 +161,7 @@ module OAuth::RequestProxy
161
161
  next unless request.env.include?(header)
162
162
 
163
163
  header = request.env[header]
164
- next unless header[0,6] == 'OAuth '
164
+ next unless header[0,6] == "OAuth "
165
165
 
166
166
  # parse the header into a Hash
167
167
  oauth_params = OAuth::Helper.parse_header(header)
@@ -1,7 +1,7 @@
1
- require 'oauth/request_proxy/base'
2
- require 'curb'
3
- require 'uri'
4
- require 'cgi'
1
+ require "oauth/request_proxy/base"
2
+ require "curb"
3
+ require "uri"
4
+ require "cgi"
5
5
 
6
6
  module OAuth::RequestProxy::Curl
7
7
  class Easy < OAuth::RequestProxy::Base
@@ -42,7 +42,7 @@ module OAuth::RequestProxy::Curl
42
42
  post_body = {}
43
43
 
44
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"))
45
+ if (request.headers["Content-Type"] && request.headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded"))
46
46
 
47
47
  request.post_body.split("&").each do |str|
48
48
  param = str.split("=")
@@ -1,7 +1,7 @@
1
- require 'oauth/request_proxy/base'
1
+ require "oauth/request_proxy/base"
2
2
  # em-http also uses adddressable so there is no need to require uri.
3
- require 'em-http'
4
- require 'cgi'
3
+ require "em-http"
4
+ require "cgi"
5
5
 
6
6
  module OAuth::RequestProxy::EventMachine
7
7
  class HttpRequest < OAuth::RequestProxy::Base
@@ -14,11 +14,11 @@ module OAuth::RequestProxy::EventMachine
14
14
  # Request in this con
15
15
 
16
16
  def method
17
- request.method
17
+ request.req[:method]
18
18
  end
19
19
 
20
20
  def uri
21
- request.normalize_uri.to_s
21
+ request.conn.normalize.to_s
22
22
  end
23
23
 
24
24
  def parameters
@@ -36,14 +36,20 @@ module OAuth::RequestProxy::EventMachine
36
36
  end
37
37
 
38
38
  def query_parameters
39
- CGI.parse(request.normalize_uri.query.to_s)
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)
40
46
  end
41
47
 
42
48
  def post_parameters
43
- headers = request.options[:head] || {}
44
- form_encoded = headers['Content-Type'].to_s.downcase.start_with?("application/x-www-form-urlencoded")
45
- if ['POST', 'PUT'].include?(method) && form_encoded
46
- CGI.parse(request.normalize_body.to_s)
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)
47
53
  else
48
54
  {}
49
55
  end
@@ -53,9 +59,9 @@ module OAuth::RequestProxy::EventMachine
53
59
  extra_params.compact.each do |params_pairs|
54
60
  params_pairs.each_pair do |key, value|
55
61
  if params.has_key?(key)
56
- params[key] += value
62
+ params[key.to_s] += value
57
63
  else
58
- params[key] = [value].flatten
64
+ params[key.to_s] = [value].flatten
59
65
  end
60
66
  end
61
67
  end
@@ -1,5 +1,5 @@
1
- require 'xmpp4r'
2
- require 'oauth/request_proxy/base'
1
+ require "xmpp4r"
2
+ require "oauth/request_proxy/base"
3
3
 
4
4
  module OAuth
5
5
  module RequestProxy
@@ -13,7 +13,7 @@ module OAuth
13
13
 
14
14
  @params = {}
15
15
 
16
- oauth = @request.get_elements('//oauth').first
16
+ oauth = @request.get_elements("//oauth").first
17
17
  return @params unless oauth
18
18
 
19
19
  %w( oauth_token oauth_consumer_key oauth_signature_method oauth_signature
@@ -1,4 +1,4 @@
1
- require 'oauth/request_proxy/base'
1
+ require "oauth/request_proxy/base"
2
2
 
3
3
  module OAuth
4
4
  module RequestProxy