oauth 0.5.7.pre.pre1 → 0.5.9

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -104
  3. data/CODE_OF_CONDUCT.md +0 -0
  4. data/CONTRIBUTING.md +23 -0
  5. data/LICENSE +0 -0
  6. data/README.md +50 -67
  7. data/SECURITY.md +16 -0
  8. data/TODO +0 -0
  9. data/lib/oauth/cli/authorize_command.rb +8 -10
  10. data/lib/oauth/cli/base_command.rb +8 -6
  11. data/lib/oauth/cli/help_command.rb +0 -0
  12. data/lib/oauth/cli/query_command.rb +3 -3
  13. data/lib/oauth/cli/sign_command.rb +12 -15
  14. data/lib/oauth/cli/version_command.rb +0 -0
  15. data/lib/oauth/cli.rb +2 -2
  16. data/lib/oauth/client/action_controller_request.rb +14 -15
  17. data/lib/oauth/client/em_http.rb +28 -28
  18. data/lib/oauth/client/helper.rb +14 -17
  19. data/lib/oauth/client/net_http.rb +27 -27
  20. data/lib/oauth/client.rb +0 -0
  21. data/lib/oauth/consumer.rb +52 -62
  22. data/lib/oauth/errors/error.rb +0 -0
  23. data/lib/oauth/errors/problem.rb +0 -0
  24. data/lib/oauth/errors/unauthorized.rb +0 -0
  25. data/lib/oauth/errors.rb +0 -0
  26. data/lib/oauth/helper.rb +7 -7
  27. data/lib/oauth/oauth.rb +4 -4
  28. data/lib/oauth/oauth_test_helper.rb +0 -0
  29. data/lib/oauth/request_proxy/action_controller_request.rb +50 -51
  30. data/lib/oauth/request_proxy/action_dispatch_request.rb +7 -3
  31. data/lib/oauth/request_proxy/base.rb +134 -130
  32. data/lib/oauth/request_proxy/curb_request.rb +45 -39
  33. data/lib/oauth/request_proxy/em_http_request.rb +56 -52
  34. data/lib/oauth/request_proxy/jabber_request.rb +9 -6
  35. data/lib/oauth/request_proxy/mock_request.rb +3 -1
  36. data/lib/oauth/request_proxy/net_http.rb +59 -50
  37. data/lib/oauth/request_proxy/rack_request.rb +32 -28
  38. data/lib/oauth/request_proxy/rest_client_request.rb +48 -45
  39. data/lib/oauth/request_proxy/typhoeus_request.rb +45 -39
  40. data/lib/oauth/request_proxy.rb +3 -3
  41. data/lib/oauth/server.rb +8 -10
  42. data/lib/oauth/signature/base.rb +3 -4
  43. data/lib/oauth/signature/hmac/sha1.rb +1 -1
  44. data/lib/oauth/signature/hmac/sha256.rb +1 -1
  45. data/lib/oauth/signature/plaintext.rb +0 -0
  46. data/lib/oauth/signature/rsa/sha1.rb +3 -3
  47. data/lib/oauth/signature.rb +5 -5
  48. data/lib/oauth/token.rb +0 -0
  49. data/lib/oauth/tokens/access_token.rb +0 -0
  50. data/lib/oauth/tokens/consumer_token.rb +2 -2
  51. data/lib/oauth/tokens/request_token.rb +7 -8
  52. data/lib/oauth/tokens/server_token.rb +0 -1
  53. data/lib/oauth/tokens/token.rb +0 -0
  54. data/lib/oauth/version.rb +1 -1
  55. data/lib/oauth.rb +0 -0
  56. metadata +12 -163
@@ -16,8 +16,8 @@ module OAuth
16
16
  end
17
17
  end
18
18
 
19
- if !defined?(CA_FILE)
20
- CA_FILES = %W(/etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /usr/share/curl/curl-ca-bundle.crt)
19
+ unless defined?(CA_FILE)
20
+ CA_FILES = %w[/etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /usr/share/curl/curl-ca-bundle.crt].freeze
21
21
  CA_FILES.each do |ca_file|
22
22
  if File.exist?(ca_file)
23
23
  CA_FILE = ca_file
@@ -29,15 +29,15 @@ module OAuth
29
29
 
30
30
  @@default_options = {
31
31
  # Signature method used by server. Defaults to HMAC-SHA1
32
- :signature_method => "HMAC-SHA1",
32
+ signature_method: "HMAC-SHA1",
33
33
 
34
34
  # default paths on site. These are the same as the defaults set up by the generators
35
- :request_token_path => "/oauth/request_token",
36
- :authenticate_path => "/oauth/authenticate",
37
- :authorize_path => "/oauth/authorize",
38
- :access_token_path => "/oauth/access_token",
35
+ request_token_path: "/oauth/request_token",
36
+ authenticate_path: "/oauth/authenticate",
37
+ authorize_path: "/oauth/authorize",
38
+ access_token_path: "/oauth/access_token",
39
39
 
40
- :proxy => nil,
40
+ proxy: nil,
41
41
  # How do we send the oauth values to the server see
42
42
  # https://oauth.net/core/1.0/#consumer_req_param for more info
43
43
  #
@@ -46,10 +46,10 @@ module OAuth
46
46
  # :header - via the Authorize header (Default) ( option 1. in spec)
47
47
  # :body - url form encoded in body of POST request ( option 2. in spec)
48
48
  # :query_string - via the query part of the url ( option 3. in spec)
49
- :scheme => :header,
49
+ scheme: :header,
50
50
 
51
51
  # Default http method used for OAuth Token Requests (defaults to :post)
52
- :http_method => :post,
52
+ http_method: :post,
53
53
 
54
54
  # Add a custom ca_file for consumer
55
55
  # :ca_file => '/etc/certs.pem'
@@ -59,9 +59,9 @@ module OAuth
59
59
  # nil, false - no debug output
60
60
  # true - uses $stdout
61
61
  # some_value - uses some_value
62
- :debug_output => nil,
62
+ debug_output: nil,
63
63
 
64
- :oauth_version => "1.0"
64
+ oauth_version: "1.0"
65
65
  }
66
66
 
67
67
  attr_accessor :options, :key, :secret
@@ -94,9 +94,8 @@ module OAuth
94
94
  @secret = consumer_secret
95
95
 
96
96
  # ensure that keys are symbols
97
- @options = @@default_options.merge(options.inject({}) do |opts, (key, value)|
97
+ @options = @@default_options.merge(options.each_with_object({}) do |(key, value), opts|
98
98
  opts[key.to_sym] = value
99
- opts
100
99
  end)
101
100
  end
102
101
 
@@ -127,7 +126,7 @@ module OAuth
127
126
  if custom_uri
128
127
  @uri = custom_uri
129
128
  @http = create_http # yike, oh well. less intrusive this way
130
- else # if no custom passed, we use existing, which, if unset, is set to site uri
129
+ else # if no custom passed, we use existing, which, if unset, is set to site uri
131
130
  @uri ||= URI.parse(site)
132
131
  end
133
132
  end
@@ -156,18 +155,18 @@ module OAuth
156
155
  # will be exchanged out of band
157
156
  request_options[:oauth_callback] ||= OAuth::OUT_OF_BAND unless request_options[:exclude_callback]
158
157
 
159
- if block_given?
160
- response = token_request(
161
- http_method,
162
- (request_token_url? ? request_token_url : request_token_path),
163
- nil,
164
- request_options,
165
- *arguments,
166
- &block
167
- )
168
- else
169
- response = token_request(http_method, (request_token_url? ? request_token_url : request_token_path), nil, request_options, *arguments)
170
- end
158
+ response = if block_given?
159
+ token_request(
160
+ http_method,
161
+ (request_token_url? ? request_token_url : request_token_path),
162
+ nil,
163
+ request_options,
164
+ *arguments,
165
+ &block
166
+ )
167
+ else
168
+ token_request(http_method, (request_token_url? ? request_token_url : request_token_path), nil, request_options, *arguments)
169
+ end
171
170
  OAuth::RequestToken.from_hash(self, response)
172
171
  end
173
172
 
@@ -190,18 +189,18 @@ module OAuth
190
189
 
191
190
  # override the request with your own, this is useful for file uploads which Net::HTTP does not do
192
191
  req = create_signed_request(http_method, path, token, request_options, *arguments)
193
- return nil if block_given? and yield(req) == :done
192
+ return nil if block_given? && (yield(req) == :done)
194
193
  rsp = http.request(req)
195
194
  # check for an error reported by the Problem Reporting extension
196
195
  # (https://wiki.oauth.net/ProblemReporting)
197
196
  # note: a 200 may actually be an error; check for an oauth_problem key to be sure
198
197
  if !(headers = rsp.to_hash["www-authenticate"]).nil? &&
199
- (h = headers.select { |hdr| hdr =~ /^OAuth / }).any? &&
200
- h.first =~ /oauth_problem/
198
+ (h = headers.select { |hdr| hdr =~ /^OAuth / }).any? &&
199
+ h.first =~ /oauth_problem/
201
200
 
202
201
  # puts "Header: #{h.first}"
203
202
 
204
- # TODO doesn't handle broken responses from api.login.yahoo.com
203
+ # TODO: doesn't handle broken responses from api.login.yahoo.com
205
204
  # remove debug code when done
206
205
  params = OAuth::Helper.parse_header(h.first)
207
206
 
@@ -235,10 +234,9 @@ module OAuth
235
234
  # symbolize keys
236
235
  # TODO this could be considered unexpected behavior; symbols or not?
237
236
  # TODO this also drops subsequent values from multi-valued keys
238
- CGI.parse(response.body).inject({}) do |h,(k,v)|
237
+ CGI.parse(response.body).each_with_object({}) do |(k, v), h|
239
238
  h[k.strip.to_sym] = v.first
240
239
  h[k.strip] = v.first
241
- h
242
240
  end
243
241
  end
244
242
  when (300..399)
@@ -250,11 +248,11 @@ module OAuth
250
248
  response.error! if uri.path == path && our_uri.host == uri.host
251
249
 
252
250
  if uri.path == path && our_uri.host != uri.host
253
- options[:site] = "#{uri.scheme}://#{uri.host}"
254
- @http = create_http
251
+ options[:site] = "#{uri.scheme}://#{uri.host}"
252
+ @http = create_http
255
253
  end
256
254
 
257
- self.token_request(http_method, uri.path, token, request_options, arguments)
255
+ token_request(http_method, uri.path, token, request_options, arguments)
258
256
  when (400..499)
259
257
  raise OAuth::Unauthorized, response
260
258
  else
@@ -301,13 +299,13 @@ module OAuth
301
299
  @options[:access_token_path]
302
300
  end
303
301
 
304
- # TODO this is ugly, rewrite
302
+ # TODO: this is ugly, rewrite
305
303
  def request_token_url
306
304
  @options[:request_token_url] || site + request_token_path
307
305
  end
308
306
 
309
307
  def request_token_url?
310
- @options.has_key?(:request_token_url)
308
+ @options.key?(:request_token_url)
311
309
  end
312
310
 
313
311
  def authenticate_url
@@ -315,7 +313,7 @@ module OAuth
315
313
  end
316
314
 
317
315
  def authenticate_url?
318
- @options.has_key?(:authenticate_url)
316
+ @options.key?(:authenticate_url)
319
317
  end
320
318
 
321
319
  def authorize_url
@@ -323,7 +321,7 @@ module OAuth
323
321
  end
324
322
 
325
323
  def authorize_url?
326
- @options.has_key?(:authorize_url)
324
+ @options.key?(:authorize_url)
327
325
  end
328
326
 
329
327
  def access_token_url
@@ -331,7 +329,7 @@ module OAuth
331
329
  end
332
330
 
333
331
  def access_token_url?
334
- @options.has_key?(:access_token_url)
332
+ @options.key?(:access_token_url)
335
333
  end
336
334
 
337
335
  def proxy
@@ -342,10 +340,7 @@ module OAuth
342
340
 
343
341
  # Instantiates the http object
344
342
  def create_http(_url = nil)
345
-
346
- if !request_endpoint.nil?
347
- _url = request_endpoint
348
- end
343
+ _url = request_endpoint unless request_endpoint.nil?
349
344
 
350
345
  our_uri = if _url.nil? || _url[0] =~ /^\//
351
346
  URI.parse(site)
@@ -372,10 +367,8 @@ module OAuth
372
367
  if @options[:no_verify]
373
368
  http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
374
369
  else
375
- ca_file = @options[:ca_file] || CA_FILE
376
- if ca_file
377
- http_object.ca_file = ca_file
378
- end
370
+ ca_file = @options[:ca_file] || CA_FILE
371
+ http_object.ca_file = ca_file if ca_file
379
372
  http_object.verify_mode = OpenSSL::SSL::VERIFY_PEER
380
373
  http_object.verify_depth = 5
381
374
  end
@@ -394,9 +387,7 @@ module OAuth
394
387
  def create_http_request(http_method, path, *arguments)
395
388
  http_method = http_method.to_sym
396
389
 
397
- if [:post, :put, :patch].include?(http_method)
398
- data = arguments.shift
399
- end
390
+ data = arguments.shift if %i[post put patch].include?(http_method)
400
391
 
401
392
  # if the base site contains a path, add it now
402
393
  # only add if the site host matches the current http object's host
@@ -408,22 +399,22 @@ module OAuth
408
399
 
409
400
  case http_method
410
401
  when :post
411
- request = Net::HTTP::Post.new(path,headers)
402
+ request = Net::HTTP::Post.new(path, headers)
412
403
  request["Content-Length"] = "0" # Default to 0
413
404
  when :put
414
- request = Net::HTTP::Put.new(path,headers)
405
+ request = Net::HTTP::Put.new(path, headers)
415
406
  request["Content-Length"] = "0" # Default to 0
416
407
  when :patch
417
- request = Net::HTTP::Patch.new(path,headers)
408
+ request = Net::HTTP::Patch.new(path, headers)
418
409
  request["Content-Length"] = "0" # Default to 0
419
410
  when :get
420
- request = Net::HTTP::Get.new(path,headers)
411
+ request = Net::HTTP::Get.new(path, headers)
421
412
  when :delete
422
- request = Net::HTTP::Delete.new(path,headers)
413
+ request = Net::HTTP::Delete.new(path, headers)
423
414
  when :head
424
- request = Net::HTTP::Head.new(path,headers)
415
+ request = Net::HTTP::Head.new(path, headers)
425
416
  else
426
- raise ArgumentError, "Don't know how to handle http_method: :#{http_method.to_s}"
417
+ raise ArgumentError, "Don't know how to handle http_method: :#{http_method}"
427
418
  end
428
419
 
429
420
  if data.is_a?(Hash)
@@ -448,13 +439,12 @@ module OAuth
448
439
  request
449
440
  end
450
441
 
451
- def marshal_dump(*args)
452
- {:key => @key, :secret => @secret, :options => @options}
442
+ def marshal_dump(*_args)
443
+ { key: @key, secret: @secret, options: @options }
453
444
  end
454
445
 
455
446
  def marshal_load(data)
456
447
  initialize(data[:key], data[:secret], data[:options])
457
448
  end
458
-
459
449
  end
460
450
  end
File without changes
File without changes
File without changes
data/lib/oauth/errors.rb CHANGED
File without changes
data/lib/oauth/helper.rb CHANGED
@@ -24,11 +24,11 @@ module OAuth
24
24
 
25
25
  # Generate a random key of up to +size+ bytes. The value returned is Base64 encoded with non-word
26
26
  # characters removed.
27
- def generate_key(size=32)
27
+ def generate_key(size = 32)
28
28
  Base64.encode64(OpenSSL::Random.random_bytes(size)).gsub(/\W/, "")
29
29
  end
30
30
 
31
- alias_method :generate_nonce, :generate_key
31
+ alias generate_nonce generate_key
32
32
 
33
33
  def generate_timestamp #:nodoc:
34
34
  Time.now.to_i.to_s
@@ -51,13 +51,13 @@ module OAuth
51
51
  normalize_nested_query(values, k)
52
52
  else
53
53
  values.sort.collect do |v|
54
- [escape(k),escape(v)] * "="
54
+ [escape(k), escape(v)].join("=")
55
55
  end
56
56
  end
57
57
  elsif values.is_a?(Hash)
58
58
  normalize_nested_query(values, k)
59
59
  else
60
- [escape(k),escape(values)] * "="
60
+ [escape(k), escape(values)].join("=")
61
61
  end
62
62
  end * "&"
63
63
  end
@@ -76,7 +76,7 @@ module OAuth
76
76
  normalize_nested_query(v, prefix ? "#{prefix}[#{k}]" : k)
77
77
  end.flatten.sort
78
78
  else
79
- [escape(prefix), escape(value)] * "="
79
+ [escape(prefix), escape(value)].join("=")
80
80
  end
81
81
  end
82
82
 
@@ -90,10 +90,10 @@ module OAuth
90
90
  #
91
91
  def parse_header(header)
92
92
  # decompose
93
- params = header[6,header.length].split(/[,=&]/)
93
+ params = header[6, header.length].split(/[,=&]/)
94
94
 
95
95
  # odd number of arguments - must be a malformed header.
96
- raise OAuth::Problem.new("Invalid authorization header") if params.size % 2 != 0
96
+ raise OAuth::Problem, "Invalid authorization header" if params.size.odd?
97
97
 
98
98
  params.map! do |v|
99
99
  # strip and unescape
data/lib/oauth/oauth.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  module OAuth
2
2
  # request tokens are passed between the consumer and the provider out of
3
3
  # band (i.e. callbacks cannot be used), per section 6.1.1
4
- OUT_OF_BAND = "oob"
4
+ OUT_OF_BAND = "oob".freeze
5
5
 
6
6
  # required parameters, per sections 6.1.1, 6.3.1, and 7
7
- PARAMETERS = %w(oauth_callback oauth_consumer_key oauth_token
8
- oauth_signature_method oauth_timestamp oauth_nonce oauth_verifier
9
- oauth_version oauth_signature oauth_body_hash)
7
+ PARAMETERS = %w[oauth_callback oauth_consumer_key oauth_token
8
+ oauth_signature_method oauth_timestamp oauth_nonce oauth_verifier
9
+ oauth_version oauth_signature oauth_body_hash].freeze
10
10
 
11
11
  # reserved character regexp, per section 5.1
12
12
  RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
File without changes
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support"
2
4
  require "active_support/version"
3
5
  require "action_controller"
4
6
  require "uri"
5
7
 
6
- if
7
- Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
8
- then # rails 2.x
8
+ if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
9
+ # rails 2.x
9
10
  require "action_controller/request"
10
11
  unless ActionController::Request::HTTP_METHODS.include?("patch")
11
12
  ActionController::Request::HTTP_METHODS << "patch"
@@ -13,9 +14,8 @@ then # rails 2.x
13
14
  ActionController::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
14
15
  end
15
16
 
16
- elsif
17
- Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
18
- then # rails 3.x
17
+ elsif Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
18
+ # rails 3.x
19
19
  require "action_dispatch/http/request"
20
20
  unless ActionDispatch::Request::HTTP_METHODS.include?("patch")
21
21
  ActionDispatch::Request::HTTP_METHODS << "patch"
@@ -27,64 +27,63 @@ else # rails 4.x and later - already has patch
27
27
  require "action_dispatch/http/request"
28
28
  end
29
29
 
30
- module OAuth::RequestProxy
31
- class ActionControllerRequest < OAuth::RequestProxy::Base
32
- proxies(defined?(ActionDispatch::AbstractRequest) ? ActionDispatch::AbstractRequest : ActionDispatch::Request)
30
+ module OAuth
31
+ module RequestProxy
32
+ class ActionControllerRequest < OAuth::RequestProxy::Base
33
+ proxies(defined?(::ActionDispatch::AbstractRequest) ? ::ActionDispatch::AbstractRequest : ::ActionDispatch::Request)
33
34
 
34
- def method
35
- request.method.to_s.upcase
36
- end
35
+ def method
36
+ request.method.to_s.upcase
37
+ end
37
38
 
38
- def uri
39
- request.url
40
- end
39
+ def uri
40
+ request.url
41
+ end
41
42
 
42
- def parameters
43
- if options[:clobber_request]
44
- options[:parameters] || {}
45
- else
46
- params = request_params.merge(query_params).merge(header_params)
47
- params.stringify_keys! if params.respond_to?(:stringify_keys!)
48
- params.merge(options[:parameters] || {})
43
+ def parameters
44
+ if options[:clobber_request]
45
+ options[:parameters] || {}
46
+ else
47
+ params = request_params.merge(query_params).merge(header_params)
48
+ params.stringify_keys! if params.respond_to?(:stringify_keys!)
49
+ params.merge(options[:parameters] || {})
50
+ end
49
51
  end
50
- end
51
52
 
52
- # Override from OAuth::RequestProxy::Base to avoid roundtrip
53
- # conversion to Hash or Array and thus preserve the original
54
- # parameter names
55
- def parameters_for_signature
56
- params = []
57
- params << options[:parameters].to_query if options[:parameters]
53
+ # Override from OAuth::RequestProxy::Base to avoid roundtrip
54
+ # conversion to Hash or Array and thus preserve the original
55
+ # parameter names
56
+ def parameters_for_signature
57
+ params = []
58
+ params << options[:parameters].to_query if options[:parameters]
58
59
 
59
- unless options[:clobber_request]
60
- params << header_params.to_query
61
- params << request.query_string unless query_string_blank?
60
+ unless options[:clobber_request]
61
+ params << header_params.to_query
62
+ params << request.query_string unless query_string_blank?
62
63
 
63
- if raw_post_signature?
64
- params << request.raw_post
64
+ params << request.raw_post if raw_post_signature?
65
65
  end
66
- end
67
66
 
68
- params.
69
- join("&").split("&").
70
- reject { |s| s.match(/\A\s*\z/) }.
71
- map { |p| p.split("=").map{|esc| CGI.unescape(esc)} }.
72
- reject { |kv| kv[0] == "oauth_signature"}
73
- end
67
+ params.
68
+ join("&").split("&").
69
+ reject { |s| s.match(/\A\s*\z/) }.
70
+ map { |p| p.split("=").map { |esc| CGI.unescape(esc) } }.
71
+ reject { |kv| kv[0] == "oauth_signature" }
72
+ end
74
73
 
75
- def raw_post_signature?
76
- (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
77
- end
74
+ def raw_post_signature?
75
+ (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
76
+ end
78
77
 
79
- protected
78
+ protected
80
79
 
81
- def query_params
82
- request.query_parameters
83
- end
80
+ def query_params
81
+ request.query_parameters
82
+ end
84
83
 
85
- def request_params
86
- request.request_parameters
84
+ def request_params
85
+ request.request_parameters
86
+ end
87
87
  end
88
-
89
88
  end
90
89
  end
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/request_proxy/rack_request"
2
4
 
3
- module OAuth::RequestProxy
4
- class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
5
- proxies ActionDispatch::Request
5
+ module OAuth
6
+ module RequestProxy
7
+ class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
8
+ proxies ::ActionDispatch::Request
9
+ end
6
10
  end
7
11
  end