oauth 0.5.6 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +454 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE +18 -17
- data/README.md +211 -0
- data/TODO +0 -0
- data/bin/oauth +2 -2
- data/lib/oauth/cli/authorize_command.rb +0 -0
- data/lib/oauth/cli/base_command.rb +1 -1
- data/lib/oauth/cli/help_command.rb +0 -0
- data/lib/oauth/cli/query_command.rb +0 -0
- data/lib/oauth/cli/sign_command.rb +0 -0
- data/lib/oauth/cli/version_command.rb +0 -0
- data/lib/oauth/cli.rb +18 -18
- data/lib/oauth/client/action_controller_request.rb +7 -7
- data/lib/oauth/client/em_http.rb +99 -99
- data/lib/oauth/client/helper.rb +22 -22
- data/lib/oauth/client/net_http.rb +5 -5
- data/lib/oauth/client.rb +0 -0
- data/lib/oauth/consumer.rb +49 -38
- data/lib/oauth/errors/error.rb +0 -0
- data/lib/oauth/errors/problem.rb +0 -0
- data/lib/oauth/errors/unauthorized.rb +3 -1
- data/lib/oauth/errors.rb +3 -3
- data/lib/oauth/helper.rb +11 -7
- data/lib/oauth/oauth.rb +0 -0
- data/lib/oauth/oauth_test_helper.rb +4 -4
- data/lib/oauth/request_proxy/action_controller_request.rb +9 -9
- data/lib/oauth/request_proxy/action_dispatch_request.rb +1 -1
- data/lib/oauth/request_proxy/base.rb +16 -16
- data/lib/oauth/request_proxy/curb_request.rb +5 -5
- data/lib/oauth/request_proxy/em_http_request.rb +18 -12
- data/lib/oauth/request_proxy/jabber_request.rb +3 -3
- data/lib/oauth/request_proxy/mock_request.rb +1 -1
- data/lib/oauth/request_proxy/net_http.rb +9 -9
- data/lib/oauth/request_proxy/rack_request.rb +4 -4
- data/lib/oauth/request_proxy/rest_client_request.rb +7 -7
- data/lib/oauth/request_proxy/typhoeus_request.rb +7 -7
- data/lib/oauth/request_proxy.rb +0 -0
- data/lib/oauth/server.rb +2 -2
- data/lib/oauth/signature/base.rb +8 -6
- data/lib/oauth/signature/hmac/sha1.rb +4 -4
- data/lib/oauth/signature/hmac/sha256.rb +4 -4
- data/lib/oauth/signature/plaintext.rb +2 -2
- data/lib/oauth/signature/rsa/sha1.rb +3 -3
- data/lib/oauth/signature.rb +0 -0
- data/lib/oauth/token.rb +5 -5
- data/lib/oauth/tokens/access_token.rb +3 -3
- data/lib/oauth/tokens/consumer_token.rb +0 -0
- data/lib/oauth/tokens/request_token.rb +0 -0
- data/lib/oauth/tokens/server_token.rb +0 -0
- data/lib/oauth/tokens/token.rb +0 -0
- data/lib/oauth/version.rb +1 -1
- data/lib/oauth.rb +8 -7
- metadata +171 -64
- data/README.rdoc +0 -88
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
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 =>
|
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[
|
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
|
data/lib/oauth/consumer.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
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
|
-
if ENV[
|
12
|
-
if File.exist?(ENV[
|
13
|
-
CA_FILE = ENV[
|
11
|
+
if ENV["SSL_CERT_FILE"]
|
12
|
+
if File.exist?(ENV["SSL_CERT_FILE"])
|
13
|
+
CA_FILE = ENV["SSL_CERT_FILE"]
|
14
14
|
else
|
15
15
|
raise "The SSL CERT provided does not exist."
|
16
16
|
end
|
@@ -29,17 +29,17 @@ module OAuth
|
|
29
29
|
|
30
30
|
@@default_options = {
|
31
31
|
# Signature method used by server. Defaults to HMAC-SHA1
|
32
|
-
:signature_method =>
|
32
|
+
:signature_method => "HMAC-SHA1",
|
33
33
|
|
34
34
|
# default paths on site. These are the same as the defaults set up by the generators
|
35
|
-
:request_token_path =>
|
36
|
-
:authenticate_path =>
|
37
|
-
:authorize_path =>
|
38
|
-
:access_token_path =>
|
35
|
+
:request_token_path => "/oauth/request_token",
|
36
|
+
:authenticate_path => "/oauth/authenticate",
|
37
|
+
:authorize_path => "/oauth/authorize",
|
38
|
+
:access_token_path => "/oauth/access_token",
|
39
39
|
|
40
40
|
:proxy => nil,
|
41
41
|
# How do we send the oauth values to the server see
|
42
|
-
#
|
42
|
+
# https://oauth.net/core/1.0/#consumer_req_param for more info
|
43
43
|
#
|
44
44
|
# Possible values:
|
45
45
|
#
|
@@ -157,11 +157,14 @@ module OAuth
|
|
157
157
|
request_options[:oauth_callback] ||= OAuth::OUT_OF_BAND unless request_options[:exclude_callback]
|
158
158
|
|
159
159
|
if block_given?
|
160
|
-
response = token_request(
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
+
)
|
165
168
|
else
|
166
169
|
response = token_request(http_method, (request_token_url? ? request_token_url : request_token_path), nil, request_options, *arguments)
|
167
170
|
end
|
@@ -190,7 +193,7 @@ module OAuth
|
|
190
193
|
return nil if block_given? and yield(req) == :done
|
191
194
|
rsp = http.request(req)
|
192
195
|
# check for an error reported by the Problem Reporting extension
|
193
|
-
# (
|
196
|
+
# (https://wiki.oauth.net/ProblemReporting)
|
194
197
|
# note: a 200 may actually be an error; check for an oauth_problem key to be sure
|
195
198
|
if !(headers = rsp.to_hash["www-authenticate"]).nil? &&
|
196
199
|
(h = headers.select { |hdr| hdr =~ /^OAuth / }).any? &&
|
@@ -239,16 +242,18 @@ module OAuth
|
|
239
242
|
end
|
240
243
|
end
|
241
244
|
when (300..399)
|
242
|
-
#
|
243
|
-
uri = URI.parse(response[
|
245
|
+
# Parse redirect to follow
|
246
|
+
uri = URI.parse(response["location"])
|
244
247
|
our_uri = URI.parse(site)
|
245
248
|
|
249
|
+
# Guard against infinite redirects
|
250
|
+
response.error! if uri.path == path && our_uri.host == uri.host
|
251
|
+
|
246
252
|
if uri.path == path && our_uri.host != uri.host
|
247
253
|
options[:site] = "#{uri.scheme}://#{uri.host}"
|
248
254
|
@http = create_http
|
249
255
|
end
|
250
256
|
|
251
|
-
response.error! if uri.path == path && our_uri.host == uri.host # careful of those infinite redirects
|
252
257
|
self.token_request(http_method, uri.path, token, request_options, arguments)
|
253
258
|
when (400..499)
|
254
259
|
raise OAuth::Unauthorized, response
|
@@ -338,18 +343,22 @@ module OAuth
|
|
338
343
|
# Instantiates the http object
|
339
344
|
def create_http(_url = nil)
|
340
345
|
|
341
|
-
|
342
346
|
if !request_endpoint.nil?
|
343
347
|
_url = request_endpoint
|
344
348
|
end
|
345
349
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
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
|
353
362
|
|
354
363
|
if proxy.nil?
|
355
364
|
http_object = Net::HTTP.new(our_uri.host, our_uri.port)
|
@@ -358,7 +367,7 @@ module OAuth
|
|
358
367
|
http_object = Net::HTTP.new(our_uri.host, our_uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
|
359
368
|
end
|
360
369
|
|
361
|
-
http_object.use_ssl = (our_uri.scheme ==
|
370
|
+
http_object.use_ssl = (our_uri.scheme == "https")
|
362
371
|
|
363
372
|
if @options[:no_verify]
|
364
373
|
http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
@@ -374,6 +383,8 @@ module OAuth
|
|
374
383
|
http_object.read_timeout = http_object.open_timeout = @options[:timeout] || 60
|
375
384
|
http_object.open_timeout = @options[:open_timeout] if @options[:open_timeout]
|
376
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]
|
377
388
|
http_object.set_debug_output(debug_output) if debug_output
|
378
389
|
|
379
390
|
http_object
|
@@ -391,20 +402,20 @@ module OAuth
|
|
391
402
|
# only add if the site host matches the current http object's host
|
392
403
|
# (in case we've specified a full url for token requests)
|
393
404
|
uri = URI.parse(site)
|
394
|
-
path = uri.path + path if uri.path && uri.path !=
|
405
|
+
path = uri.path + path if uri.path && uri.path != "/" && uri.host == http.address
|
395
406
|
|
396
407
|
headers = arguments.first.is_a?(Hash) ? arguments.shift : {}
|
397
408
|
|
398
409
|
case http_method
|
399
410
|
when :post
|
400
411
|
request = Net::HTTP::Post.new(path,headers)
|
401
|
-
request["Content-Length"] =
|
412
|
+
request["Content-Length"] = "0" # Default to 0
|
402
413
|
when :put
|
403
414
|
request = Net::HTTP::Put.new(path,headers)
|
404
|
-
request["Content-Length"] =
|
415
|
+
request["Content-Length"] = "0" # Default to 0
|
405
416
|
when :patch
|
406
417
|
request = Net::HTTP::Patch.new(path,headers)
|
407
|
-
request["Content-Length"] =
|
418
|
+
request["Content-Length"] = "0" # Default to 0
|
408
419
|
when :get
|
409
420
|
request = Net::HTTP::Get.new(path,headers)
|
410
421
|
when :delete
|
@@ -417,7 +428,7 @@ module OAuth
|
|
417
428
|
|
418
429
|
if data.is_a?(Hash)
|
419
430
|
request.body = OAuth::Helper.normalize(data)
|
420
|
-
request.content_type =
|
431
|
+
request.content_type = "application/x-www-form-urlencoded"
|
421
432
|
elsif data
|
422
433
|
if data.respond_to?(:read)
|
423
434
|
request.body_stream = data
|
data/lib/oauth/errors/error.rb
CHANGED
File without changes
|
data/lib/oauth/errors/problem.rb
CHANGED
File without changes
|
data/lib/oauth/errors.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
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
|
2
|
-
require
|
1
|
+
require "openssl"
|
2
|
+
require "base64"
|
3
3
|
|
4
4
|
module OAuth
|
5
5
|
module Helper
|
@@ -19,13 +19,13 @@ module OAuth
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def unescape(value)
|
22
|
-
URI::DEFAULT_PARSER.unescape(value.gsub(
|
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.
|
51
|
-
|
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
|
2
|
-
require
|
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[
|
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[
|
21
|
+
incoming.env["REQUEST_METHOD"] = request.http_method
|
22
22
|
incoming
|
23
23
|
end
|
24
24
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "active_support"
|
2
2
|
require "active_support/version"
|
3
|
-
require
|
4
|
-
require
|
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
|
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,7 +16,7 @@ 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
|
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
|
@@ -24,7 +24,7 @@ then # rails 3.x
|
|
24
24
|
end
|
25
25
|
|
26
26
|
else # rails 4.x and later - already has patch
|
27
|
-
require
|
27
|
+
require "action_dispatch/http/request"
|
28
28
|
end
|
29
29
|
|
30
30
|
module OAuth::RequestProxy
|
@@ -66,10 +66,10 @@ module OAuth::RequestProxy
|
|
66
66
|
end
|
67
67
|
|
68
68
|
params.
|
69
|
-
join(
|
69
|
+
join("&").split("&").
|
70
70
|
reject { |s| s.match(/\A\s*\z/) }.
|
71
|
-
map { |p| p.split(
|
72
|
-
reject { |kv| kv[0] ==
|
71
|
+
map { |p| p.split("=").map{|esc| CGI.unescape(esc)} }.
|
72
|
+
reject { |kv| kv[0] == "oauth_signature"}
|
73
73
|
end
|
74
74
|
|
75
75
|
def raw_post_signature?
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
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[
|
23
|
+
parameters["oauth_callback"]
|
24
24
|
end
|
25
25
|
|
26
26
|
def oauth_consumer_key
|
27
|
-
parameters[
|
27
|
+
parameters["oauth_consumer_key"]
|
28
28
|
end
|
29
29
|
|
30
30
|
def oauth_nonce
|
31
|
-
parameters[
|
31
|
+
parameters["oauth_nonce"]
|
32
32
|
end
|
33
33
|
|
34
34
|
def oauth_signature
|
35
35
|
# TODO can this be nil?
|
36
|
-
[parameters[
|
36
|
+
[parameters["oauth_signature"]].flatten.first || ""
|
37
37
|
end
|
38
38
|
|
39
39
|
def oauth_signature_method
|
40
|
-
case parameters[
|
40
|
+
case parameters["oauth_signature_method"]
|
41
41
|
when Array
|
42
|
-
parameters[
|
42
|
+
parameters["oauth_signature_method"].first
|
43
43
|
else
|
44
|
-
parameters[
|
44
|
+
parameters["oauth_signature_method"]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def oauth_timestamp
|
49
|
-
parameters[
|
49
|
+
parameters["oauth_timestamp"]
|
50
50
|
end
|
51
51
|
|
52
52
|
def oauth_token
|
53
|
-
parameters[
|
53
|
+
parameters["oauth_token"]
|
54
54
|
end
|
55
55
|
|
56
56
|
def oauth_verifier
|
57
|
-
parameters[
|
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[
|
151
|
-
uri.split(
|
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] ==
|
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
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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[
|
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
|
1
|
+
require "oauth/request_proxy/base"
|
2
2
|
# em-http also uses adddressable so there is no need to require uri.
|
3
|
-
require
|
4
|
-
require
|
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.
|
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
|
-
|
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.
|
44
|
-
form_encoded = headers[
|
45
|
-
if [
|
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
|
2
|
-
require
|
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(
|
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,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "oauth/request_proxy/base"
|
2
|
+
require "net/http"
|
3
|
+
require "uri"
|
4
|
+
require "cgi"
|
5
5
|
|
6
6
|
module OAuth::RequestProxy::Net
|
7
7
|
module HTTP
|
@@ -48,12 +48,12 @@ module OAuth::RequestProxy::Net
|
|
48
48
|
|
49
49
|
def query_string
|
50
50
|
params = [ query_params, auth_header_params ]
|
51
|
-
params << post_params if (method.to_s.upcase ==
|
52
|
-
params.compact.join(
|
51
|
+
params << post_params if (method.to_s.upcase == "POST" || method.to_s.upcase == "PUT") && form_url_encoded?
|
52
|
+
params.compact.join("&")
|
53
53
|
end
|
54
54
|
|
55
55
|
def form_url_encoded?
|
56
|
-
request[
|
56
|
+
request["Content-Type"] != nil && request["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")
|
57
57
|
end
|
58
58
|
|
59
59
|
def query_params
|
@@ -65,8 +65,8 @@ module OAuth::RequestProxy::Net
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def auth_header_params
|
68
|
-
return nil unless request[
|
69
|
-
request[
|
68
|
+
return nil unless request["Authorization"] && request["Authorization"][0,5] == "OAuth"
|
69
|
+
request["Authorization"]
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "oauth/request_proxy/base"
|
2
|
+
require "uri"
|
3
|
+
require "rack"
|
4
4
|
|
5
5
|
module OAuth::RequestProxy
|
6
6
|
class RackRequest < OAuth::RequestProxy::Base
|
@@ -24,7 +24,7 @@ module OAuth::RequestProxy
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def signature
|
27
|
-
parameters[
|
27
|
+
parameters["oauth_signature"]
|
28
28
|
end
|
29
29
|
|
30
30
|
protected
|