Skip to content

Commit fda4f90

Browse files
authored
🔀 Merge pull request #226 from oauth-xx/issue/225-backports-to-v0.5
Backports to v0.5
2 parents b0de10a + 8270595 commit fda4f90

14 files changed

+541
-643
lines changed

.rubocop_todo.yml

Lines changed: 44 additions & 186 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ Or install it yourself as:
4141

4242
Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.6, 2.7, and
4343
3.0. Ruby is limited to 2.0+ in the gemspec, and this may change while the gem is
44-
still at version 0.x.
44+
still at version 0.x. The `master` branch currently targets 0.6.x releases.
45+
46+
| Ruby OAuth Version | Officially Supported Rubies | Unofficially Supported Rubies |
47+
|--------------------- | ------------------------------------------- | ----------------------------- |
48+
| 0.7.x (hypothetical) | 2.7, 3.0, 3.1 | 2.6 |
49+
| 0.6.x | 2.6, 2.7, 3.0 | 2.3, 2.4, 2.5 |
50+
| 0.5.x | 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0 | |
51+
52+
NOTE: 0.5.7 is anticipated as last release of the 0.5.x series.
4553

4654
## Basics
4755

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1+
# frozen_string_literal: true
2+
13
require "active_support"
24
require "active_support/version"
35
require "action_controller"
46
require "uri"
57

6-
if
7-
Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
8-
then # rails 2.x
8+
if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
9+
# rails 2.x
910
require "action_controller/request"
1011
unless ActionController::Request::HTTP_METHODS.include?("patch")
1112
ActionController::Request::HTTP_METHODS << "patch"
1213
ActionController::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch
1314
ActionController::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
1415
end
1516

16-
elsif
17-
Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
18-
then # rails 3.x
17+
elsif Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
18+
# rails 3.x
1919
require "action_dispatch/http/request"
2020
unless ActionDispatch::Request::HTTP_METHODS.include?("patch")
2121
ActionDispatch::Request::HTTP_METHODS << "patch"
@@ -27,64 +27,63 @@
2727
require "action_dispatch/http/request"
2828
end
2929

30-
module OAuth::RequestProxy
31-
class ActionControllerRequest < OAuth::RequestProxy::Base
32-
proxies(defined?(ActionDispatch::AbstractRequest) ? ActionDispatch::AbstractRequest : ActionDispatch::Request)
30+
module OAuth
31+
module RequestProxy
32+
class ActionControllerRequest < OAuth::RequestProxy::Base
33+
proxies(defined?(::ActionDispatch::AbstractRequest) ? ::ActionDispatch::AbstractRequest : ::ActionDispatch::Request)
3334

34-
def method
35-
request.method.to_s.upcase
36-
end
35+
def method
36+
request.method.to_s.upcase
37+
end
3738

38-
def uri
39-
request.url
40-
end
39+
def uri
40+
request.url
41+
end
4142

42-
def parameters
43-
if options[:clobber_request]
44-
options[:parameters] || {}
45-
else
46-
params = request_params.merge(query_params).merge(header_params)
47-
params.stringify_keys! if params.respond_to?(:stringify_keys!)
48-
params.merge(options[:parameters] || {})
43+
def parameters
44+
if options[:clobber_request]
45+
options[:parameters] || {}
46+
else
47+
params = request_params.merge(query_params).merge(header_params)
48+
params.stringify_keys! if params.respond_to?(:stringify_keys!)
49+
params.merge(options[:parameters] || {})
50+
end
4951
end
50-
end
5152

52-
# Override from OAuth::RequestProxy::Base to avoid roundtrip
53-
# conversion to Hash or Array and thus preserve the original
54-
# parameter names
55-
def parameters_for_signature
56-
params = []
57-
params << options[:parameters].to_query if options[:parameters]
53+
# Override from OAuth::RequestProxy::Base to avoid roundtrip
54+
# conversion to Hash or Array and thus preserve the original
55+
# parameter names
56+
def parameters_for_signature
57+
params = []
58+
params << options[:parameters].to_query if options[:parameters]
5859

59-
unless options[:clobber_request]
60-
params << header_params.to_query
61-
params << request.query_string unless query_string_blank?
60+
unless options[:clobber_request]
61+
params << header_params.to_query
62+
params << request.query_string unless query_string_blank?
6263

63-
if raw_post_signature?
64-
params << request.raw_post
64+
params << request.raw_post if raw_post_signature?
6565
end
66-
end
6766

68-
params.
69-
join("&").split("&").
70-
reject { |s| s.match(/\A\s*\z/) }.
71-
map { |p| p.split("=").map{|esc| CGI.unescape(esc)} }.
72-
reject { |kv| kv[0] == "oauth_signature"}
73-
end
67+
params.
68+
join("&").split("&").
69+
reject { |s| s.match(/\A\s*\z/) }.
70+
map { |p| p.split("=").map { |esc| CGI.unescape(esc) } }.
71+
reject { |kv| kv[0] == "oauth_signature" }
72+
end
7473

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

79-
protected
78+
protected
8079

81-
def query_params
82-
request.query_parameters
83-
end
80+
def query_params
81+
request.query_parameters
82+
end
8483

85-
def request_params
86-
request.request_parameters
84+
def request_params
85+
request.request_parameters
86+
end
8787
end
88-
8988
end
9089
end
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
# frozen_string_literal: true
2+
13
require "oauth/request_proxy/rack_request"
24

3-
module OAuth::RequestProxy
4-
class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
5-
proxies ActionDispatch::Request
5+
module OAuth
6+
module RequestProxy
7+
class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
8+
proxies ::ActionDispatch::Request
9+
end
610
end
711
end

0 commit comments

Comments
 (0)