Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Drop support for Ruby 2.4 and add support for Ruby 3.0 #178

Merged
merged 2 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ AllCops:
- "Rakefile"
- "yard/**/*"
- "website/**/*"
Metrics/AbcSize:
Enabled: false
Metrics/ClassLength:
Exclude:
- "lib/signet/oauth_1/client.rb"
- "lib/signet/oauth_1/server.rb"
- "lib/signet/oauth_2/client.rb"
Enabled: false
Metrics/CyclomaticComplexity:
Max: 30
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
Exclude:
- "lib/signet/oauth_1.rb"
Enabled: false
Metrics/PerceivedComplexity:
Max: 30
Style/Documentation:
Enabled: false
7 changes: 2 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Release History

## [0.14.1](https://www.github.com/googleapis/signet/compare/v0.14.0...v0.14.1) (2021-01-27)
## 0.14.1 / 2021-01-27


### Bug Fixes

* Fix OAuth1 signature with duplicate query param names ([9f5b81a](https://www.github.com/googleapis/signet/commit/9f5b81a60625a6e6f0e5bca24c67b90e73d7479b))
* Fix OAuth1 signature with duplicate query param names

## 0.14.0 / 2020-03-31

Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ require 'signet/oauth_2/client'
client = Signet::OAuth2::Client.new(
:authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
:token_credential_uri => 'https://oauth2.googleapis.com/token',
:client_id => '44410190108-74nkm6jc5e3vvjqis803frkvmu88cu3a.apps.googleusercontent.com',
:client_secret => 'X1NUhvO-rQr9sm8uUSMY8i7v',
:client_id => "#{YOUR_CLIENT_ID}.apps.googleusercontent.com",
:client_secret => YOUR_CLIENT_SECRET,
:scope => 'email profile',
:redirect_uri => 'https://example.client.com/oauth'
)
Expand All @@ -59,8 +59,11 @@ Be sure `https://rubygems.org` is in your gem sources.

## Supported Ruby Versions

This library requires Ruby 2.4 or later.
In general, this library supports Ruby versions that are considered current and
supported by Ruby Core (that is, Ruby versions that are either in normal
maintenance or in security maintenance).
See https://www.ruby-lang.org/en/downloads/branches/ for further details.
This library is supported on Ruby 2.5+.

Google provides official support for Ruby versions that are actively supported
by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
security maintenance, and not end of life. Currently, this means Ruby 2.5 and
later. Older versions of Ruby _may_ still work, but are unsupported and not
recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
about the Ruby support schedule.
11 changes: 4 additions & 7 deletions lib/signet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
require "signet/version"

module Signet #:nodoc:
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def self.parse_auth_param_list auth_param_string
# Production rules from:
# http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-12
Expand Down Expand Up @@ -54,11 +52,12 @@ def self.parse_auth_param_list auth_param_string
# Now parse the auth-param pair strings & turn them into key-value pairs.
(auth_param_pairs.each_with_object [] do |pair, accu|
name, value = pair.split "=", 2
if value =~ /^".*"$/
case value
when /^".*"$/
value = value.gsub(/^"(.*)"$/, '\1').gsub(/\\(.)/, '\1')
elsif value =~ /^'.*'$/
when /^'.*'$/
value = value.gsub(/^'(.*)'$/, '\1').gsub(/\\(.)/, '\1')
elsif value =~ %r{[\(\)<>@,;:\\\"/\[\]?={}]}
when %r{[()<>@,;:\\"/\[\]?={}]}
# Certain special characters are not allowed
raise ParseError,
"Unexpected characters in auth param " \
Expand All @@ -68,6 +67,4 @@ def self.parse_auth_param_list auth_param_string
accu << [name, value]
end)
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength
end
30 changes: 10 additions & 20 deletions lib/signet/oauth_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def self.generate_timestamp
#
# @return [String] A random nonce.
def self.generate_nonce
SecureRandom.random_bytes(16).unpack("H*").join ""
SecureRandom.random_bytes(16).unpack("H*").join
end
# rubocop:disable Metrics/MethodLength

##
# Processes an options <code>Hash</code> to find a credential key value.
Expand All @@ -65,7 +64,7 @@ def self.generate_nonce
# @return [String] The credential key value.
def self.extract_credential_key_option credential_type, options
# Normalize key to String to allow indifferent access.
options = options.each_with_object({}) { |(k, v), accu| accu[k.to_s] = v; }
options = options.to_h.transform_keys(&:to_s)
credential_key = "#{credential_type}_credential_key"
credential = "#{credential_type}_credential"
if options[credential_key]
Expand Down Expand Up @@ -107,7 +106,7 @@ def self.extract_credential_key_option credential_type, options
# @return [String] The credential secret value.
def self.extract_credential_secret_option credential_type, options
# Normalize key to String to allow indifferent access.
options = options.each_with_object({}) { |(k, v), accu| accu[k.to_s] = v; }
options = options.to_h.transform_keys(&:to_s)
credential_secret = "#{credential_type}_credential_secret"
credential = "#{credential_type}_credential"
if options[credential_secret]
Expand Down Expand Up @@ -136,7 +135,6 @@ def self.extract_credential_secret_option credential_type, options
end
credential_secret
end
# rubocop:enable Metrics/MethodLength

##
# Normalizes a set of OAuth parameters according to the algorithm given
Expand Down Expand Up @@ -214,7 +212,7 @@ def self.generate_authorization_header parameters, realm = nil
realm = realm.gsub '"', '\"'
parameter_list.unshift "realm=\"#{realm}\""
end
"OAuth " + parameter_list.join(", ")
"OAuth #{parameter_list.join ', '}"
end

##
Expand All @@ -228,7 +226,7 @@ def self.parse_authorization_header field_value
when /^OAuth$/i
# Other token types may be supported eventually
pairs = Signet.parse_auth_param_list(field_value[/^OAuth\s+(.*)$/i, 1])
return (pairs.each_with_object [] do |(k, v), accu|
(pairs.each_with_object [] do |(k, v), accu|
if k != "realm"
k = unencode k
v = unencode v
Expand Down Expand Up @@ -274,24 +272,18 @@ def self.sign_parameters method, uri, parameters,
# be a temporary credential secret when obtaining a token credential
# for the first time
base_string = generate_base_string method, uri, parameters
parameters = parameters.each_with_object({}) { |(k, v), h| h[k.to_s] = v; }
parameters = parameters.to_h.transform_keys(&:to_s)
signature_method = parameters["oauth_signature_method"]
case signature_method
when "HMAC-SHA1"
require "signet/oauth_1/signature_methods/hmac_sha1"
return Signet::OAuth1::HMACSHA1.generate_signature(
base_string, client_credential_secret, token_credential_secret
)
Signet::OAuth1::HMACSHA1.generate_signature base_string, client_credential_secret, token_credential_secret
when "RSA-SHA1"
require "signet/oauth_1/signature_methods/rsa_sha1"
return Signet::OAuth1::RSASHA1.generate_signature(
base_string, client_credential_secret, token_credential_secret
)
Signet::OAuth1::RSASHA1.generate_signature base_string, client_credential_secret, token_credential_secret
when "PLAINTEXT"
require "signet/oauth_1/signature_methods/plaintext"
return Signet::OAuth1::PLAINTEXT.generate_signature(
base_string, client_credential_secret, token_credential_secret
)
Signet::OAuth1::PLAINTEXT.generate_signature base_string, client_credential_secret, token_credential_secret
else
raise NotImplementedError,
"Unsupported signature method: #{signature_method}"
Expand Down Expand Up @@ -396,7 +388,7 @@ def self.unsigned_token_credential_parameters options = {}
raise ArgumentError, "Missing :client_credential_key parameter." if client_credential_key.nil?
raise ArgumentError, "Missing :temporary_credential_key parameter." if temporary_credential_key.nil?
raise ArgumentError, "Missing :verifier parameter." if options[:verifier].nil?
parameters = [
[
["oauth_consumer_key", client_credential_key],
["oauth_token", temporary_credential_key],
["oauth_signature_method", options[:signature_method]],
Expand All @@ -405,8 +397,6 @@ def self.unsigned_token_credential_parameters options = {}
["oauth_verifier", options[:verifier]],
["oauth_version", "1.0"]
]
# No additional parameters allowed here
parameters
end

##
Expand Down
Loading