oauth 1.1.0 → 1.1.1

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.
@@ -18,8 +18,15 @@ module OAuth
18
18
  oauth = @request.get_elements("//oauth").first
19
19
  return @params unless oauth
20
20
 
21
- %w[ oauth_token oauth_consumer_key oauth_signature_method oauth_signature
22
- oauth_timestamp oauth_nonce oauth_version ].each do |param|
21
+ %w[
22
+ oauth_token
23
+ oauth_consumer_key
24
+ oauth_signature_method
25
+ oauth_signature
26
+ oauth_timestamp
27
+ oauth_nonce
28
+ oauth_version
29
+ ].each do |param|
23
30
  next unless (element = oauth.first_element(param))
24
31
 
25
32
  @params[param] = element.text
@@ -69,7 +69,7 @@ module OAuth
69
69
  end
70
70
 
71
71
  def auth_header_params
72
- return nil unless request["Authorization"] && request["Authorization"][0, 5] == "OAuth"
72
+ return unless request["Authorization"] && request["Authorization"][0, 5] == "OAuth"
73
73
 
74
74
  request["Authorization"]
75
75
  end
@@ -34,7 +34,8 @@ module OAuth
34
34
  query ? CGI.parse(query) : {}
35
35
  end
36
36
 
37
- def request_params; end
37
+ def request_params
38
+ end
38
39
 
39
40
  def post_parameters
40
41
  # Post params are only used if posting form data
@@ -52,9 +53,9 @@ module OAuth
52
53
  query.split("&").inject({}) do |result, q|
53
54
  k, v = q.split("=")
54
55
  if !v.nil?
55
- result.merge({ k => v })
56
+ result.merge({k => v})
56
57
  elsif !result.key?(k)
57
- result.merge({ k => true })
58
+ result.merge({k => true})
58
59
  else
59
60
  result
60
61
  end
data/lib/oauth/server.rb CHANGED
@@ -7,12 +7,13 @@ module OAuth
7
7
  # This is mainly used to create consumer credentials and can pretty much be ignored if you want to create your own
8
8
  class Server
9
9
  include OAuth::Helper
10
+
10
11
  attr_accessor :base_url
11
12
 
12
13
  @@server_paths = {
13
14
  request_token_path: "/oauth/request_token",
14
15
  authorize_path: "/oauth/authorize",
15
- access_token_path: "/oauth/access_token"
16
+ access_token_path: "/oauth/access_token",
16
17
  }
17
18
 
18
19
  # Create a new server instance
@@ -32,13 +33,16 @@ module OAuth
32
33
  # mainly for testing purposes
33
34
  def create_consumer
34
35
  creds = generate_credentials
35
- Consumer.new(creds[0], creds[1],
36
- {
37
- site: base_url,
38
- request_token_path: request_token_path,
39
- authorize_path: authorize_path,
40
- access_token_path: access_token_path
41
- })
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
+ )
42
46
  end
43
47
 
44
48
  def request_token_path
@@ -43,7 +43,7 @@ module OAuth
43
43
  # override secrets based on the values returned from the block (if any)
44
44
  if block
45
45
  # consumer secret and token secret need to be looked up based on pieces of the request
46
- secrets = yield block.arity == 1 ? request : [token, consumer_key, nonce, request.timestamp]
46
+ secrets = yield (block.arity == 1) ? request : [token, consumer_key, nonce, request.timestamp]
47
47
  if secrets.is_a?(Array) && secrets.size == 2
48
48
  @token_secret = secrets[0]
49
49
  @consumer_secret = secrets[1]
@@ -9,8 +9,8 @@ module OAuth
9
9
  implements "rsa-sha1"
10
10
 
11
11
  def ==(other)
12
- public_key.verify(OpenSSL::Digest.new("SHA1"),
13
- Base64.decode64(other.is_a?(Array) ? other.first : other), signature_base_string)
12
+ decoded = Base64.decode64(other.is_a?(Array) ? other.first : other)
13
+ public_key.verify(OpenSSL::Digest.new("SHA1"), decoded, signature_base_string)
14
14
  end
15
15
 
16
16
  def public_key
@@ -25,7 +25,14 @@ module OAuth
25
25
  end
26
26
 
27
27
  def body_hash
28
- Base64.encode64(OpenSSL::Digest.digest("SHA1", request.body || "")).chomp.delete("\n")
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")
29
36
  end
30
37
 
31
38
  private
@@ -47,7 +54,7 @@ module OAuth
47
54
  options[:private_key]
48
55
  else
49
56
  consumer_secret
50
- end
57
+ end,
51
58
  )
52
59
 
53
60
  private_key.sign(OpenSSL::Digest.new("SHA1"), signature_base_string)
@@ -8,7 +8,7 @@ module OAuth
8
8
  def request(http_method, path, *arguments)
9
9
  request_uri = URI.parse(path)
10
10
  site_uri = consumer.uri
11
- is_service_uri_different = (request_uri.absolute? && request_uri != site_uri)
11
+ is_service_uri_different = request_uri.absolute? && request_uri != site_uri
12
12
  begin
13
13
  consumer.uri(request_uri) if is_service_uri_different
14
14
  @response = super(http_method, path, *arguments)
@@ -4,7 +4,7 @@ module OAuth
4
4
  # Superclass for tokens used by OAuth Clients
5
5
  class ConsumerToken < Token
6
6
  attr_accessor :consumer, :params
7
- attr_reader :response
7
+ attr_reader :response
8
8
 
9
9
  def self.from_hash(consumer, hash)
10
10
  token = new(consumer, hash[:oauth_token], hash[:oauth_token_secret])
@@ -15,7 +15,7 @@ module OAuth
15
15
  def initialize(consumer, token = "", secret = "")
16
16
  super(token, secret)
17
17
  @consumer = consumer
18
- @params = {}
18
+ @params = {}
19
19
  end
20
20
 
21
21
  # Make a signed request using given http_method to the path
@@ -6,14 +6,14 @@ module OAuth
6
6
  class RequestToken < ConsumerToken
7
7
  # Generate an authorization URL for user authorization
8
8
  def authorize_url(params = nil)
9
- return nil if token.nil?
9
+ return if token.nil?
10
10
 
11
11
  params = (params || {}).merge(oauth_token: token)
12
12
  build_url(consumer.authorize_url, params)
13
13
  end
14
14
 
15
15
  def authenticate_url(params = nil)
16
- return nil if token.nil?
16
+ return if token.nil?
17
17
 
18
18
  params = (params || {}).merge(oauth_token: token)
19
19
  build_url(consumer.authenticate_url, params)
@@ -25,8 +25,13 @@ module OAuth
25
25
 
26
26
  # exchange for AccessToken on server
27
27
  def get_access_token(options = {}, *arguments)
28
- response = consumer.token_request(consumer.http_method,
29
- (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
+ )
30
35
  OAuth::AccessToken.from_hash(consumer, response)
31
36
  end
32
37
 
data/lib/oauth/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OAuth
4
4
  module Version
5
- VERSION = "1.1.0"
5
+ VERSION = "1.1.1"
6
6
  end
7
7
  end
data.tar.gz.sig ADDED
Binary file