mojodna-oauth 0.3.1.5 → 0.3.1.6

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.
data/History.txt CHANGED
@@ -1,5 +1,7 @@
1
1
  == 0.3.2
2
2
 
3
+ * Fixed ActionController parameter escaping behavior (Thiago Arrais, László
4
+ Bácsi, Brett Gibson, et al)
3
5
  * Fixed signature calculation when both options and a block were provided to
4
6
  OAuth::Signature::Base#initialize. (Seth)
5
7
  * Added help to the 'oauth' CLI. (Seth)
data/Manifest.txt CHANGED
@@ -5,6 +5,7 @@ README.rdoc
5
5
  Rakefile
6
6
  TODO
7
7
  bin/oauth
8
+ examples/yql.rb
8
9
  lib/oauth.rb
9
10
  lib/oauth/oauth.rb
10
11
  lib/oauth/cli.rb
@@ -35,6 +36,11 @@ lib/oauth/signature/plaintext.rb
35
36
  lib/oauth/signature/rsa/sha1.rb
36
37
  lib/oauth/signature/sha1.rb
37
38
  lib/oauth/token.rb
39
+ lib/oauth/tokens/access_token.rb
40
+ lib/oauth/tokens/consumer_token.rb
41
+ lib/oauth/tokens/request_token.rb
42
+ lib/oauth/tokens/server_token.rb
43
+ lib/oauth/tokens/token.rb
38
44
  lib/oauth/version.rb
39
45
  oauth.gemspec
40
46
  script/destroy
@@ -51,6 +57,7 @@ test/cases/spec/1_0-final/test_parameter_encodings.rb
51
57
  test/cases/spec/1_0-final/test_signature_base_strings.rb
52
58
  test/keys/rsa.cert
53
59
  test/keys/rsa.pem
60
+ test/test_access_token.rb
54
61
  test/test_action_controller_request_proxy.rb
55
62
  test/test_consumer.rb
56
63
  test/test_helper.rb
@@ -58,6 +65,7 @@ test/test_hmac_sha1.rb
58
65
  test/test_net_http_client.rb
59
66
  test/test_net_http_request_proxy.rb
60
67
  test/test_rack_request_proxy.rb
68
+ test/test_request_token.rb
61
69
  test/test_rsa_sha1.rb
62
70
  test/test_server.rb
63
71
  test/test_signature.rb
data/Rakefile CHANGED
@@ -6,14 +6,14 @@ require 'oauth/version'
6
6
  # Generate all the Rake tasks
7
7
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
8
8
  $hoe = Hoe.new('oauth', OAuth::VERSION) do |p|
9
- p.author = ['Pelle Braendgaard','Blaine Cook','Larry Halff','Jesse Clark','Jon Crosby', 'Seth Fitzsimmons']
9
+ p.author = ['Pelle Braendgaard','Blaine Cook','Larry Halff','Jesse Clark','Jon Crosby', 'Seth Fitzsimmons']
10
10
  p.email = "pelleb@gmail.com"
11
11
  p.description = "OAuth Core Ruby implementation"
12
12
  p.summary = p.description
13
13
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
14
14
  p.rubyforge_name = p.name # TODO this is default value
15
15
  p.url = "http://oauth.rubyforge.org"
16
-
16
+
17
17
  p.extra_deps = [
18
18
  ['ruby-hmac','>= 0.3.1']
19
19
  ]
@@ -22,7 +22,7 @@ $hoe = Hoe.new('oauth', OAuth::VERSION) do |p|
22
22
  ['actionpack'],
23
23
  ['rack']
24
24
  ]
25
-
25
+
26
26
  p.clean_globs |= %w[**/.DS_Store tmp *.log **/.*.sw? *.gem .config **/.DS_Store]
27
27
  path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
28
28
  p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
data/examples/yql.rb ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+
3
+ # Sample queries:
4
+ # ./yql.rb --consumer-key <key> --consumer-secret <secret> "show tables"
5
+ # ./yql.rb --consumer-key <key> --consumer-secret <secret> "select * from flickr.photos.search where text='Cat' limit 10"
6
+
7
+ require 'oauth'
8
+ require 'optparse'
9
+ require 'json'
10
+ require 'pp'
11
+
12
+ options = {}
13
+
14
+ option_parser = OptionParser.new do |opts|
15
+ opts.banner = "Usage: #{$0} [options] <query>"
16
+
17
+ opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v|
18
+ options[:consumer_key] = v
19
+ end
20
+
21
+ opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v|
22
+ options[:consumer_secret] = v
23
+ end
24
+ end
25
+
26
+ option_parser.parse!
27
+ query = ARGV.pop
28
+ query = STDIN.read if query == "-"
29
+
30
+ if options[:consumer_key].nil? || options[:consumer_secret].nil? || query.nil?
31
+ puts option_parser.help
32
+ exit 1
33
+ end
34
+
35
+ consumer = OAuth::Consumer.new \
36
+ options[:consumer_key],
37
+ options[:consumer_secret],
38
+ :site => "http://query.yahooapis.com"
39
+
40
+ access_token = OAuth::AccessToken.new(consumer)
41
+
42
+ response = access_token.request(:get, url = "/v1/yql?q=#{OAuth::Helper.escape(query)}&format=json")
43
+ rsp = JSON.parse(response.body)
44
+ pp rsp
data/lib/oauth/cli.rb CHANGED
@@ -3,7 +3,10 @@ require 'oauth'
3
3
 
4
4
  module OAuth
5
5
  class CLI
6
- SUPPORTED_COMMANDS = %w(sign)
6
+ SUPPORTED_COMMANDS = {
7
+ "debug" => "Verbosely generate an OAuth signature",
8
+ "sign" => "Generate an OAuth signature"
9
+ }
7
10
 
8
11
  attr_reader :command
9
12
  attr_reader :options
@@ -22,6 +25,11 @@ module OAuth
22
25
  extract_command_and_parse_options(arguments)
23
26
 
24
27
  if sufficient_options? && valid_command?
28
+ if command == "debug"
29
+ @command = "sign"
30
+ @options[:verbose] = true
31
+ end
32
+
25
33
  case command
26
34
  when "sign"
27
35
  parameters = prepare_parameters
@@ -82,7 +90,7 @@ module OAuth
82
90
  stdout.puts "Signature: #{request.oauth_signature}"
83
91
  stdout.puts "Escaped signature: #{OAuth::Helper.escape(request.oauth_signature)}"
84
92
  else
85
- stdout.puts signature
93
+ stdout.puts request.oauth_signature
86
94
  end
87
95
  end
88
96
  else
@@ -207,13 +215,13 @@ module OAuth
207
215
  stdout.puts option_parser.help
208
216
  stdout.puts
209
217
  stdout.puts "Available commands:"
210
- SUPPORTED_COMMANDS.each do |command|
211
- puts " #{command.ljust(15)}"
218
+ SUPPORTED_COMMANDS.each do |command, desc|
219
+ puts " #{command.ljust(15)}#{desc}"
212
220
  end
213
221
  end
214
222
 
215
223
  def valid_command?
216
- SUPPORTED_COMMANDS.include?(command)
224
+ SUPPORTED_COMMANDS.keys.include?(command)
217
225
  end
218
226
 
219
227
  def verbose?
@@ -34,7 +34,7 @@ module OAuth::Client
34
34
  'oauth_timestamp' => timestamp,
35
35
  'oauth_nonce' => nonce,
36
36
  'oauth_version' => '1.0'
37
- }.reject { |k,v| v == "" }
37
+ }.reject { |k,v| v.to_s == "" }
38
38
  end
39
39
 
40
40
  def signature(extra_options = {})
@@ -64,7 +64,7 @@ private
64
64
  end
65
65
 
66
66
  def set_oauth_query_string
67
- oauth_params_str = @oauth_helper.oauth_parameters.map { |k,v| "#{k}=#{v}" }.join("&")
67
+ oauth_params_str = @oauth_helper.oauth_parameters.map { |k,v| [escape(k), escape(v)] * "=" }.join("&")
68
68
 
69
69
  uri = URI.parse(path)
70
70
  if !uri.query || uri.query == ''
data/lib/oauth/helper.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  require 'openssl'
2
2
  require 'base64'
3
- require 'cgi'
4
3
 
5
4
  module OAuth
6
5
  module Helper
7
6
  extend self
8
7
 
9
8
  def escape(value)
10
- CGI.escape(value.to_s).gsub("%7E", '~').gsub("+", "%20")
9
+ URI::escape(value.to_s, OAuth::RESERVED_CHARACTERS)
11
10
  end
12
11
 
13
12
  def generate_key(size=32)
@@ -34,6 +33,21 @@ module OAuth
34
33
  end * "&"
35
34
  end
36
35
 
36
+ # Parse an Authorization / WWW-Authenticate header into a hash
37
+ def parse_header(header)
38
+ # decompose
39
+ params = header[6,header.length].split(/[,=]/)
40
+
41
+ # strip and unescape
42
+ params.map! { |v| unescape(v.strip) }
43
+
44
+ # strip quotes
45
+ params.map! { |v| v =~ /^\".*\"$/ ? v[1..-2] : v }
46
+
47
+ # convert into a Hash
48
+ Hash[*params.flatten]
49
+ end
50
+
37
51
  def unescape(value)
38
52
  URI.unescape(value.gsub('+', '%2B'))
39
53
  end
data/lib/oauth/oauth.rb CHANGED
@@ -1,3 +1,7 @@
1
1
  module OAuth
2
+ # required parameters, per sections 6.1.1, 6.3.1, and 7
2
3
  PARAMETERS = %w(oauth_consumer_key oauth_token oauth_signature_method oauth_timestamp oauth_nonce oauth_version oauth_signature)
3
- end
4
+
5
+ # reserved character regexp, per section 5.1
6
+ RESERVED_CHARACTERS = /[^\w\d\-\.\_\~]/
7
+ end
@@ -142,10 +142,10 @@ module OAuth::RequestProxy
142
142
  header = request.env[header]
143
143
  next unless header[0,6] == 'OAuth '
144
144
 
145
- oauth_param_string = header[6,header.length].split(/[,=]/)
146
- oauth_param_string.map! { |v| unescape(v.strip) }
147
- oauth_param_string.map! { |v| v =~ /^\".*\"$/ ? v[1..-2] : v }
148
- oauth_params = Hash[*oauth_param_string.flatten]
145
+ # parse the header into a Hash
146
+ oauth_params = OAuth::Helper.parse_header(header)
147
+
148
+ # remove non-OAuth parameters
149
149
  oauth_params.reject! { |k,v| k !~ /^oauth_/ }
150
150
 
151
151
  return oauth_params
data/lib/oauth/token.rb CHANGED
@@ -1,135 +1,7 @@
1
- require 'oauth/helper'
2
- module OAuth
1
+ # this exists for backwards-compatibility
3
2
 
4
- # Superclass for the various tokens used by OAuth
5
- class Token
6
- include OAuth::Helper
7
-
8
- attr_accessor :token, :secret
9
-
10
- def initialize(token, secret)
11
- @token = token
12
- @secret = secret
13
- end
14
-
15
- def to_query
16
- "oauth_token=#{escape(token)}&oauth_secret=#{escape(secret)}"
17
- end
18
- end
19
-
20
- # Used on the server for generating tokens
21
- class ServerToken < Token
22
-
23
- def initialize
24
- super(generate_key(16), generate_key)
25
- end
26
- end
27
-
28
- # Superclass for tokens used by OAuth Clients
29
- class ConsumerToken < Token
30
- attr_accessor :consumer
31
-
32
- def initialize(consumer, token="", secret="")
33
- super(token, secret)
34
- @consumer = consumer
35
- end
36
-
37
- # Make a signed request using given http_method to the path
38
- #
39
- # @token.request(:get, '/people')
40
- # @token.request(:post, '/people', @person.to_xml, { 'Content-Type' => 'application/xml' })
41
- #
42
- def request(http_method, path, *arguments)
43
- response = consumer.request(http_method, path, self, {}, *arguments)
44
- end
45
-
46
- # Sign a request generated elsewhere using Net:HTTP::Post.new or friends
47
- def sign!(request, options = {})
48
- consumer.sign!(request, self, options)
49
- end
50
- end
51
-
52
- # The RequestToken is used for the initial Request.
53
- # This is normally created by the Consumer object.
54
- class RequestToken < ConsumerToken
55
-
56
- # Returns the authorization url that you need to use for redirecting the user
57
- def authorize_url
58
- consumer.authorize_url + "?oauth_token=" + CGI.escape(token)
59
- end
60
-
61
- # exchange for AccessToken on server
62
- def get_access_token(options = {})
63
- response = consumer.token_request(consumer.http_method, (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path), self, options)
64
- OAuth::AccessToken.new(consumer, response[:oauth_token], response[:oauth_token_secret])
65
- end
66
- end
67
-
68
- # The Access Token is used for the actual "real" web service calls thatyou perform against the server
69
- class AccessToken < ConsumerToken
70
-
71
- # The less intrusive way. Otherwise, if we are to do it correctly inside consumer,
72
- # we need to restructure and touch more methods: request(), sign!(), etc.
73
- def request(http_method, path, *arguments)
74
- request_uri = URI.parse(path)
75
- site_uri = consumer.uri
76
- is_service_uri_different = (request_uri.absolute? && request_uri != site_uri)
77
- consumer.uri(request_uri) if is_service_uri_different
78
- resp = super(http_method, path, *arguments)
79
- # NOTE: reset for wholesomeness? meaning that we admit only AccessToken service calls may use different URIs?
80
- # so reset in case consumer is still used for other token-management tasks subsequently?
81
- consumer.uri(site_uri) if is_service_uri_different
82
- resp
83
- end
84
-
85
- # Make a regular GET request using AccessToken
86
- #
87
- # @response = @token.get('/people')
88
- # @response = @token.get('/people', { 'Accept'=>'application/xml' })
89
- #
90
- def get(path, headers = {})
91
- request(:get, path, headers)
92
- end
93
-
94
- # Make a regular HEAD request using AccessToken
95
- #
96
- # @response = @token.head('/people')
97
- #
98
- def head(path, headers = {})
99
- request(:head, path, headers)
100
- end
101
-
102
- # Make a regular POST request using AccessToken
103
- #
104
- # @response = @token.post('/people')
105
- # @response = @token.post('/people', { :name => 'Bob', :email => 'bob@mailinator.com' })
106
- # @response = @token.post('/people', { :name => 'Bob', :email => 'bob@mailinator.com' }, { 'Accept' => 'application/xml' })
107
- # @response = @token.post('/people', nil, {'Accept' => 'application/xml' })
108
- # @response = @token.post('/people', @person.to_xml, { 'Accept'=>'application/xml', 'Content-Type' => 'application/xml' })
109
- #
110
- def post(path, body = '', headers = {})
111
- request(:post, path, body, headers)
112
- end
113
-
114
- # Make a regular PUT request using AccessToken
115
- #
116
- # @response = @token.put('/people/123')
117
- # @response = @token.put('/people/123', { :name => 'Bob', :email => 'bob@mailinator.com' })
118
- # @response = @token.put('/people/123', { :name => 'Bob', :email => 'bob@mailinator.com' }, { 'Accept' => 'application/xml' })
119
- # @response = @token.put('/people/123', nil, { 'Accept' => 'application/xml' })
120
- # @response = @token.put('/people/123', @person.to_xml, { 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' })
121
- #
122
- def put(path, body = '', headers = {})
123
- request(:put, path, body, headers)
124
- end
125
-
126
- # Make a regular DELETE request using AccessToken
127
- #
128
- # @response = @token.delete('/people/123')
129
- # @response = @token.delete('/people/123', { 'Accept' => 'application/xml' })
130
- #
131
- def delete(path, headers = {})
132
- request(:delete, path, headers)
133
- end
134
- end
135
- end
3
+ require 'oauth/tokens/token'
4
+ require 'oauth/tokens/server_token'
5
+ require 'oauth/tokens/consumer_token'
6
+ require 'oauth/tokens/request_token'
7
+ require 'oauth/tokens/access_token'
@@ -0,0 +1,68 @@
1
+ module OAuth
2
+ # The Access Token is used for the actual "real" web service calls that you perform against the server
3
+ class AccessToken < ConsumerToken
4
+ # The less intrusive way. Otherwise, if we are to do it correctly inside consumer,
5
+ # we need to restructure and touch more methods: request(), sign!(), etc.
6
+ def request(http_method, path, *arguments)
7
+ request_uri = URI.parse(path)
8
+ site_uri = consumer.uri
9
+ is_service_uri_different = (request_uri.absolute? && request_uri != site_uri)
10
+ consumer.uri(request_uri) if is_service_uri_different
11
+ @response = super(http_method, path, *arguments)
12
+ # NOTE: reset for wholesomeness? meaning that we admit only AccessToken service calls may use different URIs?
13
+ # so reset in case consumer is still used for other token-management tasks subsequently?
14
+ consumer.uri(site_uri) if is_service_uri_different
15
+ @response
16
+ end
17
+
18
+ # Make a regular GET request using AccessToken
19
+ #
20
+ # @response = @token.get('/people')
21
+ # @response = @token.get('/people', { 'Accept'=>'application/xml' })
22
+ #
23
+ def get(path, headers = {})
24
+ request(:get, path, headers)
25
+ end
26
+
27
+ # Make a regular HEAD request using AccessToken
28
+ #
29
+ # @response = @token.head('/people')
30
+ #
31
+ def head(path, headers = {})
32
+ request(:head, path, headers)
33
+ end
34
+
35
+ # Make a regular POST request using AccessToken
36
+ #
37
+ # @response = @token.post('/people')
38
+ # @response = @token.post('/people', { :name => 'Bob', :email => 'bob@mailinator.com' })
39
+ # @response = @token.post('/people', { :name => 'Bob', :email => 'bob@mailinator.com' }, { 'Accept' => 'application/xml' })
40
+ # @response = @token.post('/people', nil, {'Accept' => 'application/xml' })
41
+ # @response = @token.post('/people', @person.to_xml, { 'Accept'=>'application/xml', 'Content-Type' => 'application/xml' })
42
+ #
43
+ def post(path, body = '', headers = {})
44
+ request(:post, path, body, headers)
45
+ end
46
+
47
+ # Make a regular PUT request using AccessToken
48
+ #
49
+ # @response = @token.put('/people/123')
50
+ # @response = @token.put('/people/123', { :name => 'Bob', :email => 'bob@mailinator.com' })
51
+ # @response = @token.put('/people/123', { :name => 'Bob', :email => 'bob@mailinator.com' }, { 'Accept' => 'application/xml' })
52
+ # @response = @token.put('/people/123', nil, { 'Accept' => 'application/xml' })
53
+ # @response = @token.put('/people/123', @person.to_xml, { 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' })
54
+ #
55
+ def put(path, body = '', headers = {})
56
+ request(:put, path, body, headers)
57
+ end
58
+
59
+ # Make a regular DELETE request using AccessToken
60
+ #
61
+ # @response = @token.delete('/people/123')
62
+ # @response = @token.delete('/people/123', { 'Accept' => 'application/xml' })
63
+ #
64
+ def delete(path, headers = {})
65
+ request(:delete, path, headers)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,32 @@
1
+ module OAuth
2
+ # Superclass for tokens used by OAuth Clients
3
+ class ConsumerToken < Token
4
+ attr_accessor :consumer, :params
5
+ attr_reader :response
6
+
7
+ def self.from_hash(consumer, hash)
8
+ token = self.new(consumer, hash[:oauth_token], hash[:oauth_token_secret])
9
+ token.params = hash
10
+ token
11
+ end
12
+
13
+ def initialize(consumer, token="", secret="")
14
+ super(token, secret)
15
+ @consumer = consumer
16
+ end
17
+
18
+ # Make a signed request using given http_method to the path
19
+ #
20
+ # @token.request(:get, '/people')
21
+ # @token.request(:post, '/people', @person.to_xml, { 'Content-Type' => 'application/xml' })
22
+ #
23
+ def request(http_method, path, *arguments)
24
+ @response = consumer.request(http_method, path, self, {}, *arguments)
25
+ end
26
+
27
+ # Sign a request generated elsewhere using Net:HTTP::Post.new or friends
28
+ def sign!(request, options = {})
29
+ consumer.sign!(request, self, options)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ module OAuth
2
+ # The RequestToken is used for the initial Request.
3
+ # This is normally created by the Consumer object.
4
+ class RequestToken < ConsumerToken
5
+
6
+ # Generate an authorization URL for user authorization
7
+ def authorize_url(params = nil)
8
+ params = (params || {}).merge(:oauth_token => self.token)
9
+ build_authorize_url(consumer.authorize_url, params)
10
+ end
11
+
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)
15
+ OAuth::AccessToken.from_hash(consumer, response)
16
+ end
17
+
18
+ protected
19
+
20
+ # construct an authorization url
21
+ def build_authorize_url(base_url, params)
22
+ uri = URI.parse(base_url.to_s)
23
+ # TODO doesn't handle array values correctly
24
+ uri.query = params.map { |k,v| [k, CGI.escape(v)] * "=" } * "&"
25
+ uri.to_s
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ module OAuth
2
+ # Used on the server for generating tokens
3
+ class ServerToken < Token
4
+
5
+ def initialize
6
+ super(generate_key(16), generate_key)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module OAuth
2
+ # Superclass for the various tokens used by OAuth
3
+ class Token
4
+ include OAuth::Helper
5
+
6
+ attr_accessor :token, :secret
7
+
8
+ def initialize(token, secret)
9
+ @token = token
10
+ @secret = secret
11
+ end
12
+
13
+ def to_query
14
+ "oauth_token=#{escape(token)}&oauth_secret=#{escape(secret)}"
15
+ end
16
+ end
17
+ end
data/lib/oauth/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OAuth #:nodoc:
2
- VERSION = '0.3.1.5'
2
+ VERSION = '0.3.1.6'
3
3
  end
data/oauth.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{oauth}
5
- s.version = "0.3.1.5"
5
+ s.version = "0.3.1.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", "Seth Fitzsimmons"]
9
- s.date = %q{2009-02-05}
9
+ s.date = %q{2009-02-11}
10
10
  s.default_executable = %q{oauth}
11
11
  s.description = %q{OAuth Core Ruby implementation}
12
12
  s.email = %q{pelleb@gmail.com}
13
13
  s.executables = ["oauth"]
14
14
  s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "website/index.txt"]
15
- s.files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "bin/oauth", "lib/oauth.rb", "lib/oauth/oauth.rb", "lib/oauth/cli.rb", "lib/oauth/client.rb", "lib/oauth/client/action_controller_request.rb", "lib/oauth/client/helper.rb", "lib/oauth/client/net_http.rb", "lib/oauth/consumer.rb", "lib/oauth/helper.rb", "lib/oauth/oauth_test_helper.rb", "lib/oauth/request_proxy.rb", "lib/oauth/request_proxy/action_controller_request.rb", "lib/oauth/request_proxy/base.rb", "lib/oauth/request_proxy/jabber_request.rb", "lib/oauth/request_proxy/mock_request.rb", "lib/oauth/request_proxy/net_http.rb", "lib/oauth/request_proxy/rack_request.rb", "lib/oauth/server.rb", "lib/oauth/signature.rb", "lib/oauth/signature/base.rb", "lib/oauth/signature/hmac/base.rb", "lib/oauth/signature/hmac/md5.rb", "lib/oauth/signature/hmac/rmd160.rb", "lib/oauth/signature/hmac/sha1.rb", "lib/oauth/signature/hmac/sha2.rb", "lib/oauth/signature/md5.rb", "lib/oauth/signature/plaintext.rb", "lib/oauth/signature/rsa/sha1.rb", "lib/oauth/signature/sha1.rb", "lib/oauth/token.rb", "lib/oauth/version.rb", "oauth.gemspec", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/cases/oauth_case.rb", "test/cases/spec/1_0-final/test_construct_request_url.rb", "test/cases/spec/1_0-final/test_normalize_request_parameters.rb", "test/cases/spec/1_0-final/test_parameter_encodings.rb", "test/cases/spec/1_0-final/test_signature_base_strings.rb", "test/keys/rsa.cert", "test/keys/rsa.pem", "test/test_action_controller_request_proxy.rb", "test/test_consumer.rb", "test/test_helper.rb", "test/test_hmac_sha1.rb", "test/test_net_http_client.rb", "test/test_net_http_request_proxy.rb", "test/test_rack_request_proxy.rb", "test/test_rsa_sha1.rb", "test/test_server.rb", "test/test_signature.rb", "test/test_signature_base.rb", "test/test_signature_plain_text.rb", "test/test_token.rb", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.rhtml"]
15
+ s.files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "bin/oauth", "examples/yql.rb", "lib/oauth.rb", "lib/oauth/oauth.rb", "lib/oauth/cli.rb", "lib/oauth/client.rb", "lib/oauth/client/action_controller_request.rb", "lib/oauth/client/helper.rb", "lib/oauth/client/net_http.rb", "lib/oauth/consumer.rb", "lib/oauth/helper.rb", "lib/oauth/oauth_test_helper.rb", "lib/oauth/request_proxy.rb", "lib/oauth/request_proxy/action_controller_request.rb", "lib/oauth/request_proxy/base.rb", "lib/oauth/request_proxy/jabber_request.rb", "lib/oauth/request_proxy/mock_request.rb", "lib/oauth/request_proxy/net_http.rb", "lib/oauth/request_proxy/rack_request.rb", "lib/oauth/server.rb", "lib/oauth/signature.rb", "lib/oauth/signature/base.rb", "lib/oauth/signature/hmac/base.rb", "lib/oauth/signature/hmac/md5.rb", "lib/oauth/signature/hmac/rmd160.rb", "lib/oauth/signature/hmac/sha1.rb", "lib/oauth/signature/hmac/sha2.rb", "lib/oauth/signature/md5.rb", "lib/oauth/signature/plaintext.rb", "lib/oauth/signature/rsa/sha1.rb", "lib/oauth/signature/sha1.rb", "lib/oauth/token.rb", "lib/oauth/tokens/access_token.rb", "lib/oauth/tokens/consumer_token.rb", "lib/oauth/tokens/request_token.rb", "lib/oauth/tokens/server_token.rb", "lib/oauth/tokens/token.rb", "lib/oauth/version.rb", "oauth.gemspec", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/cases/oauth_case.rb", "test/cases/spec/1_0-final/test_construct_request_url.rb", "test/cases/spec/1_0-final/test_normalize_request_parameters.rb", "test/cases/spec/1_0-final/test_parameter_encodings.rb", "test/cases/spec/1_0-final/test_signature_base_strings.rb", "test/keys/rsa.cert", "test/keys/rsa.pem", "test/test_access_token.rb", "test/test_action_controller_request_proxy.rb", "test/test_consumer.rb", "test/test_helper.rb", "test/test_hmac_sha1.rb", "test/test_net_http_client.rb", "test/test_net_http_request_proxy.rb", "test/test_rack_request_proxy.rb", "test/test_request_token.rb", "test/test_rsa_sha1.rb", "test/test_server.rb", "test/test_signature.rb", "test/test_signature_base.rb", "test/test_signature_plain_text.rb", "test/test_token.rb", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.rhtml"]
16
16
  s.has_rdoc = true
17
17
  s.homepage = %q{http://oauth.rubyforge.org}
18
18
  s.rdoc_options = ["--main", "README.rdoc"]
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.rubyforge_project = %q{oauth}
21
21
  s.rubygems_version = %q{1.3.1}
22
22
  s.summary = %q{OAuth Core Ruby implementation}
23
- s.test_files = ["test/cases/spec/1_0-final/test_construct_request_url.rb", "test/cases/spec/1_0-final/test_normalize_request_parameters.rb", "test/cases/spec/1_0-final/test_parameter_encodings.rb", "test/cases/spec/1_0-final/test_signature_base_strings.rb", "test/test_action_controller_request_proxy.rb", "test/test_consumer.rb", "test/test_helper.rb", "test/test_hmac_sha1.rb", "test/test_net_http_client.rb", "test/test_net_http_request_proxy.rb", "test/test_rack_request_proxy.rb", "test/test_rsa_sha1.rb", "test/test_server.rb", "test/test_signature.rb", "test/test_signature_base.rb", "test/test_signature_plain_text.rb", "test/test_token.rb"]
23
+ s.test_files = ["test/cases/spec/1_0-final/test_construct_request_url.rb", "test/cases/spec/1_0-final/test_normalize_request_parameters.rb", "test/cases/spec/1_0-final/test_parameter_encodings.rb", "test/cases/spec/1_0-final/test_signature_base_strings.rb", "test/test_access_token.rb", "test/test_action_controller_request_proxy.rb", "test/test_consumer.rb", "test/test_helper.rb", "test/test_hmac_sha1.rb", "test/test_net_http_client.rb", "test/test_net_http_request_proxy.rb", "test/test_rack_request_proxy.rb", "test/test_request_token.rb", "test/test_rsa_sha1.rb", "test/test_server.rb", "test/test_signature.rb", "test/test_signature_base.rb", "test/test_signature_plain_text.rb", "test/test_token.rb"]
24
24
 
25
25
  if s.respond_to? :specification_version then
26
26
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'oauth/token'
3
+ require 'oauth/consumer'
4
+
5
+ class TestAccessToken < Test::Unit::TestCase
6
+ def setup
7
+ @fake_response = {
8
+ :user_id => 5734758743895,
9
+ :oauth_token => "key",
10
+ :oauth_token_secret => "secret"
11
+ }
12
+ # setup a fake req. token. mocking Consumer would be more appropriate...
13
+ @access_token = OAuth::AccessToken.from_hash(
14
+ OAuth::Consumer.new("key", "secret", {}),
15
+ @fake_response
16
+ )
17
+ end
18
+
19
+ def test_provides_response_parameters
20
+ assert @access_token
21
+ assert_respond_to @access_token, :params
22
+ end
23
+
24
+ def test_access_token_makes_non_oauth_response_params_available
25
+ assert_not_nil @access_token.params[:user_id]
26
+ assert_equal 5734758743895, @access_token.params[:user_id]
27
+ end
28
+ end
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'oauth/token'
3
+ require 'oauth/consumer'
4
+
5
+ class StubbedToken < OAuth::RequestToken
6
+ define_method :build_authorize_url_promoted do |root_domain, params|
7
+ build_authorize_url root_domain, params
8
+ end
9
+ end
10
+
11
+ class TestRequestToken < Test::Unit::TestCase
12
+ def setup
13
+ # setup a fake req. token. mocking Consumer would be more appropriate...
14
+ @request_token = OAuth::RequestToken.new(
15
+ OAuth::Consumer.new("key", "secret", {}),
16
+ "key",
17
+ "secret"
18
+ )
19
+ end
20
+
21
+ def test_request_token_builds_authorize_url_connectly_with_additional_params
22
+ auth_url = @request_token.authorize_url({:oauth_callback => "github.com"})
23
+ assert_not_nil auth_url
24
+ assert_match(/oauth_token/, auth_url)
25
+ assert_match(/oauth_callback/, auth_url)
26
+ end
27
+
28
+ def test_request_token_builds_authorize_url_connectly_with_no_or_nil_params
29
+ # we should only have 1 key in the url returned if we didn't pass anything.
30
+ # this is the only required param to authenticate the client.
31
+ auth_url = @request_token.authorize_url(nil)
32
+ assert_not_nil auth_url
33
+ assert_match(/\?oauth_token=/, auth_url)
34
+
35
+ auth_url = @request_token.authorize_url
36
+ assert_not_nil auth_url
37
+ assert_match(/\?oauth_token=/, auth_url)
38
+ end
39
+
40
+ #TODO: mock out the Consumer to test the Consumer/AccessToken interaction.
41
+ def test_get_access_token
42
+ end
43
+
44
+ def test_build_authorize_url
45
+ @stubbed_token = StubbedToken.new(nil, nil, nil)
46
+ assert_respond_to @stubbed_token, :build_authorize_url_promoted
47
+ url = @stubbed_token.build_authorize_url_promoted(
48
+ "http://github.com/oauth/authorize",
49
+ {:foo => "bar bar"})
50
+ assert url
51
+ assert_equal "http://github.com/oauth/authorize?foo=bar+bar", url
52
+ end
53
+ end
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.1.5
4
+ version: 0.3.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pelle Braendgaard
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2009-02-05 00:00:00 -08:00
17
+ date: 2009-02-11 00:00:00 -08:00
18
18
  default_executable: oauth
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,7 @@ files:
82
82
  - Rakefile
83
83
  - TODO
84
84
  - bin/oauth
85
+ - examples/yql.rb
85
86
  - lib/oauth.rb
86
87
  - lib/oauth/oauth.rb
87
88
  - lib/oauth/cli.rb
@@ -112,6 +113,11 @@ files:
112
113
  - lib/oauth/signature/rsa/sha1.rb
113
114
  - lib/oauth/signature/sha1.rb
114
115
  - lib/oauth/token.rb
116
+ - lib/oauth/tokens/access_token.rb
117
+ - lib/oauth/tokens/consumer_token.rb
118
+ - lib/oauth/tokens/request_token.rb
119
+ - lib/oauth/tokens/server_token.rb
120
+ - lib/oauth/tokens/token.rb
115
121
  - lib/oauth/version.rb
116
122
  - oauth.gemspec
117
123
  - script/destroy
@@ -128,6 +134,7 @@ files:
128
134
  - test/cases/spec/1_0-final/test_signature_base_strings.rb
129
135
  - test/keys/rsa.cert
130
136
  - test/keys/rsa.pem
137
+ - test/test_access_token.rb
131
138
  - test/test_action_controller_request_proxy.rb
132
139
  - test/test_consumer.rb
133
140
  - test/test_helper.rb
@@ -135,6 +142,7 @@ files:
135
142
  - test/test_net_http_client.rb
136
143
  - test/test_net_http_request_proxy.rb
137
144
  - test/test_rack_request_proxy.rb
145
+ - test/test_request_token.rb
138
146
  - test/test_rsa_sha1.rb
139
147
  - test/test_server.rb
140
148
  - test/test_signature.rb
@@ -178,6 +186,7 @@ test_files:
178
186
  - test/cases/spec/1_0-final/test_normalize_request_parameters.rb
179
187
  - test/cases/spec/1_0-final/test_parameter_encodings.rb
180
188
  - test/cases/spec/1_0-final/test_signature_base_strings.rb
189
+ - test/test_access_token.rb
181
190
  - test/test_action_controller_request_proxy.rb
182
191
  - test/test_consumer.rb
183
192
  - test/test_helper.rb
@@ -185,6 +194,7 @@ test_files:
185
194
  - test/test_net_http_client.rb
186
195
  - test/test_net_http_request_proxy.rb
187
196
  - test/test_rack_request_proxy.rb
197
+ - test/test_request_token.rb
188
198
  - test/test_rsa_sha1.rb
189
199
  - test/test_server.rb
190
200
  - test/test_signature.rb