oauth_weshays 0.4.8.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +15 -0
  2. data/.gemtest +0 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +47 -0
  5. data/HISTORY +173 -0
  6. data/LICENSE +20 -0
  7. data/README.rdoc +75 -0
  8. data/Rakefile +37 -0
  9. data/TODO +32 -0
  10. data/bin/oauth +5 -0
  11. data/examples/yql.rb +44 -0
  12. data/lib/digest/hmac.rb +104 -0
  13. data/lib/oauth/cli.rb +378 -0
  14. data/lib/oauth/client/action_controller_request.rb +65 -0
  15. data/lib/oauth/client/em_http.rb +120 -0
  16. data/lib/oauth/client/helper.rb +91 -0
  17. data/lib/oauth/client/net_http.rb +120 -0
  18. data/lib/oauth/client.rb +4 -0
  19. data/lib/oauth/consumer.rb +389 -0
  20. data/lib/oauth/core_ext.rb +31 -0
  21. data/lib/oauth/errors/error.rb +4 -0
  22. data/lib/oauth/errors/problem.rb +14 -0
  23. data/lib/oauth/errors/unauthorized.rb +12 -0
  24. data/lib/oauth/errors.rb +3 -0
  25. data/lib/oauth/helper.rb +109 -0
  26. data/lib/oauth/oauth.rb +13 -0
  27. data/lib/oauth/oauth_test_helper.rb +25 -0
  28. data/lib/oauth/request_proxy/action_controller_request.rb +62 -0
  29. data/lib/oauth/request_proxy/base.rb +174 -0
  30. data/lib/oauth/request_proxy/curb_request.rb +55 -0
  31. data/lib/oauth/request_proxy/em_http_request.rb +66 -0
  32. data/lib/oauth/request_proxy/jabber_request.rb +41 -0
  33. data/lib/oauth/request_proxy/mock_request.rb +44 -0
  34. data/lib/oauth/request_proxy/net_http.rb +73 -0
  35. data/lib/oauth/request_proxy/rack_request.rb +44 -0
  36. data/lib/oauth/request_proxy/typhoeus_request.rb +53 -0
  37. data/lib/oauth/request_proxy.rb +24 -0
  38. data/lib/oauth/server.rb +66 -0
  39. data/lib/oauth/signature/base.rb +110 -0
  40. data/lib/oauth/signature/hmac/base.rb +15 -0
  41. data/lib/oauth/signature/hmac/md5.rb +8 -0
  42. data/lib/oauth/signature/hmac/rmd160.rb +8 -0
  43. data/lib/oauth/signature/hmac/sha1.rb +9 -0
  44. data/lib/oauth/signature/hmac/sha2.rb +8 -0
  45. data/lib/oauth/signature/md5.rb +13 -0
  46. data/lib/oauth/signature/plaintext.rb +23 -0
  47. data/lib/oauth/signature/rsa/sha1.rb +46 -0
  48. data/lib/oauth/signature/sha1.rb +13 -0
  49. data/lib/oauth/signature.rb +45 -0
  50. data/lib/oauth/token.rb +7 -0
  51. data/lib/oauth/tokens/access_token.rb +71 -0
  52. data/lib/oauth/tokens/consumer_token.rb +33 -0
  53. data/lib/oauth/tokens/request_token.rb +32 -0
  54. data/lib/oauth/tokens/server_token.rb +9 -0
  55. data/lib/oauth/tokens/token.rb +17 -0
  56. data/lib/oauth.rb +13 -0
  57. data/oauth.gemspec +148 -0
  58. data/tasks/deployment.rake +34 -0
  59. data/tasks/environment.rake +7 -0
  60. data/tasks/website.rake +17 -0
  61. data/test/cases/oauth_case.rb +19 -0
  62. data/test/cases/spec/1_0-final/test_construct_request_url.rb +62 -0
  63. data/test/cases/spec/1_0-final/test_normalize_request_parameters.rb +88 -0
  64. data/test/cases/spec/1_0-final/test_parameter_encodings.rb +86 -0
  65. data/test/cases/spec/1_0-final/test_signature_base_strings.rb +77 -0
  66. data/test/integration/consumer_test.rb +307 -0
  67. data/test/keys/rsa.cert +11 -0
  68. data/test/keys/rsa.pem +16 -0
  69. data/test/test_access_token.rb +26 -0
  70. data/test/test_action_controller_request_proxy.rb +133 -0
  71. data/test/test_consumer.rb +220 -0
  72. data/test/test_curb_request_proxy.rb +77 -0
  73. data/test/test_em_http_client.rb +80 -0
  74. data/test/test_em_http_request_proxy.rb +115 -0
  75. data/test/test_helper.rb +28 -0
  76. data/test/test_hmac_sha1.rb +20 -0
  77. data/test/test_net_http_client.rb +292 -0
  78. data/test/test_net_http_request_proxy.rb +72 -0
  79. data/test/test_oauth_helper.rb +94 -0
  80. data/test/test_rack_request_proxy.rb +40 -0
  81. data/test/test_request_token.rb +51 -0
  82. data/test/test_rsa_sha1.rb +59 -0
  83. data/test/test_server.rb +40 -0
  84. data/test/test_signature.rb +22 -0
  85. data/test/test_signature_base.rb +32 -0
  86. data/test/test_signature_plain_text.rb +31 -0
  87. data/test/test_token.rb +14 -0
  88. data/test/test_typhoeus_request_proxy.rb +80 -0
  89. metadata +252 -0
@@ -0,0 +1,13 @@
1
+ module OAuth
2
+ # request tokens are passed between the consumer and the provider out of
3
+ # band (i.e. callbacks cannot be used), per section 6.1.1
4
+ OUT_OF_BAND = "oob"
5
+
6
+ # required parameters, per sections 6.1.1, 6.3.1, and 7
7
+ PARAMETERS = %w(oauth_callback oauth_consumer_key oauth_token
8
+ oauth_signature_method oauth_timestamp oauth_nonce oauth_verifier
9
+ oauth_version oauth_signature oauth_body_hash)
10
+
11
+ # reserved character regexp, per section 5.1
12
+ RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
13
+ end
@@ -0,0 +1,25 @@
1
+ require 'action_controller'
2
+ require 'action_controller/test_process'
3
+
4
+ module OAuth
5
+ module OAuthTestHelper
6
+ def mock_incoming_request_with_query(request)
7
+ incoming = ActionController::TestRequest.new(request.to_hash)
8
+ incoming.request_uri = request.path
9
+ incoming.host = request.uri.host
10
+ incoming.env["SERVER_PORT"] = request.uri.port
11
+ incoming.env['REQUEST_METHOD'] = request.http_method
12
+ incoming
13
+ end
14
+
15
+ def mock_incoming_request_with_authorize_header(request)
16
+ incoming = ActionController::TestRequest.new
17
+ incoming.request_uri = request.path
18
+ incoming.host = request.uri.host
19
+ incoming.env["HTTP_AUTHORIZATION"] = request.to_auth_string
20
+ incoming.env["SERVER_PORT"] = request.uri.port
21
+ incoming.env['REQUEST_METHOD'] = request.http_method
22
+ incoming
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,62 @@
1
+ require 'active_support'
2
+ require 'action_controller'
3
+ require 'action_controller/request'
4
+ require 'uri'
5
+
6
+ module OAuth::RequestProxy
7
+ class ActionControllerRequest < OAuth::RequestProxy::Base
8
+ proxies(defined?(ActionController::AbstractRequest) ? ActionController::AbstractRequest : ActionController::Request)
9
+
10
+ def method
11
+ request.method.to_s.upcase
12
+ end
13
+
14
+ def uri
15
+ request.url
16
+ end
17
+
18
+ def parameters
19
+ if options[:clobber_request]
20
+ options[:parameters] || {}
21
+ else
22
+ params = request_params.merge(query_params).merge(header_params)
23
+ params.stringify_keys! if params.respond_to?(:stringify_keys!)
24
+ params.merge(options[:parameters] || {})
25
+ end
26
+ end
27
+
28
+ # Override from OAuth::RequestProxy::Base to avoid roundtrip
29
+ # conversion to Hash or Array and thus preserve the original
30
+ # parameter names
31
+ def parameters_for_signature
32
+ params = []
33
+ params << options[:parameters].to_query if options[:parameters]
34
+
35
+ unless options[:clobber_request]
36
+ params << header_params.to_query
37
+ params << request.query_string unless query_string_blank?
38
+
39
+ if request.post? && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
40
+ params << request.raw_post
41
+ end
42
+ end
43
+
44
+ params.
45
+ join('&').split('&').
46
+ reject(&:blank?).
47
+ map { |p| p.split('=').map{|esc| CGI.unescape(esc)} }.
48
+ reject { |kv| kv[0] == 'oauth_signature'}
49
+ end
50
+
51
+ protected
52
+
53
+ def query_params
54
+ request.query_parameters
55
+ end
56
+
57
+ def request_params
58
+ request.request_parameters
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,174 @@
1
+ require 'oauth/request_proxy'
2
+ require 'oauth/helper'
3
+
4
+ module OAuth::RequestProxy
5
+ class Base
6
+ include OAuth::Helper
7
+
8
+ def self.proxies(klass)
9
+ OAuth::RequestProxy.available_proxies[klass] = self
10
+ end
11
+
12
+ attr_accessor :request, :options, :unsigned_parameters
13
+
14
+ def initialize(request, options = {})
15
+ @request = request
16
+ @unsigned_parameters = (options[:unsigned_parameters] || []).map {|param| param.to_s}
17
+ @options = options
18
+ end
19
+
20
+ ## OAuth parameters
21
+
22
+ def oauth_callback
23
+ parameters['oauth_callback']
24
+ end
25
+
26
+ def oauth_consumer_key
27
+ parameters['oauth_consumer_key']
28
+ end
29
+
30
+ def oauth_nonce
31
+ parameters['oauth_nonce']
32
+ end
33
+
34
+ def oauth_signature
35
+ # TODO can this be nil?
36
+ [parameters['oauth_signature']].flatten.first || ""
37
+ end
38
+
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']
45
+ end
46
+ end
47
+
48
+ def oauth_timestamp
49
+ parameters['oauth_timestamp']
50
+ end
51
+
52
+ def oauth_token
53
+ parameters['oauth_token']
54
+ end
55
+
56
+ def oauth_verifier
57
+ parameters['oauth_verifier']
58
+ end
59
+
60
+ def oauth_version
61
+ parameters["oauth_version"]
62
+ end
63
+
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
71
+
72
+ ## Parameter accessors
73
+
74
+ def parameters
75
+ raise NotImplementedError, "Must be implemented by subclasses"
76
+ end
77
+
78
+ def parameters_for_signature
79
+ parameters.reject { |k,v| k == "oauth_signature" || unsigned_parameters.include?(k)}
80
+ end
81
+
82
+ def oauth_parameters
83
+ parameters.select { |k,v| OAuth::PARAMETERS.include?(k) }.reject { |k,v| v == "" }
84
+ end
85
+
86
+ def non_oauth_parameters
87
+ parameters.reject { |k,v| OAuth::PARAMETERS.include?(k) }
88
+ end
89
+
90
+ # See 9.1.2 in specs
91
+ def normalized_uri
92
+ u = URI.parse(uri)
93
+ "#{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 : '/'}"
94
+ end
95
+
96
+ # See 9.1.1. in specs Normalize Request Parameters
97
+ def normalized_parameters
98
+ normalize(parameters_for_signature)
99
+ end
100
+
101
+ def sign(options = {})
102
+ OAuth::Signature.sign(self, options)
103
+ end
104
+
105
+ def sign!(options = {})
106
+ parameters["oauth_signature"] = sign(options)
107
+ @signed = true
108
+ signature
109
+ end
110
+
111
+ # See 9.1 in specs
112
+ def signature_base_string
113
+ base = [method, normalized_uri, normalized_parameters]
114
+ base.map { |v| escape(v) }.join("&")
115
+ end
116
+
117
+ # Has this request been signed yet?
118
+ def signed?
119
+ @signed
120
+ end
121
+
122
+ # URI, including OAuth parameters
123
+ def signed_uri(with_oauth = true)
124
+ if signed?
125
+ if with_oauth
126
+ params = parameters
127
+ else
128
+ params = non_oauth_parameters
129
+ end
130
+
131
+ [uri, normalize(params)] * "?"
132
+ else
133
+ STDERR.puts "This request has not yet been signed!"
134
+ end
135
+ end
136
+
137
+ # Authorization header for OAuth
138
+ def oauth_header(options = {})
139
+ header_params_str = oauth_parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')
140
+
141
+ realm = "realm=\"#{options[:realm]}\", " if options[:realm]
142
+ "OAuth #{realm}#{header_params_str}"
143
+ end
144
+
145
+ def query_string_blank?
146
+ if uri = request.request_uri
147
+ uri.split('?', 2)[1].nil?
148
+ else
149
+ request.query_string.blank?
150
+ end
151
+ end
152
+
153
+ protected
154
+
155
+ def header_params
156
+ %w( X-HTTP_AUTHORIZATION Authorization HTTP_AUTHORIZATION ).each do |header|
157
+ next unless request.env.include?(header)
158
+
159
+ header = request.env[header]
160
+ next unless header[0,6] == 'OAuth '
161
+
162
+ # parse the header into a Hash
163
+ oauth_params = OAuth::Helper.parse_header(header)
164
+
165
+ # remove non-OAuth parameters
166
+ oauth_params.reject! { |k,v| k !~ /^oauth_/ }
167
+
168
+ return oauth_params
169
+ end
170
+
171
+ return {}
172
+ end
173
+ end
174
+ end
@@ -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'].to_s.downcase.start_with?("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,66 @@
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.start_with?("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
@@ -0,0 +1,41 @@
1
+ require 'xmpp4r'
2
+ require 'oauth/request_proxy/base'
3
+
4
+ module OAuth
5
+ module RequestProxy
6
+ class JabberRequest < OAuth::RequestProxy::Base
7
+ proxies Jabber::Iq
8
+ proxies Jabber::Presence
9
+ proxies Jabber::Message
10
+
11
+ def parameters
12
+ return @params if @params
13
+
14
+ @params = {}
15
+
16
+ oauth = @request.get_elements('//oauth').first
17
+ return @params unless oauth
18
+
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)
22
+ @params[param] = element.text
23
+ end
24
+
25
+ @params
26
+ end
27
+
28
+ def method
29
+ @request.name
30
+ end
31
+
32
+ def uri
33
+ [@request.from.strip.to_s, @request.to.strip.to_s].join("&")
34
+ end
35
+
36
+ def normalized_uri
37
+ uri
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ require 'oauth/request_proxy/base'
2
+
3
+ module OAuth
4
+ module RequestProxy
5
+ # RequestProxy for Hashes to facilitate simpler signature creation.
6
+ # Usage:
7
+ # request = OAuth::RequestProxy.proxy \
8
+ # "method" => "iq",
9
+ # "uri" => [from, to] * "&",
10
+ # "parameters" => {
11
+ # "oauth_consumer_key" => oauth_consumer_key,
12
+ # "oauth_token" => oauth_token,
13
+ # "oauth_signature_method" => "HMAC-SHA1"
14
+ # }
15
+ #
16
+ # signature = OAuth::Signature.sign \
17
+ # request,
18
+ # :consumer_secret => oauth_consumer_secret,
19
+ # :token_secret => oauth_token_secret,
20
+ class MockRequest < OAuth::RequestProxy::Base
21
+ proxies Hash
22
+
23
+ def parameters
24
+ @request["parameters"]
25
+ end
26
+
27
+ def method
28
+ @request["method"]
29
+ end
30
+
31
+ def normalized_uri
32
+ super
33
+ rescue
34
+ # if this is a non-standard URI, it may not parse properly
35
+ # in that case, assume that it's already been normalized
36
+ uri
37
+ end
38
+
39
+ def uri
40
+ @request["uri"]
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,73 @@
1
+ require 'oauth/request_proxy/base'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'cgi'
5
+
6
+ module OAuth::RequestProxy::Net
7
+ module HTTP
8
+ class HTTPRequest < OAuth::RequestProxy::Base
9
+ proxies ::Net::HTTPGenericRequest
10
+
11
+ def method
12
+ request.method
13
+ end
14
+
15
+ def uri
16
+ options[:uri].to_s
17
+ end
18
+
19
+ def parameters
20
+ if options[:clobber_request]
21
+ options[:parameters]
22
+ else
23
+ all_parameters
24
+ end
25
+ end
26
+
27
+ def body
28
+ request.body
29
+ end
30
+
31
+ private
32
+
33
+ def all_parameters
34
+ request_params = CGI.parse(query_string)
35
+ # request_params.each{|k,v| request_params[k] = [nil] if v == []}
36
+
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]
43
+ end
44
+ end
45
+ end
46
+ request_params
47
+ end
48
+
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
54
+
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
58
+
59
+ def query_params
60
+ URI.parse(request.path).query
61
+ end
62
+
63
+ def post_params
64
+ request.body
65
+ end
66
+
67
+ def auth_header_params
68
+ return nil unless request['Authorization'] && request['Authorization'][0,5] == 'OAuth'
69
+ auth_params = request['Authorization']
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,44 @@
1
+ require 'oauth/request_proxy/base'
2
+ require 'uri'
3
+ require 'rack'
4
+
5
+ module OAuth::RequestProxy
6
+ class RackRequest < OAuth::RequestProxy::Base
7
+ proxies Rack::Request
8
+
9
+ def method
10
+ request.env["rack.methodoverride.original_method"] || request.request_method
11
+ end
12
+
13
+ def uri
14
+ request.url
15
+ end
16
+
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] || {})
23
+ end
24
+ end
25
+
26
+ def signature
27
+ parameters['oauth_signature']
28
+ end
29
+
30
+ protected
31
+
32
+ def query_params
33
+ request.GET
34
+ end
35
+
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
+ {}
41
+ end
42
+ end
43
+ end
44
+ 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.options[: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
+ 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'
47
+ OAuth::Helper.stringify_keys(request.params || {})
48
+ else
49
+ {}
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ module OAuth
2
+ module RequestProxy
3
+ def self.available_proxies #:nodoc:
4
+ @available_proxies ||= {}
5
+ end
6
+
7
+ def self.proxy(request, options = {})
8
+ return request if request.kind_of?(OAuth::RequestProxy::Base)
9
+
10
+ klass = available_proxies[request.class]
11
+
12
+ # Search for possible superclass matches.
13
+ if klass.nil?
14
+ request_parent = available_proxies.keys.find { |rc| request.kind_of?(rc) }
15
+ klass = available_proxies[request_parent]
16
+ end
17
+
18
+ raise UnknownRequestType, request.class.to_s unless klass
19
+ klass.new(request, options)
20
+ end
21
+
22
+ class UnknownRequestType < Exception; end
23
+ end
24
+ end