oauth 0.5.4 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +455 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE +18 -17
- data/README.md +223 -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 +29 -23
- data/lib/oauth/client/net_http.rb +5 -5
- data/lib/oauth/client.rb +0 -0
- data/lib/oauth/consumer.rb +88 -44
- 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 +56 -53
- data/lib/oauth/request_proxy/action_dispatch_request.rb +8 -4
- data/lib/oauth/request_proxy/base.rb +136 -132
- data/lib/oauth/request_proxy/curb_request.rb +49 -43
- data/lib/oauth/request_proxy/em_http_request.rb +59 -49
- data/lib/oauth/request_proxy/jabber_request.rb +12 -9
- data/lib/oauth/request_proxy/mock_request.rb +4 -2
- data/lib/oauth/request_proxy/net_http.rb +63 -54
- data/lib/oauth/request_proxy/rack_request.rb +35 -31
- data/lib/oauth/request_proxy/rest_client_request.rb +53 -50
- data/lib/oauth/request_proxy/typhoeus_request.rb +51 -45
- 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 +17 -0
- 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 +10 -3
- 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 -6
- metadata +176 -58
- data/README.rdoc +0 -86
data/lib/oauth/client/helper.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "oauth/client"
|
2
|
+
require "oauth/consumer"
|
3
|
+
require "oauth/helper"
|
4
|
+
require "oauth/token"
|
5
|
+
require "oauth/signature/hmac/sha1"
|
6
6
|
|
7
7
|
module OAuth::Client
|
8
8
|
class Helper
|
@@ -11,7 +11,7 @@ module OAuth::Client
|
|
11
11
|
def initialize(request, options = {})
|
12
12
|
@request = request
|
13
13
|
@options = options
|
14
|
-
@options[:signature_method] ||=
|
14
|
+
@options[:signature_method] ||= "HMAC-SHA1"
|
15
15
|
end
|
16
16
|
|
17
17
|
def options
|
@@ -27,18 +27,24 @@ module OAuth::Client
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def oauth_parameters
|
30
|
-
{
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
30
|
+
out = {
|
31
|
+
"oauth_body_hash" => options[:body_hash],
|
32
|
+
"oauth_callback" => options[:oauth_callback],
|
33
|
+
"oauth_consumer_key" => options[:consumer].key,
|
34
|
+
"oauth_token" => options[:token] ? options[:token].token : "",
|
35
|
+
"oauth_signature_method" => options[:signature_method],
|
36
|
+
"oauth_timestamp" => timestamp,
|
37
|
+
"oauth_nonce" => nonce,
|
38
|
+
"oauth_verifier" => options[:oauth_verifier],
|
39
|
+
"oauth_version" => (options[:oauth_version] || "1.0"),
|
40
|
+
"oauth_session_handle" => options[:oauth_session_handle]
|
41
|
+
}
|
42
|
+
allowed_empty_params = options[:allow_empty_params]
|
43
|
+
if allowed_empty_params != true && !allowed_empty_params.kind_of?(Array)
|
44
|
+
allowed_empty_params = allowed_empty_params == false ? [] : [allowed_empty_params]
|
45
|
+
end
|
46
|
+
out.select! { |k,v| v.to_s != "" || allowed_empty_params == true || allowed_empty_params.include?(k) }
|
47
|
+
out
|
42
48
|
end
|
43
49
|
|
44
50
|
def signature(extra_options = {})
|
@@ -67,18 +73,18 @@ module OAuth::Client
|
|
67
73
|
def amend_user_agent_header(headers)
|
68
74
|
@oauth_ua_string ||= "OAuth gem v#{OAuth::VERSION}"
|
69
75
|
# Net::HTTP in 1.9 appends Ruby
|
70
|
-
if headers[
|
71
|
-
headers[
|
76
|
+
if headers["User-Agent"] && headers["User-Agent"] != "Ruby"
|
77
|
+
headers["User-Agent"] += " (#{@oauth_ua_string})"
|
72
78
|
else
|
73
|
-
headers[
|
79
|
+
headers["User-Agent"] = @oauth_ua_string
|
74
80
|
end
|
75
81
|
end
|
76
82
|
|
77
83
|
def header
|
78
84
|
parameters = oauth_parameters
|
79
|
-
parameters.merge!(
|
85
|
+
parameters.merge!("oauth_signature" => signature(options.merge(:parameters => parameters)))
|
80
86
|
|
81
|
-
header_params_str = parameters.sort.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(
|
87
|
+
header_params_str = parameters.sort.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(", ")
|
82
88
|
|
83
89
|
realm = "realm=\"#{options[:realm]}\", " if options[:realm]
|
84
90
|
"OAuth #{realm}#{header_params_str}"
|
@@ -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,34 +1,45 @@
|
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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 =>
|
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 =>
|
26
|
-
:
|
27
|
-
:
|
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
|
-
#
|
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(
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
# (
|
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
|
-
#
|
232
|
-
uri = URI.parse(response[
|
233
|
-
|
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
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
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 ==
|
370
|
+
http_object.use_ssl = (our_uri.scheme == "https")
|
332
371
|
|
333
|
-
if @options[:
|
334
|
-
http_object.
|
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] ||
|
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 !=
|
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"] =
|
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"] =
|
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"] =
|
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 =
|
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
|
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,22 +1,22 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support"
|
2
4
|
require "active_support/version"
|
3
|
-
require
|
4
|
-
require
|
5
|
+
require "action_controller"
|
6
|
+
require "uri"
|
5
7
|
|
6
|
-
if
|
7
|
-
|
8
|
-
|
9
|
-
require 'action_controller/request'
|
8
|
+
if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
|
9
|
+
# rails 2.x
|
10
|
+
require "action_controller/request"
|
10
11
|
unless ActionController::Request::HTTP_METHODS.include?("patch")
|
11
12
|
ActionController::Request::HTTP_METHODS << "patch"
|
12
13
|
ActionController::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch
|
13
14
|
ActionController::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
|
14
15
|
end
|
15
16
|
|
16
|
-
elsif
|
17
|
-
|
18
|
-
|
19
|
-
require 'action_dispatch/http/request'
|
17
|
+
elsif Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
|
18
|
+
# rails 3.x
|
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,63 +24,66 @@ 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
|
-
module OAuth
|
31
|
-
|
32
|
-
|
30
|
+
module OAuth
|
31
|
+
module RequestProxy
|
32
|
+
class ActionControllerRequest < OAuth::RequestProxy::Base
|
33
|
+
proxies(defined?(::ActionDispatch::AbstractRequest) ? ::ActionDispatch::AbstractRequest : ::ActionDispatch::Request)
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
def method
|
36
|
+
request.method.to_s.upcase
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def uri
|
40
|
+
request.url
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
60
|
+
unless options[:clobber_request]
|
61
|
+
params << header_params.to_query
|
62
|
+
params << request.query_string unless query_string_blank?
|
62
63
|
|
63
|
-
|
64
|
-
params << request.raw_post
|
64
|
+
params << request.raw_post if raw_post_signature?
|
65
65
|
end
|
66
|
+
|
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" }
|
66
72
|
end
|
67
73
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
map { |p| p.split('=').map{|esc| CGI.unescape(esc)} }.
|
72
|
-
reject { |kv| kv[0] == 'oauth_signature'}
|
73
|
-
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
|
74
77
|
|
75
|
-
|
78
|
+
protected
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
def query_params
|
81
|
+
request.query_parameters
|
82
|
+
end
|
80
83
|
|
81
|
-
|
82
|
-
|
84
|
+
def request_params
|
85
|
+
request.request_parameters
|
86
|
+
end
|
83
87
|
end
|
84
|
-
|
85
88
|
end
|
86
89
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require "oauth/request_proxy/rack_request"
|
4
|
+
|
5
|
+
module OAuth
|
6
|
+
module RequestProxy
|
7
|
+
class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
|
8
|
+
proxies ::ActionDispatch::Request
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|