mojodna-oauth 0.3.2.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,10 +1,13 @@
1
- == 0.3.3 / 0.4.0
1
+ == 0.3.3 2009-05-04
2
2
 
3
3
  * Corrected OAuth XMPP namespace (Seth)
4
4
  * Improved error handling for invalid Authorization headers (Matt Sanford)
5
5
  * Fixed signatures for non-ASCII under $KCODE other than 'u' (Matt Sanford)
6
6
  * Fixed edge cases in ActionControllerRequestProxy where params were being
7
7
  incorrectly signed (Marcos Wright Kuhns)
8
+ * Support for arguments in OAuth::Consumer#get_access_token (Matt Sanford)
9
+ * Add gem version to user-agent header (Matt Sanford)
10
+ * Handle input from aggressive form encoding libraries (Matt Wood)
8
11
 
9
12
  == 0.3.2 2009-03-23
10
13
 
data/TODO CHANGED
@@ -27,6 +27,5 @@ the pre-release checks to make sure that there have been no regressions.
27
27
  Random TODOs:
28
28
  * finish CLI
29
29
  * sensible Exception hierarchy
30
- * User Agent
31
30
  * Tokens as Modules
32
31
  * don't tie to Net::HTTP
data/bin/oauth CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby -w -rubygems
2
2
 
3
3
  require "oauth/cli"
4
4
 
@@ -34,6 +34,7 @@ module ActionController
34
34
  return unless ActionController::TestRequest.use_oauth? && @oauth_options
35
35
 
36
36
  @oauth_helper = OAuth::Client::Helper.new(self, @oauth_options.merge(:request_uri => request_uri))
37
+ @oauth_helper.amend_user_agent_header(env)
37
38
 
38
39
  self.send("set_oauth_#{@oauth_options[:scheme]}")
39
40
  end
@@ -50,6 +50,15 @@ module OAuth::Client
50
50
  :parameters => oauth_parameters}.merge(extra_options) )
51
51
  end
52
52
 
53
+ def amend_user_agent_header(headers)
54
+ @oauth_ua_string ||= "OAuth gem v#{OAuth::VERSION}"
55
+ if headers['User-Agent']
56
+ headers['User-Agent'] += " (#{@oauth_ua_string})"
57
+ else
58
+ headers['User-Agent'] = @oauth_ua_string
59
+ end
60
+ end
61
+
53
62
  def header
54
63
  parameters = oauth_parameters
55
64
  parameters.merge!('oauth_signature' => signature(options.merge(:parameters => parameters)))
@@ -7,6 +7,14 @@ class Net::HTTPRequest
7
7
 
8
8
  attr_reader :oauth_helper
9
9
 
10
+ # Add the OAuth information to an HTTP request. Depending on the <tt>options[:scheme]</tt> setting
11
+ # this may add a header, additional query string parameters, or additional POST body parameters.
12
+ # The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
13
+ # header.
14
+ #
15
+ # This method also modifies the <tt>User-Agent</tt> header to add the OAuth gem version.
16
+ #
17
+ # See Also: {OAuth core spec version 1.0, section 5.4.1}[http://oauth.net/core/1.0#rfc.section.5.4.1]
10
18
  def oauth!(http, consumer = nil, token = nil, options = {})
11
19
  options = { :request_uri => oauth_full_request_uri(http),
12
20
  :consumer => consumer,
@@ -17,9 +25,17 @@ class Net::HTTPRequest
17
25
  :timestamp => nil }.merge(options)
18
26
 
19
27
  @oauth_helper = OAuth::Client::Helper.new(self, options)
28
+ @oauth_helper.amend_user_agent_header(self)
20
29
  self.send("set_oauth_#{options[:scheme]}")
21
30
  end
22
31
 
32
+ # Create a string suitable for signing for an HTTP request. This process involves parameter
33
+ # normalization as specified in the OAuth specification. The exact normalization also depends
34
+ # on the <tt>options[:scheme]</tt> being used so this must match what will be used for the request
35
+ # itself. The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
36
+ # header.
37
+ #
38
+ # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
23
39
  def signature_base_string(http, consumer = nil, token = nil, options = {})
24
40
  options = { :request_uri => oauth_full_request_uri(http),
25
41
  :consumer => consumer,
data/lib/oauth/helper.rb CHANGED
@@ -5,20 +5,32 @@ module OAuth
5
5
  module Helper
6
6
  extend self
7
7
 
8
+ # Escape +value+ by URL encoding all non-reserved character.
9
+ #
10
+ # See Also: {OAuth core spec version 1.0, section 5.1}[http://oauth.net/core/1.0#rfc.section.5.1]
8
11
  def escape(value)
9
12
  URI::escape(value.to_s, OAuth::RESERVED_CHARACTERS)
10
13
  end
11
14
 
15
+ # Generate a random key of up to +size+ bytes. The value returned is Base64 encoded with non-word
16
+ # characters removed.
12
17
  def generate_key(size=32)
13
18
  Base64.encode64(OpenSSL::Random.random_bytes(size)).gsub(/\W/, '')
14
19
  end
15
20
 
16
21
  alias_method :generate_nonce, :generate_key
17
22
 
18
- def generate_timestamp
23
+ def generate_timestamp #:nodoc:
19
24
  Time.now.to_i.to_s
20
25
  end
21
26
 
27
+ # Normalize a +Hash+ of parameter values. Parameters are sorted by name, using lexicographical
28
+ # byte value ordering. If two or more parameters share the same name, they are sorted by their value.
29
+ # Parameters are concatenated in their sorted order into a single string. For each parameter, the name
30
+ # is separated from the corresponding value by an "=" character, even if the value is empty. Each
31
+ # name-value pair is separated by an "&" character.
32
+ #
33
+ # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
22
34
  def normalize(params)
23
35
  params.sort.map do |k, values|
24
36
 
@@ -33,7 +45,14 @@ module OAuth
33
45
  end * "&"
34
46
  end
35
47
 
36
- # Parse an Authorization / WWW-Authenticate header into a hash
48
+ # Parse an Authorization / WWW-Authenticate header into a hash. Takes care of unescaping and
49
+ # removing surrounding quotes. Raises a OAuth::Problem if the header is not parsable into a
50
+ # valid hash. Does not validate the keys or values.
51
+ #
52
+ # hash = parse_header(headers['Authorization'] || headers['WWW-Authenticate'])
53
+ # hash['oauth_timestamp']
54
+ # #=>"1234567890"
55
+ #
37
56
  def parse_header(header)
38
57
  # decompose
39
58
  params = header[6,header.length].split(/[,=]/)
@@ -41,11 +60,12 @@ module OAuth
41
60
  # odd number of arguments - must be a malformed header.
42
61
  raise OAuth::Problem.new("Invalid authorization header") if params.size % 2 != 0
43
62
 
44
- # strip and unescape
45
- params.map! { |v| unescape(v.strip) }
46
-
47
- # strip quotes
48
- params.map! { |v| v =~ /^\".*\"$/ ? v[1..-2] : v }
63
+ params.map! do |v|
64
+ # strip and unescape
65
+ val = unescape(v.strip)
66
+ # strip quotes
67
+ val.sub(/^\"(.*)\"$/, '\1')
68
+ end
49
69
 
50
70
  # convert into a Hash
51
71
  Hash[*params.flatten]
@@ -42,9 +42,9 @@ module OAuth::RequestProxy
42
42
 
43
43
  params.
44
44
  join('&').split('&').
45
- reject { |kv| kv =~ /^oauth_signature=.*/}.
46
45
  reject(&:blank?).
47
- map { |p| p.split('=').map{|esc| CGI.unescape(esc)} }
46
+ map { |p| p.split('=').map{|esc| CGI.unescape(esc)} }.
47
+ reject { |kv| kv =~ /^oauth_signature=.*/}
48
48
  end
49
49
 
50
50
  protected
@@ -1,9 +1,13 @@
1
1
  module OAuth
2
2
  module Signature
3
+ # Returns a list of available signature methods
3
4
  def self.available_methods
4
5
  @available_methods ||= {}
5
6
  end
6
7
 
8
+ # Build a signature from a +request+.
9
+ #
10
+ # Raises UnknownSignatureMethod exception if the signature method is unknown.
7
11
  def self.build(request, options = {}, &block)
8
12
  request = OAuth::RequestProxy.proxy(request, options)
9
13
  klass = available_methods[(request.signature_method || "").downcase]
@@ -11,14 +15,19 @@ module OAuth
11
15
  klass.new(request, options, &block)
12
16
  end
13
17
 
18
+ # Sign a +request+
14
19
  def self.sign(request, options = {}, &block)
15
20
  self.build(request, options, &block).signature
16
21
  end
17
22
 
23
+ # Verify the signature of +request+
18
24
  def self.verify(request, options = {}, &block)
19
25
  self.build(request, options, &block).verify
20
26
  end
21
27
 
28
+ # Create the signature base string for +request+. This string is the normalized parameter information.
29
+ #
30
+ # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
22
31
  def self.signature_base_string(request, options = {}, &block)
23
32
  self.build(request, options, &block).signature_base_string
24
33
  end
@@ -10,8 +10,8 @@ module OAuth
10
10
  end
11
11
 
12
12
  # exchange for AccessToken on server
13
- def get_access_token(options = {})
14
- response = consumer.token_request(consumer.http_method, (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path), self, options)
13
+ def get_access_token(options = {}, *arguments)
14
+ response = consumer.token_request(consumer.http_method, (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path), self, options, *arguments)
15
15
  OAuth::AccessToken.from_hash(consumer, response)
16
16
  end
17
17
 
data/lib/oauth/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OAuth #:nodoc:
2
- VERSION = '0.3.2.2'
2
+ VERSION = '0.3.3'
3
3
  end
data/oauth.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{oauth}
5
- s.version = "0.3.2.2"
5
+ s.version = "0.3.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", "Seth Fitzsimmons"]
9
- s.date = %q{2009-03-23}
8
+ s.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", "Seth Fitzsimmons", "Matt Sanford"]
9
+ s.date = %q{2009-05-04}
10
10
  s.default_executable = %q{oauth}
11
11
  s.description = %q{OAuth Core Ruby implementation}
12
12
  s.email = %q{oauth-ruby@googlegroups.com}
@@ -1,5 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
  require 'oauth/client/net_http'
3
+ require 'oauth/version'
3
4
 
4
5
  class NetHTTPClientTest < Test::Unit::TestCase
5
6
 
@@ -33,6 +34,23 @@ class NetHTTPClientTest < Test::Unit::TestCase
33
34
  assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"".split(', ').sort, request['authorization'].split(', ').sort
34
35
  end
35
36
 
37
+ def test_that_version_is_added_to_existing_user_agent
38
+ request = Net::HTTP::Post.new(@request_uri.path)
39
+ request['User-Agent'] = "MyApp"
40
+ request.set_form_data( @request_parameters )
41
+ request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
42
+
43
+ assert_equal "MyApp (OAuth gem v#{OAuth::VERSION})", request['User-Agent']
44
+ end
45
+
46
+ def test_that_version_is_set_when_no_user_agent
47
+ request = Net::HTTP::Post.new(@request_uri.path)
48
+ request.set_form_data( @request_parameters )
49
+ request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
50
+
51
+ assert_equal "OAuth gem v#{OAuth::VERSION}", request['User-Agent']
52
+ end
53
+
36
54
  def test_that_using_get_params_works
37
55
  request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
38
56
  request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp})
@@ -16,6 +16,13 @@ class TestOAuthHelper < Test::Unit::TestCase
16
16
  params = OAuth::Helper.parse_header(header)
17
17
 
18
18
  assert_equal "http://example.com/method", params['realm']
19
+ assert_equal "vince_clortho", params['oauth_consumer_key']
20
+ assert_equal "token_value", params['oauth_token']
21
+ assert_equal "HMAC-SHA1", params['oauth_signature_method']
22
+ assert_equal "signature_here", params['oauth_signature']
23
+ assert_equal "1240004133", params['oauth_timestamp']
24
+ assert_equal "nonce", params['oauth_nonce']
25
+ assert_equal "1.0", params['oauth_version']
19
26
  end
20
27
 
21
28
  def test_parse_header_ill_formed
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.3.2</a>
36
+ <a href="http://rubyforge.org/projects/oauth" class="numbers">0.3.3</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
  <p>This is a RubyGem for implementing both OAuth clients and servers in Ruby applications.</p>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mojodna-oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pelle Braendgaard
@@ -10,11 +10,12 @@ authors:
10
10
  - Jesse Clark
11
11
  - Jon Crosby
12
12
  - Seth Fitzsimmons
13
+ - Matt Sanford
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2009-03-23 00:00:00 -07:00
18
+ date: 2009-05-04 00:00:00 -07:00
18
19
  default_executable: oauth
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency