oauth 0.3.6 → 0.3.7.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.
Potentially problematic release.
This version of oauth might be problematic. Click here for more details.
- data/.gitignore +1 -0
- data/History.txt +16 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +13 -0
- data/Rakefile +27 -27
- data/TODO +1 -0
- data/lib/digest/hmac.rb +104 -0
- data/lib/oauth.rb +5 -1
- data/lib/oauth/client/action_controller_request.rb +1 -1
- data/lib/oauth/client/em_http.rb +94 -0
- data/lib/oauth/client/helper.rb +7 -4
- data/lib/oauth/client/net_http.rb +9 -6
- data/lib/oauth/consumer.rb +45 -25
- data/lib/oauth/core_ext.rb +31 -0
- data/lib/oauth/helper.rb +11 -1
- data/lib/oauth/request_proxy/base.rb +4 -3
- data/lib/oauth/request_proxy/curb_request.rb +55 -0
- data/lib/oauth/request_proxy/em_http_request.rb +67 -0
- data/lib/oauth/request_proxy/net_http.rb +9 -6
- data/lib/oauth/request_proxy/typhoeus_request.rb +53 -0
- data/lib/oauth/signature.rb +4 -1
- data/lib/oauth/signature/base.rb +9 -3
- data/lib/oauth/signature/hmac/base.rb +5 -2
- data/lib/oauth/signature/hmac/md5.rb +1 -2
- data/lib/oauth/signature/hmac/rmd160.rb +1 -2
- data/lib/oauth/signature/hmac/sha1.rb +2 -3
- data/lib/oauth/signature/hmac/sha2.rb +1 -2
- data/lib/oauth/signature/plaintext.rb +2 -2
- data/lib/oauth/version.rb +1 -1
- data/oauth.gemspec +157 -27
- data/test/integration/consumer_test.rb +304 -0
- data/test/test_action_controller_request_proxy.rb +4 -1
- data/test/test_consumer.rb +51 -254
- data/test/test_curb_request_proxy.rb +69 -0
- data/test/test_em_http_client.rb +74 -0
- data/test/test_em_http_request_proxy.rb +107 -0
- data/test/test_helper.rb +15 -9
- data/test/test_net_http_client.rb +59 -5
- data/test/test_net_http_request_proxy.rb +1 -1
- data/test/test_signature.rb +6 -3
- data/test/test_typhoeus_request_proxy.rb +73 -0
- data/website/index.html +2 -2
- metadata +43 -25
@@ -0,0 +1,31 @@
|
|
1
|
+
# these are to backport methods from 1.8.7/1.9.1 to 1.8.6
|
2
|
+
|
3
|
+
class Object
|
4
|
+
|
5
|
+
unless method_defined?(:tap)
|
6
|
+
def tap
|
7
|
+
yield self
|
8
|
+
self
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class String
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
unless method_defined?(:bytesize)
|
19
|
+
def bytesize
|
20
|
+
self.size
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
unless method_defined?(:bytes)
|
25
|
+
def bytes
|
26
|
+
require 'enumerator'
|
27
|
+
Enumerable::Enumerator.new(self, :each_byte)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/oauth/helper.rb
CHANGED
@@ -10,6 +10,8 @@ module OAuth
|
|
10
10
|
# See Also: {OAuth core spec version 1.0, section 5.1}[http://oauth.net/core/1.0#rfc.section.5.1]
|
11
11
|
def escape(value)
|
12
12
|
URI::escape(value.to_s, OAuth::RESERVED_CHARACTERS)
|
13
|
+
rescue ArgumentError
|
14
|
+
URI::escape(value.to_s.force_encoding(Encoding::UTF_8), OAuth::RESERVED_CHARACTERS)
|
13
15
|
end
|
14
16
|
|
15
17
|
# Generate a random key of up to +size+ bytes. The value returned is Base64 encoded with non-word
|
@@ -74,5 +76,13 @@ module OAuth
|
|
74
76
|
def unescape(value)
|
75
77
|
URI.unescape(value.gsub('+', '%2B'))
|
76
78
|
end
|
79
|
+
|
80
|
+
def stringify_keys(hash)
|
81
|
+
new_h = {}
|
82
|
+
hash.each do |k, v|
|
83
|
+
new_h[k.to_s] = v.is_a?(Hash) ? stringify_keys(v) : v
|
84
|
+
end
|
85
|
+
new_h
|
86
|
+
end
|
77
87
|
end
|
78
|
-
end
|
88
|
+
end
|
@@ -9,10 +9,11 @@ module OAuth::RequestProxy
|
|
9
9
|
OAuth::RequestProxy.available_proxies[klass] = self
|
10
10
|
end
|
11
11
|
|
12
|
-
attr_accessor :request, :options
|
12
|
+
attr_accessor :request, :options, :unsigned_parameters
|
13
13
|
|
14
14
|
def initialize(request, options = {})
|
15
15
|
@request = request
|
16
|
+
@unsigned_parameters = (options[:unsigned_parameters] || []).map {|param| param.to_s}
|
16
17
|
@options = options
|
17
18
|
end
|
18
19
|
|
@@ -32,7 +33,7 @@ module OAuth::RequestProxy
|
|
32
33
|
|
33
34
|
def oauth_signature
|
34
35
|
# TODO can this be nil?
|
35
|
-
parameters['oauth_signature'] || ""
|
36
|
+
[parameters['oauth_signature']].flatten.first || ""
|
36
37
|
end
|
37
38
|
|
38
39
|
def oauth_signature_method
|
@@ -75,7 +76,7 @@ module OAuth::RequestProxy
|
|
75
76
|
end
|
76
77
|
|
77
78
|
def parameters_for_signature
|
78
|
-
parameters.reject { |k,v| k == "oauth_signature" }
|
79
|
+
parameters.reject { |k,v| k == "oauth_signature" || unsigned_parameters.include?(k)}
|
79
80
|
end
|
80
81
|
|
81
82
|
def oauth_parameters
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'oauth/request_proxy/base'
|
2
|
+
require 'curb'
|
3
|
+
require 'uri'
|
4
|
+
require 'cgi'
|
5
|
+
|
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
|
21
|
+
|
22
|
+
def uri
|
23
|
+
options[:uri].to_s
|
24
|
+
end
|
25
|
+
|
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
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def query_parameters
|
37
|
+
query = URI.parse(request.url).query
|
38
|
+
return(query ? CGI.parse(query) : {})
|
39
|
+
end
|
40
|
+
|
41
|
+
def post_parameters
|
42
|
+
post_body = {}
|
43
|
+
|
44
|
+
# Post params are only used if posting form data
|
45
|
+
if (request.headers['Content-Type'] && request.headers['Content-Type'].downcase == 'application/x-www-form-urlencoded')
|
46
|
+
|
47
|
+
request.post_body.split("&").each do |str|
|
48
|
+
param = str.split("=")
|
49
|
+
post_body[param[0]] = param[1]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
post_body
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'oauth/request_proxy/base'
|
2
|
+
# em-http also uses adddressable so there is no need to require uri.
|
3
|
+
require 'em-http'
|
4
|
+
require 'cgi'
|
5
|
+
|
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
|
15
|
+
|
16
|
+
def method
|
17
|
+
request.method
|
18
|
+
end
|
19
|
+
|
20
|
+
def uri
|
21
|
+
request.normalize_uri.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def parameters
|
25
|
+
if options[:clobber_request]
|
26
|
+
options[:parameters]
|
27
|
+
else
|
28
|
+
all_parameters
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def all_parameters
|
35
|
+
merged_parameters({}, post_parameters, query_parameters, options[:parameters])
|
36
|
+
end
|
37
|
+
|
38
|
+
def query_parameters
|
39
|
+
CGI.parse(request.normalize_uri.query.to_s)
|
40
|
+
end
|
41
|
+
|
42
|
+
def post_parameters
|
43
|
+
headers = request.options[:head] || {}
|
44
|
+
form_encoded = headers['Content-Type'].to_s.downcase == 'application/x-www-form-urlencoded'
|
45
|
+
if ['POST', 'PUT'].include?(method) && form_encoded
|
46
|
+
CGI.parse(request.normalize_body.to_s)
|
47
|
+
else
|
48
|
+
{}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def merged_parameters(params, *extra_params)
|
53
|
+
extra_params.compact.each do |params_pairs|
|
54
|
+
params_pairs.each_pair do |key, value|
|
55
|
+
if params.has_key?(key)
|
56
|
+
params[key] += value
|
57
|
+
else
|
58
|
+
params[key] = [value].flatten
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
params
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -13,8 +13,7 @@ module OAuth::RequestProxy::Net
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def uri
|
16
|
-
|
17
|
-
uri.to_s
|
16
|
+
options[:uri].to_s
|
18
17
|
end
|
19
18
|
|
20
19
|
def parameters
|
@@ -29,12 +28,13 @@ module OAuth::RequestProxy::Net
|
|
29
28
|
|
30
29
|
def all_parameters
|
31
30
|
request_params = CGI.parse(query_string)
|
31
|
+
|
32
32
|
if options[:parameters]
|
33
33
|
options[:parameters].each do |k,v|
|
34
|
-
if request_params.has_key?(k)
|
34
|
+
if request_params.has_key?(k) && v
|
35
35
|
request_params[k] << v
|
36
36
|
else
|
37
|
-
request_params[k] = [v]
|
37
|
+
request_params[k] = [v]
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -43,11 +43,14 @@ module OAuth::RequestProxy::Net
|
|
43
43
|
|
44
44
|
def query_string
|
45
45
|
params = [ query_params, auth_header_params ]
|
46
|
-
|
47
|
-
params << post_params if method.to_s.upcase == 'POST' && is_form_urlencoded
|
46
|
+
params << post_params if method.to_s.upcase == 'POST' && form_url_encoded?
|
48
47
|
params.compact.join('&')
|
49
48
|
end
|
50
49
|
|
50
|
+
def form_url_encoded?
|
51
|
+
request['Content-Type'] != nil && request['Content-Type'].downcase == 'application/x-www-form-urlencoded'
|
52
|
+
end
|
53
|
+
|
51
54
|
def query_params
|
52
55
|
URI.parse(request.path).query
|
53
56
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'oauth/request_proxy/base'
|
2
|
+
require 'typhoeus'
|
3
|
+
require 'typhoeus/request'
|
4
|
+
require 'uri'
|
5
|
+
require 'cgi'
|
6
|
+
|
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.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.to_s.upcase
|
23
|
+
end
|
24
|
+
|
25
|
+
def uri
|
26
|
+
options[:uri].to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def parameters
|
30
|
+
if options[:clobber_request]
|
31
|
+
options[:parameters]
|
32
|
+
else
|
33
|
+
post_parameters.merge(query_parameters).merge(options[:parameters] || {})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def query_parameters
|
40
|
+
query = URI.parse(request.url).query
|
41
|
+
return(query ? CGI.parse(query) : {})
|
42
|
+
end
|
43
|
+
|
44
|
+
def post_parameters
|
45
|
+
# Post params are only used if posting form data
|
46
|
+
if(method == 'POST' && request.headers['Content-Type'] && request.headers['Content-Type'].downcase == 'application/x-www-form-urlencoded')
|
47
|
+
request.body || {}
|
48
|
+
else
|
49
|
+
{}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/oauth/signature.rb
CHANGED
@@ -10,7 +10,10 @@ module OAuth
|
|
10
10
|
# Raises UnknownSignatureMethod exception if the signature method is unknown.
|
11
11
|
def self.build(request, options = {}, &block)
|
12
12
|
request = OAuth::RequestProxy.proxy(request, options)
|
13
|
-
klass = available_methods[
|
13
|
+
klass = available_methods[
|
14
|
+
(request.signature_method ||
|
15
|
+
((c = request.options[:consumer]) && c.options[:signature_method]) ||
|
16
|
+
"").downcase]
|
14
17
|
raise UnknownSignatureMethod, request.signature_method unless klass
|
15
18
|
klass.new(request, options, &block)
|
16
19
|
end
|
data/lib/oauth/signature/base.rb
CHANGED
@@ -10,14 +10,21 @@ module OAuth::Signature
|
|
10
10
|
attr_accessor :options
|
11
11
|
attr_reader :token_secret, :consumer_secret, :request
|
12
12
|
|
13
|
-
def self.implements(signature_method)
|
14
|
-
|
13
|
+
def self.implements(signature_method = nil)
|
14
|
+
return @implements if signature_method.nil?
|
15
|
+
@implements = signature_method
|
16
|
+
OAuth::Signature.available_methods[@implements] = self
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.digest_class(digest_class = nil)
|
18
20
|
return @digest_class if digest_class.nil?
|
19
21
|
@digest_class = digest_class
|
20
22
|
end
|
23
|
+
|
24
|
+
def self.digest_klass(digest_klass = nil)
|
25
|
+
return @digest_klass if digest_klass.nil?
|
26
|
+
@digest_klass = digest_klass
|
27
|
+
end
|
21
28
|
|
22
29
|
def initialize(request, options = {}, &block)
|
23
30
|
raise TypeError unless request.kind_of?(OAuth::RequestProxy::Base)
|
@@ -38,7 +45,6 @@ module OAuth::Signature
|
|
38
45
|
# presence of :token_secret option will override any Token that's provided
|
39
46
|
@token_secret = options[:token_secret] if options[:token_secret]
|
40
47
|
|
41
|
-
|
42
48
|
# override secrets based on the values returned from the block (if any)
|
43
49
|
if block_given?
|
44
50
|
# consumer secret and token secret need to be looked up based on pieces of the request
|
@@ -1,12 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
require 'oauth/signature/base'
|
4
|
+
require 'digest/hmac'
|
2
5
|
|
3
6
|
module OAuth::Signature::HMAC
|
4
7
|
class Base < OAuth::Signature::Base
|
5
8
|
|
6
9
|
private
|
7
|
-
|
8
10
|
def digest
|
9
|
-
self.class.digest_class.
|
11
|
+
self.class.digest_class Object.module_eval("::Digest::#{self.class.digest_klass}")
|
12
|
+
Digest::HMAC.digest(signature_base_string, secret, self.class.digest_class)
|
10
13
|
end
|
11
14
|
end
|
12
15
|
end
|
@@ -9,7 +9,7 @@ module OAuth::Signature
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def ==(cmp_signature)
|
12
|
-
signature ==
|
12
|
+
signature.to_s == cmp_signature.to_s
|
13
13
|
end
|
14
14
|
|
15
15
|
def signature_base_string
|
@@ -17,7 +17,7 @@ module OAuth::Signature
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def secret
|
20
|
-
|
20
|
+
super
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/oauth/version.rb
CHANGED