diff --git a/.rubocop.yml b/.rubocop.yml index d7a5da66..1206d111 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,6 @@ inherit_gem: rubocop-lts: rubocop-lts.yml require: - - 'rubocop-faker' - 'rubocop-md' - 'rubocop-minitest' - 'rubocop-packaging' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1caba68b..06969419 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2022-08-23 11:43:55 UTC using RuboCop version 1.30.1. +# on 2022-08-23 21:37:33 UTC using RuboCop version 1.30.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -18,12 +18,12 @@ Lint/UnderscorePrefixedVariableName: Exclude: - 'lib/oauth/consumer.rb' -# Offense count: 47 +# Offense count: 38 # Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: Max: 62 -# Offense count: 9 +# Offense count: 8 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: Max: 302 @@ -33,7 +33,7 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 18 -# Offense count: 75 +# Offense count: 66 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. Metrics/MethodLength: Max: 43 @@ -52,19 +52,6 @@ Metrics/PerceivedComplexity: Minitest/MultipleAssertions: Max: 18 -# Offense count: 2 -Naming/AccessorMethodName: - Exclude: - - 'lib/oauth/cli/authorize_command.rb' - -# Offense count: 2 -# Configuration parameters: ForbiddenDelimiters. -# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) -Naming/HeredocDelimiterNaming: - Exclude: - - 'lib/oauth/cli/help_command.rb' - - 'lib/oauth/cli/sign_command.rb' - # Offense count: 1 # Configuration parameters: EnforcedStyleForLeadingUnderscores. # SupportedStylesForLeadingUnderscores: disallowed, required, optional @@ -72,27 +59,21 @@ Naming/MemoizedInstanceVariableName: Exclude: - 'lib/oauth/client/em_http.rb' -# Offense count: 1 -Security/Open: - Exclude: - - 'lib/oauth/cli/base_command.rb' - # Offense count: 2 Style/ClassVars: Exclude: - 'lib/oauth/consumer.rb' - 'lib/oauth/server.rb' -# Offense count: 67 +# Offense count: 60 # Configuration parameters: AllowedConstants. Style/Documentation: Enabled: false -# Offense count: 3 +# Offense count: 2 # Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. Style/GuardClause: Exclude: - - 'lib/oauth/cli/sign_command.rb' - 'lib/oauth/consumer.rb' - 'lib/oauth/signature/base.rb' @@ -103,7 +84,7 @@ Style/IfUnlessModifier: - 'bin/bundle' - 'lib/oauth/request_proxy/net_http.rb' -# Offense count: 1 +# Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: InverseMethods, InverseBlocks. Style/InverseMethods: @@ -123,11 +104,11 @@ ThreadSafety/InstanceVariableInClassMethod: - 'lib/oauth/signature.rb' - 'lib/oauth/signature/base.rb' -# Offense count: 77 +# Offense count: 76 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns. # URISchemes: http, https -# AllowedPatterns: (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#) +# AllowedPatterns: (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#) # IgnoredPatterns: (?-mix:^\#) Layout/LineLength: Max: 429 diff --git a/.simplecov b/.simplecov index 68a3acb2..c912b856 100644 --- a/.simplecov +++ b/.simplecov @@ -26,7 +26,7 @@ if RUN_COVERAGE formatter SimpleCov::Formatter::HTMLFormatter end - minimum_coverage(66) + minimum_coverage(65) end else puts "Not running coverage on #{RUBY_ENGINE} #{RUBY_VERSION}" diff --git a/CHANGELOG.md b/CHANGELOG.md index 006af424..275bb956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed +## [1.1.0] 2022-08-26 +### 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. + ## [1.0.0] 2022-08-23 ### Changed * Dropped support for Ruby < 2.7 @@ -440,7 +447,8 @@ but please have a look at the unit tests. * Moved all non-Rails functionality from the Rails plugin: http://code.google.com/p/oauth-plugin/ -[Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v1.0.0...main +[Unreleased]: https://github.com/oauth-xx/oauth-ruby/compare/v1.1.0...main +[1.1.0]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v1.1.0 [1.0.0]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v1.0.0 [0.6.1]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.6.1 [0.6.0]: https://github.com/oauth-xx/oauth-ruby/releases/tag/v0.6.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d0ba48f5..51310057 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,6 +8,23 @@ To submit a patch, please fork the project and create a patch with tests. Once you're happy with it send a pull request and post a message to the [google group][mailinglist]. +## Run tests + +### Against Rails 6 + +```bash +BUNDLE_GEMFILE=gemfiles/a6.gemfile bundle install +BUNDLE_GEMFILE=gemfiles/a6.gemfile bundle exec rake +``` + + +### Against Rails 7 + +```bash +BUNDLE_GEMFILE=gemfiles/a7.gemfile bundle install +BUNDLE_GEMFILE=gemfiles/a7.gemfile bundle exec rake +``` + ## Contributors [![Contributors](https://contrib.rocks/image?repo=oauth-xx/oauth-ruby)][contributors] diff --git a/Gemfile b/Gemfile index aaf494c6..5ec08f48 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,6 @@ gem "pry", platforms: %i[mri] platforms :mri do gem "codecov", "~> 0.6" # For CodeCov gem "overcommit", "~> 0.58" - gem "rubocop-faker" gem "rubocop-md" gem "rubocop-minitest" gem "rubocop-packaging" @@ -27,8 +26,8 @@ platforms :mri do # Add `byebug` to your code where you want to drop to REPL, and add DEBUG=true when running tests gem "byebug" - # WebMock is known to work with Curb >= 0.7.16, < 0.10, except versions 0.8.7 - gem "curb", [">= 0.7.16", "< 0.10", "!= 0.8.7"] if curb + # WebMock is known to work with Curb >= 0.7.16, < 1.1, except versions 0.8.7 + gem "curb", [">= 0.7.16", "< 1.1", "!= 0.8.7"] if curb gem "pry-byebug" end diff --git a/README.md b/README.md index 342e8701..06281bb0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ See the sibling `oauth2` gem for OAuth 2.0 implementations in Ruby. **New EOL Policy** -Versions 1.0.x will be EOL no later than April, 2025. +Versions 1.x will be EOL no later than April, 2025. Versions 0.6.x will be EOL no later than April, 2024. Versions 0.5.x will be EOL no later than April, 2023. @@ -30,7 +30,7 @@ This will facilitate dropping support for old, dead, and crusty versions of Ruby Non-commercial support for the oldest version of Ruby (which itself is going EOL) will be dropped each year in April. -Please upgrade to version 1.0. The only breaking change in 1.0 is dropping old Rubies. +Please upgrade to version 1.1. The only breaking change in 1.x is dropping old Rubies. ## Status @@ -191,7 +191,7 @@ Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.7, 3.0, and 3.1. Ruby is limited to 2.7+ in the gemspec, and this will change with minor version bumps, while the gem is still in 0.x, in accordance with the SemVer spec. -The `main` branch now targets 1.0.x releases, for Ruby >= 2.7. +The `main` branch now targets 1.x releases, for Ruby >= 2.7. See `v0.6-maintenance` (EOL April, 2024) branch for Ruby >= 2.4. See `v0.5-maintenance` (EOL April, 2023) branch for Ruby >= 2.0. @@ -248,7 +248,11 @@ gem. After extraction that gem was made to depend on this gem. Unfortunately, this gem does have some Rails related bits that are **optional** to load. You don't need Rails! The Rails bits may be pulled out -into a separate gem with the release of version 1.0 of this gem. +into a separate gem with the 1.x minor updates of this gem. + +## Extensions + +* [oauth-tty (on Gitlab)](https://gitlab.com/oauth-xx/oauth-tty) ([rubygems.org](https://rubygems.org/gems/oauth-tty)) ## Usage @@ -335,7 +339,7 @@ the [Pessimistic Version Constraint][pvc] with two digits of precision. For example: ```ruby -spec.add_dependency "oauth", "~> 1.0" +spec.add_dependency "oauth", "~> 1.1" ``` ## License diff --git a/SECURITY.md b/SECURITY.md index 142fd110..1c881029 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,6 +4,7 @@ | Version | Supported | EOL | |---------|--------------------|---------| +| 1.1.x | :white_check_mark: | 04/2025 | | 1.0.x | :white_check_mark: | 04/2025 | | 0.6.x | :white_check_mark: | 04/2024 | | 0.5.x | :white_check_mark: | 04/2023 | diff --git a/bin/oauth b/bin/oauth deleted file mode 100755 index fa3f72fa..00000000 --- a/bin/oauth +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -require "oauth" -require "oauth/cli" - -# don't dump a backtrace on a ^C -Signal.trap("INT") do - puts - exit(1) -end -ARGV << "help" if ARGV.empty? -command = ARGV.shift - -OAuth::CLI.new($stdout, $stdin, $stderr, command, ARGV).run diff --git a/lib/oauth/cli.rb b/lib/oauth/cli.rb deleted file mode 100644 index 06e0cfc8..00000000 --- a/lib/oauth/cli.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -require "optparse" -require "oauth/cli/base_command" -require "oauth/cli/help_command" -require "oauth/cli/query_command" -require "oauth/cli/authorize_command" -require "oauth/cli/sign_command" -require "oauth/cli/version_command" -require "active_support/core_ext/string/inflections" - -module OAuth - class CLI - def self.puts_red(string) - puts "\033[0;91m#{string}\033[0m" - end - - ALIASES = { - "h" => "help", - "v" => "version", - "q" => "query", - "a" => "authorize", - "s" => "sign" - }.freeze - - def initialize(stdout, stdin, stderr, command, arguments) - klass = get_command_class(parse_command(command)) - @command = klass.new(stdout, stdin, stderr, arguments) - @help_command = HelpCommand.new(stdout, stdin, stderr, []) - end - - def run - @command.run - end - - private - - def get_command_class(command) - Object.const_get("OAuth::CLI::#{command.camelize}Command") - end - - def parse_command(command) - case command = command.to_s.downcase - when "--version", "-v" - "version" - when "--help", "-h", nil, "" - "help" - when *ALIASES.keys - ALIASES[command] - when *ALIASES.values - command - else - OAuth::CLI.puts_red "Command '#{command}' not found" - "help" - end - end - end -end diff --git a/lib/oauth/cli/authorize_command.rb b/lib/oauth/cli/authorize_command.rb deleted file mode 100644 index 2f2fcff9..00000000 --- a/lib/oauth/cli/authorize_command.rb +++ /dev/null @@ -1,73 +0,0 @@ -# frozen_string_literal: true - -module OAuth - class CLI - class AuthorizeCommand < BaseCommand - def required_options - [:uri] - end - - def _run - request_token = get_request_token - - if request_token.callback_confirmed? - puts "Server appears to support OAuth 1.0a; enabling support." - options[:version] = "1.0a" - end - - puts "Please visit this url to authorize:" - puts request_token.authorize_url - - # parameters for OAuth 1.0a - oauth_verifier = ask_user_for_verifier - - verbosely_get_access_token(request_token, oauth_verifier) - end - - def get_request_token - consumer = get_consumer - scope_options = options[:scope] ? { "scope" => options[:scope] } : {} - consumer.get_request_token({ oauth_callback: options[:oauth_callback] }, scope_options) - rescue OAuth::Unauthorized => e - alert "A problem occurred while attempting to authorize:" - alert e - alert e.request.body - end - - def get_consumer - OAuth::Consumer.new \ - options[:oauth_consumer_key], - options[:oauth_consumer_secret], - access_token_url: options[:access_token_url], - authorize_url: options[:authorize_url], - request_token_url: options[:request_token_url], - scheme: options[:scheme], - http_method: options[:method].to_s.downcase.to_sym - end - - def ask_user_for_verifier - if options[:version] == "1.0a" - puts "Please enter the verification code provided by the SP (oauth_verifier):" - @stdin.gets.chomp - else - puts "Press return to continue..." - @stdin.gets - nil - end - end - - def verbosely_get_access_token(request_token, oauth_verifier) - access_token = request_token.get_access_token(oauth_verifier: oauth_verifier) - - puts "Response:" - access_token.params.each do |k, v| - puts " #{k}: #{v}" unless k.is_a?(Symbol) - end - rescue OAuth::Unauthorized => e - alert "A problem occurred while attempting to obtain an access token:" - alert e - alert e.request.body - end - end - end -end diff --git a/lib/oauth/cli/base_command.rb b/lib/oauth/cli/base_command.rb deleted file mode 100644 index 80106447..00000000 --- a/lib/oauth/cli/base_command.rb +++ /dev/null @@ -1,214 +0,0 @@ -# frozen_string_literal: true - -module OAuth - class CLI - class BaseCommand - def initialize(stdout, stdin, stderr, arguments) - @stdout = stdout - @stdin = stdin - @stderr = stderr - - @options = {} - option_parser.parse!(arguments) - end - - def run - missing = required_options - options.keys - if missing.empty? - _run - else - show_missing(missing) - puts option_parser.help - end - end - - def required_options - [] - end - - protected - - attr_reader :options - - def show_missing(array) - array = array.map { |s| "--#{s}" }.join(" ") - OAuth::CLI.puts_red "Options missing to OAuth CLI: #{array}" - end - - def xmpp? - options[:xmpp] - end - - def verbose? - options[:verbose] - end - - def puts(string = nil) - @stdout.puts(string) - end - - def alert(string = nil) - @stderr.puts(string) - end - - def parameters - @parameters ||= begin - escaped_pairs = options[:params].collect do |pair| - if /:/.match?(pair) - Hash[*pair.split(":", 2)].collect do |k, v| - [CGI.escape(k.strip), CGI.escape(v.strip)].join("=") - end - else - pair - end - end - - querystring = escaped_pairs * "&" - cli_params = CGI.parse(querystring) - - { - "oauth_consumer_key" => options[:oauth_consumer_key], - "oauth_nonce" => options[:oauth_nonce], - "oauth_timestamp" => options[:oauth_timestamp], - "oauth_token" => options[:oauth_token], - "oauth_signature_method" => options[:oauth_signature_method], - "oauth_version" => options[:oauth_version] - }.reject { |_k, v| v.nil? || v == "" }.merge(cli_params) - end - end - - def option_parser - @option_parser ||= OptionParser.new do |opts| - opts.banner = "Usage: oauth [ARGS]" - - _option_parser_defaults - _option_parser_common(opts) - _option_parser_sign_and_query(opts) - _option_parser_authorization(opts) - end - end - - def _option_parser_defaults - options[:oauth_nonce] = OAuth::Helper.generate_key - options[:oauth_signature_method] = "HMAC-SHA1" - options[:oauth_timestamp] = OAuth::Helper.generate_timestamp - options[:oauth_version] = "1.0" - options[:method] = :post - options[:params] = [] - options[:scheme] = :header - options[:version] = "1.0" - end - - def _option_parser_common(opts) - ## Common Options - - opts.on("-B", "--body", "Use the request body for OAuth parameters.") do - options[:scheme] = :body - end - - opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v| - options[:oauth_consumer_key] = v - end - - opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v| - options[:oauth_consumer_secret] = v - end - - opts.on("-H", "--header", "Use the 'Authorization' header for OAuth parameters (default).") do - options[:scheme] = :header - end - - opts.on("-Q", "--query-string", "Use the query string for OAuth parameters.") do - options[:scheme] = :query_string - end - - opts.on("-O", "--options FILE", "Read options from a file") do |v| - arguments = open(v).readlines.map { |l| l.chomp.split }.flatten - options2 = parse_options(arguments) - options.merge!(options2) - end - end - - def _option_parser_sign_and_query(opts) - opts.separator("\n options for signing and querying") - - opts.on("--method METHOD", "Specifies the method (e.g. GET) to use when signing.") do |v| - options[:method] = v - end - - opts.on("--nonce NONCE", "Specifies the nonce to use.") do |v| - options[:oauth_nonce] = v - end - - opts.on("--parameters PARAMS", "Specifies the parameters to use when signing.") do |v| - options[:params] << v - end - - opts.on("--signature-method METHOD", "Specifies the signature method to use; defaults to HMAC-SHA1.") do |v| - options[:oauth_signature_method] = v - end - - opts.on("--token TOKEN", "Specifies the token to use.") do |v| - options[:oauth_token] = v - end - - opts.on("--secret SECRET", "Specifies the token secret to use.") do |v| - options[:oauth_token_secret] = v - end - - opts.on("--timestamp TIMESTAMP", "Specifies the timestamp to use.") do |v| - options[:oauth_timestamp] = v - end - - opts.on("--realm REALM", "Specifies the realm to use.") do |v| - options[:realm] = v - end - - opts.on("--uri URI", "Specifies the URI to use when signing.") do |v| - options[:uri] = v - end - - opts.on("--version [VERSION]", "Specifies the OAuth version to use.") do |v| - options[:oauth_version] = v - end - - opts.on("--no-version", "Omit oauth_version.") do - options[:oauth_version] = nil - end - - opts.on("--xmpp", "Generate XMPP stanzas.") do - options[:xmpp] = true - options[:method] ||= "iq" - end - - opts.on("-v", "--verbose", "Be verbose.") do - options[:verbose] = true - end - end - - def _option_parser_authorization(opts) - opts.separator("\n options for authorization") - - opts.on("--access-token-url URL", "Specifies the access token URL.") do |v| - options[:access_token_url] = v - end - - opts.on("--authorize-url URL", "Specifies the authorization URL.") do |v| - options[:authorize_url] = v - end - - opts.on("--callback-url URL", "Specifies a callback URL.") do |v| - options[:oauth_callback] = v - end - - opts.on("--request-token-url URL", "Specifies the request token URL.") do |v| - options[:request_token_url] = v - end - - opts.on("--scope SCOPE", "Specifies the scope (Google-specific).") do |v| - options[:scope] = v - end - end - end - end -end diff --git a/lib/oauth/cli/help_command.rb b/lib/oauth/cli/help_command.rb deleted file mode 100644 index 54ce7cbd..00000000 --- a/lib/oauth/cli/help_command.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -module OAuth - class CLI - class HelpCommand < BaseCommand - def run - puts <<-EOT - Usage: oauth COMMAND [ARGS] - - Available oauth commands are: - a, authorize Obtain an access token and secret for a user - q, query Query a protected resource - s, sign Generate an OAuth signature - - In addition to those, there are: - v, version Displays the current version of the library (or --version, -v) - h, help Displays this help (or --help, -h) - - Tip: All commands can be run without args for specific help. - - - EOT - end - end - end -end diff --git a/lib/oauth/cli/query_command.rb b/lib/oauth/cli/query_command.rb deleted file mode 100644 index edff851c..00000000 --- a/lib/oauth/cli/query_command.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -module OAuth - class CLI - class QueryCommand < BaseCommand - extend OAuth::Helper - - def required_options - %i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret] - end - - def _run - consumer = OAuth::Consumer.new(options[:oauth_consumer_key], options[:oauth_consumer_secret], - scheme: options[:scheme]) - - access_token = OAuth::AccessToken.new(consumer, options[:oauth_token], options[:oauth_token_secret]) - - # append params to the URL - uri = URI.parse(options[:uri]) - params = parameters.map do |k, v| - Array(v).map do |v2| - "#{OAuth::Helper.escape(k)}=#{OAuth::Helper.escape(v2)}" - end * "&" - end - uri.query = [uri.query, *params].compact * "&" - puts uri.to_s - - response = access_token.request(options[:method].to_s.downcase.to_sym, uri.to_s) - puts "#{response.code} #{response.message}" - puts response.body - end - end - end -end diff --git a/lib/oauth/cli/sign_command.rb b/lib/oauth/cli/sign_command.rb deleted file mode 100644 index a773da1a..00000000 --- a/lib/oauth/cli/sign_command.rb +++ /dev/null @@ -1,82 +0,0 @@ -# frozen_string_literal: true - -module OAuth - class CLI - class SignCommand < BaseCommand - def required_options - %i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret] - end - - def _run - request = OAuth::RequestProxy.proxy \ - "method" => options[:method], - "uri" => options[:uri], - "parameters" => parameters - - puts_verbose_parameters(request) if verbose? - - request.sign! \ - consumer_secret: options[:oauth_consumer_secret], - token_secret: options[:oauth_token_secret] - - if verbose? - puts_verbose_request(request) - else - puts request.oauth_signature - end - end - - def puts_verbose_parameters(request) - puts "OAuth parameters:" - request.oauth_parameters.each do |k, v| - puts " #{[k, v].join(": ")}" - end - puts - - if request.non_oauth_parameters.any? - puts "Parameters:" - request.non_oauth_parameters.each do |k, v| - puts " #{[k, v].join(": ")}" - end - puts - end - end - - def puts_verbose_request(request) - puts "Method: #{request.method}" - puts "URI: #{request.uri}" - puts "Normalized params: #{request.normalized_parameters}" unless options[:xmpp] - puts "Signature base string: #{request.signature_base_string}" - - if xmpp? - puts - puts "XMPP Stanza:" - puts xmpp_output(request) - puts - puts "Note: You may want to use bare JIDs in your URI." - puts - else - puts "OAuth Request URI: #{request.signed_uri}" - puts "Request URI: #{request.signed_uri(with_oauth: false)}" - puts "Authorization header: #{request.oauth_header(realm: options[:realm])}" - end - puts "Signature: #{request.oauth_signature}" - puts "Escaped signature: #{OAuth::Helper.escape(request.oauth_signature)}" - end - - def xmpp_output(request) - <<-EOS - - #{request.oauth_consumer_key} - #{request.oauth_token} - #{request.oauth_signature_method} - #{request.oauth_signature} - #{request.oauth_timestamp} - #{request.oauth_nonce} - #{request.oauth_version} - - EOS - end - end - end -end diff --git a/lib/oauth/cli/version_command.rb b/lib/oauth/cli/version_command.rb deleted file mode 100644 index f297d003..00000000 --- a/lib/oauth/cli/version_command.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module OAuth - class CLI - class VersionCommand < BaseCommand - def run - puts "OAuth Gem #{OAuth::Version::VERSION}" - end - end - end -end diff --git a/lib/oauth/request_proxy/base.rb b/lib/oauth/request_proxy/base.rb index 9723c67b..e175b461 100644 --- a/lib/oauth/request_proxy/base.rb +++ b/lib/oauth/request_proxy/base.rb @@ -79,7 +79,7 @@ def parameters end def parameters_for_signature - parameters.reject { |k, _v| signature_and_unsigned_parameters.include?(k) } + parameters.select { |k, _v| !signature_and_unsigned_parameters.include?(k) } end def oauth_parameters diff --git a/lib/oauth/version.rb b/lib/oauth/version.rb index f331c7c5..22957622 100644 --- a/lib/oauth/version.rb +++ b/lib/oauth/version.rb @@ -2,6 +2,6 @@ module OAuth module Version - VERSION = "1.0.0" + VERSION = "1.1.0" end end diff --git a/oauth.gemspec b/oauth.gemspec index 073a8b4c..231ac811 100644 --- a/oauth.gemspec +++ b/oauth.gemspec @@ -3,6 +3,10 @@ require_relative "lib/oauth/version" Gem::Specification.new do |spec| + # "oauth-tty" was extracted from this gem with release 1.1 of this gem + # 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("version_gem", "~> 1.1") spec.name = "oauth" @@ -14,7 +18,6 @@ Gem::Specification.new do |spec| spec.email = "oauth-ruby@googlegroups.com" spec.summary = "OAuth Core Ruby implementation" - spec.executables = ["oauth"] spec.homepage = "https://github.com/oauth-xx/oauth-ruby" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "#{spec.homepage}/tree/v#{spec.version}" diff --git a/test/support/minitest_helpers.rb b/test/support/minitest_helpers.rb index 0049734b..1bffdad6 100644 --- a/test/support/minitest_helpers.rb +++ b/test/support/minitest_helpers.rb @@ -26,5 +26,4 @@ def stub_test_ie end end -# TODO: When dropping support to Ruby 2.0, stop using send Minitest::Test.include OAuth::MinitestHelpers diff --git a/test/units/cli_test.rb b/test/units/cli_test.rb index 151a5820..8ab34962 100644 --- a/test/units/cli_test.rb +++ b/test/units/cli_test.rb @@ -69,7 +69,7 @@ def test_help def test_version out = run_command(%w[version]) - assert_equal "OAuth Gem #{OAuth::Version::VERSION}\n", out + assert_match "OAuth Gem #{OAuth::Version::VERSION}\n", out end def test_query_empty