signet 0.14.1 → 0.15.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c94f4ee9a5ea982bba69826873be998a4cbf833af8c70920fd2384558efe33e5
4
- data.tar.gz: 211e019a051159858a4e18cbe64efe9989a13df08b2d449e67ac4057f91f4332
3
+ metadata.gz: 9d6cce64f05742592f4945a2a394ab1fc239107e9c5d8145f38a4189689e46ea
4
+ data.tar.gz: a20b6a81fac21113e804c8cbac63db3464da5357aa7428bc17509212217e50a3
5
5
  SHA512:
6
- metadata.gz: d8e5ac7a7977d89976275a4988e62139622436dea9f539a934b99e94f32832e57c8c522a91647449f9b5ea199fa561ad62680803f7d1dbe5b40946087b95dae4
7
- data.tar.gz: 2b6476b3b89d09d66c0274fa9bd1b5da6aebb68932e7e15325cf34ccca14b5d5f5a16f76a22330bbcb9f6b66882e016eeccb54977e7a87cc4ce6f32568361808
6
+ metadata.gz: b1f2c4ab3031aa346f118bc152f129559436f92ae8b3d0008f3a2efa51fb82e0e45fec0f999c6984772be58661c90f6fbe1a1c973cf6ccdec8329696da4e1101
7
+ data.tar.gz: fc909052f1a89ec0f79d9b9a36ca7196cef5be879595e8c1e7699050ced959b3062881e1418fc9b8258985819f3c2bb64e7e9f60008f25e5ddccb6375934c2f5
data/CHANGELOG.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # Release History
2
2
 
3
- ## [0.14.1](https://www.github.com/googleapis/signet/compare/v0.14.0...v0.14.1) (2021-01-27)
3
+ ## [0.15.0](https://www.github.com/googleapis/signet/compare/v0.14.1...v0.15.0) (2021-03-04)
4
4
 
5
5
 
6
- ### Bug Fixes
6
+ ### Features
7
7
 
8
- * Fix OAuth1 signature with duplicate query param names ([9f5b81a](https://www.github.com/googleapis/signet/commit/9f5b81a60625a6e6f0e5bca24c67b90e73d7479b))
8
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0 ([bd6fe87](https://www.github.com/googleapis/signet/commit/bd6fe87948f8fc7702720dae651e82f4fd348b5d))
9
+
10
+ ## 0.14.1 / 2021-01-27
11
+
12
+ * Fix OAuth1 signature with duplicate query param names
9
13
 
10
14
  ## 0.14.0 / 2020-03-31
11
15
 
data/README.md CHANGED
@@ -31,8 +31,8 @@ require 'signet/oauth_2/client'
31
31
  client = Signet::OAuth2::Client.new(
32
32
  :authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
33
33
  :token_credential_uri => 'https://oauth2.googleapis.com/token',
34
- :client_id => '44410190108-74nkm6jc5e3vvjqis803frkvmu88cu3a.apps.googleusercontent.com',
35
- :client_secret => 'X1NUhvO-rQr9sm8uUSMY8i7v',
34
+ :client_id => "#{YOUR_CLIENT_ID}.apps.googleusercontent.com",
35
+ :client_secret => YOUR_CLIENT_SECRET,
36
36
  :scope => 'email profile',
37
37
  :redirect_uri => 'https://example.client.com/oauth'
38
38
  )
@@ -59,8 +59,11 @@ Be sure `https://rubygems.org` is in your gem sources.
59
59
 
60
60
  ## Supported Ruby Versions
61
61
 
62
- This library requires Ruby 2.4 or later.
63
- In general, this library supports Ruby versions that are considered current and
64
- supported by Ruby Core (that is, Ruby versions that are either in normal
65
- maintenance or in security maintenance).
66
- See https://www.ruby-lang.org/en/downloads/branches/ for further details.
62
+ This library is supported on Ruby 2.5+.
63
+
64
+ Google provides official support for Ruby versions that are actively supported
65
+ by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
66
+ security maintenance, and not end of life. Currently, this means Ruby 2.5 and
67
+ later. Older versions of Ruby _may_ still work, but are unsupported and not
68
+ recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
69
+ about the Ruby support schedule.
data/lib/signet.rb CHANGED
@@ -15,8 +15,6 @@
15
15
  require "signet/version"
16
16
 
17
17
  module Signet #:nodoc:
18
- # rubocop:disable Metrics/AbcSize
19
- # rubocop:disable Metrics/MethodLength
20
18
  def self.parse_auth_param_list auth_param_string
21
19
  # Production rules from:
22
20
  # http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-12
@@ -54,11 +52,12 @@ module Signet #:nodoc:
54
52
  # Now parse the auth-param pair strings & turn them into key-value pairs.
55
53
  (auth_param_pairs.each_with_object [] do |pair, accu|
56
54
  name, value = pair.split "=", 2
57
- if value =~ /^".*"$/
55
+ case value
56
+ when /^".*"$/
58
57
  value = value.gsub(/^"(.*)"$/, '\1').gsub(/\\(.)/, '\1')
59
- elsif value =~ /^'.*'$/
58
+ when /^'.*'$/
60
59
  value = value.gsub(/^'(.*)'$/, '\1').gsub(/\\(.)/, '\1')
61
- elsif value =~ %r{[\(\)<>@,;:\\\"/\[\]?={}]}
60
+ when %r{[()<>@,;:\\"/\[\]?={}]}
62
61
  # Certain special characters are not allowed
63
62
  raise ParseError,
64
63
  "Unexpected characters in auth param " \
@@ -68,6 +67,4 @@ module Signet #:nodoc:
68
67
  accu << [name, value]
69
68
  end)
70
69
  end
71
- # rubocop:enable Metrics/AbcSize
72
- # rubocop:enable Metrics/MethodLength
73
70
  end
@@ -49,9 +49,8 @@ module Signet #:nodoc:
49
49
  #
50
50
  # @return [String] A random nonce.
51
51
  def self.generate_nonce
52
- SecureRandom.random_bytes(16).unpack("H*").join ""
52
+ SecureRandom.random_bytes(16).unpack("H*").join
53
53
  end
54
- # rubocop:disable Metrics/MethodLength
55
54
 
56
55
  ##
57
56
  # Processes an options <code>Hash</code> to find a credential key value.
@@ -65,7 +64,7 @@ module Signet #:nodoc:
65
64
  # @return [String] The credential key value.
66
65
  def self.extract_credential_key_option credential_type, options
67
66
  # Normalize key to String to allow indifferent access.
68
- options = options.each_with_object({}) { |(k, v), accu| accu[k.to_s] = v; }
67
+ options = options.to_h.transform_keys(&:to_s)
69
68
  credential_key = "#{credential_type}_credential_key"
70
69
  credential = "#{credential_type}_credential"
71
70
  if options[credential_key]
@@ -107,7 +106,7 @@ module Signet #:nodoc:
107
106
  # @return [String] The credential secret value.
108
107
  def self.extract_credential_secret_option credential_type, options
109
108
  # Normalize key to String to allow indifferent access.
110
- options = options.each_with_object({}) { |(k, v), accu| accu[k.to_s] = v; }
109
+ options = options.to_h.transform_keys(&:to_s)
111
110
  credential_secret = "#{credential_type}_credential_secret"
112
111
  credential = "#{credential_type}_credential"
113
112
  if options[credential_secret]
@@ -136,7 +135,6 @@ module Signet #:nodoc:
136
135
  end
137
136
  credential_secret
138
137
  end
139
- # rubocop:enable Metrics/MethodLength
140
138
 
141
139
  ##
142
140
  # Normalizes a set of OAuth parameters according to the algorithm given
@@ -214,7 +212,7 @@ module Signet #:nodoc:
214
212
  realm = realm.gsub '"', '\"'
215
213
  parameter_list.unshift "realm=\"#{realm}\""
216
214
  end
217
- "OAuth " + parameter_list.join(", ")
215
+ "OAuth #{parameter_list.join ', '}"
218
216
  end
219
217
 
220
218
  ##
@@ -228,7 +226,7 @@ module Signet #:nodoc:
228
226
  when /^OAuth$/i
229
227
  # Other token types may be supported eventually
230
228
  pairs = Signet.parse_auth_param_list(field_value[/^OAuth\s+(.*)$/i, 1])
231
- return (pairs.each_with_object [] do |(k, v), accu|
229
+ (pairs.each_with_object [] do |(k, v), accu|
232
230
  if k != "realm"
233
231
  k = unencode k
234
232
  v = unencode v
@@ -274,24 +272,18 @@ module Signet #:nodoc:
274
272
  # be a temporary credential secret when obtaining a token credential
275
273
  # for the first time
276
274
  base_string = generate_base_string method, uri, parameters
277
- parameters = parameters.each_with_object({}) { |(k, v), h| h[k.to_s] = v; }
275
+ parameters = parameters.to_h.transform_keys(&:to_s)
278
276
  signature_method = parameters["oauth_signature_method"]
279
277
  case signature_method
280
278
  when "HMAC-SHA1"
281
279
  require "signet/oauth_1/signature_methods/hmac_sha1"
282
- return Signet::OAuth1::HMACSHA1.generate_signature(
283
- base_string, client_credential_secret, token_credential_secret
284
- )
280
+ Signet::OAuth1::HMACSHA1.generate_signature base_string, client_credential_secret, token_credential_secret
285
281
  when "RSA-SHA1"
286
282
  require "signet/oauth_1/signature_methods/rsa_sha1"
287
- return Signet::OAuth1::RSASHA1.generate_signature(
288
- base_string, client_credential_secret, token_credential_secret
289
- )
283
+ Signet::OAuth1::RSASHA1.generate_signature base_string, client_credential_secret, token_credential_secret
290
284
  when "PLAINTEXT"
291
285
  require "signet/oauth_1/signature_methods/plaintext"
292
- return Signet::OAuth1::PLAINTEXT.generate_signature(
293
- base_string, client_credential_secret, token_credential_secret
294
- )
286
+ Signet::OAuth1::PLAINTEXT.generate_signature base_string, client_credential_secret, token_credential_secret
295
287
  else
296
288
  raise NotImplementedError,
297
289
  "Unsupported signature method: #{signature_method}"
@@ -396,7 +388,7 @@ module Signet #:nodoc:
396
388
  raise ArgumentError, "Missing :client_credential_key parameter." if client_credential_key.nil?
397
389
  raise ArgumentError, "Missing :temporary_credential_key parameter." if temporary_credential_key.nil?
398
390
  raise ArgumentError, "Missing :verifier parameter." if options[:verifier].nil?
399
- parameters = [
391
+ [
400
392
  ["oauth_consumer_key", client_credential_key],
401
393
  ["oauth_token", temporary_credential_key],
402
394
  ["oauth_signature_method", options[:signature_method]],
@@ -405,8 +397,6 @@ module Signet #:nodoc:
405
397
  ["oauth_verifier", options[:verifier]],
406
398
  ["oauth_version", "1.0"]
407
399
  ]
408
- # No additional parameters allowed here
409
- parameters
410
400
  end
411
401
 
412
402
  ##
@@ -89,7 +89,7 @@ module Signet
89
89
  # @see Signet::OAuth1::Client#initialize
90
90
  def update! options = {}
91
91
  # Normalize key to String to allow indifferent access.
92
- options = options.each_with_object({}) { |(k, v), accu| accu[k.to_s] = v; }
92
+ options = options.to_h.transform_keys(&:to_s)
93
93
  self.temporary_credential_uri = options["temporary_credential_uri"]
94
94
  self.authorization_uri = options["authorization_uri"]
95
95
  self.token_credential_uri = options["token_credential_uri"]
@@ -128,12 +128,12 @@ module Signet
128
128
  # new_temporary_credential_uri
129
129
  # The temporary credentials URI.
130
130
  def temporary_credential_uri= new_temporary_credential_uri
131
- if !new_temporary_credential_uri.nil?
131
+ if new_temporary_credential_uri.nil?
132
+ @temporary_credential_uri = nil
133
+ else
132
134
  new_temporary_credential_uri =
133
135
  Addressable::URI.parse new_temporary_credential_uri
134
136
  @temporary_credential_uri = new_temporary_credential_uri
135
- else
136
- @temporary_credential_uri = nil
137
137
  end
138
138
  end
139
139
  alias request_token_uri= temporary_credential_uri=
@@ -163,14 +163,14 @@ module Signet
163
163
  # @param [Addressable::URI, String, #to_str] new_authorization_uri
164
164
  # The authorization URI.
165
165
  def authorization_uri= new_authorization_uri
166
- if !new_authorization_uri.nil?
166
+ if new_authorization_uri.nil?
167
+ @authorization_uri = nil
168
+ else
167
169
  new_authorization_uri = Addressable::URI.send(
168
170
  new_authorization_uri.is_a?(Hash) ? :new : :parse,
169
171
  new_authorization_uri
170
172
  )
171
173
  @authorization_uri = new_authorization_uri
172
- else
173
- @authorization_uri = nil
174
174
  end
175
175
  end
176
176
 
@@ -189,14 +189,14 @@ module Signet
189
189
  # @param [Addressable::URI, Hash, String, #to_str] new_token_credential_uri
190
190
  # The token credential URI.
191
191
  def token_credential_uri= new_token_credential_uri
192
- if !new_token_credential_uri.nil?
192
+ if new_token_credential_uri.nil?
193
+ @token_credential_uri = nil
194
+ else
193
195
  new_token_credential_uri = Addressable::URI.send(
194
196
  new_token_credential_uri.is_a?(Hash) ? :new : :parse,
195
197
  new_token_credential_uri
196
198
  )
197
199
  @token_credential_uri = new_token_credential_uri
198
- else
199
- @token_credential_uri = nil
200
200
  end
201
201
  end
202
202
  alias access_token_uri= token_credential_uri=
@@ -217,8 +217,7 @@ module Signet
217
217
  elsif !client_credential_key && !client_credential_secret
218
218
  nil
219
219
  else
220
- raise ArgumentError,
221
- "The client credential key and secret must be set."
220
+ raise ArgumentError, "The client credential key and secret must be set."
222
221
  end
223
222
  end
224
223
  alias consumer_token client_credential
@@ -229,7 +228,10 @@ module Signet
229
228
  # @param [Signet::OAuth1::Credential] new_client_credential
230
229
  # The client credentials.
231
230
  def client_credential= new_client_credential
232
- if !new_client_credential.nil?
231
+ if new_client_credential.nil?
232
+ @client_credential_key = nil
233
+ @client_credential_secret = nil
234
+ else
233
235
  unless new_client_credential.is_a? ::Signet::OAuth1::Credential
234
236
  raise TypeError,
235
237
  "Expected Signet::OAuth1::Credential, " \
@@ -237,9 +239,6 @@ module Signet
237
239
  end
238
240
  @client_credential_key = new_client_credential.key
239
241
  @client_credential_secret = new_client_credential.secret
240
- else
241
- @client_credential_key = nil
242
- @client_credential_secret = nil
243
242
  end
244
243
  end
245
244
  alias consumer_token= client_credential=
@@ -259,15 +258,15 @@ module Signet
259
258
  # @param [String, #to_str] new_client_credential_key
260
259
  # The client credential key.
261
260
  def client_credential_key= new_client_credential_key
262
- if !new_client_credential_key.nil?
261
+ if new_client_credential_key.nil?
262
+ @client_credential_key = nil
263
+ else
263
264
  unless new_client_credential_key.respond_to? :to_str
264
265
  raise TypeError,
265
266
  "Can't convert #{new_client_credential_key.class} into String."
266
267
  end
267
268
  new_client_credential_key = new_client_credential_key.to_str
268
269
  @client_credential_key = new_client_credential_key
269
- else
270
- @client_credential_key = nil
271
270
  end
272
271
  end
273
272
  alias consumer_key= client_credential_key=
@@ -287,7 +286,9 @@ module Signet
287
286
  # @param [String, #to_str] new_client_credential_secret
288
287
  # The client credential secret.
289
288
  def client_credential_secret= new_client_credential_secret
290
- if !new_client_credential_secret.nil?
289
+ if new_client_credential_secret.nil?
290
+ @client_credential_secret = nil
291
+ else
291
292
  unless new_client_credential_secret.respond_to? :to_str
292
293
  raise TypeError,
293
294
  "Can't convert #{new_client_credential_secret.class} " \
@@ -295,8 +296,6 @@ module Signet
295
296
  end
296
297
  new_client_credential_secret = new_client_credential_secret.to_str
297
298
  @client_credential_secret = new_client_credential_secret
298
- else
299
- @client_credential_secret = nil
300
299
  end
301
300
  end
302
301
  alias consumer_secret= client_credential_secret=
@@ -311,12 +310,10 @@ module Signet
311
310
  temporary_credential_key,
312
311
  temporary_credential_secret
313
312
  )
314
- elsif !temporary_credential_key &&
315
- !temporary_credential_secret
313
+ elsif !temporary_credential_key && !temporary_credential_secret
316
314
  nil
317
315
  else
318
- raise ArgumentError,
319
- "The temporary credential key and secret must be set."
316
+ raise ArgumentError, "The temporary credential key and secret must be set."
320
317
  end
321
318
  end
322
319
  alias request_token temporary_credential
@@ -327,7 +324,10 @@ module Signet
327
324
  # @param [Signet::OAuth1::Credential] new_temporary_credential
328
325
  # The temporary credentials.
329
326
  def temporary_credential= new_temporary_credential
330
- if !new_temporary_credential.nil?
327
+ if new_temporary_credential.nil?
328
+ @temporary_credential_key = nil
329
+ @temporary_credential_secret = nil
330
+ else
331
331
  unless new_temporary_credential.is_a? ::Signet::OAuth1::Credential
332
332
  raise TypeError,
333
333
  "Expected Signet::OAuth1::Credential, " \
@@ -335,9 +335,6 @@ module Signet
335
335
  end
336
336
  @temporary_credential_key = new_temporary_credential.key
337
337
  @temporary_credential_secret = new_temporary_credential.secret
338
- else
339
- @temporary_credential_key = nil
340
- @temporary_credential_secret = nil
341
338
  end
342
339
  end
343
340
  alias request_token= temporary_credential=
@@ -357,7 +354,9 @@ module Signet
357
354
  # @param [String, #to_str] new_temporary_credential_key
358
355
  # The temporary credential key.
359
356
  def temporary_credential_key= new_temporary_credential_key
360
- if !new_temporary_credential_key.nil?
357
+ if new_temporary_credential_key.nil?
358
+ @temporary_credential_key = nil
359
+ else
361
360
  unless new_temporary_credential_key.respond_to? :to_str
362
361
  raise TypeError,
363
362
  "Can't convert #{new_temporary_credential_key.class} " \
@@ -365,8 +364,6 @@ module Signet
365
364
  end
366
365
  new_temporary_credential_key = new_temporary_credential_key.to_str
367
366
  @temporary_credential_key = new_temporary_credential_key
368
- else
369
- @temporary_credential_key = nil
370
367
  end
371
368
  end
372
369
  alias request_token_key= temporary_credential_key=
@@ -386,7 +383,9 @@ module Signet
386
383
  # @param [String, #to_str] new_temporary_credential_secret
387
384
  # The temporary credential secret.
388
385
  def temporary_credential_secret= new_temporary_credential_secret
389
- if !new_temporary_credential_secret.nil?
386
+ if new_temporary_credential_secret.nil?
387
+ @temporary_credential_secret = nil
388
+ else
390
389
  unless new_temporary_credential_secret.respond_to? :to_str
391
390
  raise TypeError,
392
391
  "Can't convert #{new_temporary_credential_secret.class} " \
@@ -395,8 +394,6 @@ module Signet
395
394
  new_temporary_credential_secret =
396
395
  new_temporary_credential_secret.to_str
397
396
  @temporary_credential_secret = new_temporary_credential_secret
398
- else
399
- @temporary_credential_secret = nil
400
397
  end
401
398
  end
402
399
  alias request_token_secret= temporary_credential_secret=
@@ -411,12 +408,10 @@ module Signet
411
408
  token_credential_key,
412
409
  token_credential_secret
413
410
  )
414
- elsif !token_credential_key &&
415
- !token_credential_secret
411
+ elsif !token_credential_key && !token_credential_secret
416
412
  nil
417
413
  else
418
- raise ArgumentError,
419
- "The token credential key and secret must be set."
414
+ raise ArgumentError, "The token credential key and secret must be set."
420
415
  end
421
416
  end
422
417
  alias access_token token_credential
@@ -427,7 +422,10 @@ module Signet
427
422
  # @param [Signet::OAuth1::Credential] new_token_credential
428
423
  # The token credentials.
429
424
  def token_credential= new_token_credential
430
- if !new_token_credential.nil?
425
+ if new_token_credential.nil?
426
+ @token_credential_key = nil
427
+ @token_credential_secret = nil
428
+ else
431
429
  unless new_token_credential.is_a? ::Signet::OAuth1::Credential
432
430
  raise TypeError,
433
431
  "Expected Signet::OAuth1::Credential, " \
@@ -435,9 +433,6 @@ module Signet
435
433
  end
436
434
  @token_credential_key = new_token_credential.key
437
435
  @token_credential_secret = new_token_credential.secret
438
- else
439
- @token_credential_key = nil
440
- @token_credential_secret = nil
441
436
  end
442
437
  end
443
438
  alias access_token= token_credential=
@@ -457,7 +452,9 @@ module Signet
457
452
  # @param [String, #to_str] new_token_credential_key
458
453
  # The token credential key.
459
454
  def token_credential_key= new_token_credential_key
460
- if !new_token_credential_key.nil?
455
+ if new_token_credential_key.nil?
456
+ @token_credential_key = nil
457
+ else
461
458
  unless new_token_credential_key.respond_to? :to_str
462
459
  raise TypeError,
463
460
  "Can't convert #{new_token_credential_key.class} " \
@@ -465,8 +462,6 @@ module Signet
465
462
  end
466
463
  new_token_credential_key = new_token_credential_key.to_str
467
464
  @token_credential_key = new_token_credential_key
468
- else
469
- @token_credential_key = nil
470
465
  end
471
466
  end
472
467
  alias access_token_key= token_credential_key=
@@ -486,7 +481,9 @@ module Signet
486
481
  # @param [String, #to_str] new_token_credential_secret
487
482
  # The token credential secret.
488
483
  def token_credential_secret= new_token_credential_secret
489
- if !new_token_credential_secret.nil?
484
+ if new_token_credential_secret.nil?
485
+ @token_credential_secret = nil
486
+ else
490
487
  unless new_token_credential_secret.respond_to? :to_str
491
488
  raise TypeError,
492
489
  "Can't convert #{new_token_credential_secret.class} " \
@@ -495,8 +492,6 @@ module Signet
495
492
  new_token_credential_secret =
496
493
  new_token_credential_secret.to_str
497
494
  @token_credential_secret = new_token_credential_secret
498
- else
499
- @token_credential_secret = nil
500
495
  end
501
496
  end
502
497
  alias access_token_secret= token_credential_secret=
@@ -515,15 +510,15 @@ module Signet
515
510
  # @param [String, #to_str] new_callback
516
511
  # The OAuth callback.
517
512
  def callback= new_callback
518
- if !new_callback.nil?
513
+ if new_callback.nil?
514
+ @callback = nil
515
+ else
519
516
  unless new_callback.respond_to? :to_str
520
517
  raise TypeError,
521
518
  "Can't convert #{new_callback.class} into String."
522
519
  end
523
520
  new_callback = new_callback.to_str
524
521
  @callback = new_callback
525
- else
526
- @callback = nil
527
522
  end
528
523
  end
529
524
 
@@ -556,7 +551,7 @@ module Signet
556
551
  # @note A serialized client contains sensitive information. Persist or transmit with care.
557
552
  #
558
553
  # @return [String] A serialized JSON representation of the client.
559
- def to_json
554
+ def to_json *_args
560
555
  MultiJson.dump(
561
556
  "temporary_credential_uri" => temporary_credential_uri,
562
557
  "authorization_uri" => authorization_uri,
@@ -571,8 +566,6 @@ module Signet
571
566
  "token_credential_secret" => token_credential_secret
572
567
  )
573
568
  end
574
- # rubocop:disable Metrics/AbcSize
575
- # rubocop:disable Metrics/MethodLength
576
569
 
577
570
  ##
578
571
  # Generates a request for temporary credentials.
@@ -635,8 +628,6 @@ module Signet
635
628
  req.headers = Faraday::Utils::Headers.new headers
636
629
  end
637
630
  end
638
- # rubocop:enable Metrics/AbcSize
639
- # rubocop:enable Metrics/MethodLength
640
631
  alias generate_request_token_request generate_temporary_credential_request
641
632
 
642
633
  ##
@@ -709,8 +700,6 @@ module Signet
709
700
  self.temporary_credential = credential
710
701
  end
711
702
  alias fetch_request_token! fetch_temporary_credential!
712
- # rubocop:disable Metrics/AbcSize
713
- # rubocop:disable Metrics/MethodLength
714
703
 
715
704
  ##
716
705
  # Generates a request for token credentials.
@@ -776,7 +765,6 @@ module Signet
776
765
  req.headers = Faraday::Utils::Headers.new headers
777
766
  end
778
767
  end
779
- # rubocop:enable Metrics/MethodLength
780
768
  alias generate_access_token_request generate_token_credential_request
781
769
 
782
770
  ##
@@ -818,7 +806,6 @@ module Signet
818
806
  message, request: request, response: response
819
807
  )
820
808
  end
821
- # rubocop:enable Metrics/AbcSize
822
809
  alias fetch_access_token fetch_token_credential
823
810
 
824
811
  ##
@@ -846,10 +833,6 @@ module Signet
846
833
  self.token_credential = credential
847
834
  end
848
835
  alias fetch_access_token! fetch_token_credential!
849
- # rubocop:disable Metrics/AbcSize
850
- # rubocop:disable Metrics/CyclomaticComplexity
851
- # rubocop:disable Metrics/MethodLength
852
- # rubocop:disable Metrics/PerceivedComplexity
853
836
 
854
837
  ##
855
838
  # Generates an authenticated request for protected resources.
@@ -950,7 +933,7 @@ module Signet
950
933
  request.body = env[:body]
951
934
 
952
935
  post_parameters = Addressable::URI.form_unencode env[:body]
953
- parameters = parameters.concat post_parameters
936
+ parameters.concat post_parameters
954
937
  end
955
938
 
956
939
  # No need to attach URI query parameters, the .sign_parameters
@@ -970,10 +953,6 @@ module Signet
970
953
  request["Cache-Control"] = "no-store"
971
954
  request
972
955
  end
973
- # rubocop:enable Metrics/AbcSize
974
- # rubocop:enable Metrics/CyclomaticComplexity
975
- # rubocop:enable Metrics/MethodLength
976
- # rubocop:enable Metrics/PerceivedComplexity
977
956
 
978
957
  ##
979
958
  # Transmits a request for a protected resource.
@@ -15,11 +15,6 @@
15
15
  module Signet #:nodoc:
16
16
  module OAuth1
17
17
  class Credential
18
- # rubocop:disable Metrics/AbcSize
19
- # rubocop:disable Metrics/CyclomaticComplexity
20
- # rubocop:disable Metrics/MethodLength
21
- # rubocop:disable Metrics/PerceivedComplexity
22
-
23
18
  ##
24
19
  # Creates a token object from a key and secret.
25
20
  #
@@ -95,12 +90,9 @@ module Signet #:nodoc:
95
90
  raise TypeError, "Expected String, got #{@secret.class}." unless @secret.respond_to? :to_str
96
91
  @secret = @secret.to_str
97
92
  end
98
- # rubocop:enable Metrics/AbcSize
99
- # rubocop:enable Metrics/CyclomaticComplexity
100
- # rubocop:enable Metrics/MethodLength
101
- # rubocop:enable Metrics/PerceivedComplexity
102
93
 
103
- attr_accessor :key, :secret
94
+ attr_accessor :key
95
+ attr_accessor :secret
104
96
 
105
97
  def to_hash
106
98
  {
@@ -55,15 +55,13 @@ module Signet
55
55
  instance_variable_set "@#{attr}", options[attr]
56
56
  end
57
57
  end
58
- # rubocop:disable Naming/UncommunicativeMethodParamName
59
58
 
60
59
  # Constant time string comparison.
61
- def safe_equals? a, b
62
- check = a.bytesize ^ b.bytesize
63
- a.bytes.zip(b.bytes) { |x, y| check |= x ^ y.to_i }
60
+ def safe_equals? left, right
61
+ check = left.bytesize ^ right.bytesize
62
+ left.bytes.zip(right.bytes) { |x, y| check |= x ^ y.to_i }
64
63
  check.zero?
65
64
  end
66
- # rubocop:enable Naming/UncommunicativeMethodParamName
67
65
 
68
66
  ##
69
67
  # Determine if the supplied nonce/timestamp pair is valid by calling
@@ -141,8 +139,6 @@ module Signet
141
139
  verified = @verifier.call verifier if @verifier.respond_to? :call
142
140
  verified ? true : false
143
141
  end
144
- # rubocop:disable Metrics/MethodLength
145
- # rubocop:disable Metrics/PerceivedComplexity
146
142
 
147
143
  ##
148
144
  # Validate and normalize the components from an HTTP request.
@@ -188,8 +184,6 @@ module Signet
188
184
  request_components[:body] = body
189
185
  request_components
190
186
  end
191
- # rubocop:enable Metrics/MethodLength
192
- # rubocop:enable Metrics/PerceivedComplexity
193
187
 
194
188
  ##
195
189
  # Validate and normalize the HTTP Authorization header.
@@ -199,11 +193,7 @@ module Signet
199
193
  def verify_auth_header_components headers
200
194
  auth_header = headers.find { |x| x[0] == "Authorization" }
201
195
  raise MalformedAuthorizationError, "Authorization header is missing" if auth_header.nil? || auth_header[1] == ""
202
- auth_hash = ::Signet::OAuth1.parse_authorization_header(
203
- auth_header[1]
204
- ).each_with_object({}) { |(key, val), acc| acc[key.downcase] = val; }
205
-
206
- auth_hash
196
+ ::Signet::OAuth1.parse_authorization_header(auth_header[1]).to_h.transform_keys(&:downcase)
207
197
  end
208
198
 
209
199
  ##
@@ -232,14 +222,9 @@ module Signet
232
222
 
233
223
  auth_header = request_components[:headers].find { |x| x[0] == "Authorization" }
234
224
  raise MalformedAuthorizationError, "Authorization header is missing" if auth_header.nil? || auth_header[1] == ""
235
- auth_hash = ::Signet::OAuth1.parse_authorization_header(
236
- auth_header[1]
237
- ).each_with_object({}) { |(key, val), acc| acc[key.downcase] = val; }
225
+ auth_hash = ::Signet::OAuth1.parse_authorization_header(auth_header[1]).to_h.transform_keys(&:downcase)
238
226
  auth_hash["realm"]
239
227
  end
240
- # rubocop:disable Metrics/AbcSize
241
- # rubocop:disable Metrics/MethodLength
242
- # rubocop:disable Metrics/PerceivedComplexity
243
228
 
244
229
  ##
245
230
  # Authenticates a temporary credential request. If no oauth_callback is
@@ -308,7 +293,6 @@ module Signet
308
293
  false
309
294
  end
310
295
  end
311
- # rubocop:enable Metrics/PerceivedComplexity
312
296
 
313
297
  ##
314
298
  # Authenticates a token credential request.
@@ -379,8 +363,6 @@ module Signet
379
363
  temporary_credential: temporary_credential,
380
364
  realm: auth_hash["realm"] }
381
365
  end
382
- # rubocop:disable Metrics/CyclomaticComplexity
383
- # rubocop:disable Metrics/PerceivedComplexity
384
366
 
385
367
  ##
386
368
  # Authenticates a request for a protected resource.
@@ -496,10 +478,6 @@ module Signet
496
478
  token_credential: token_credential,
497
479
  realm: auth_hash["realm"] }
498
480
  end
499
- # rubocop:enable Metrics/AbcSize
500
- # rubocop:enable Metrics/CyclomaticComplexity
501
- # rubocop:enable Metrics/MethodLength
502
- # rubocop:enable Metrics/PerceivedComplexity
503
481
  end
504
482
  end
505
483
  end
@@ -11,7 +11,7 @@ module Signet #:nodoc:
11
11
 
12
12
 
13
13
  private_key = OpenSSL::PKey::RSA.new client_credential_secret
14
- signature = private_key.sign OpenSSL::Digest::SHA1.new, base_string
14
+ signature = private_key.sign OpenSSL::Digest.new("SHA1"), base_string
15
15
  # using strict_encode64 because the encode64 method adds newline characters after ever 60 chars
16
16
  Base64.strict_encode64(signature).strip
17
17
  end
@@ -28,10 +28,10 @@ module Signet #:nodoc:
28
28
  case auth_scheme
29
29
  when /^Basic$/i
30
30
  # HTTP Basic is allowed in OAuth 2
31
- return parse_basic_credentials(field_value[/^Basic\s+(.*)$/i, 1])
31
+ parse_basic_credentials(field_value[/^Basic\s+(.*)$/i, 1])
32
32
  when /^OAuth$/i
33
33
  # Other token types may be supported eventually
34
- return parse_bearer_credentials(field_value[/^OAuth\s+(.*)$/i, 1])
34
+ parse_bearer_credentials(field_value[/^OAuth\s+(.*)$/i, 1])
35
35
  else
36
36
  raise ParseError,
37
37
  "Parsing non-OAuth Authorization headers is out of scope."
@@ -43,7 +43,7 @@ module Signet #:nodoc:
43
43
  case auth_scheme
44
44
  when /^OAuth$/i
45
45
  # Other token types may be supported eventually
46
- return parse_oauth_challenge(field_value[/^OAuth\s+(.*)$/i, 1])
46
+ parse_oauth_challenge(field_value[/^OAuth\s+(.*)$/i, 1])
47
47
  else
48
48
  raise ParseError,
49
49
  "Parsing non-OAuth WWW-Authenticate headers is out of scope."
@@ -76,9 +76,9 @@ module Signet #:nodoc:
76
76
  raise TypeError, "Expected String, got #{body.class}." unless body.is_a? String
77
77
  case content_type
78
78
  when %r{^application/json.*}
79
- return MultiJson.load body
79
+ MultiJson.load body
80
80
  when %r{^application/x-www-form-urlencoded.*}
81
- return Hash[Addressable::URI.form_unencode(body)]
81
+ Hash[Addressable::URI.form_unencode(body)]
82
82
  else
83
83
  raise ArgumentError, "Invalid content type '#{content_type}'"
84
84
  end
@@ -100,9 +100,8 @@ module Signet #:nodoc:
100
100
  raise ArgumentError,
101
101
  "A client identifier may not contain a ':' character."
102
102
  end
103
- "Basic " + Base64.encode64(
104
- client_id + ":" + client_password
105
- ).delete("\n")
103
+ token = Base64.encode64("#{client_id}:#{client_password}").delete("\n")
104
+ "Basic #{token}"
106
105
  end
107
106
 
108
107
  ##
@@ -121,11 +120,8 @@ module Signet #:nodoc:
121
120
  # TODO: escaping?
122
121
  header = "Bearer #{access_token}"
123
122
  if auth_params && !auth_params.empty?
124
- header += (", " +
125
- (auth_params.each_with_object [] do |(key, value), accu|
126
- accu << "#{key}=\"#{value}\""
127
- end).join(", ")
128
- )
123
+ additional_headers = auth_params.map { |key, value| "#{key}=\"#{value}\"" }
124
+ header = ([header] + additional_headers).join ", "
129
125
  end
130
126
  header
131
127
  end
@@ -110,9 +110,6 @@ module Signet
110
110
  @access_type = nil
111
111
  update! options
112
112
  end
113
- # rubocop:disable Metrics/AbcSize
114
- # rubocop:disable Metrics/CyclomaticComplexity
115
- # rubocop:disable Metrics/PerceivedComplexity
116
113
 
117
114
  ##
118
115
  # Updates an OAuth 2.0 client.
@@ -202,13 +199,10 @@ module Signet
202
199
  self.signing_key = options[:signing_key] if options.key? :signing_key
203
200
  self.extension_parameters = options[:extension_parameters] || {}
204
201
  self.additional_parameters = options[:additional_parameters] || {}
205
- self.access_type = options.fetch(:access_type) { :offline }
202
+ self.access_type = options.fetch :access_type, :offline
206
203
  update_token! options
207
204
  self
208
205
  end
209
- # rubocop:enable Metrics/AbcSize
210
- # rubocop:enable Metrics/CyclomaticComplexity
211
- # rubocop:enable Metrics/PerceivedComplexity
212
206
 
213
207
  ##
214
208
  # Updates an OAuth 2.0 client.
@@ -261,10 +255,6 @@ module Signet
261
255
 
262
256
  self
263
257
  end
264
- # rubocop:disable Metrics/AbcSize
265
- # rubocop:disable Metrics/CyclomaticComplexity
266
- # rubocop:disable Metrics/MethodLength
267
- # rubocop:disable Metrics/PerceivedComplexity
268
258
 
269
259
  ##
270
260
  # Returns the authorization URI that the user should be redirected to.
@@ -290,9 +280,7 @@ module Signet
290
280
  options[:state] = state unless options[:state]
291
281
  options.merge!(additional_parameters.merge(options[:additional_parameters] || {}))
292
282
  options.delete :additional_parameters
293
- options = Hash[options.map do |key, option|
294
- [key.to_s, option]
295
- end]
283
+ options = options.transform_keys(&:to_s)
296
284
  uri = Addressable::URI.parse(
297
285
  ::Signet::OAuth2.generate_authorization_uri(
298
286
  @authorization_uri, options
@@ -304,10 +292,6 @@ module Signet
304
292
  end
305
293
  uri
306
294
  end
307
- # rubocop:enable Metrics/AbcSize
308
- # rubocop:enable Metrics/CyclomaticComplexity
309
- # rubocop:enable Metrics/MethodLength
310
- # rubocop:enable Metrics/PerceivedComplexity
311
295
 
312
296
  ##
313
297
  # Sets the authorization URI for this client.
@@ -423,7 +407,7 @@ module Signet
423
407
  end
424
408
  @scope = new_scope
425
409
  when String
426
- @scope = new_scope.split " "
410
+ @scope = new_scope.split
427
411
  when nil
428
412
  @scope = nil
429
413
  else
@@ -793,12 +777,12 @@ module Signet
793
777
  # @param [String, Integer, nil] new_expires_in
794
778
  # The access token lifetime.
795
779
  def expires_in= new_expires_in
796
- if !new_expires_in.nil?
797
- @issued_at = Time.now
798
- @expires_at = @issued_at + new_expires_in.to_i
799
- else
780
+ if new_expires_in.nil?
800
781
  @expires_at = nil
801
782
  @issued_at = nil
783
+ else
784
+ @issued_at = Time.now
785
+ @expires_at = @issued_at + new_expires_in.to_i
802
786
  end
803
787
  end
804
788
 
@@ -922,8 +906,6 @@ module Signet
922
906
  assertion["sub"] = sub unless sub.nil?
923
907
  JWT.encode assertion, signing_key, signing_algorithm
924
908
  end
925
- # rubocop:disable Style/MethodDefParentheses
926
- # rubocop:disable Metrics/AbcSize
927
909
 
928
910
  ##
929
911
  # Serialize the client object to JSON.
@@ -931,7 +913,7 @@ module Signet
931
913
  # @note A serialized client contains sensitive information. Persist or transmit with care.
932
914
  #
933
915
  # @return [String] A serialized JSON representation of the client.
934
- def to_json(*)
916
+ def to_json *_args
935
917
  MultiJson.dump(
936
918
  "authorization_uri" => authorization_uri ? authorization_uri.to_s : nil,
937
919
  "token_credential_uri" => token_credential_uri ? token_credential_uri.to_s : nil,
@@ -956,10 +938,6 @@ module Signet
956
938
  "extension_parameters" => extension_parameters
957
939
  )
958
940
  end
959
- # rubocop:enable Style/MethodDefParentheses
960
- # rubocop:disable Metrics/CyclomaticComplexity
961
- # rubocop:disable Metrics/MethodLength
962
- # rubocop:disable Metrics/PerceivedComplexity
963
941
 
964
942
  ##
965
943
  # Generates a request for token credentials.
@@ -1005,8 +983,6 @@ module Signet
1005
983
  additional.each { |k, v| parameters[k.to_s] = v }
1006
984
  parameters
1007
985
  end
1008
- # rubocop:enable Metrics/CyclomaticComplexity
1009
- # rubocop:enable Metrics/PerceivedComplexity
1010
986
 
1011
987
  def fetch_access_token options = {}
1012
988
  raise ArgumentError, "Missing token endpoint URI." if token_credential_uri.nil?
@@ -1035,20 +1011,16 @@ module Signet
1035
1011
 
1036
1012
  message = " Server message:\n#{response.body.to_s.strip}" unless body.to_s.strip.empty?
1037
1013
  if [400, 401, 403].include? status
1038
- message = "Authorization failed." + message
1039
- raise ::Signet::AuthorizationError.new(
1040
- message, response: response
1041
- )
1014
+ message = "Authorization failed.#{message}"
1015
+ raise ::Signet::AuthorizationError.new message, response: response
1042
1016
  elsif status.to_s[0] == "5"
1043
- message = "Remote server error." + message
1017
+ message = "Remote server error.#{message}"
1044
1018
  raise ::Signet::RemoteServerError, message
1045
1019
  else
1046
- message = "Unexpected status code: #{response.status}." + message
1020
+ message = "Unexpected status code: #{response.status}.#{message}"
1047
1021
  raise ::Signet::UnexpectedStatusError, message
1048
1022
  end
1049
1023
  end
1050
- # rubocop:enable Metrics/AbcSize
1051
- # rubocop:enable Metrics/MethodLength
1052
1024
 
1053
1025
  def fetch_access_token! options = {}
1054
1026
  token_hash = fetch_access_token options
@@ -1068,9 +1040,6 @@ module Signet
1068
1040
  def refresh! options = {}
1069
1041
  fetch_access_token! options
1070
1042
  end
1071
- # rubocop:disable Metrics/AbcSize
1072
- # rubocop:disable Metrics/MethodLength
1073
- # rubocop:disable Metrics/PerceivedComplexity
1074
1043
 
1075
1044
  ##
1076
1045
  # Generates an authenticated request for protected resources.
@@ -1137,9 +1106,6 @@ module Signet
1137
1106
  request["Cache-Control"] = "no-store"
1138
1107
  request
1139
1108
  end
1140
- # rubocop:enable Metrics/AbcSize
1141
- # rubocop:enable Metrics/MethodLength
1142
- # rubocop:enable Metrics/PerceivedComplexity
1143
1109
 
1144
1110
  ##
1145
1111
  # Transmits a request for a protected resource.
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module Signet
16
- VERSION = "0.14.1".freeze
16
+ VERSION = "0.15.0".freeze
17
17
  end
data/signet.gemspec CHANGED
@@ -21,14 +21,15 @@ Gem::Specification.new do |gem|
21
21
  gem.homepage = "https://github.com/googleapis/signet"
22
22
  gem.rdoc_options = ["--main", "README.md"]
23
23
  gem.summary = "Signet is an OAuth 1.0 / OAuth 2.0 implementation."
24
- gem.required_ruby_version = ">= 2.4.0"
24
+
25
+ gem.required_ruby_version = ">= 2.5"
25
26
 
26
27
  gem.add_runtime_dependency "addressable", "~> 2.3"
27
28
  gem.add_runtime_dependency "faraday", ">= 0.17.3", "< 2.0"
28
29
  gem.add_runtime_dependency "jwt", ">= 1.5", "< 3.0"
29
30
  gem.add_runtime_dependency "multi_json", "~> 1.10"
30
31
 
31
- gem.add_development_dependency "google-style", "~> 0.3"
32
+ gem.add_development_dependency "google-style", "~> 1.25.1"
32
33
  gem.add_development_dependency "kramdown", "~> 1.5"
33
34
  gem.add_development_dependency "launchy", "~> 2.4"
34
35
  gem.add_development_dependency "rake", "~> 12.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: signet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Aman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-27 00:00:00.000000000 Z
12
+ date: 2021-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -85,14 +85,14 @@ dependencies:
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '0.3'
88
+ version: 1.25.1
89
89
  type: :development
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0.3'
95
+ version: 1.25.1
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: kramdown
98
98
  requirement: !ruby/object:Gem::Requirement
@@ -241,14 +241,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
241
241
  requirements:
242
242
  - - ">="
243
243
  - !ruby/object:Gem::Version
244
- version: 2.4.0
244
+ version: '2.5'
245
245
  required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  requirements:
247
247
  - - ">="
248
248
  - !ruby/object:Gem::Version
249
249
  version: 1.3.5
250
250
  requirements: []
251
- rubygems_version: 3.2.6
251
+ rubygems_version: 3.2.11
252
252
  signing_key:
253
253
  specification_version: 4
254
254
  summary: Signet is an OAuth 1.0 / OAuth 2.0 implementation.