Skip to content

Commit

Permalink
🔀 Merge pull request #226 from oauth-xx/issue/225-backports-to-v0.5
Browse files Browse the repository at this point in the history
Backports to v0.5
  • Loading branch information
pboling committed Nov 2, 2021
2 parents b0de10a + 8270595 commit fda4f90
Show file tree
Hide file tree
Showing 14 changed files with 541 additions and 643 deletions.
230 changes: 44 additions & 186 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -41,7 +41,15 @@ Or install it yourself as:

Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.6, 2.7, and
3.0. Ruby is limited to 2.0+ in the gemspec, and this may change while the gem is
still at version 0.x.
still at version 0.x. The `master` branch currently targets 0.6.x releases.

| Ruby OAuth Version | Officially Supported Rubies | Unofficially Supported Rubies |
|--------------------- | ------------------------------------------- | ----------------------------- |
| 0.7.x (hypothetical) | 2.7, 3.0, 3.1 | 2.6 |
| 0.6.x | 2.6, 2.7, 3.0 | 2.3, 2.4, 2.5 |
| 0.5.x | 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0 | |

NOTE: 0.5.7 is anticipated as last release of the 0.5.x series.

## Basics

Expand Down
101 changes: 50 additions & 51 deletions lib/oauth/request_proxy/action_controller_request.rb
@@ -1,21 +1,21 @@
# frozen_string_literal: true

require "active_support"
require "active_support/version"
require "action_controller"
require "uri"

if
Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
then # rails 2.x
if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
# rails 2.x
require "action_controller/request"
unless ActionController::Request::HTTP_METHODS.include?("patch")
ActionController::Request::HTTP_METHODS << "patch"
ActionController::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch
ActionController::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
end

elsif
Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
then # rails 3.x
elsif Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
# rails 3.x
require "action_dispatch/http/request"
unless ActionDispatch::Request::HTTP_METHODS.include?("patch")
ActionDispatch::Request::HTTP_METHODS << "patch"
Expand All @@ -27,64 +27,63 @@
require "action_dispatch/http/request"
end

module OAuth::RequestProxy
class ActionControllerRequest < OAuth::RequestProxy::Base
proxies(defined?(ActionDispatch::AbstractRequest) ? ActionDispatch::AbstractRequest : ActionDispatch::Request)
module OAuth
module RequestProxy
class ActionControllerRequest < OAuth::RequestProxy::Base
proxies(defined?(::ActionDispatch::AbstractRequest) ? ::ActionDispatch::AbstractRequest : ::ActionDispatch::Request)

def method
request.method.to_s.upcase
end
def method
request.method.to_s.upcase
end

def uri
request.url
end
def uri
request.url
end

def parameters
if options[:clobber_request]
options[:parameters] || {}
else
params = request_params.merge(query_params).merge(header_params)
params.stringify_keys! if params.respond_to?(:stringify_keys!)
params.merge(options[:parameters] || {})
def parameters
if options[:clobber_request]
options[:parameters] || {}
else
params = request_params.merge(query_params).merge(header_params)
params.stringify_keys! if params.respond_to?(:stringify_keys!)
params.merge(options[:parameters] || {})
end
end
end

# Override from OAuth::RequestProxy::Base to avoid roundtrip
# conversion to Hash or Array and thus preserve the original
# parameter names
def parameters_for_signature
params = []
params << options[:parameters].to_query if options[:parameters]
# Override from OAuth::RequestProxy::Base to avoid roundtrip
# conversion to Hash or Array and thus preserve the original
# parameter names
def parameters_for_signature
params = []
params << options[:parameters].to_query if options[:parameters]

unless options[:clobber_request]
params << header_params.to_query
params << request.query_string unless query_string_blank?
unless options[:clobber_request]
params << header_params.to_query
params << request.query_string unless query_string_blank?

if raw_post_signature?
params << request.raw_post
params << request.raw_post if raw_post_signature?
end
end

params.
join("&").split("&").
reject { |s| s.match(/\A\s*\z/) }.
map { |p| p.split("=").map{|esc| CGI.unescape(esc)} }.
reject { |kv| kv[0] == "oauth_signature"}
end
params.
join("&").split("&").
reject { |s| s.match(/\A\s*\z/) }.
map { |p| p.split("=").map { |esc| CGI.unescape(esc) } }.
reject { |kv| kv[0] == "oauth_signature" }
end

def raw_post_signature?
(request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
end
def raw_post_signature?
(request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
end

protected
protected

def query_params
request.query_parameters
end
def query_params
request.query_parameters
end

def request_params
request.request_parameters
def request_params
request.request_parameters
end
end

end
end
10 changes: 7 additions & 3 deletions lib/oauth/request_proxy/action_dispatch_request.rb
@@ -1,7 +1,11 @@
# frozen_string_literal: true

require "oauth/request_proxy/rack_request"

module OAuth::RequestProxy
class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
proxies ActionDispatch::Request
module OAuth
module RequestProxy
class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
proxies ::ActionDispatch::Request
end
end
end

0 comments on commit fda4f90

Please sign in to comment.