oauth 0.5.6 → 1.1.7

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 (72) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +915 -0
  4. data/CITATION.cff +20 -0
  5. data/CODE_OF_CONDUCT.md +134 -0
  6. data/CONTRIBUTING.md +272 -0
  7. data/FUNDING.md +74 -0
  8. data/LICENSE.md +71 -0
  9. data/README.md +718 -0
  10. data/RUBOCOP.md +71 -0
  11. data/SECURITY.md +21 -0
  12. data/certs/pboling.pem +27 -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 +282 -149
  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 +71 -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 +19 -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/sig/oauth/version.rbs +6 -0
  59. data.tar.gz.sig +2 -0
  60. metadata +313 -84
  61. metadata.gz.sig +3 -0
  62. data/LICENSE +0 -20
  63. data/README.rdoc +0 -88
  64. data/TODO +0 -32
  65. data/bin/oauth +0 -11
  66. data/lib/oauth/cli/authorize_command.rb +0 -71
  67. data/lib/oauth/cli/base_command.rb +0 -208
  68. data/lib/oauth/cli/help_command.rb +0 -22
  69. data/lib/oauth/cli/query_command.rb +0 -25
  70. data/lib/oauth/cli/sign_command.rb +0 -81
  71. data/lib/oauth/cli/version_command.rb +0 -7
  72. data/lib/oauth/cli.rb +0 -56
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,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ |----------|-----------|
7
+ | 1.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
+ ## Additional Support
16
+
17
+ If you are interested in support for versions older than the latest release,
18
+ please consider sponsoring the project / maintainer @ https://liberapay.com/pboling/donate,
19
+ or find other sponsorship links in the [README].
20
+
21
+ [README]: README.md
data/certs/pboling.pem ADDED
@@ -0,0 +1,27 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEgDCCAuigAwIBAgIBATANBgkqhkiG9w0BAQsFADBDMRUwEwYDVQQDDAxwZXRl
3
+ ci5ib2xpbmcxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
4
+ A2NvbTAeFw0yNTA1MDQxNTMzMDlaFw00NTA0MjkxNTMzMDlaMEMxFTATBgNVBAMM
5
+ DHBldGVyLmJvbGluZzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
6
+ LGQBGRYDY29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAruUoo0WA
7
+ uoNuq6puKWYeRYiZekz/nsDeK5x/0IEirzcCEvaHr3Bmz7rjo1I6On3gGKmiZs61
8
+ LRmQ3oxy77ydmkGTXBjruJB+pQEn7UfLSgQ0xa1/X3kdBZt6RmabFlBxnHkoaGY5
9
+ mZuZ5+Z7walmv6sFD9ajhzj+oIgwWfnEHkXYTR8I6VLN7MRRKGMPoZ/yvOmxb2DN
10
+ coEEHWKO9CvgYpW7asIihl/9GMpKiRkcYPm9dGQzZc6uTwom1COfW0+ZOFrDVBuV
11
+ FMQRPswZcY4Wlq0uEBLPU7hxnCL9nKK6Y9IhdDcz1mY6HZ91WImNslOSI0S8hRpj
12
+ yGOWxQIhBT3fqCBlRIqFQBudrnD9jSNpSGsFvbEijd5ns7Z9ZMehXkXDycpGAUj1
13
+ to/5cuTWWw1JqUWrKJYoifnVhtE1o1DZ+LkPtWxHtz5kjDG/zR3MG0Ula0UOavlD
14
+ qbnbcXPBnwXtTFeZ3C+yrWpE4pGnl3yGkZj9SMTlo9qnTMiPmuWKQDatAgMBAAGj
15
+ fzB9MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBQE8uWvNbPVNRXZ
16
+ HlgPbc2PCzC4bjAhBgNVHREEGjAYgRZwZXRlci5ib2xpbmdAZ21haWwuY29tMCEG
17
+ A1UdEgQaMBiBFnBldGVyLmJvbGluZ0BnbWFpbC5jb20wDQYJKoZIhvcNAQELBQAD
18
+ ggGBAJbnUwfJQFPkBgH9cL7hoBfRtmWiCvdqdjeTmi04u8zVNCUox0A4gT982DE9
19
+ wmuN12LpdajxZONqbXuzZvc+nb0StFwmFYZG6iDwaf4BPywm2e/Vmq0YG45vZXGR
20
+ L8yMDSK1cQXjmA+ZBKOHKWavxP6Vp7lWvjAhz8RFwqF9GuNIdhv9NpnCAWcMZtpm
21
+ GUPyIWw/Cw/2wZp74QzZj6Npx+LdXoLTF1HMSJXZ7/pkxLCsB8m4EFVdb/IrW/0k
22
+ kNSfjtAfBHO8nLGuqQZVH9IBD1i9K6aSs7pT6TW8itXUIlkIUI2tg5YzW6OFfPzq
23
+ QekSkX3lZfY+HTSp/o+YvKkqWLUV7PQ7xh1ZYDtocpaHwgxe/j3bBqHE+CUPH2vA
24
+ 0V/FwdTRWcwsjVoOJTrYcff8pBZ8r2MvtAc54xfnnhGFzeRHfcltobgFxkAXdE6p
25
+ DVjBtqT23eugOqQ73umLcYDZkc36vnqGxUBSsXrzY9pzV5gGr2I8YUxMqf6ATrZt
26
+ L9nRqA==
27
+ -----END CERTIFICATE-----
@@ -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