oauth 0.5.6 → 1.1.5

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 (71) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -0
  3. data/CHANGELOG.md +848 -0
  4. data/CITATION.cff +20 -0
  5. data/CODE_OF_CONDUCT.md +134 -0
  6. data/CONTRIBUTING.md +218 -0
  7. data/FUNDING.md +77 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +662 -0
  10. data/REEK +2 -0
  11. data/RUBOCOP.md +71 -0
  12. data/SECURITY.md +24 -0
  13. data/lib/oauth/auth_sanitizer.rb +36 -0
  14. data/lib/oauth/client/action_controller_request.rb +33 -22
  15. data/lib/oauth/client/em_http.rb +110 -103
  16. data/lib/oauth/client/helper.rb +87 -82
  17. data/lib/oauth/client/net_http.rb +140 -107
  18. data/lib/oauth/client.rb +2 -0
  19. data/lib/oauth/consumer.rb +222 -141
  20. data/lib/oauth/errors/error.rb +2 -0
  21. data/lib/oauth/errors/problem.rb +4 -1
  22. data/lib/oauth/errors/unauthorized.rb +7 -1
  23. data/lib/oauth/errors.rb +5 -3
  24. data/lib/oauth/helper.rb +48 -18
  25. data/lib/oauth/oauth.rb +31 -7
  26. data/lib/oauth/oauth_test_helper.rb +6 -4
  27. data/lib/oauth/optional.rb +20 -0
  28. data/lib/oauth/request_proxy/action_controller_request.rb +53 -71
  29. data/lib/oauth/request_proxy/action_dispatch_request.rb +42 -4
  30. data/lib/oauth/request_proxy/base.rb +146 -131
  31. data/lib/oauth/request_proxy/curb_request.rb +49 -43
  32. data/lib/oauth/request_proxy/em_http_request.rb +60 -49
  33. data/lib/oauth/request_proxy/jabber_request.rb +19 -9
  34. data/lib/oauth/request_proxy/mock_request.rb +5 -3
  35. data/lib/oauth/request_proxy/net_http.rb +61 -54
  36. data/lib/oauth/request_proxy/rack_request.rb +31 -31
  37. data/lib/oauth/request_proxy/rest_client_request.rb +55 -50
  38. data/lib/oauth/request_proxy/typhoeus_request.rb +51 -45
  39. data/lib/oauth/request_proxy.rb +21 -14
  40. data/lib/oauth/server.rb +18 -12
  41. data/lib/oauth/signature/base.rb +88 -71
  42. data/lib/oauth/signature/hmac/sha1.rb +16 -10
  43. data/lib/oauth/signature/hmac/sha256.rb +16 -10
  44. data/lib/oauth/signature/plaintext.rb +18 -20
  45. data/lib/oauth/signature/rsa/sha1.rb +53 -38
  46. data/lib/oauth/signature.rb +41 -34
  47. data/lib/oauth/token.rb +7 -5
  48. data/lib/oauth/tokens/access_token.rb +6 -4
  49. data/lib/oauth/tokens/consumer_token.rb +11 -7
  50. data/lib/oauth/tokens/request_token.rb +17 -10
  51. data/lib/oauth/tokens/server_token.rb +2 -1
  52. data/lib/oauth/tokens/token.rb +15 -1
  53. data/lib/oauth/version.rb +6 -1
  54. data/lib/oauth.rb +18 -9
  55. data/sig/oauth/consumer.rbs +9 -0
  56. data/sig/oauth/signature/base.rbs +12 -0
  57. data/sig/oauth/tokens/token.rbs +8 -0
  58. data.tar.gz.sig +3 -0
  59. metadata +301 -82
  60. metadata.gz.sig +2 -0
  61. data/LICENSE +0 -20
  62. data/README.rdoc +0 -88
  63. data/TODO +0 -32
  64. data/bin/oauth +0 -11
  65. data/lib/oauth/cli/authorize_command.rb +0 -71
  66. data/lib/oauth/cli/base_command.rb +0 -208
  67. data/lib/oauth/cli/help_command.rb +0 -22
  68. data/lib/oauth/cli/query_command.rb +0 -25
  69. data/lib/oauth/cli/sign_command.rb +0 -81
  70. data/lib/oauth/cli/version_command.rb +0 -7
  71. data/lib/oauth/cli.rb +0 -56
data/REEK ADDED
@@ -0,0 +1,2 @@
1
+ Error: No such file - is
2
+ Error: No such file - empty
data/RUBOCOP.md ADDED
@@ -0,0 +1,71 @@
1
+ # RuboCop Usage Guide
2
+
3
+ ## Overview
4
+
5
+ A tale of two RuboCop plugin gems.
6
+
7
+ ### RuboCop Gradual
8
+
9
+ This project uses `rubocop_gradual` instead of vanilla RuboCop for code style checking. The `rubocop_gradual` tool allows for gradual adoption of RuboCop rules by tracking violations in a lock file.
10
+
11
+ ### RuboCop LTS
12
+
13
+ This project uses `rubocop-lts` to ensure, on a best-effort basis, compatibility with Ruby >= 1.9.2.
14
+ RuboCop rules are meticulously configured by the `rubocop-lts` family of gems to ensure that a project is compatible with a specific version of Ruby. See: https://rubocop-lts.gitlab.io for more.
15
+
16
+ ## Checking RuboCop Violations
17
+
18
+ To check for RuboCop violations in this project, always use:
19
+
20
+ ```bash
21
+ bundle exec rake rubocop_gradual:check
22
+ ```
23
+
24
+ **Do not use** the standard RuboCop commands like:
25
+ - `bundle exec rubocop`
26
+ - `rubocop`
27
+
28
+ ## Understanding the Lock File
29
+
30
+ The `.rubocop_gradual.lock` file tracks all current RuboCop violations in the project. This allows the team to:
31
+
32
+ 1. Prevent new violations while gradually fixing existing ones
33
+ 2. Track progress on code style improvements
34
+ 3. Ensure CI builds don't fail due to pre-existing violations
35
+
36
+ ## Common Commands
37
+
38
+ - **Check violations**
39
+ - `bundle exec rake rubocop_gradual`
40
+ - `bundle exec rake rubocop_gradual:check`
41
+ - **(Safe) Autocorrect violations, and update lockfile if no new violations**
42
+ - `bundle exec rake rubocop_gradual:autocorrect`
43
+ - **Force update the lock file (w/o autocorrect) to match violations present in code**
44
+ - `bundle exec rake rubocop_gradual:force_update`
45
+
46
+ ## Workflow
47
+
48
+ 1. Before submitting a PR, run `bundle exec rake rubocop_gradual:autocorrect`
49
+ a. or just the default `bundle exec rake`, as autocorrection is a pre-requisite of the default task.
50
+ 2. If there are new violations, either:
51
+ - Fix them in your code
52
+ - Run `bundle exec rake rubocop_gradual:force_update` to update the lock file (only for violations you can't fix immediately)
53
+ 3. Commit the updated `.rubocop_gradual.lock` file along with your changes
54
+
55
+ ## Never add inline RuboCop disables
56
+
57
+ Do not add inline `rubocop:disable` / `rubocop:enable` comments anywhere in the codebase (including specs, except when following the few existing `rubocop:disable` patterns for a rule already being disabled elsewhere in the code). We handle exceptions in two supported ways:
58
+
59
+ - Permanent/structural exceptions: prefer adjusting the RuboCop configuration (e.g., in `.rubocop.yml`) to exclude a rule for a path or file pattern when it makes sense project-wide.
60
+ - Temporary exceptions while improving code: record the current violations in `.rubocop_gradual.lock` via the gradual workflow:
61
+ - `bundle exec rake rubocop_gradual:autocorrect` (preferred; will autocorrect what it can and update the lock only if no new violations were introduced)
62
+ - If needed, `bundle exec rake rubocop_gradual:force_update` (as a last resort when you cannot fix the newly reported violations immediately)
63
+
64
+ In general, treat the rules as guidance to follow; fix violations rather than ignore them. For example, RSpec conventions in this project expect `described_class` to be used in specs that target a specific class under test.
65
+
66
+ ## Benefits of rubocop_gradual
67
+
68
+ - Allows incremental adoption of code style rules
69
+ - Prevents CI failures due to pre-existing violations
70
+ - Provides a clear record of code style debt
71
+ - Enables focused efforts on improving code quality over time
data/SECURITY.md ADDED
@@ -0,0 +1,24 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ |----------|-----------|
7
+ | 1.latest | ✅ |
8
+
9
+ ## Security contact information
10
+
11
+ To report a security vulnerability, please use the
12
+ [Tidelift security contact](https://tidelift.com/security).
13
+ Tidelift will coordinate the fix and disclosure.
14
+
15
+ More detailed explanation of the process is in [IRP.md][IRP].
16
+
17
+ ## Additional Support
18
+
19
+ If you are interested in support for versions older than the latest release,
20
+ please consider sponsoring the project / maintainer @ https://liberapay.com/pboling/donate,
21
+ or find other sponsorship links in the [README].
22
+
23
+ [README]: README.md
24
+ [IRP]: IRP.md
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OAuth
4
+ AUTH_SANITIZER = begin
5
+ auth_sanitizer_requirement = Gem::Requirement.new("~> 0.1", ">= 0.1.3")
6
+ auth_sanitizer_spec = Gem.loaded_specs["auth-sanitizer"]
7
+ unless auth_sanitizer_spec && auth_sanitizer_requirement.satisfied_by?(auth_sanitizer_spec.version)
8
+ # :nocov:
9
+ auth_sanitizer_spec = Gem::Specification.find_by_name("auth-sanitizer", auth_sanitizer_requirement)
10
+ # :nocov:
11
+ end
12
+
13
+ auth_sanitizer_loader_path = File.join(
14
+ auth_sanitizer_spec.full_gem_path,
15
+ "lib/auth_sanitizer/loader.rb",
16
+ )
17
+ unless File.file?(auth_sanitizer_loader_path)
18
+ # :nocov:
19
+ raise LoadError, "oauth requires auth-sanitizer #{auth_sanitizer_requirement}; " \
20
+ "loader not found at #{auth_sanitizer_loader_path}"
21
+ # :nocov:
22
+ end
23
+
24
+ auth_sanitizer_loader_namespace = Module.new
25
+ auth_sanitizer_loader_namespace.module_eval(
26
+ File.read(auth_sanitizer_loader_path),
27
+ auth_sanitizer_loader_path,
28
+ 1,
29
+ )
30
+
31
+ auth_sanitizer_loader_namespace
32
+ .const_get(:AuthSanitizer)
33
+ .const_get(:Loader)
34
+ .load_isolated
35
+ end
36
+ end
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined? ActionDispatch
2
- require 'oauth/request_proxy/rack_request'
3
- require 'oauth/request_proxy/action_dispatch_request'
4
- require 'action_dispatch/testing/test_process'
4
+ require "oauth/request_proxy/rack_request"
5
+ require "oauth/request_proxy/action_dispatch_request"
6
+ require "action_dispatch/testing/test_process"
5
7
  else
6
- require 'oauth/request_proxy/action_controller_request'
7
- require 'action_controller/test_process'
8
+ require "oauth/request_proxy/action_controller_request"
9
+ require "action_controller/test_process"
8
10
  end
9
11
 
10
12
  module ActionController
11
13
  class Base
12
14
  if defined? ActionDispatch
13
- def process_with_new_base_test(request, response=nil)
15
+ def process_with_new_base_test(request, response = nil)
14
16
  request.apply_oauth! if request.respond_to?(:apply_oauth!)
15
17
  super(request, response)
16
18
  end
17
19
  else
18
- def process_with_oauth(request, response=nil)
20
+ def process_with_oauth(request, response = nil)
19
21
  request.apply_oauth! if request.respond_to?(:apply_oauth!)
20
22
  process_without_oauth(request, response)
21
23
  end
@@ -24,39 +26,48 @@ module ActionController
24
26
  end
25
27
 
26
28
  class TestRequest
27
- def self.use_oauth=(bool)
28
- @use_oauth = bool
29
- end
29
+ OAUTH_ENABLED_KEY = :oauth_action_controller_test_request_use_oauth
30
30
 
31
- def self.use_oauth?
32
- @use_oauth
31
+ class << self
32
+ def use_oauth=(value)
33
+ Thread.current[OAUTH_ENABLED_KEY] = value
34
+ end
35
+
36
+ def use_oauth?
37
+ Thread.current[OAUTH_ENABLED_KEY]
38
+ end
33
39
  end
34
40
 
35
41
  def configure_oauth(consumer = nil, token = nil, options = {})
36
- @oauth_options = { :consumer => consumer,
37
- :token => token,
38
- :scheme => 'header',
39
- :signature_method => nil,
40
- :nonce => nil,
41
- :timestamp => nil }.merge(options)
42
+ @oauth_options = {
43
+ consumer: consumer,
44
+ token: token,
45
+ scheme: "header",
46
+ signature_method: nil,
47
+ nonce: nil,
48
+ timestamp: nil,
49
+ }.merge(options)
42
50
  end
43
51
 
44
52
  def apply_oauth!
45
53
  return unless ActionController::TestRequest.use_oauth? && @oauth_options
46
54
 
47
- @oauth_helper = OAuth::Client::Helper.new(self, @oauth_options.merge(:request_uri => (respond_to?(:fullpath) ? fullpath : request_uri)))
55
+ @oauth_helper = OAuth::Client::Helper.new(
56
+ self,
57
+ @oauth_options.merge(request_uri: (respond_to?(:fullpath) ? fullpath : request_uri)),
58
+ )
48
59
  @oauth_helper.amend_user_agent_header(env)
49
60
 
50
- self.send("set_oauth_#{@oauth_options[:scheme]}")
61
+ send("set_oauth_#{@oauth_options[:scheme]}")
51
62
  end
52
63
 
53
64
  def set_oauth_header
54
- env['Authorization'] = @oauth_helper.header
65
+ env["Authorization"] = @oauth_helper.header
55
66
  end
56
67
 
57
68
  def set_oauth_parameters
58
69
  @query_parameters = @oauth_helper.parameters_with_oauth
59
- @query_parameters.merge!(:oauth_signature => @oauth_helper.signature)
70
+ @query_parameters.merge!(oauth_signature: @oauth_helper.signature)
60
71
  end
61
72
 
62
73
  def set_oauth_query_string
@@ -1,119 +1,126 @@
1
- require 'em-http'
2
- require 'oauth/helper'
3
- require 'oauth/request_proxy/em_http_request'
1
+ # frozen_string_literal: true
4
2
 
5
- # Extensions for em-http so that we can use consumer.sign! with an EventMachine::HttpClient
6
- # instance. This is purely syntactic sugar.
7
- class EventMachine::HttpClient
3
+ require "oauth/helper"
4
+ require "oauth/optional"
8
5
 
9
- attr_reader :oauth_helper
6
+ if OAuth::Optional.em_http_available?
7
+ require "oauth/request_proxy/em_http_request"
10
8
 
11
- # Add the OAuth information to an HTTP request. Depending on the <tt>options[:scheme]</tt> setting
12
- # this may add a header, additional query string parameters, or additional POST body parameters.
13
- # The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
14
- # header.
15
- #
16
- # * http - Configured Net::HTTP instance, ignored in this scenario except for getting host.
17
- # * consumer - OAuth::Consumer instance
18
- # * token - OAuth::Token instance
19
- # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+,
20
- # +signature_method+, +nonce+, +timestamp+)
21
- #
22
- # This method also modifies the <tt>User-Agent</tt> header to add the OAuth gem version.
23
- #
24
- # See Also: {OAuth core spec version 1.0, section 5.4.1}[http://oauth.net/core/1.0#rfc.section.5.4.1]
25
- def oauth!(http, consumer = nil, token = nil, options = {})
26
- options = { :request_uri => normalized_oauth_uri(http),
27
- :consumer => consumer,
28
- :token => token,
29
- :scheme => 'header',
30
- :signature_method => nil,
31
- :nonce => nil,
32
- :timestamp => nil }.merge(options)
9
+ # Extensions for em-http so that we can use consumer.sign! with an EventMachine::HttpClient
10
+ # instance. This is purely syntactic sugar.
11
+ module EventMachine
12
+ class HttpClient
13
+ attr_reader :oauth_helper
33
14
 
34
- @oauth_helper = OAuth::Client::Helper.new(self, options)
35
- self.__send__(:"set_oauth_#{options[:scheme]}")
36
- end
15
+ # Add the OAuth information to an HTTP request. Depending on the <tt>options[:scheme]</tt> setting
16
+ # this may add a header, additional query string parameters, or additional POST body parameters.
17
+ # The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
18
+ # header.
19
+ #
20
+ # * http - Configured Net::HTTP instance, ignored in this scenario except for getting host.
21
+ # * consumer - OAuth::Consumer instance
22
+ # * token - OAuth::Token instance
23
+ # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+,
24
+ # +signature_method+, +nonce+, +timestamp+)
25
+ #
26
+ # This method also modifies the <tt>User-Agent</tt> header to add the OAuth gem version.
27
+ #
28
+ # See Also: {OAuth core spec version 1.0, section 5.4.1}[http://oauth.net/core/1.0#rfc.section.5.4.1]
29
+ def oauth!(http, consumer = nil, token = nil, options = {})
30
+ options = {
31
+ request_uri: normalized_oauth_uri(http),
32
+ consumer: consumer,
33
+ token: token,
34
+ scheme: "header",
35
+ signature_method: nil,
36
+ nonce: nil,
37
+ timestamp: nil,
38
+ }.merge(options)
37
39
 
38
- # Create a string suitable for signing for an HTTP request. This process involves parameter
39
- # normalization as specified in the OAuth specification. The exact normalization also depends
40
- # on the <tt>options[:scheme]</tt> being used so this must match what will be used for the request
41
- # itself. The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
42
- # header.
43
- #
44
- # * http - Configured Net::HTTP instance
45
- # * consumer - OAuth::Consumer instance
46
- # * token - OAuth::Token instance
47
- # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+,
48
- # +signature_method+, +nonce+, +timestamp+)
49
- #
50
- # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
51
- def signature_base_string(http, consumer = nil, token = nil, options = {})
52
- options = { :request_uri => normalized_oauth_uri(http),
53
- :consumer => consumer,
54
- :token => token,
55
- :scheme => 'header',
56
- :signature_method => nil,
57
- :nonce => nil,
58
- :timestamp => nil }.merge(options)
40
+ @oauth_helper = OAuth::Client::Helper.new(self, options)
41
+ __send__(:"set_oauth_#{options[:scheme]}")
42
+ end
59
43
 
60
- OAuth::Client::Helper.new(self, options).signature_base_string
61
- end
44
+ # Create a string suitable for signing for an HTTP request. This process involves parameter
45
+ # normalization as specified in the OAuth specification. The exact normalization also depends
46
+ # on the <tt>options[:scheme]</tt> being used so this must match what will be used for the request
47
+ # itself. The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
48
+ # header.
49
+ #
50
+ # * http - Configured Net::HTTP instance
51
+ # * consumer - OAuth::Consumer instance
52
+ # * token - OAuth::Token instance
53
+ # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+,
54
+ # +signature_method+, +nonce+, +timestamp+)
55
+ #
56
+ # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
57
+ def signature_base_string(http, consumer = nil, token = nil, options = {})
58
+ options = {
59
+ request_uri: normalized_oauth_uri(http),
60
+ consumer: consumer,
61
+ token: token,
62
+ scheme: "header",
63
+ signature_method: nil,
64
+ nonce: nil,
65
+ timestamp: nil,
66
+ }.merge(options)
62
67
 
63
- # This code was lifted from the em-http-request because it was removed from
64
- # the gem June 19, 2010
65
- # see: http://github.com/igrigorik/em-http-request/commit/d536fc17d56dbe55c487eab01e2ff9382a62598b
66
- def normalize_uri
67
- @normalized_uri ||= begin
68
- uri = @uri.dup
69
- encoded_query = encode_query(@uri, @options[:query])
70
- path, query = encoded_query.split("?", 2)
71
- uri.query = query unless encoded_query.empty?
72
- uri.path = path
73
- uri
74
- end
75
- end
68
+ OAuth::Client::Helper.new(self, options).signature_base_string
69
+ end
76
70
 
77
- protected
71
+ # This code was lifted from the em-http-request because it was removed from
72
+ # the gem June 19, 2010
73
+ # see: http://github.com/igrigorik/em-http-request/commit/d536fc17d56dbe55c487eab01e2ff9382a62598b
74
+ def normalize_uri
75
+ @normalized_uri ||= begin
76
+ uri = @conn.dup
77
+ encoded_query = encode_query(@conn, @req[:query])
78
+ path, query = encoded_query.split("?", 2)
79
+ uri.query = query unless encoded_query.empty?
80
+ uri.path = path
81
+ uri
82
+ end
83
+ end
78
84
 
79
- def combine_query(path, query, uri_query)
80
- combined_query = if query.kind_of?(Hash)
81
- query.map { |k, v| encode_param(k, v) }.join('&')
82
- else
83
- query.to_s
84
- end
85
- if !uri_query.to_s.empty?
86
- combined_query = [combined_query, uri_query].reject {|part| part.empty?}.join("&")
87
- end
88
- combined_query.to_s.empty? ? path : "#{path}?#{combined_query}"
89
- end
85
+ protected
90
86
 
91
- # Since we expect to get the host etc details from the http instance (...),
92
- # we create a fake url here. Surely this is a horrible, horrible idea?
93
- def normalized_oauth_uri(http)
94
- uri = URI.parse(normalize_uri.path)
95
- uri.host = http.address
96
- uri.port = http.port
87
+ def combine_query(path, query, uri_query)
88
+ combined_query = if query.is_a?(Hash)
89
+ query.map { |k, v| encode_param(k, v) }.join("&")
90
+ else
91
+ query.to_s
92
+ end
93
+ combined_query = [combined_query, uri_query].reject(&:empty?).join("&") unless uri_query.to_s.empty?
94
+ combined_query.to_s.empty? ? path : "#{path}?#{combined_query}"
95
+ end
97
96
 
98
- if http.respond_to?(:use_ssl?) && http.use_ssl?
99
- uri.scheme = "https"
100
- else
101
- uri.scheme = "http"
102
- end
103
- uri.to_s
104
- end
97
+ # Since we expect to get the host etc details from the http instance (...),
98
+ # we create a fake url here. Surely this is a horrible, horrible idea?
99
+ def normalized_oauth_uri(http)
100
+ uri = URI.parse(normalize_uri.path)
101
+ uri.host = http.address
102
+ uri.port = http.port
105
103
 
106
- def set_oauth_header
107
- headers = (self.options[:head] ||= {})
108
- headers['Authorization'] = @oauth_helper.header
109
- end
104
+ uri.scheme = if http.respond_to?(:use_ssl?) && http.use_ssl?
105
+ "https"
106
+ else
107
+ "http"
108
+ end
109
+ uri.to_s
110
+ end
110
111
 
111
- def set_oauth_body
112
- raise NotImplementedError, 'please use the set_oauth_header method instead'
113
- end
112
+ def set_oauth_header
113
+ req[:head] ||= {}
114
+ req[:head].merge!("Authorization" => @oauth_helper.header)
115
+ end
114
116
 
115
- def set_oauth_query_string
116
- raise NotImplementedError, 'please use the set_oauth_header method instead'
117
- end
117
+ def set_oauth_body
118
+ raise NotImplementedError, "please use the set_oauth_header method instead"
119
+ end
118
120
 
121
+ def set_oauth_query_string
122
+ raise NotImplementedError, "please use the set_oauth_header method instead"
123
+ end
124
+ end
125
+ end
119
126
  end
@@ -1,101 +1,106 @@
1
- require 'oauth/client'
2
- require 'oauth/consumer'
3
- require 'oauth/helper'
4
- require 'oauth/token'
5
- require 'oauth/signature/hmac/sha1'
6
-
7
- module OAuth::Client
8
- class Helper
9
- include OAuth::Helper
10
-
11
- def initialize(request, options = {})
12
- @request = request
13
- @options = options
14
- @options[:signature_method] ||= 'HMAC-SHA1'
15
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "oauth/client"
4
+ require "oauth/consumer"
5
+ require "oauth/helper"
6
+ require "oauth/token"
7
+ require "oauth/signature/hmac/sha1"
8
+
9
+ module OAuth
10
+ module Client
11
+ class Helper
12
+ include OAuth::Helper
13
+
14
+ def initialize(request, options = {})
15
+ @request = request
16
+ @options = options
17
+ @options[:signature_method] ||= "HMAC-SHA1"
18
+ end
16
19
 
17
- def options
18
- @options
19
- end
20
+ attr_reader :options
20
21
 
21
- def nonce
22
- options[:nonce] ||= generate_key
23
- end
22
+ def nonce
23
+ options[:nonce] ||= generate_key
24
+ end
24
25
 
25
- def timestamp
26
- options[:timestamp] ||= generate_timestamp
27
- end
26
+ def timestamp
27
+ options[:timestamp] ||= generate_timestamp
28
+ end
28
29
 
29
- def oauth_parameters
30
- out = {
31
- 'oauth_body_hash' => options[:body_hash],
32
- 'oauth_callback' => options[:oauth_callback],
33
- 'oauth_consumer_key' => options[:consumer].key,
34
- 'oauth_token' => options[:token] ? options[:token].token : '',
35
- 'oauth_signature_method' => options[:signature_method],
36
- 'oauth_timestamp' => timestamp,
37
- 'oauth_nonce' => nonce,
38
- 'oauth_verifier' => options[:oauth_verifier],
39
- 'oauth_version' => (options[:oauth_version] || '1.0'),
40
- 'oauth_session_handle' => options[:oauth_session_handle]
41
- }
42
- allowed_empty_params = options[:allow_empty_params]
43
- if allowed_empty_params != true && !allowed_empty_params.kind_of?(Array)
44
- allowed_empty_params = allowed_empty_params == false ? [] : [allowed_empty_params]
30
+ def oauth_parameters
31
+ out = {
32
+ "oauth_body_hash" => options[:body_hash],
33
+ "oauth_callback" => options[:oauth_callback],
34
+ "oauth_consumer_key" => options[:consumer].key,
35
+ "oauth_token" => options[:token] ? options[:token].token : "",
36
+ "oauth_signature_method" => options[:signature_method],
37
+ "oauth_timestamp" => timestamp,
38
+ "oauth_nonce" => nonce,
39
+ "oauth_verifier" => options[:oauth_verifier],
40
+ "oauth_version" => options[:oauth_version] || "1.0",
41
+ "oauth_session_handle" => options[:oauth_session_handle],
42
+ }
43
+ allowed_empty_params = options[:allow_empty_params]
44
+ if allowed_empty_params != true && !allowed_empty_params.is_a?(Array)
45
+ allowed_empty_params = (allowed_empty_params == false) ? [] : [allowed_empty_params]
46
+ end
47
+ out.select! { |k, v| v.to_s != "" || allowed_empty_params == true || allowed_empty_params.include?(k) }
48
+ out
45
49
  end
46
- out.select! { |k,v| v.to_s != '' || allowed_empty_params == true || allowed_empty_params.include?(k) }
47
- out
48
- end
49
50
 
50
- def signature(extra_options = {})
51
- OAuth::Signature.sign(@request, { :uri => options[:request_uri],
52
- :consumer => options[:consumer],
53
- :token => options[:token],
54
- :unsigned_parameters => options[:unsigned_parameters]
55
- }.merge(extra_options) )
56
- end
51
+ def signature(extra_options = {})
52
+ OAuth::Signature.sign(@request, {
53
+ uri: options[:request_uri],
54
+ consumer: options[:consumer],
55
+ token: options[:token],
56
+ unsigned_parameters: options[:unsigned_parameters],
57
+ }.merge(extra_options))
58
+ end
57
59
 
58
- def signature_base_string(extra_options = {})
59
- OAuth::Signature.signature_base_string(@request, { :uri => options[:request_uri],
60
- :consumer => options[:consumer],
61
- :token => options[:token],
62
- :parameters => oauth_parameters}.merge(extra_options) )
63
- end
60
+ def signature_base_string(extra_options = {})
61
+ OAuth::Signature.signature_base_string(@request, {
62
+ uri: options[:request_uri],
63
+ consumer: options[:consumer],
64
+ token: options[:token],
65
+ parameters: oauth_parameters,
66
+ }.merge(extra_options))
67
+ end
64
68
 
65
- def token_request?
66
- @options[:token_request].eql?(true)
67
- end
69
+ def token_request?
70
+ @options[:token_request].eql?(true)
71
+ end
68
72
 
69
- def hash_body
70
- @options[:body_hash] = OAuth::Signature.body_hash(@request, :parameters => oauth_parameters)
71
- end
73
+ def hash_body
74
+ @options[:body_hash] = OAuth::Signature.body_hash(@request, parameters: oauth_parameters)
75
+ end
72
76
 
73
- def amend_user_agent_header(headers)
74
- @oauth_ua_string ||= "OAuth gem v#{OAuth::VERSION}"
75
- # Net::HTTP in 1.9 appends Ruby
76
- if headers['User-Agent'] && headers['User-Agent'] != 'Ruby'
77
- headers['User-Agent'] += " (#{@oauth_ua_string})"
78
- else
79
- headers['User-Agent'] = @oauth_ua_string
77
+ def amend_user_agent_header(headers)
78
+ @oauth_ua_string ||= "OAuth gem v#{OAuth::Version::VERSION}"
79
+ # Net::HTTP in 1.9 appends Ruby
80
+ if headers["User-Agent"] && headers["User-Agent"] != "Ruby"
81
+ headers["User-Agent"] += " (#{@oauth_ua_string})"
82
+ else
83
+ headers["User-Agent"] = @oauth_ua_string
84
+ end
80
85
  end
81
- end
82
86
 
83
- def header
84
- parameters = oauth_parameters
85
- parameters.merge!('oauth_signature' => signature(options.merge(:parameters => parameters)))
87
+ def header
88
+ parameters = oauth_parameters
89
+ parameters["oauth_signature"] = signature(options.merge(parameters: parameters))
86
90
 
87
- header_params_str = parameters.sort.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')
91
+ header_params_str = parameters.sort.map { |k, v| "#{k}=\"#{escape(v)}\"" }.join(", ")
88
92
 
89
- realm = "realm=\"#{options[:realm]}\", " if options[:realm]
90
- "OAuth #{realm}#{header_params_str}"
91
- end
93
+ realm = "realm=\"#{options[:realm]}\", " if options[:realm]
94
+ "OAuth #{realm}#{header_params_str}"
95
+ end
92
96
 
93
- def parameters
94
- OAuth::RequestProxy.proxy(@request).parameters
95
- end
97
+ def parameters
98
+ OAuth::RequestProxy.proxy(@request).parameters
99
+ end
96
100
 
97
- def parameters_with_oauth
98
- oauth_parameters.merge(parameters)
101
+ def parameters_with_oauth
102
+ oauth_parameters.merge(parameters)
103
+ end
99
104
  end
100
105
  end
101
106
  end