oauth 0.5.14 → 1.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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +1 -0
  3. data/CHANGELOG.md +663 -239
  4. data/CITATION.cff +20 -0
  5. data/CODE_OF_CONDUCT.md +79 -29
  6. data/CONTRIBUTING.md +264 -15
  7. data/FUNDING.md +74 -0
  8. data/LICENSE.md +71 -0
  9. data/README.md +642 -297
  10. data/RUBOCOP.md +71 -0
  11. data/SECURITY.md +11 -12
  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 +24 -12
  15. data/lib/oauth/client/em_http.rb +107 -100
  16. data/lib/oauth/client/helper.rb +80 -72
  17. data/lib/oauth/client/net_http.rb +139 -106
  18. data/lib/oauth/client.rb +2 -0
  19. data/lib/oauth/consumer.rb +250 -118
  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 +4 -0
  23. data/lib/oauth/errors.rb +2 -0
  24. data/lib/oauth/helper.rb +34 -8
  25. data/lib/oauth/oauth.rb +32 -8
  26. data/lib/oauth/oauth_test_helper.rb +2 -0
  27. data/lib/oauth/optional.rb +20 -0
  28. data/lib/oauth/request_proxy/action_controller_request.rb +14 -31
  29. data/lib/oauth/request_proxy/action_dispatch_request.rb +34 -0
  30. data/lib/oauth/request_proxy/base.rb +42 -31
  31. data/lib/oauth/request_proxy/em_http_request.rb +53 -52
  32. data/lib/oauth/request_proxy/jabber_request.rb +9 -2
  33. data/lib/oauth/request_proxy/mock_request.rb +1 -1
  34. data/lib/oauth/request_proxy/net_http.rb +6 -8
  35. data/lib/oauth/request_proxy/rack_request.rb +0 -4
  36. data/lib/oauth/request_proxy/rest_client_request.rb +6 -4
  37. data/lib/oauth/request_proxy.rb +20 -13
  38. data/lib/oauth/server.rb +14 -6
  39. data/lib/oauth/signature/base.rb +82 -66
  40. data/lib/oauth/signature/hmac/sha1.rb +15 -9
  41. data/lib/oauth/signature/hmac/sha256.rb +15 -9
  42. data/lib/oauth/signature/plaintext.rb +18 -20
  43. data/lib/oauth/signature/rsa/sha1.rb +53 -38
  44. data/lib/oauth/signature.rb +40 -33
  45. data/lib/oauth/token.rb +2 -0
  46. data/lib/oauth/tokens/access_token.rb +3 -1
  47. data/lib/oauth/tokens/consumer_token.rb +10 -6
  48. data/lib/oauth/tokens/request_token.rb +12 -4
  49. data/lib/oauth/tokens/server_token.rb +2 -0
  50. data/lib/oauth/tokens/token.rb +15 -1
  51. data/lib/oauth/version.rb +6 -1
  52. data/lib/oauth.rb +11 -2
  53. data/sig/oauth/consumer.rbs +9 -0
  54. data/sig/oauth/signature/base.rbs +12 -0
  55. data/sig/oauth/tokens/token.rbs +8 -0
  56. data/sig/oauth/version.rbs +6 -0
  57. data.tar.gz.sig +0 -0
  58. metadata +349 -90
  59. metadata.gz.sig +0 -0
  60. data/LICENSE +0 -21
  61. data/TODO +0 -32
  62. data/bin/oauth +0 -11
  63. data/lib/oauth/cli/authorize_command.rb +0 -69
  64. data/lib/oauth/cli/base_command.rb +0 -210
  65. data/lib/oauth/cli/help_command.rb +0 -22
  66. data/lib/oauth/cli/query_command.rb +0 -25
  67. data/lib/oauth/cli/sign_command.rb +0 -78
  68. data/lib/oauth/cli/version_command.rb +0 -7
  69. data/lib/oauth/cli.rb +0 -56
@@ -1,22 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OAuth
2
4
  module RequestProxy
3
- def self.available_proxies #:nodoc:
4
- @available_proxies ||= {}
5
- end
5
+ AVAILABLE_PROXIES = {}
6
6
 
7
- def self.proxy(request, options = {})
8
- return request if request.is_a?(OAuth::RequestProxy::Base)
7
+ class << self
8
+ def available_proxies # :nodoc:
9
+ AVAILABLE_PROXIES
10
+ end
9
11
 
10
- klass = available_proxies[request.class]
12
+ def proxy(request, options = {})
13
+ return request if request.is_a?(OAuth::RequestProxy::Base)
11
14
 
12
- # Search for possible superclass matches.
13
- if klass.nil?
14
- request_parent = available_proxies.keys.find { |rc| request.is_a?(rc) }
15
- klass = available_proxies[request_parent]
16
- end
15
+ klass = available_proxies[request.class]
17
16
 
18
- raise UnknownRequestType, request.class.to_s unless klass
19
- klass.new(request, options)
17
+ # Search for possible superclass matches.
18
+ if klass.nil?
19
+ request_parent = available_proxies.keys.find { |rc| request.is_a?(rc) }
20
+ klass = available_proxies[request_parent]
21
+ end
22
+
23
+ raise UnknownRequestType, request.class.to_s unless klass
24
+
25
+ klass.new(request, options)
26
+ end
20
27
  end
21
28
 
22
29
  class UnknownRequestType < RuntimeError; end
data/lib/oauth/server.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/helper"
2
4
  require "oauth/consumer"
3
5
 
@@ -5,12 +7,13 @@ module OAuth
5
7
  # This is mainly used to create consumer credentials and can pretty much be ignored if you want to create your own
6
8
  class Server
7
9
  include OAuth::Helper
10
+
8
11
  attr_accessor :base_url
9
12
 
10
13
  @@server_paths = {
11
14
  request_token_path: "/oauth/request_token",
12
15
  authorize_path: "/oauth/authorize",
13
- access_token_path: "/oauth/access_token"
16
+ access_token_path: "/oauth/access_token",
14
17
  }
15
18
 
16
19
  # Create a new server instance
@@ -30,11 +33,16 @@ module OAuth
30
33
  # mainly for testing purposes
31
34
  def create_consumer
32
35
  creds = generate_credentials
33
- Consumer.new(creds[0], creds[1],
34
- site: base_url,
35
- request_token_path: request_token_path,
36
- authorize_path: authorize_path,
37
- access_token_path: access_token_path)
36
+ Consumer.new(
37
+ creds[0],
38
+ creds[1],
39
+ {
40
+ site: base_url,
41
+ request_token_path: request_token_path,
42
+ authorize_path: authorize_path,
43
+ access_token_path: access_token_path,
44
+ },
45
+ )
38
46
  end
39
47
 
40
48
  def request_token_path
@@ -1,97 +1,113 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/signature"
2
4
  require "oauth/helper"
3
5
  require "oauth/request_proxy/base"
4
6
  require "base64"
5
7
 
6
- module OAuth::Signature
7
- class Base
8
- include OAuth::Helper
8
+ module OAuth
9
+ module Signature
10
+ # Base class for OAuth signature implementations.
11
+ #
12
+ # Includes {OAuth::AUTH_SANITIZER::FilteredAttributes} so inspect output redacts
13
+ # secret-bearing fields captured during signature construction.
14
+ class Base
15
+ include OAuth::Helper
16
+ include OAuth::AUTH_SANITIZER::FilteredAttributes
17
+
18
+ # Signature construction options.
19
+ #
20
+ # @return [Hash]
21
+ attr_accessor :options
22
+ attr_reader :token_secret, :consumer_secret, :request
23
+ filtered_attributes :options, :consumer_secret, :token_secret
24
+
25
+ class << self
26
+ def implements(signature_method = nil)
27
+ return OAuth::Signature.available_methods.key(self) if signature_method.nil?
28
+
29
+ OAuth::Signature.available_methods[signature_method] = self
30
+ end
31
+ end
9
32
 
10
- attr_accessor :options
11
- attr_reader :token_secret, :consumer_secret, :request
33
+ def initialize(request, options = {}, &block)
34
+ raise TypeError unless request.is_a?(OAuth::RequestProxy::Base)
12
35
 
13
- def self.implements(signature_method = nil)
14
- return @implements if signature_method.nil?
15
- @implements = signature_method
16
- OAuth::Signature.available_methods[@implements] = self
17
- end
36
+ @request = request
37
+ @options = options
18
38
 
19
- def initialize(request, options = {}, &block)
20
- raise TypeError unless request.is_a?(OAuth::RequestProxy::Base)
21
- @request = request
22
- @options = options
39
+ ## consumer secret was determined beforehand
23
40
 
24
- ## consumer secret was determined beforehand
41
+ @consumer_secret = options[:consumer].secret if options[:consumer]
25
42
 
26
- @consumer_secret = options[:consumer].secret if options[:consumer]
43
+ # presence of :consumer_secret option will override any Consumer that's provided
44
+ @consumer_secret = options[:consumer_secret] if options[:consumer_secret]
27
45
 
28
- # presence of :consumer_secret option will override any Consumer that's provided
29
- @consumer_secret = options[:consumer_secret] if options[:consumer_secret]
46
+ ## token secret was determined beforehand
30
47
 
31
- ## token secret was determined beforehand
48
+ @token_secret = options[:token].secret if options[:token]
32
49
 
33
- @token_secret = options[:token].secret if options[:token]
50
+ # presence of :token_secret option will override any Token that's provided
51
+ @token_secret = options[:token_secret] if options[:token_secret]
34
52
 
35
- # presence of :token_secret option will override any Token that's provided
36
- @token_secret = options[:token_secret] if options[:token_secret]
37
-
38
- # override secrets based on the values returned from the block (if any)
39
- if block_given?
40
- # consumer secret and token secret need to be looked up based on pieces of the request
41
- secrets = yield block.arity == 1 ? request : [token, consumer_key, nonce, request.timestamp]
42
- if secrets.is_a?(Array) && secrets.size == 2
43
- @token_secret = secrets[0]
44
- @consumer_secret = secrets[1]
53
+ # override secrets based on the values returned from the block (if any)
54
+ if block
55
+ # consumer secret and token secret need to be looked up based on pieces of the request
56
+ secrets = yield (block.arity == 1) ? request : [token, consumer_key, nonce, request.timestamp]
57
+ if secrets.is_a?(Array) && secrets.size == 2
58
+ @token_secret = secrets[0]
59
+ @consumer_secret = secrets[1]
60
+ end
45
61
  end
46
62
  end
47
- end
48
63
 
49
- def signature
50
- Base64.encode64(digest).chomp.delete("\n")
51
- end
64
+ def signature
65
+ Base64.encode64(digest).chomp.delete("\n")
66
+ end
52
67
 
53
- def ==(cmp_signature)
54
- check = signature.bytesize ^ cmp_signature.bytesize
55
- signature.bytes.zip(cmp_signature.bytes) { |x, y| check |= x ^ y.to_i }
56
- check.zero?
57
- end
68
+ def ==(other)
69
+ check = signature.bytesize ^ other.bytesize
70
+ signature.bytes.zip(other.bytes) { |x, y| check |= x ^ y.to_i }
71
+ check.zero?
72
+ end
58
73
 
59
- def verify
60
- self == request.signature
61
- end
74
+ def verify
75
+ self == request.signature
76
+ end
62
77
 
63
- def signature_base_string
64
- request.signature_base_string
65
- end
78
+ def signature_base_string
79
+ request.signature_base_string
80
+ end
66
81
 
67
- def body_hash
68
- raise_instantiation_error
69
- end
82
+ def body_hash
83
+ raise_instantiation_error
84
+ end
70
85
 
71
- private
86
+ private
72
87
 
73
- def token
74
- request.token
75
- end
88
+ def token
89
+ request.token
90
+ end
76
91
 
77
- def consumer_key
78
- request.consumer_key
79
- end
92
+ def consumer_key
93
+ request.consumer_key
94
+ end
80
95
 
81
- def nonce
82
- request.nonce
83
- end
96
+ def nonce
97
+ request.nonce
98
+ end
84
99
 
85
- def secret
86
- "#{escape(consumer_secret)}&#{escape(token_secret)}"
87
- end
100
+ def secret
101
+ "#{escape(consumer_secret)}&#{escape(token_secret)}"
102
+ end
88
103
 
89
- def digest
90
- raise_instantiation_error
91
- end
104
+ def digest
105
+ raise_instantiation_error
106
+ end
92
107
 
93
- def raise_instantiation_error
94
- raise NotImplementedError, "Cannot instantiate #{self.class.name} class directly."
108
+ def raise_instantiation_error
109
+ raise NotImplementedError, "Cannot instantiate #{self.class.name} class directly."
110
+ end
95
111
  end
96
112
  end
97
113
  end
@@ -1,17 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/signature/base"
2
4
 
3
- module OAuth::Signature::HMAC
4
- class SHA1 < OAuth::Signature::Base
5
- implements "hmac-sha1"
5
+ module OAuth
6
+ module Signature
7
+ module HMAC
8
+ class SHA1 < OAuth::Signature::Base
9
+ implements "hmac-sha1"
6
10
 
7
- def body_hash
8
- Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || "")).chomp.delete("\n")
9
- end
11
+ def body_hash
12
+ Base64.encode64(OpenSSL::Digest.digest("SHA1", request.body || "")).chomp.delete("\n")
13
+ end
10
14
 
11
- private
15
+ private
12
16
 
13
- def digest
14
- OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha1"), secret, signature_base_string)
17
+ def digest
18
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha1"), secret, signature_base_string)
19
+ end
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -1,17 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "oauth/signature/base"
2
4
 
3
- module OAuth::Signature::HMAC
4
- class SHA256 < OAuth::Signature::Base
5
- implements "hmac-sha256"
5
+ module OAuth
6
+ module Signature
7
+ module HMAC
8
+ class SHA256 < OAuth::Signature::Base
9
+ implements "hmac-sha256"
6
10
 
7
- def body_hash
8
- Base64.encode64(OpenSSL::Digest::SHA256.digest(request.body || "")).chomp.delete("\n")
9
- end
11
+ def body_hash
12
+ Base64.encode64(OpenSSL::Digest.digest("SHA256", request.body || "")).chomp.delete("\n")
13
+ end
10
14
 
11
- private
15
+ private
12
16
 
13
- def digest
14
- OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), secret, signature_base_string)
17
+ def digest
18
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), secret, signature_base_string)
19
+ end
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -1,29 +1,27 @@
1
- require "oauth/signature/base"
1
+ # frozen_string_literal: true
2
2
 
3
- module OAuth::Signature
4
- class PLAINTEXT < Base
5
- implements "plaintext"
3
+ require "oauth/signature/base"
6
4
 
7
- def signature
8
- signature_base_string
9
- end
5
+ module OAuth
6
+ module Signature
7
+ class PLAINTEXT < Base
8
+ implements "plaintext"
10
9
 
11
- def ==(cmp_signature)
12
- signature.to_s == cmp_signature.to_s
13
- end
10
+ def signature
11
+ signature_base_string
12
+ end
14
13
 
15
- def signature_base_string
16
- secret
17
- end
18
-
19
- def body_hash
20
- nil
21
- end
14
+ def ==(other)
15
+ signature.to_s == other.to_s
16
+ end
22
17
 
23
- private
18
+ def signature_base_string
19
+ secret
20
+ end
24
21
 
25
- def secret
26
- super
22
+ def body_hash
23
+ nil
24
+ end
27
25
  end
28
26
  end
29
27
  end
@@ -1,50 +1,65 @@
1
- require "oauth/signature/base"
1
+ # frozen_string_literal: true
2
2
 
3
- module OAuth::Signature::RSA
4
- class SHA1 < OAuth::Signature::Base
5
- implements "rsa-sha1"
3
+ require "oauth/signature/base"
6
4
 
7
- def ==(cmp_signature)
8
- public_key.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(cmp_signature.is_a?(Array) ? cmp_signature.first : cmp_signature), signature_base_string)
9
- end
5
+ module OAuth
6
+ module Signature
7
+ module RSA
8
+ class SHA1 < OAuth::Signature::Base
9
+ implements "rsa-sha1"
10
10
 
11
- def public_key
12
- if consumer_secret.is_a?(String)
13
- decode_public_key
14
- elsif consumer_secret.is_a?(OpenSSL::X509::Certificate)
15
- consumer_secret.public_key
16
- else
17
- consumer_secret
18
- end
19
- end
11
+ def ==(other)
12
+ decoded = Base64.decode64(other.is_a?(Array) ? other.first : other)
13
+ public_key.verify(OpenSSL::Digest.new("SHA1"), decoded, signature_base_string)
14
+ end
20
15
 
21
- def body_hash
22
- Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || "")).chomp.delete("\n")
23
- end
16
+ def public_key
17
+ case consumer_secret
18
+ when String
19
+ decode_public_key
20
+ when OpenSSL::X509::Certificate
21
+ consumer_secret.public_key
22
+ else
23
+ consumer_secret
24
+ end
25
+ end
24
26
 
25
- private
27
+ def body_hash
28
+ # Use SHA1 body hash with compatibility across OpenSSL versions
29
+ data = request.body || ""
30
+ begin
31
+ digest_bytes = OpenSSL::Digest.digest("SHA1", data)
32
+ rescue StandardError
33
+ digest_bytes = ::Digest::SHA1.digest(data)
34
+ end
35
+ Base64.encode64(digest_bytes).chomp.delete("\n")
36
+ end
26
37
 
27
- def decode_public_key
28
- case consumer_secret
29
- when /-----BEGIN CERTIFICATE-----/
30
- OpenSSL::X509::Certificate.new(consumer_secret).public_key
31
- else
32
- OpenSSL::PKey::RSA.new(consumer_secret)
33
- end
34
- end
38
+ private
35
39
 
36
- def digest
37
- private_key = OpenSSL::PKey::RSA.new(
38
- if options[:private_key_file]
39
- IO.read(options[:private_key_file])
40
- elsif options[:private_key]
41
- options[:private_key]
42
- else
43
- consumer_secret
40
+ def decode_public_key
41
+ case consumer_secret
42
+ when /-----BEGIN CERTIFICATE-----/
43
+ OpenSSL::X509::Certificate.new(consumer_secret).public_key
44
+ else
45
+ OpenSSL::PKey::RSA.new(consumer_secret)
46
+ end
44
47
  end
45
- )
46
48
 
47
- private_key.sign(OpenSSL::Digest::SHA1.new, signature_base_string)
49
+ def digest
50
+ private_key = OpenSSL::PKey::RSA.new(
51
+ if options[:private_key_file]
52
+ File.read(options[:private_key_file])
53
+ elsif options[:private_key]
54
+ options[:private_key]
55
+ else
56
+ consumer_secret
57
+ end,
58
+ )
59
+
60
+ private_key.sign(OpenSSL::Digest.new("SHA1"), signature_base_string)
61
+ end
62
+ end
48
63
  end
49
64
  end
50
65
  end
@@ -1,43 +1,50 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OAuth
2
4
  module Signature
3
- # Returns a list of available signature methods
4
- def self.available_methods
5
- @available_methods ||= {}
6
- end
5
+ AVAILABLE_METHODS = {}
7
6
 
8
- # Build a signature from a +request+.
9
- #
10
- # Raises UnknownSignatureMethod exception if the signature method is unknown.
11
- def self.build(request, options = {}, &block)
12
- request = OAuth::RequestProxy.proxy(request, options)
13
- klass = available_methods[
14
- (request.signature_method ||
15
- ((c = request.options[:consumer]) && c.options[:signature_method]) ||
16
- "").downcase]
17
- raise UnknownSignatureMethod, request.signature_method unless klass
18
- klass.new(request, options, &block)
19
- end
7
+ class << self
8
+ # Returns a list of available signature methods
9
+ def available_methods
10
+ AVAILABLE_METHODS
11
+ end
20
12
 
21
- # Sign a +request+
22
- def self.sign(request, options = {}, &block)
23
- build(request, options, &block).signature
24
- end
13
+ # Build a signature from a +request+.
14
+ #
15
+ # Raises UnknownSignatureMethod exception if the signature method is unknown.
16
+ def build(request, options = {}, &block)
17
+ request = OAuth::RequestProxy.proxy(request, options)
18
+ klass = available_methods[
19
+ (request.signature_method ||
20
+ ((c = request.options[:consumer]) && c.options[:signature_method]) ||
21
+ "").downcase]
22
+ raise UnknownSignatureMethod, request.signature_method unless klass
25
23
 
26
- # Verify the signature of +request+
27
- def self.verify(request, options = {}, &block)
28
- build(request, options, &block).verify
29
- end
24
+ klass.new(request, options, &block)
25
+ end
30
26
 
31
- # Create the signature base string for +request+. This string is the normalized parameter information.
32
- #
33
- # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
34
- def self.signature_base_string(request, options = {}, &block)
35
- build(request, options, &block).signature_base_string
36
- end
27
+ # Sign a +request+
28
+ def sign(request, options = {}, &block)
29
+ build(request, options, &block).signature
30
+ end
31
+
32
+ # Verify the signature of +request+
33
+ def verify(request, options = {}, &block)
34
+ build(request, options, &block).verify
35
+ end
36
+
37
+ # Create the signature base string for +request+. This string is the normalized parameter information.
38
+ #
39
+ # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
40
+ def signature_base_string(request, options = {}, &block)
41
+ build(request, options, &block).signature_base_string
42
+ end
37
43
 
38
- # Create the body hash for a request
39
- def self.body_hash(request, options = {}, &block)
40
- build(request, options, &block).body_hash
44
+ # Create the body hash for a request
45
+ def body_hash(request, options = {}, &block)
46
+ build(request, options, &block).body_hash
47
+ end
41
48
  end
42
49
 
43
50
  class UnknownSignatureMethod < RuntimeError; end
data/lib/oauth/token.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # this exists for backwards-compatibility
2
4
 
3
5
  require "oauth/tokens/token"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OAuth
2
4
  # The Access Token is used for the actual "real" web service calls that you perform against the server
3
5
  class AccessToken < ConsumerToken
@@ -6,7 +8,7 @@ module OAuth
6
8
  def request(http_method, path, *arguments)
7
9
  request_uri = URI.parse(path)
8
10
  site_uri = consumer.uri
9
- is_service_uri_different = (request_uri.absolute? && request_uri != site_uri)
11
+ is_service_uri_different = request_uri.absolute? && request_uri != site_uri
10
12
  begin
11
13
  consumer.uri(request_uri) if is_service_uri_different
12
14
  @response = super(http_method, path, *arguments)
@@ -1,19 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OAuth
2
4
  # Superclass for tokens used by OAuth Clients
3
5
  class ConsumerToken < Token
4
6
  attr_accessor :consumer, :params
5
- attr_reader :response
7
+ attr_reader :response
6
8
 
7
- def self.from_hash(consumer, hash)
8
- token = new(consumer, hash[:oauth_token], hash[:oauth_token_secret])
9
- token.params = hash
10
- token
9
+ class << self
10
+ def from_hash(consumer, hash)
11
+ token = new(consumer, hash[:oauth_token], hash[:oauth_token_secret])
12
+ token.params = hash
13
+ token
14
+ end
11
15
  end
12
16
 
13
17
  def initialize(consumer, token = "", secret = "")
14
18
  super(token, secret)
15
19
  @consumer = consumer
16
- @params = {}
20
+ @params = {}
17
21
  end
18
22
 
19
23
  # Make a signed request using given http_method to the path
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OAuth
2
4
  # The RequestToken is used for the initial Request.
3
5
  # This is normally created by the Consumer object.
4
6
  class RequestToken < ConsumerToken
5
7
  # Generate an authorization URL for user authorization
6
8
  def authorize_url(params = nil)
7
- return nil if token.nil?
9
+ return if token.nil?
8
10
 
9
11
  params = (params || {}).merge(oauth_token: token)
10
12
  build_url(consumer.authorize_url, params)
11
13
  end
12
14
 
13
15
  def authenticate_url(params = nil)
14
- return nil if token.nil?
16
+ return if token.nil?
15
17
 
16
18
  params = (params || {}).merge(oauth_token: token)
17
19
  build_url(consumer.authenticate_url, params)
@@ -23,7 +25,13 @@ module OAuth
23
25
 
24
26
  # exchange for AccessToken on server
25
27
  def get_access_token(options = {}, *arguments)
26
- response = consumer.token_request(consumer.http_method, (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path), self, options, *arguments)
28
+ response = consumer.token_request(
29
+ consumer.http_method,
30
+ (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path),
31
+ self,
32
+ options,
33
+ *arguments,
34
+ )
27
35
  OAuth::AccessToken.from_hash(consumer, response)
28
36
  end
29
37
 
@@ -33,7 +41,7 @@ module OAuth
33
41
  def build_url(base_url, params)
34
42
  uri = URI.parse(base_url.to_s)
35
43
  queries = {}
36
- queries = Hash[URI.decode_www_form(uri.query)] if uri.query
44
+ queries = URI.decode_www_form(uri.query).to_h if uri.query
37
45
  # TODO: doesn't handle array values correctly
38
46
  queries.merge!(params) if params
39
47
  uri.query = URI.encode_www_form(queries) unless queries.empty?