mastercard_oauth1_signer 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e66edf3b0c03d25a2eeec6d3b3672539c9fb7c83d1c53027b503beb188011ce5
4
- data.tar.gz: 30c885f68af13a3664ef2ca24e3f68106f9d44787a99c61b815a9012d305b91f
3
+ metadata.gz: bc99c2f741d407afea8bfa4a173841c65c65388b01bbb188e0d91229bdbdbb1c
4
+ data.tar.gz: fde6a72486a7b34b7cc53829694099b68ff9827feb24952314346fe45f8c678a
5
5
  SHA512:
6
- metadata.gz: dfafbf1ba178b3dfcb1b34036b2ae4f76fac07d7ab6bf99e45e4c6dfa983ed0374ed8678e9d95f64a2c864758b85347052ec6f3f351ca8a561f19277aa217769
7
- data.tar.gz: 33be101c0648a58d6d99cb03e9e9095da355f0542aab98ce9be29311c4a20858e62fd1ab143e8c53e4fbcc1de7b3e757b3178302dd408de64f928398a69ee58a
6
+ metadata.gz: 03edc59be830218437c63ba5027920e42bbcf7740a139067920076f48e1d88b67b622bd9bdf23da7b9606c61f3b3c9190ad8a373c8146d48a5be4ae65e7916aa
7
+ data.tar.gz: 97f9570af04be215ff34d00ce45f7a9934dc6d8b69ff617f820a3b2f2efab06523e468e88aa0310cda7d53ce961ef7e3f805c0b71a2582b94c3aab3c95f0d6a1
data/lib/oauth.rb CHANGED
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
  require 'openssl'
3
5
  require 'uri'
4
6
 
5
7
  class OAuth
6
8
  class << self
7
-
8
- EMPTY_STRING = ''.freeze
9
- SHA_BITS = '256'.freeze
9
+ EMPTY_STRING = ''
10
+ SHA_BITS = '256'
10
11
 
11
12
  # Creates a Mastercard API compliant OAuth Authorization header
12
13
  #
@@ -53,17 +54,17 @@ class OAuth
53
54
  query_pairs = {}
54
55
  pairs = query_params.split('&').sort_by(&:downcase)
55
56
 
56
- pairs.each { |pair|
57
+ pairs.each do |pair|
57
58
  idx = pair.index('=')
58
- key = idx > 0 ? pair[0..(idx - 1)] : pair
59
+ key = idx.positive? ? pair[0..(idx - 1)] : pair
59
60
  query_pairs[key] = [] unless query_pairs.include?(key)
60
- value = if idx > 0 && pair.length > idx + 1
61
+ value = if idx.positive? && pair.length > idx + 1
61
62
  pair[(idx + 1)..pair.length]
62
63
  else
63
64
  EMPTY_STRING
64
65
  end
65
66
  query_pairs[key].push(value)
66
- }
67
+ end
67
68
  query_pairs
68
69
  end
69
70
 
@@ -93,11 +94,11 @@ class OAuth
93
94
  #
94
95
  def get_authorization_string(oauth_params)
95
96
  header = 'OAuth '
96
- oauth_params.each {|entry|
97
+ oauth_params.each do |entry|
97
98
  entry_key = entry[0]
98
99
  entry_val = entry[1]
99
100
  header = "#{header}#{entry_key}=\"#{entry_val}\","
100
- }
101
+ end
101
102
  # Remove trailing ,
102
103
  header.slice(0, header.length - 1)
103
104
  end
@@ -114,8 +115,8 @@ class OAuth
114
115
  # Lowercase scheme and authority
115
116
  # Remove redundant port, query, and fragment
116
117
  base_uri = "#{url.scheme.downcase}://#{url.host.downcase}"
117
- base_uri += ":#{url.port}" if url.scheme.downcase == "https" and url.port != 443
118
- base_uri += ":#{url.port}" if url.scheme.downcase == "http" and url.port != 80
118
+ base_uri += ":#{url.port}" if (url.scheme.downcase == 'https') && (url.port != 443)
119
+ base_uri += ":#{url.port}" if (url.scheme.downcase == 'http') && (url.port != 80)
119
120
  base_uri += "/#{url.path[1..-1]}"
120
121
  end
121
122
 
@@ -131,7 +132,7 @@ class OAuth
131
132
  consolidated_params = {}.merge(query_params_map)
132
133
 
133
134
  # Add OAuth params to consolidated params map
134
- oauth_param_map.each {|entry|
135
+ oauth_param_map.each do |entry|
135
136
  entry_key = entry[0]
136
137
  entry_val = entry[1]
137
138
  consolidated_params[entry_key] =
@@ -140,8 +141,9 @@ class OAuth
140
141
  else
141
142
  [].push(entry_val)
142
143
  end
143
- }
144
+ end
144
145
 
146
+ consolidated_params = consolidated_params.sort_by { |k, _| k }.to_h
145
147
  oauth_params = ''
146
148
 
147
149
  # Add all parameters to the parameter string for signing
@@ -159,9 +161,7 @@ class OAuth
159
161
 
160
162
  # Remove trailing ampersand
161
163
  string_length = oauth_params.length - 1
162
- if oauth_params.end_with?('&')
163
- oauth_params = oauth_params.slice(0, string_length)
164
- end
164
+ oauth_params = oauth_params.slice(0, string_length) if oauth_params.end_with?('&')
165
165
 
166
166
  oauth_params
167
167
  end
@@ -198,7 +198,7 @@ class OAuth
198
198
  #
199
199
  # noinspection RubyArgCount
200
200
  def OAuth.sign_signature_base_string(sbs, signing_key)
201
- digest = OpenSSL::Digest::SHA256.new
201
+ digest = OpenSSL::Digest.new('SHA256')
202
202
  rsa_key = OpenSSL::PKey::RSA.new signing_key
203
203
 
204
204
  signature = ''
@@ -3,7 +3,7 @@ Gem::Specification.new do |gem|
3
3
  gem.authors = ["Mastercard"]
4
4
  gem.summary = %q{Mastercard client authentication library}
5
5
  gem.description = %q{Zero dependency library for generating a Mastercard API compliant OAuth signature}
6
- gem.version = "1.1.1"
6
+ gem.version = "1.1.2"
7
7
  gem.license = "MIT"
8
8
  gem.homepage = "https://github.com/Mastercard/oauth1-signer-ruby"
9
9
  gem.files = Dir["{bin,spec,lib}/**/*"]+ Dir["data/*"] + ["oauth1_signer_ruby.gemspec"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mastercard_oauth1_signer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mastercard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler