oauth 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oauth might be problematic. Click here for more details.

data/Manifest.txt CHANGED
@@ -16,6 +16,7 @@ lib/oauth/request_proxy.rb
16
16
  lib/oauth/request_proxy/action_controller_request.rb
17
17
  lib/oauth/request_proxy/base.rb
18
18
  lib/oauth/request_proxy/net_http.rb
19
+ lib/oauth/request_proxy/rack_request.rb
19
20
  lib/oauth/server.rb
20
21
  lib/oauth/signature.rb
21
22
  lib/oauth/signature/base.rb
@@ -43,6 +44,7 @@ test/test_helper.rb
43
44
  test/test_hmac_sha1.rb
44
45
  test/test_net_http_client.rb
45
46
  test/test_net_http_request_proxy.rb
47
+ test/test_rack_request_proxy.rb
46
48
  test/test_signature.rb
47
49
  test/test_signature_base.rb
48
50
  test/test_token.rb
data/config/hoe.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'oauth/version'
2
2
 
3
- AUTHOR = ['Pelle Braendgaard','Blaine Cook','Larry Halff','Jesse Clark'] # can also be an array of Authors
3
+ AUTHOR = ['Pelle Braendgaard','Blaine Cook','Larry Halff','Jesse Clark','Jon Crosby', 'Seth Fitzsimmons'] # can also be an array of Authors
4
4
  EMAIL = "pelleb@gmail.com"
5
5
  DESCRIPTION = "OAuth Core Ruby implementation"
6
6
  GEM_NAME = 'oauth' # what ppl will type to install your gem
@@ -2,6 +2,8 @@ require 'oauth/client/helper'
2
2
  require 'oauth/request_proxy/net_http'
3
3
 
4
4
  class Net::HTTPRequest
5
+ include OAuth::Helper
6
+
5
7
  def oauth!(http, consumer = nil, token = nil, options = {})
6
8
  options = { :request_uri => oauth_full_request_uri(http),
7
9
  :consumer => consumer,
@@ -67,6 +69,6 @@ class Net::HTTPRequest
67
69
 
68
70
  @path = uri.to_s
69
71
 
70
- @path << "&oauth_signature=#{@oauth_helper.signature}"
72
+ @path << "&oauth_signature=#{escape(@oauth_helper.signature)}"
71
73
  end
72
74
  end
@@ -14,7 +14,7 @@ module OAuth
14
14
  :access_token_path=>'/oauth/access_token',
15
15
 
16
16
  # How do we send the oauth values to the server see
17
- # http://oauth.googlecode.com/svn/spec/branches/1.0/drafts/6/spec.html#consumer_req_param for more info
17
+ # http://oauth.net/core/1.0/#consumer_req_param for more info
18
18
  #
19
19
  # Possible values:
20
20
  #
@@ -66,27 +66,32 @@ module OAuth
66
66
  @secret = consumer_secret
67
67
  end
68
68
 
69
+ # The default http method
69
70
  def http_method
70
71
  @http_method||=@options[:http_method]||:post
71
72
  end
72
73
 
74
+ # The HTTP object for the site. The HTTP Object is what you get when you do Net::HTTP.new
73
75
  def http
74
76
  @http ||= create_http
75
77
  end
76
78
 
77
- # will change
79
+ # Contains the root URI for this site
78
80
  def uri(url=nil)
79
81
  @uri||=URI.parse(url||site)
80
82
  end
81
83
 
82
- # Get a Request Token
84
+ # Makes a request to the service for a new OAuth::RequestToken
85
+ #
86
+ # @request_token=@consumer.get_request_token
87
+ #
83
88
  def get_request_token
84
89
  response=token_request(http_method,request_token_path)
85
90
  OAuth::RequestToken.new(self,response[:oauth_token],response[:oauth_token_secret])
86
91
  end
87
92
 
88
93
  # Creates, signs and performs an http request.
89
- # It's recommended to use the Token classes to set this up correctly.
94
+ # It's recommended to use the OAuth::Token classes to set this up correctly.
90
95
  # The arguments parameters are a hash or string encoded set of parameters if it's a post request as well as optional http headers.
91
96
  #
92
97
  # @consumer.request(:get,'/people',@token,{:scheme=>:query_string})
@@ -30,25 +30,6 @@ module OAuth::RequestProxy
30
30
 
31
31
  protected
32
32
 
33
- def header_params
34
- %w( X-HTTP_AUTHORIZATION Authorization HTTP_AUTHORIZATION ).each do |header|
35
- next unless request.env.include?(header)
36
-
37
- header = request.env[header]
38
- next unless header[0,6] == 'OAuth '
39
-
40
- oauth_param_string = header[6,header.length].split(/[,=]/)
41
- oauth_param_string.map! { |v| unescape(v.strip) }
42
- oauth_param_string.map! { |v| v =~ /^\".*\"$/ ? v[1..-2] : v }
43
- oauth_params = Hash[*oauth_param_string.flatten]
44
- oauth_params.reject! { |k,v| k !~ /^oauth_/ }
45
-
46
- return oauth_params
47
- end
48
-
49
- return {}
50
- end
51
-
52
33
  def query_params
53
34
  request.query_parameters
54
35
  end
@@ -57,9 +38,5 @@ module OAuth::RequestProxy
57
38
  request.request_parameters
58
39
  end
59
40
 
60
- def unescape(value)
61
- URI.unescape(value.gsub('+', '%2B'))
62
- end
63
-
64
41
  end
65
42
  end
@@ -46,5 +46,31 @@ module OAuth::RequestProxy
46
46
  def signature
47
47
  parameters['oauth_signature'] || ""
48
48
  end
49
+
50
+ protected
51
+
52
+ def header_params
53
+ %w( X-HTTP_AUTHORIZATION Authorization HTTP_AUTHORIZATION ).each do |header|
54
+ next unless request.env.include?(header)
55
+
56
+ header = request.env[header]
57
+ next unless header[0,6] == 'OAuth '
58
+
59
+ oauth_param_string = header[6,header.length].split(/[,=]/)
60
+ oauth_param_string.map! { |v| unescape(v.strip) }
61
+ oauth_param_string.map! { |v| v =~ /^\".*\"$/ ? v[1..-2] : v }
62
+ oauth_params = Hash[*oauth_param_string.flatten]
63
+ oauth_params.reject! { |k,v| k !~ /^oauth_/ }
64
+
65
+ return oauth_params
66
+ end
67
+
68
+ return {}
69
+ end
70
+
71
+ def unescape(value)
72
+ URI.unescape(value.gsub('+', '%2B'))
73
+ end
74
+
49
75
  end
50
76
  end
@@ -0,0 +1,42 @@
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.request_method
11
+ end
12
+
13
+ def uri
14
+ uri = URI.parse(request.url)
15
+ uri.query = nil
16
+ uri.to_s
17
+ end
18
+
19
+ def parameters
20
+ if options[:clobber_request]
21
+ options[:parameters] || {}
22
+ else
23
+ params = request_params.merge(query_params).merge(header_params)
24
+ params.merge(options[:parameters] || {})
25
+ end
26
+ end
27
+
28
+ def signature
29
+ parameters['oauth_signature']
30
+ end
31
+
32
+ protected
33
+
34
+ def query_params
35
+ request.GET
36
+ end
37
+
38
+ def request_params
39
+ request.params
40
+ end
41
+ end
42
+ end
data/lib/oauth/version.rb CHANGED
@@ -2,7 +2,7 @@ module Oauth #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 2
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/script/destroy CHANGED
File without changes
data/script/generate CHANGED
File without changes
data/script/txt2html CHANGED
File without changes
@@ -52,7 +52,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
52
52
  uri = URI.parse(request.path)
53
53
  assert_equal '/test', uri.path
54
54
  assert_equal nil, uri.fragment
55
- assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=1oO2izFav1GP4kEH2EskwXkCRFg=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&")
55
+ assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=1oO2izFav1GP4kEH2EskwXkCRFg%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&")
56
56
  assert_equal nil, request['authorization']
57
57
  end
58
58
 
@@ -64,7 +64,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
64
64
  uri = URI.parse(request.path)
65
65
  assert_equal '/test', uri.path
66
66
  assert_equal nil, uri.fragment
67
- assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&')
67
+ assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&')
68
68
  assert_equal nil, request.body
69
69
  assert_equal nil, request['authorization']
70
70
  end
@@ -78,7 +78,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
78
78
  uri = URI.parse(request.path)
79
79
  assert_equal '/test', uri.path
80
80
  assert_equal nil, uri.fragment
81
- assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=4kSU8Zd1blWo3W6qJH7eaRTMkg0=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&')
81
+ assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=4kSU8Zd1blWo3W6qJH7eaRTMkg0%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&')
82
82
  assert_equal "key2=value2", request.body
83
83
  assert_equal nil, request['authorization']
84
84
  end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'oauth/request_proxy/rack_request'
3
+ require 'rack/request'
4
+ require 'rack/mock'
5
+
6
+ class RackRequestProxyTest < Test::Unit::TestCase
7
+
8
+ def test_that_proxy_simple_get_request_works
9
+ request = Rack::Request.new(Rack::MockRequest.env_for('http://example.com/test?key=value'))
10
+ request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'})
11
+
12
+ expected_parameters = {'key' => 'value'}
13
+ assert_equal expected_parameters, request_proxy.parameters
14
+ assert_equal 'http://example.com/test', request_proxy.uri
15
+ assert_equal 'GET', request_proxy.method
16
+ end
17
+
18
+ def test_that_proxy_simple_post_request_works
19
+ request = Rack::Request.new(Rack::MockRequest.env_for('http://example.com/test', :method => 'POST'))
20
+ params = {'key' => 'value'}
21
+ request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
22
+
23
+ expected_parameters = {'key' => 'value'}
24
+ assert_equal expected_parameters, request_proxy.parameters
25
+ assert_equal 'http://example.com/test', request_proxy.uri
26
+ assert_equal 'POST', request_proxy.method
27
+ end
28
+
29
+ def test_that_proxy_post_and_get_request_works
30
+ request = Rack::Request.new(Rack::MockRequest.env_for('http://example.com/test?key=value', :method => 'POST', :input => 'key2=value2'))
31
+ params = {'key2' => 'value2'}
32
+ request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => params})
33
+
34
+ expected_parameters = {'key' => 'value', 'key2' => 'value2'}
35
+ assert_equal expected_parameters, request_proxy.parameters
36
+ assert_equal 'http://example.com/test', request_proxy.uri
37
+ assert_equal 'POST', request_proxy.method
38
+ end
39
+
40
+ end
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>Ruby OAuth GEM</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/oauth"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/oauth" class="numbers">0.2.2</a>
36
+ <a href="http://rubyforge.org/projects/oauth" class="numbers">0.2.3</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
 
@@ -59,7 +59,7 @@
59
59
  <p>This is a ruby library which is intended to be used in creating Ruby Consumer and Service Provider applications. It is <span class="caps">NOT</span> a Rails plugin, but could easily be used for the foundation for such a Rails plugin.</p>
60
60
 
61
61
 
62
- <p>As a matter of fact it has been pulled out from an <a href="http://code.google.com/p/oauth-plugin/">OAuth Rails Plugin</a> which in the future will require this <span class="caps">GEM</span>.</p>
62
+ <p>As a matter of fact it has been pulled out from an <a href="http://code.google.com/p/oauth-plugin/">OAuth Rails Plugin</a> which now requires this <span class="caps">GEM</span>.</p>
63
63
 
64
64
 
65
65
  <h2>Demonstration of usage</h2>
@@ -85,6 +85,12 @@ redirect_to @request_token.authorize_url</code></pre>
85
85
  <pre><code>@access_token=@request_token.get_access_token
86
86
  @photos=@access_token.get('/photos.xml')</code></pre>
87
87
 
88
+ <p>For more detailed instructions I have written this <a href="http://stakeventures.com/articles/2008/02/23/developing-oauth-clients-in-ruby">OAuth Client Tutorial</a> and <a href="http://stakeventures.com/articles/2007/11/26/how-to-turn-your-rails-site-into-an-oauth-provider">How to turn your rails site into an OAuth Provider</a>.</p>
89
+
90
+
91
+ <p>Finally be sure to check out the <a href="http://oauth.rubyforge.org/rdoc/">OAuth RDoc Manual</a>.</p>
92
+
93
+
88
94
  <h2>Documentation Wiki</h2>
89
95
 
90
96
 
@@ -123,7 +129,7 @@ redirect_to @request_token.authorize_url</code></pre>
123
129
 
124
130
  <p>Comments are welcome. Send an email to <a href="mailto:pelleb@gmail.com">Pelle Braendgaard</a> email via the <a href="http://groups.google.com/group/oauth-ruby">OAuth Ruby mailing list</a></p>
125
131
  <p class="coda">
126
- <a href="FIXME email">FIXME full name</a>, 21st January 2008<br>
132
+ <a href="FIXME email">FIXME full name</a>, 25th February 2008<br>
127
133
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
128
134
  </p>
129
135
  </div>
data/website/index.txt CHANGED
@@ -16,7 +16,7 @@ h2. The basics
16
16
 
17
17
  This is a ruby library which is intended to be used in creating Ruby Consumer and Service Provider applications. It is NOT a Rails plugin, but could easily be used for the foundation for such a Rails plugin.
18
18
 
19
- As a matter of fact it has been pulled out from an "OAuth Rails Plugin":http://code.google.com/p/oauth-plugin/ which in the future will require this GEM.
19
+ As a matter of fact it has been pulled out from an "OAuth Rails Plugin":http://code.google.com/p/oauth-plugin/ which now requires this GEM.
20
20
 
21
21
  h2. Demonstration of usage
22
22
 
@@ -37,6 +37,10 @@ When user returns create an access_token
37
37
  <pre><code>@access_token=@request_token.get_access_token
38
38
  @photos=@access_token.get('/photos.xml')</code></pre>
39
39
 
40
+ For more detailed instructions I have written this "OAuth Client Tutorial":http://stakeventures.com/articles/2008/02/23/developing-oauth-clients-in-ruby and "How to turn your rails site into an OAuth Provider ":http://stakeventures.com/articles/2007/11/26/how-to-turn-your-rails-site-into-an-oauth-provider.
41
+
42
+ Finally be sure to check out the "OAuth RDoc Manual":http://oauth.rubyforge.org/rdoc/.
43
+
40
44
  h2. Documentation Wiki
41
45
 
42
46
  There is some documentation on the Google Code project for the "OAuth Rails Plugin":http://code.google.com/p/oauth-plugin/ :
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pelle Braendgaard
8
8
  - Blaine Cook
9
9
  - Larry Halff
10
10
  - Jesse Clark
11
+ - Jon Crosby
12
+ - Seth Fitzsimmons
11
13
  autorequire:
12
14
  bindir: bin
13
15
  cert_chain: []
14
16
 
15
- date: 2008-02-22 00:00:00 -08:00
17
+ date: 2008-04-27 00:00:00 -07:00
16
18
  default_executable:
17
19
  dependencies:
18
20
  - !ruby/object:Gem::Dependency
@@ -55,6 +57,7 @@ files:
55
57
  - lib/oauth/request_proxy/action_controller_request.rb
56
58
  - lib/oauth/request_proxy/base.rb
57
59
  - lib/oauth/request_proxy/net_http.rb
60
+ - lib/oauth/request_proxy/rack_request.rb
58
61
  - lib/oauth/server.rb
59
62
  - lib/oauth/signature.rb
60
63
  - lib/oauth/signature/base.rb
@@ -82,6 +85,7 @@ files:
82
85
  - test/test_hmac_sha1.rb
83
86
  - test/test_net_http_client.rb
84
87
  - test/test_net_http_request_proxy.rb
88
+ - test/test_rack_request_proxy.rb
85
89
  - test/test_signature.rb
86
90
  - test/test_signature_base.rb
87
91
  - test/test_token.rb
@@ -113,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
117
  requirements: []
114
118
 
115
119
  rubyforge_project: oauth
116
- rubygems_version: 1.0.1
120
+ rubygems_version: 1.1.1
117
121
  signing_key:
118
122
  specification_version: 2
119
123
  summary: OAuth Core Ruby implementation
@@ -124,6 +128,7 @@ test_files:
124
128
  - test/test_hmac_sha1.rb
125
129
  - test/test_net_http_client.rb
126
130
  - test/test_net_http_request_proxy.rb
131
+ - test/test_rack_request_proxy.rb
127
132
  - test/test_server.rb
128
133
  - test/test_signature.rb
129
134
  - test/test_signature_base.rb