diff --git a/CHANGELOG.md b/CHANGELOG.md index 275bb956..a5fca4d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,12 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed -## [1.1.0] 2022-08-26 +## [1.1.0] 2022-08-29 ### Changed * `OAuth::CLI` has been extracted to a new gem, `oauth-tty`, hosted on [Gitlab](https://gitlab.com/oauth-xx/oauth-tty) * The public API of `oauth-tty` is backwards compatible (meaning `OAuth::CLI`) * The change within the `oauth` gem is backwards compatible as `oauth-tty` has been added as a dependency * Minor version bump is cautionary, as many lines of code have changed. +* `OAuth::Comsumer#options` hash is now handled by `snaky_hash`, which was extracted from `oauth2` + * symbolized keys, dot-access and snake-case are now normalized ## [1.0.0] 2022-08-23 ### Changed diff --git a/lib/oauth.rb b/lib/oauth.rb index 190295d3..de0d4d11 100644 --- a/lib/oauth.rb +++ b/lib/oauth.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # third party gems +require "snaky_hash" require "version_gem" require "oauth/version" diff --git a/lib/oauth/consumer.rb b/lib/oauth/consumer.rb index bbfe6534..11ab1fcb 100644 --- a/lib/oauth/consumer.rb +++ b/lib/oauth/consumer.rb @@ -30,47 +30,49 @@ class Consumer end CA_FILE = nil unless defined?(CA_FILE) - @@default_options = { - # Signature method used by server. Defaults to HMAC-SHA1 - signature_method: "HMAC-SHA1", - - # default paths on site. These are the same as the defaults set up by the generators - request_token_path: "/oauth/request_token", - authenticate_path: "/oauth/authenticate", - authorize_path: "/oauth/authorize", - access_token_path: "/oauth/access_token", - - proxy: nil, - # How do we send the oauth values to the server see - # https://oauth.net/core/1.0/#consumer_req_param for more info - # - # Possible values: - # - # :header - via the Authorize header (Default) ( option 1. in spec) - # :body - url form encoded in body of POST request ( option 2. in spec) - # :query_string - via the query part of the url ( option 3. in spec) - scheme: :header, - - # Default http method used for OAuth Token Requests (defaults to :post) - http_method: :post, - - # Add a custom ca_file for consumer - # :ca_file => '/etc/certs.pem' - - # Possible values: - # - # nil, false - no debug output - # true - uses $stdout - # some_value - uses some_value - debug_output: nil, - - # Defaults to producing a body_hash as part of the signature but - # can be disabled since it's not officially part of the OAuth 1.0 - # spec. Possible values are true and false - body_hash_enabled: true, - - oauth_version: "1.0" - } + @@default_options = SnakyHash::SymbolKeyed.new( + { + # Signature method used by server. Defaults to HMAC-SHA1 + signature_method: "HMAC-SHA1", + + # default paths on site. These are the same as the defaults set up by the generators + request_token_path: "/oauth/request_token", + authenticate_path: "/oauth/authenticate", + authorize_path: "/oauth/authorize", + access_token_path: "/oauth/access_token", + + proxy: nil, + # How do we send the oauth values to the server see + # https://oauth.net/core/1.0/#consumer_req_param for more info + # + # Possible values: + # + # :header - via the Authorize header (Default) ( option 1. in spec) + # :body - url form encoded in body of POST request ( option 2. in spec) + # :query_string - via the query part of the url ( option 3. in spec) + scheme: :header, + + # Default http method used for OAuth Token Requests (defaults to :post) + http_method: :post, + + # Add a custom ca_file for consumer + # :ca_file => '/etc/certs.pem' + + # Possible values: + # + # nil, false - no debug output + # true - uses $stdout + # some_value - uses some_value + debug_output: nil, + + # Defaults to producing a body_hash as part of the signature but + # can be disabled since it's not officially part of the OAuth 1.0 + # spec. Possible values are true and false + body_hash_enabled: true, + + oauth_version: "1.0" + } + ) attr_accessor :options, :key, :secret attr_writer :site, :http @@ -103,7 +105,8 @@ def initialize(consumer_key, consumer_secret, options = {}) @secret = consumer_secret # ensure that keys are symbols - @options = @@default_options.merge(options.transform_keys(&:to_sym)) + snaky_options = SnakyHash::SymbolKeyed.new(options) + @options = @@default_options.merge(snaky_options) end # The default http method diff --git a/oauth.gemspec b/oauth.gemspec index 231ac811..06837ef5 100644 --- a/oauth.gemspec +++ b/oauth.gemspec @@ -7,6 +7,7 @@ Gem::Specification.new do |spec| # It is now a dependency for backward compatibility. # The dependency will be removed with release 2.0, by April 2023. spec.add_dependency("oauth-tty", ["~> 1.0", ">= 1.0.1"]) + spec.add_dependency("snaky_hash", "~> 2.0") spec.add_dependency("version_gem", "~> 1.1") spec.name = "oauth" @@ -36,13 +37,13 @@ Gem::Specification.new do |spec| spec.post_install_message = " You have installed oauth version #{OAuth::Version::VERSION}, congratulations! -Non-commercial support for the 1.0.x series will end in April, 2025. Please make a plan to upgrade to the next version prior to that date. -The only breaking change will be dropped support for Ruby 2.7. +Non-commercial support for the 1.x series will end by April, 2025. Please make a plan to upgrade to the next version prior to that date. +The only breaking change will be dropped support for Ruby 2.7 and any other versions which will also have reached EOL by then. Please see: • https://github.com/oauth-xx/oauth/blob/main/SECURITY.md -Note also that I, and this project, am in the process of leaving Github. +Note also that I am, and this project is, in the process of leaving Github. I wrote about some of the reasons here: • https://dev.to/galtzo/im-leaving-github-50ba