Skip to content

Commit

Permalink
Added support for proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhuss authored and mojodna committed May 26, 2009
1 parent b0fc4dd commit 048c33f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/oauth/consumer.rb
Expand Up @@ -25,6 +25,7 @@ class Consumer
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/access_token',

:proxy => nil,
# How do we send the oauth values to the server see
# http://oauth.net/core/1.0/#consumer_req_param for more info
#
Expand Down Expand Up @@ -254,6 +255,10 @@ def access_token_url?
@options.has_key?(:access_token_url)
end

def proxy
@options[:proxy]
end

protected

# Instantiates the http object
Expand All @@ -264,7 +269,12 @@ def create_http(_url = nil)
our_uri = URI.parse(_url)
end

http_object = Net::HTTP.new(our_uri.host, our_uri.port)
if proxy.nil?
http_object = Net::HTTP.new(our_uri.host, our_uri.port)
else
proxy_uri = proxy.is_a?(URI) ? proxy : URI.parse(proxy)
http_object = Net::HTTP.new(our_uri.host, our_uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
end

http_object.use_ssl = (our_uri.scheme == 'https')

Expand Down
1 change: 1 addition & 0 deletions lib/oauth/request_proxy/action_controller_request.rb
@@ -1,4 +1,5 @@
require 'active_support'
require 'action_controller'
require 'action_controller/request'
require 'oauth/request_proxy/base'
require 'uri'
Expand Down
3 changes: 3 additions & 0 deletions test/test_consumer.rb
Expand Up @@ -13,6 +13,7 @@ def setup
'consumer_key_86cad9', '5888bf0345e5d237',
{
:site=>"http://blabla.bla",
:proxy=>"http://user:password@proxy.bla:8080",
:request_token_path=>"/oauth/example/request_token.php",
:access_token_path=>"/oauth/example/access_token.php",
:authorize_path=>"/oauth/example/authorize.php",
Expand All @@ -31,6 +32,7 @@ def test_initializer
assert_equal "consumer_key_86cad9",@consumer.key
assert_equal "5888bf0345e5d237",@consumer.secret
assert_equal "http://blabla.bla",@consumer.site
assert_equal "http://user:password@proxy.bla:8080",@consumer.proxy
assert_equal "/oauth/example/request_token.php",@consumer.request_token_path
assert_equal "/oauth/example/access_token.php",@consumer.access_token_path
assert_equal "http://blabla.bla/oauth/example/request_token.php",@consumer.request_token_url
Expand All @@ -50,6 +52,7 @@ def test_defaults
assert_equal "key",@consumer.key
assert_equal "secret",@consumer.secret
assert_equal "http://twitter.com",@consumer.site
assert_nil @consumer.proxy
assert_equal "/oauth/request_token",@consumer.request_token_path
assert_equal "/oauth/access_token",@consumer.access_token_path
assert_equal "http://twitter.com/oauth/request_token",@consumer.request_token_url
Expand Down

0 comments on commit 048c33f

Please sign in to comment.