oauth 0.5.0 → 0.5.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.

Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +13 -2
  3. data/bin/oauth +8 -2
  4. data/lib/oauth.rb +2 -2
  5. data/lib/oauth/cli.rb +37 -359
  6. data/lib/oauth/cli/authorize_command.rb +71 -0
  7. data/lib/oauth/cli/base_command.rb +208 -0
  8. data/lib/oauth/cli/help_command.rb +22 -0
  9. data/lib/oauth/cli/query_command.rb +25 -0
  10. data/lib/oauth/cli/sign_command.rb +81 -0
  11. data/lib/oauth/cli/version_command.rb +7 -0
  12. data/lib/oauth/client/action_controller_request.rb +1 -1
  13. data/lib/oauth/client/em_http.rb +0 -1
  14. data/lib/oauth/client/net_http.rb +0 -1
  15. data/lib/oauth/consumer.rb +26 -3
  16. data/lib/oauth/helper.rb +10 -6
  17. data/lib/oauth/request_proxy/action_controller_request.rb +2 -2
  18. data/lib/oauth/request_proxy/action_dispatch_request.rb +7 -0
  19. data/lib/oauth/request_proxy/base.rb +6 -2
  20. data/lib/oauth/tokens/request_token.rb +4 -4
  21. data/lib/oauth/version.rb +1 -1
  22. metadata +82 -90
  23. data/lib/oauth/core_ext.rb +0 -31
  24. data/test/cases/oauth_case.rb +0 -19
  25. data/test/cases/spec/1_0-final/test_construct_request_url.rb +0 -62
  26. data/test/cases/spec/1_0-final/test_normalize_request_parameters.rb +0 -88
  27. data/test/cases/spec/1_0-final/test_parameter_encodings.rb +0 -86
  28. data/test/cases/spec/1_0-final/test_signature_base_strings.rb +0 -77
  29. data/test/integration/consumer_test.rb +0 -307
  30. data/test/test_access_token.rb +0 -26
  31. data/test/test_action_controller_request_proxy.rb +0 -157
  32. data/test/test_consumer.rb +0 -226
  33. data/test/test_curb_request_proxy.rb +0 -77
  34. data/test/test_em_http_client.rb +0 -80
  35. data/test/test_em_http_request_proxy.rb +0 -115
  36. data/test/test_helper.rb +0 -33
  37. data/test/test_hmac_sha1.rb +0 -20
  38. data/test/test_net_http_client.rb +0 -298
  39. data/test/test_net_http_request_proxy.rb +0 -72
  40. data/test/test_oauth_helper.rb +0 -94
  41. data/test/test_rack_request_proxy.rb +0 -40
  42. data/test/test_request_token.rb +0 -56
  43. data/test/test_rest_client_request_proxy.rb +0 -81
  44. data/test/test_rsa_sha1.rb +0 -59
  45. data/test/test_server.rb +0 -41
  46. data/test/test_signature.rb +0 -15
  47. data/test/test_signature_base.rb +0 -32
  48. data/test/test_signature_hmac_sha1.rb +0 -40
  49. data/test/test_signature_plain_text.rb +0 -31
  50. data/test/test_token.rb +0 -14
  51. data/test/test_typhoeus_request_proxy.rb +0 -101
@@ -9,9 +9,17 @@ module OAuth
9
9
  #
10
10
  # See Also: {OAuth core spec version 1.0, section 5.1}[http://oauth.net/core/1.0#rfc.section.5.1]
11
11
  def escape(value)
12
- URI::escape(value.to_s.to_str, OAuth::RESERVED_CHARACTERS)
12
+ _escape(value.to_s.to_str)
13
13
  rescue ArgumentError
14
- URI::escape(value.to_s.to_str.force_encoding(Encoding::UTF_8), OAuth::RESERVED_CHARACTERS)
14
+ _escape(value.to_s.to_str.force_encoding(Encoding::UTF_8))
15
+ end
16
+
17
+ def _escape(string)
18
+ URI::DEFAULT_PARSER.escape(string, OAuth::RESERVED_CHARACTERS)
19
+ end
20
+
21
+ def unescape(value)
22
+ URI::DEFAULT_PARSER.unescape(value.gsub('+', '%2B'))
15
23
  end
16
24
 
17
25
  # Generate a random key of up to +size+ bytes. The value returned is Base64 encoded with non-word
@@ -94,10 +102,6 @@ module OAuth
94
102
  Hash[*params.flatten]
95
103
  end
96
104
 
97
- def unescape(value)
98
- URI.unescape(value.gsub('+', '%2B'))
99
- end
100
-
101
105
  def stringify_keys(hash)
102
106
  new_h = {}
103
107
  hash.each do |k, v|
@@ -23,7 +23,7 @@ then # rails 3.x
23
23
  ActionDispatch::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
24
24
  end
25
25
 
26
- else # rails 4.x - already has patch
26
+ else # rails 4.x and later - already has patch
27
27
  require 'action_dispatch/http/request'
28
28
  end
29
29
 
@@ -67,7 +67,7 @@ module OAuth::RequestProxy
67
67
 
68
68
  params.
69
69
  join('&').split('&').
70
- reject(&:blank?).
70
+ reject { |s| s.match(/\A\s*\z/) }.
71
71
  map { |p| p.split('=').map{|esc| CGI.unescape(esc)} }.
72
72
  reject { |kv| kv[0] == 'oauth_signature'}
73
73
  end
@@ -0,0 +1,7 @@
1
+ require 'oauth/request_proxy/rack_request'
2
+
3
+ module OAuth::RequestProxy
4
+ class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
5
+ proxies ActionDispatch::Request
6
+ end
7
+ end
@@ -76,7 +76,7 @@ module OAuth::RequestProxy
76
76
  end
77
77
 
78
78
  def parameters_for_signature
79
- parameters.reject { |k,v| k == "oauth_signature" || unsigned_parameters.include?(k)}
79
+ parameters.select { |k,v| not signature_and_unsigned_parameters.include?(k) }
80
80
  end
81
81
 
82
82
  def oauth_parameters
@@ -87,6 +87,10 @@ module OAuth::RequestProxy
87
87
  parameters.reject { |k,v| OAuth::PARAMETERS.include?(k) }
88
88
  end
89
89
 
90
+ def signature_and_unsigned_parameters
91
+ unsigned_parameters+["oauth_signature"]
92
+ end
93
+
90
94
  # See 9.1.2 in specs
91
95
  def normalized_uri
92
96
  u = URI.parse(uri)
@@ -146,7 +150,7 @@ module OAuth::RequestProxy
146
150
  if uri = request.env['REQUEST_URI']
147
151
  uri.split('?', 2)[1].nil?
148
152
  else
149
- request.query_string.blank?
153
+ request.query_string.match(/\A\s*\z/)
150
154
  end
151
155
  end
152
156
 
@@ -26,11 +26,11 @@ module OAuth
26
26
  # construct an authorization url
27
27
  def build_authorize_url(base_url, params)
28
28
  uri = URI.parse(base_url.to_s)
29
- if(!uri.query.blank? && !params.empty?)
30
- uri.query += "&"
31
- end
29
+ queries = {}
30
+ queries = Hash[URI.decode_www_form(uri.query)] if uri.query
32
31
  # TODO doesn't handle array values correctly
33
- uri.query = params.map { |k,v| [k, CGI.escape(v)] * "=" } * "&"
32
+ queries.merge!(params) if params
33
+ uri.query = URI.encode_www_form(queries) if !queries.empty?
34
34
  uri.to_s
35
35
  end
36
36
  end
@@ -1,3 +1,3 @@
1
1
  module OAuth
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pelle Braendgaard
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2016-02-20 00:00:00.000000000 Z
18
+ date: 2017-12-08 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
@@ -59,62 +59,48 @@ dependencies:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: jeweler
64
- requirement: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- type: :development
70
- prerelease: false
71
- version_requirements: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
62
  - !ruby/object:Gem::Dependency
77
63
  name: actionpack
78
64
  requirement: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: 4.0.2
68
+ version: '5.0'
83
69
  type: :development
84
70
  prerelease: false
85
71
  version_requirements: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
88
74
  - !ruby/object:Gem::Version
89
- version: 4.0.2
75
+ version: '5.0'
90
76
  - !ruby/object:Gem::Dependency
91
77
  name: iconv
92
78
  requirement: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - "~>"
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
- version: 1.0.3
82
+ version: '0'
97
83
  type: :development
98
84
  prerelease: false
99
85
  version_requirements: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - "~>"
87
+ - - ">="
102
88
  - !ruby/object:Gem::Version
103
- version: 1.0.3
89
+ version: '0'
104
90
  - !ruby/object:Gem::Dependency
105
91
  name: rack
106
92
  requirement: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: 1.6.1
96
+ version: '2.0'
111
97
  type: :development
112
98
  prerelease: false
113
99
  version_requirements: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: 1.6.1
103
+ version: '2.0'
118
104
  - !ruby/object:Gem::Dependency
119
105
  name: rack-test
120
106
  requirement: !ruby/object:Gem::Requirement
@@ -175,16 +161,72 @@ dependencies:
175
161
  name: curb
176
162
  requirement: !ruby/object:Gem::Requirement
177
163
  requirements:
178
- - - '='
164
+ - - ">="
179
165
  - !ruby/object:Gem::Version
180
- version: 0.7.16
166
+ version: '0'
181
167
  type: :development
182
168
  prerelease: false
183
169
  version_requirements: !ruby/object:Gem::Requirement
184
170
  requirements:
185
- - - '='
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: webmock
176
+ requirement: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "<"
179
+ - !ruby/object:Gem::Version
180
+ version: '2.0'
181
+ type: :development
182
+ prerelease: false
183
+ version_requirements: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "<"
186
+ - !ruby/object:Gem::Version
187
+ version: '2.0'
188
+ - !ruby/object:Gem::Dependency
189
+ name: codeclimate-test-reporter
190
+ requirement: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ type: :development
196
+ prerelease: false
197
+ version_requirements: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
186
200
  - !ruby/object:Gem::Version
187
- version: 0.7.16
201
+ version: '0'
202
+ - !ruby/object:Gem::Dependency
203
+ name: simplecov
204
+ requirement: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ type: :development
210
+ prerelease: false
211
+ version_requirements: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ - !ruby/object:Gem::Dependency
217
+ name: rest-client
218
+ requirement: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ type: :development
224
+ prerelease: false
225
+ version_requirements: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
188
230
  description:
189
231
  email: oauth-ruby@googlegroupspec.com
190
232
  executables:
@@ -201,13 +243,18 @@ files:
201
243
  - bin/oauth
202
244
  - lib/oauth.rb
203
245
  - lib/oauth/cli.rb
246
+ - lib/oauth/cli/authorize_command.rb
247
+ - lib/oauth/cli/base_command.rb
248
+ - lib/oauth/cli/help_command.rb
249
+ - lib/oauth/cli/query_command.rb
250
+ - lib/oauth/cli/sign_command.rb
251
+ - lib/oauth/cli/version_command.rb
204
252
  - lib/oauth/client.rb
205
253
  - lib/oauth/client/action_controller_request.rb
206
254
  - lib/oauth/client/em_http.rb
207
255
  - lib/oauth/client/helper.rb
208
256
  - lib/oauth/client/net_http.rb
209
257
  - lib/oauth/consumer.rb
210
- - lib/oauth/core_ext.rb
211
258
  - lib/oauth/errors.rb
212
259
  - lib/oauth/errors/error.rb
213
260
  - lib/oauth/errors/problem.rb
@@ -217,6 +264,7 @@ files:
217
264
  - lib/oauth/oauth_test_helper.rb
218
265
  - lib/oauth/request_proxy.rb
219
266
  - lib/oauth/request_proxy/action_controller_request.rb
267
+ - lib/oauth/request_proxy/action_dispatch_request.rb
220
268
  - lib/oauth/request_proxy/base.rb
221
269
  - lib/oauth/request_proxy/curb_request.rb
222
270
  - lib/oauth/request_proxy/em_http_request.rb
@@ -239,36 +287,9 @@ files:
239
287
  - lib/oauth/tokens/server_token.rb
240
288
  - lib/oauth/tokens/token.rb
241
289
  - lib/oauth/version.rb
242
- - test/cases/oauth_case.rb
243
- - test/cases/spec/1_0-final/test_construct_request_url.rb
244
- - test/cases/spec/1_0-final/test_normalize_request_parameters.rb
245
- - test/cases/spec/1_0-final/test_parameter_encodings.rb
246
- - test/cases/spec/1_0-final/test_signature_base_strings.rb
247
- - test/integration/consumer_test.rb
248
- - test/test_access_token.rb
249
- - test/test_action_controller_request_proxy.rb
250
- - test/test_consumer.rb
251
- - test/test_curb_request_proxy.rb
252
- - test/test_em_http_client.rb
253
- - test/test_em_http_request_proxy.rb
254
- - test/test_helper.rb
255
- - test/test_hmac_sha1.rb
256
- - test/test_net_http_client.rb
257
- - test/test_net_http_request_proxy.rb
258
- - test/test_oauth_helper.rb
259
- - test/test_rack_request_proxy.rb
260
- - test/test_request_token.rb
261
- - test/test_rest_client_request_proxy.rb
262
- - test/test_rsa_sha1.rb
263
- - test/test_server.rb
264
- - test/test_signature.rb
265
- - test/test_signature_base.rb
266
- - test/test_signature_hmac_sha1.rb
267
- - test/test_signature_plain_text.rb
268
- - test/test_token.rb
269
- - test/test_typhoeus_request_proxy.rb
270
290
  homepage:
271
- licenses: []
291
+ licenses:
292
+ - MIT
272
293
  metadata: {}
273
294
  post_install_message:
274
295
  rdoc_options: []
@@ -278,7 +299,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
299
  requirements:
279
300
  - - ">="
280
301
  - !ruby/object:Gem::Version
281
- version: '0'
302
+ version: '2.0'
282
303
  required_rubygems_version: !ruby/object:Gem::Requirement
283
304
  requirements:
284
305
  - - ">="
@@ -286,37 +307,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
307
  version: '0'
287
308
  requirements: []
288
309
  rubyforge_project:
289
- rubygems_version: 2.5.1
310
+ rubygems_version: 2.2.2
290
311
  signing_key:
291
312
  specification_version: 4
292
313
  summary: OAuth Core Ruby implementation
293
- test_files:
294
- - test/test_rsa_sha1.rb
295
- - test/test_helper.rb
296
- - test/test_server.rb
297
- - test/test_em_http_client.rb
298
- - test/test_signature_hmac_sha1.rb
299
- - test/test_signature.rb
300
- - test/test_em_http_request_proxy.rb
301
- - test/test_net_http_client.rb
302
- - test/test_rest_client_request_proxy.rb
303
- - test/cases/oauth_case.rb
304
- - test/cases/spec/1_0-final/test_parameter_encodings.rb
305
- - test/cases/spec/1_0-final/test_signature_base_strings.rb
306
- - test/cases/spec/1_0-final/test_normalize_request_parameters.rb
307
- - test/cases/spec/1_0-final/test_construct_request_url.rb
308
- - test/test_hmac_sha1.rb
309
- - test/test_consumer.rb
310
- - test/test_rack_request_proxy.rb
311
- - test/test_signature_base.rb
312
- - test/test_typhoeus_request_proxy.rb
313
- - test/integration/consumer_test.rb
314
- - test/test_signature_plain_text.rb
315
- - test/test_curb_request_proxy.rb
316
- - test/test_token.rb
317
- - test/test_action_controller_request_proxy.rb
318
- - test/test_oauth_helper.rb
319
- - test/test_access_token.rb
320
- - test/test_request_token.rb
321
- - test/test_net_http_request_proxy.rb
322
- has_rdoc:
314
+ test_files: []
@@ -1,31 +0,0 @@
1
- # these are to backport methods from 1.8.7/1.9.1 to 1.8.6
2
-
3
- class Object
4
-
5
- unless method_defined?(:tap)
6
- def tap
7
- yield self
8
- self
9
- end
10
- end
11
-
12
- end
13
-
14
- class String
15
-
16
-
17
-
18
- unless method_defined?(:bytesize)
19
- def bytesize
20
- self.size
21
- end
22
- end
23
-
24
- unless method_defined?(:bytes)
25
- def bytes
26
- require 'enumerator'
27
- Enumerable::Enumerator.new(self, :each_byte)
28
- end
29
- end
30
-
31
- end
@@ -1,19 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'oauth/signature'
3
- require 'oauth/request_proxy/mock_request'
4
-
5
-
6
- class OAuthCase < Minitest::Test
7
- # avoid whining about a lack of tests
8
- def run(*args)
9
- return if @method_name.to_s == "default_test"
10
- super
11
- end
12
-
13
- protected
14
-
15
- # Creates a fake request
16
- def request(params={},method='GET',uri="http://photos.example.net/photos")
17
- OAuth::RequestProxy.proxy({'parameters'=>params,'method'=>method,'uri'=>uri})
18
- end
19
- end
@@ -1,62 +0,0 @@
1
- require File.expand_path('../../../oauth_case', __FILE__)
2
-
3
- # See http://oauth.net/core/1.0/#anchor14
4
- #
5
- #9.1.2. Construct Request URL
6
- #
7
- #The Signature Base String includes the request absolute URL, tying the signature to a specific endpoint. The URL used in the Signature Base String MUST include the scheme, authority, and path, and MUST exclude the query and fragment as defined by [RFC3986] section 3.
8
- #
9
- #If the absolute request URL is not available to the Service Provider (it is always available to the Consumer), it can be constructed by combining the scheme being used, the HTTP Host header, and the relative HTTP request URL. If the Host header is not available, the Service Provider SHOULD use the host name communicated to the Consumer in the documentation or other means.
10
- #
11
- #The Service Provider SHOULD document the form of URL used in the Signature Base String to avoid ambiguity due to URL normalization. Unless specified, URL scheme and authority MUST be lowercase and include the port number; http default port 80 and https default port 443 MUST be excluded.
12
- #
13
- #For example, the request:
14
- #
15
- # HTTP://Example.com:80/resource?id=123
16
- #Is included in the Signature Base String as:
17
- #
18
- # http://example.com/resource
19
-
20
-
21
- class ConstructRequestUrlTest < OAuthCase
22
-
23
- def test_from_spec
24
- assert_request_url("http://example.com/resource","HTTP://Example.com:80/resource?id=123")
25
- end
26
-
27
- def test_simple_url_with_ending_slash
28
- assert_request_url("http://example.com/","http://example.com/")
29
- end
30
-
31
- def test_simple_url_without_ending_slash
32
- assert_request_url("http://example.com/","http://example.com")
33
- end
34
-
35
- def test_of_normalized_http
36
- assert_request_url("http://example.com/resource","http://example.com/resource")
37
- end
38
-
39
- def test_of_https
40
- assert_request_url("https://example.com/resource","HTTPS://Example.com:443/resource?id=123")
41
- end
42
-
43
- def test_of_normalized_https
44
- assert_request_url("https://example.com/resource","https://example.com/resource")
45
- end
46
-
47
- def test_of_http_with_non_standard_port
48
- assert_request_url("http://example.com:8080/resource","http://example.com:8080/resource")
49
- end
50
-
51
- def test_of_https_with_non_standard_port
52
- assert_request_url("https://example.com:8080/resource","https://example.com:8080/resource")
53
- end
54
-
55
- protected
56
-
57
-
58
- def assert_request_url(expected,given,message=nil)
59
- assert_equal expected, request({},'GET',given).normalized_uri, message
60
- end
61
-
62
- end