oauth 0.5.7.pre.pre1 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/README.md +13 -1
- data/lib/oauth/request_proxy/action_controller_request.rb +50 -51
- data/lib/oauth/request_proxy/action_dispatch_request.rb +7 -3
- data/lib/oauth/request_proxy/base.rb +134 -130
- data/lib/oauth/request_proxy/curb_request.rb +45 -39
- data/lib/oauth/request_proxy/em_http_request.rb +56 -52
- data/lib/oauth/request_proxy/jabber_request.rb +9 -6
- data/lib/oauth/request_proxy/mock_request.rb +3 -1
- data/lib/oauth/request_proxy/net_http.rb +59 -50
- data/lib/oauth/request_proxy/rack_request.rb +32 -28
- data/lib/oauth/request_proxy/rest_client_request.rb +48 -45
- data/lib/oauth/request_proxy/typhoeus_request.rb +45 -39
- data/lib/oauth/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c08e223971fca8aa5c3d76ed37e5576c61519b505498104d585436088ce6629
|
4
|
+
data.tar.gz: 0ccc2c1e6a5da2173358c5d9ffd7c69d7e54f91a3c67606d8ae523e7d81f36f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69762d403a1e19c3f4f89278e46115b70e86661b8db64916b00cb8cb7297f7c25e2bf84031965856783874306f3b1b57642aa5145fbbf71dcde618ef6470dc16
|
7
|
+
data.tar.gz: 9c4cd4916e04a79f8e969089c817e2d2942705a13159124442587d96ea6e812c92fed6388adc723b12d0f638cad4f947a797b933992a87d14bf82e98cbd204ad
|
data/CHANGELOG.md
CHANGED
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
32
32
|
* Fixed Unsafe String Comparison (#156, #209 by @pboling and @drosseau)
|
33
33
|
* Fixed typos in Gemspec (#204, #203, #208 by @pboling)
|
34
34
|
* Copyright Notice in LICENSE - added correct years (#217, #218 by @pboling)
|
35
|
+
* Fixed request proxy Class constant reference scopes - was missing `::` in many places (#225, #226 by @pboling)
|
35
36
|
|
36
37
|
### Removed
|
37
38
|
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Ruby OAuth
|
2
2
|
|
3
|
+
**NOTE**
|
4
|
+
|
5
|
+
This README, on branch `v0.5-maintenance`, targets 0.5.x series releases. For later releases please see the `msater` branch README.
|
6
|
+
|
3
7
|
## Status
|
4
8
|
|
5
9
|
| Project | Ruby Oauth |
|
@@ -41,7 +45,15 @@ Or install it yourself as:
|
|
41
45
|
|
42
46
|
Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.6, 2.7, and
|
43
47
|
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.
|
48
|
+
still at version 0.x. The `master` branch currently targets 0.6.x releases.
|
49
|
+
|
50
|
+
| Ruby OAuth Version | Maintenance Branch | Officially Supported Rubies | Unofficially Supported Rubies |
|
51
|
+
|--------------------- | ------------------ | ------------------------------------------- | ----------------------------- |
|
52
|
+
| 0.7.x (hypothetical) | N/A | 2.7, 3.0, 3.1 | 2.6 |
|
53
|
+
| 0.6.x | `master` | 2.6, 2.7, 3.0 | 2.3, 2.4, 2.5 |
|
54
|
+
| 0.5.x | `v0.5-maintenance` | 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0 | |
|
55
|
+
|
56
|
+
NOTE: 0.5.7 is anticipated as last release of the 0.5.x series.
|
45
57
|
|
46
58
|
## Basics
|
47
59
|
|
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support"
|
2
4
|
require "active_support/version"
|
3
5
|
require "action_controller"
|
4
6
|
require "uri"
|
5
7
|
|
6
|
-
if
|
7
|
-
|
8
|
-
then # rails 2.x
|
8
|
+
if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
|
9
|
+
# rails 2.x
|
9
10
|
require "action_controller/request"
|
10
11
|
unless ActionController::Request::HTTP_METHODS.include?("patch")
|
11
12
|
ActionController::Request::HTTP_METHODS << "patch"
|
@@ -13,9 +14,8 @@ then # rails 2.x
|
|
13
14
|
ActionController::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
|
14
15
|
end
|
15
16
|
|
16
|
-
elsif
|
17
|
-
|
18
|
-
then # rails 3.x
|
17
|
+
elsif Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
|
18
|
+
# rails 3.x
|
19
19
|
require "action_dispatch/http/request"
|
20
20
|
unless ActionDispatch::Request::HTTP_METHODS.include?("patch")
|
21
21
|
ActionDispatch::Request::HTTP_METHODS << "patch"
|
@@ -27,64 +27,63 @@ else # rails 4.x and later - already has patch
|
|
27
27
|
require "action_dispatch/http/request"
|
28
28
|
end
|
29
29
|
|
30
|
-
module OAuth
|
31
|
-
|
32
|
-
|
30
|
+
module OAuth
|
31
|
+
module RequestProxy
|
32
|
+
class ActionControllerRequest < OAuth::RequestProxy::Base
|
33
|
+
proxies(defined?(::ActionDispatch::AbstractRequest) ? ::ActionDispatch::AbstractRequest : ::ActionDispatch::Request)
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
def method
|
36
|
+
request.method.to_s.upcase
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def uri
|
40
|
+
request.url
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
49
51
|
end
|
50
|
-
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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]
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
unless options[:clobber_request]
|
61
|
+
params << header_params.to_query
|
62
|
+
params << request.query_string unless query_string_blank?
|
62
63
|
|
63
|
-
|
64
|
-
params << request.raw_post
|
64
|
+
params << request.raw_post if raw_post_signature?
|
65
65
|
end
|
66
|
-
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
78
77
|
|
79
|
-
|
78
|
+
protected
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
def query_params
|
81
|
+
request.query_parameters
|
82
|
+
end
|
84
83
|
|
85
|
-
|
86
|
-
|
84
|
+
def request_params
|
85
|
+
request.request_parameters
|
86
|
+
end
|
87
87
|
end
|
88
|
-
|
89
88
|
end
|
90
89
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "oauth/request_proxy/rack_request"
|
2
4
|
|
3
|
-
module OAuth
|
4
|
-
|
5
|
-
|
5
|
+
module OAuth
|
6
|
+
module RequestProxy
|
7
|
+
class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
|
8
|
+
proxies ::ActionDispatch::Request
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,178 +1,182 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "oauth/request_proxy"
|
2
4
|
require "oauth/helper"
|
3
5
|
|
4
|
-
module OAuth
|
5
|
-
|
6
|
-
|
6
|
+
module OAuth
|
7
|
+
module RequestProxy
|
8
|
+
class Base
|
9
|
+
include OAuth::Helper
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
def self.proxies(klass)
|
12
|
+
OAuth::RequestProxy.available_proxies[klass] = self
|
13
|
+
end
|
11
14
|
|
12
|
-
|
15
|
+
attr_accessor :request, :options, :unsigned_parameters
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def initialize(request, options = {})
|
18
|
+
@request = request
|
19
|
+
@unsigned_parameters = (options[:unsigned_parameters] || []).map(&:to_s)
|
20
|
+
@options = options
|
21
|
+
end
|
19
22
|
|
20
|
-
|
23
|
+
## OAuth parameters
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
def oauth_callback
|
26
|
+
parameters["oauth_callback"]
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
def oauth_consumer_key
|
30
|
+
parameters["oauth_consumer_key"]
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
def oauth_nonce
|
34
|
+
parameters["oauth_nonce"]
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
def oauth_signature
|
38
|
+
# TODO: can this be nil?
|
39
|
+
[parameters["oauth_signature"]].flatten.first || ""
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
def oauth_signature_method
|
43
|
+
case parameters["oauth_signature_method"]
|
44
|
+
when Array
|
45
|
+
parameters["oauth_signature_method"].first
|
46
|
+
else
|
47
|
+
parameters["oauth_signature_method"]
|
48
|
+
end
|
45
49
|
end
|
46
|
-
end
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
def oauth_timestamp
|
52
|
+
parameters["oauth_timestamp"]
|
53
|
+
end
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
def oauth_token
|
56
|
+
parameters["oauth_token"]
|
57
|
+
end
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
def oauth_verifier
|
60
|
+
parameters["oauth_verifier"]
|
61
|
+
end
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
def oauth_version
|
64
|
+
parameters["oauth_version"]
|
65
|
+
end
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
# TODO: deprecate these
|
68
|
+
alias consumer_key oauth_consumer_key
|
69
|
+
alias token oauth_token
|
70
|
+
alias nonce oauth_nonce
|
71
|
+
alias timestamp oauth_timestamp
|
72
|
+
alias signature oauth_signature
|
73
|
+
alias signature_method oauth_signature_method
|
71
74
|
|
72
|
-
|
75
|
+
## Parameter accessors
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
+
def parameters
|
78
|
+
raise NotImplementedError, "Must be implemented by subclasses"
|
79
|
+
end
|
77
80
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
+
def parameters_for_signature
|
82
|
+
parameters.select { |k, _v| !signature_and_unsigned_parameters.include?(k) }
|
83
|
+
end
|
81
84
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
+
def oauth_parameters
|
86
|
+
parameters.select { |k, _v| OAuth::PARAMETERS.include?(k) }.select { |_k, v| v != "" }
|
87
|
+
end
|
85
88
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
+
def non_oauth_parameters
|
90
|
+
parameters.select { |k, _v| !OAuth::PARAMETERS.include?(k) }
|
91
|
+
end
|
89
92
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
def signature_and_unsigned_parameters
|
94
|
+
unsigned_parameters + ["oauth_signature"]
|
95
|
+
end
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
# See 9.1.2 in specs
|
98
|
+
def normalized_uri
|
99
|
+
u = URI.parse(uri)
|
100
|
+
"#{u.scheme.downcase}://#{u.host.downcase}#{(u.scheme.casecmp("http").zero? && u.port != 80) || (u.scheme.casecmp("https").zero? && u.port != 443) ? ":#{u.port}" : ""}#{u.path && u.path != "" ? u.path : "/"}"
|
101
|
+
end
|
99
102
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
103
|
+
# See 9.1.1. in specs Normalize Request Parameters
|
104
|
+
def normalized_parameters
|
105
|
+
normalize(parameters_for_signature)
|
106
|
+
end
|
104
107
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
+
def sign(options = {})
|
109
|
+
OAuth::Signature.sign(self, options)
|
110
|
+
end
|
108
111
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
def sign!(options = {})
|
113
|
+
parameters["oauth_signature"] = sign(options)
|
114
|
+
@signed = true
|
115
|
+
signature
|
116
|
+
end
|
114
117
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
# See 9.1 in specs
|
119
|
+
def signature_base_string
|
120
|
+
base = [method, normalized_uri, normalized_parameters]
|
121
|
+
base.map { |v| escape(v) }.join("&")
|
122
|
+
end
|
120
123
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
124
|
+
# Has this request been signed yet?
|
125
|
+
def signed?
|
126
|
+
@signed
|
127
|
+
end
|
128
|
+
|
129
|
+
# URI, including OAuth parameters
|
130
|
+
def signed_uri(with_oauth = true)
|
131
|
+
if signed?
|
132
|
+
params = if with_oauth
|
133
|
+
parameters
|
134
|
+
else
|
135
|
+
non_oauth_parameters
|
136
|
+
end
|
125
137
|
|
126
|
-
|
127
|
-
def signed_uri(with_oauth = true)
|
128
|
-
if signed?
|
129
|
-
if with_oauth
|
130
|
-
params = parameters
|
138
|
+
[uri, normalize(params)].join("?")
|
131
139
|
else
|
132
|
-
|
140
|
+
warn "This request has not yet been signed!"
|
133
141
|
end
|
134
|
-
|
135
|
-
[uri, normalize(params)] * "?"
|
136
|
-
else
|
137
|
-
STDERR.puts "This request has not yet been signed!"
|
138
142
|
end
|
139
|
-
end
|
140
143
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
+
# Authorization header for OAuth
|
145
|
+
def oauth_header(options = {})
|
146
|
+
header_params_str = oauth_parameters.map { |k, v| "#{k}=\"#{escape(v)}\"" }.join(", ")
|
144
147
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
+
realm = "realm=\"#{options[:realm]}\", " if options[:realm]
|
149
|
+
"OAuth #{realm}#{header_params_str}"
|
150
|
+
end
|
148
151
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
152
|
+
def query_string_blank?
|
153
|
+
if (uri = request.env["REQUEST_URI"])
|
154
|
+
uri.split("?", 2)[1].nil?
|
155
|
+
else
|
156
|
+
request.query_string.match(/\A\s*\z/)
|
157
|
+
end
|
154
158
|
end
|
155
|
-
end
|
156
159
|
|
157
|
-
|
160
|
+
protected
|
158
161
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
+
def header_params
|
163
|
+
%w[X-HTTP_AUTHORIZATION Authorization HTTP_AUTHORIZATION].each do |header|
|
164
|
+
next unless request.env.include?(header)
|
162
165
|
|
163
|
-
|
164
|
-
|
166
|
+
header = request.env[header]
|
167
|
+
next unless header[0, 6] == "OAuth "
|
165
168
|
|
166
|
-
|
167
|
-
|
169
|
+
# parse the header into a Hash
|
170
|
+
oauth_params = OAuth::Helper.parse_header(header)
|
168
171
|
|
169
|
-
|
170
|
-
|
172
|
+
# remove non-OAuth parameters
|
173
|
+
oauth_params.select! { |k, _v| k =~ /^oauth_/ }
|
171
174
|
|
172
|
-
|
173
|
-
|
175
|
+
return oauth_params
|
176
|
+
end
|
174
177
|
|
175
|
-
|
178
|
+
{}
|
179
|
+
end
|
176
180
|
end
|
177
181
|
end
|
178
182
|
end
|
@@ -1,55 +1,61 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "oauth/request_proxy/base"
|
2
4
|
require "curb"
|
3
5
|
require "uri"
|
4
6
|
require "cgi"
|
5
7
|
|
6
|
-
module OAuth
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
module OAuth
|
9
|
+
module RequestProxy
|
10
|
+
module Curl
|
11
|
+
class Easy < OAuth::RequestProxy::Base
|
12
|
+
# Proxy for signing Curl::Easy requests
|
13
|
+
# Usage example:
|
14
|
+
# oauth_params = {:consumer => oauth_consumer, :token => access_token}
|
15
|
+
# req = Curl::Easy.new(uri)
|
16
|
+
# oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
|
17
|
+
# req.headers.merge!({"Authorization" => oauth_helper.header})
|
18
|
+
# req.http_get
|
19
|
+
# response = req.body_str
|
20
|
+
proxies ::Curl::Easy
|
21
|
+
|
22
|
+
def method
|
23
|
+
nil
|
24
|
+
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
def uri
|
27
|
+
options[:uri].to_s
|
28
|
+
end
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
def parameters
|
31
|
+
if options[:clobber_request]
|
32
|
+
options[:parameters]
|
33
|
+
else
|
34
|
+
post_parameters.merge(query_parameters).merge(options[:parameters] || {})
|
35
|
+
end
|
36
|
+
end
|
33
37
|
|
34
|
-
|
38
|
+
private
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
def query_parameters
|
41
|
+
query = URI.parse(request.url).query
|
42
|
+
(query ? CGI.parse(query) : {})
|
43
|
+
end
|
40
44
|
|
41
|
-
|
42
|
-
|
45
|
+
def post_parameters
|
46
|
+
post_body = {}
|
43
47
|
|
44
|
-
|
45
|
-
|
48
|
+
# Post params are only used if posting form data
|
49
|
+
if request.headers["Content-Type"] && request.headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
request.post_body.split("&").each do |str|
|
52
|
+
param = str.split("=")
|
53
|
+
post_body[param[0]] = param[1]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
post_body
|
50
57
|
end
|
51
58
|
end
|
52
|
-
post_body
|
53
59
|
end
|
54
60
|
end
|
55
61
|
end
|
@@ -1,72 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "oauth/request_proxy/base"
|
2
4
|
# em-http also uses adddressable so there is no need to require uri.
|
3
5
|
require "em-http"
|
4
6
|
require "cgi"
|
5
7
|
|
6
|
-
module OAuth
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# Request in this con
|
8
|
+
module OAuth
|
9
|
+
module RequestProxy
|
10
|
+
module EventMachine
|
11
|
+
class HttpRequest < OAuth::RequestProxy::Base
|
12
|
+
# A Proxy for use when you need to sign EventMachine::HttpClient instances.
|
13
|
+
# It needs to be called once the client is construct but before data is sent.
|
14
|
+
# Also see oauth/client/em-http
|
15
|
+
proxies ::EventMachine::HttpClient
|
15
16
|
|
16
|
-
|
17
|
-
request.req[:method]
|
18
|
-
end
|
17
|
+
# Request in this con
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def method
|
20
|
+
request.req[:method]
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
else
|
28
|
-
all_parameters
|
29
|
-
end
|
30
|
-
end
|
23
|
+
def uri
|
24
|
+
request.conn.normalize.to_s
|
25
|
+
end
|
31
26
|
|
32
|
-
|
27
|
+
def parameters
|
28
|
+
if options[:clobber_request]
|
29
|
+
options[:parameters]
|
30
|
+
else
|
31
|
+
all_parameters
|
32
|
+
end
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
merged_parameters({}, post_parameters, query_parameters, options[:parameters])
|
36
|
-
end
|
35
|
+
protected
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
quer
|
42
|
-
else
|
43
|
-
CGI.parse(quer.to_s)
|
44
|
-
end
|
45
|
-
CGI.parse(request.conn.query.to_s).merge(hash_quer)
|
46
|
-
end
|
37
|
+
def all_parameters
|
38
|
+
merged_parameters({}, post_parameters, query_parameters, options[:parameters])
|
39
|
+
end
|
47
40
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
41
|
+
def query_parameters
|
42
|
+
quer = request.req[:query]
|
43
|
+
hash_quer = if quer.respond_to?(:merge)
|
44
|
+
quer
|
45
|
+
else
|
46
|
+
CGI.parse(quer.to_s)
|
47
|
+
end
|
48
|
+
CGI.parse(request.conn.query.to_s).merge(hash_quer)
|
49
|
+
end
|
57
50
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
if
|
62
|
-
|
51
|
+
def post_parameters
|
52
|
+
headers = request.req[:head] || {}
|
53
|
+
form_encoded = headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")
|
54
|
+
if %w[POST PUT].include?(method) && form_encoded
|
55
|
+
CGI.parse(request.normalize_body(request.req[:body]).to_s)
|
63
56
|
else
|
64
|
-
|
57
|
+
{}
|
65
58
|
end
|
66
59
|
end
|
60
|
+
|
61
|
+
def merged_parameters(params, *extra_params)
|
62
|
+
extra_params.compact.each do |params_pairs|
|
63
|
+
params_pairs.each_pair do |key, value|
|
64
|
+
if params.key?(key)
|
65
|
+
params[key.to_s] += value
|
66
|
+
else
|
67
|
+
params[key.to_s] = [value].flatten
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
params
|
72
|
+
end
|
67
73
|
end
|
68
|
-
params
|
69
74
|
end
|
70
|
-
|
71
75
|
end
|
72
76
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "xmpp4r"
|
2
4
|
require "oauth/request_proxy/base"
|
3
5
|
|
4
6
|
module OAuth
|
5
7
|
module RequestProxy
|
6
8
|
class JabberRequest < OAuth::RequestProxy::Base
|
7
|
-
proxies Jabber::Iq
|
8
|
-
proxies Jabber::Presence
|
9
|
-
proxies Jabber::Message
|
9
|
+
proxies ::Jabber::Iq
|
10
|
+
proxies ::Jabber::Presence
|
11
|
+
proxies ::Jabber::Message
|
10
12
|
|
11
13
|
def parameters
|
12
14
|
return @params if @params
|
@@ -16,9 +18,10 @@ module OAuth
|
|
16
18
|
oauth = @request.get_elements("//oauth").first
|
17
19
|
return @params unless oauth
|
18
20
|
|
19
|
-
%w
|
20
|
-
oauth_timestamp oauth_nonce oauth_version
|
21
|
-
next unless element = oauth.first_element(param)
|
21
|
+
%w[ oauth_token oauth_consumer_key oauth_signature_method oauth_signature
|
22
|
+
oauth_timestamp oauth_nonce oauth_version ].each do |param|
|
23
|
+
next unless (element = oauth.first_element(param))
|
24
|
+
|
22
25
|
@params[param] = element.text
|
23
26
|
end
|
24
27
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "oauth/request_proxy/base"
|
2
4
|
|
3
5
|
module OAuth
|
@@ -18,7 +20,7 @@ module OAuth
|
|
18
20
|
# :consumer_secret => oauth_consumer_secret,
|
19
21
|
# :token_secret => oauth_token_secret,
|
20
22
|
class MockRequest < OAuth::RequestProxy::Base
|
21
|
-
proxies Hash
|
23
|
+
proxies ::Hash
|
22
24
|
|
23
25
|
def parameters
|
24
26
|
@request["parameters"]
|
@@ -1,72 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "oauth/request_proxy/base"
|
2
4
|
require "net/http"
|
3
5
|
require "uri"
|
4
6
|
require "cgi"
|
5
7
|
|
6
|
-
module OAuth
|
7
|
-
module
|
8
|
-
|
9
|
-
|
8
|
+
module OAuth
|
9
|
+
module RequestProxy
|
10
|
+
module Net
|
11
|
+
module HTTP
|
12
|
+
class HTTPRequest < OAuth::RequestProxy::Base
|
13
|
+
proxies ::Net::HTTPGenericRequest
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
def method
|
16
|
+
request.method
|
17
|
+
end
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
def uri
|
20
|
+
options[:uri].to_s
|
21
|
+
end
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def parameters
|
24
|
+
if options[:clobber_request]
|
25
|
+
options[:parameters]
|
26
|
+
else
|
27
|
+
all_parameters
|
28
|
+
end
|
29
|
+
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
def body
|
32
|
+
request.body
|
33
|
+
end
|
30
34
|
|
31
|
-
|
35
|
+
private
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
def all_parameters
|
38
|
+
request_params = CGI.parse(query_string)
|
39
|
+
# request_params.each{|k,v| request_params[k] = [nil] if v == []}
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
if options[:parameters]
|
42
|
+
options[:parameters].each do |k,v|
|
43
|
+
if request_params.has_key?(k) && v
|
44
|
+
request_params[k] << v
|
45
|
+
else
|
46
|
+
request_params[k] = [v]
|
47
|
+
end
|
48
|
+
end
|
43
49
|
end
|
50
|
+
request_params
|
44
51
|
end
|
45
|
-
end
|
46
|
-
request_params
|
47
|
-
end
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
def query_string
|
54
|
+
params = [query_params, auth_header_params]
|
55
|
+
if (method.to_s.casecmp("POST").zero? || method.to_s.casecmp("PUT").zero?) && form_url_encoded?
|
56
|
+
params << post_params
|
57
|
+
end
|
58
|
+
params.compact.join("&")
|
59
|
+
end
|
54
60
|
|
55
|
-
|
56
|
-
|
57
|
-
|
61
|
+
def form_url_encoded?
|
62
|
+
!request["Content-Type"].nil? && request["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")
|
63
|
+
end
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
def query_params
|
66
|
+
URI.parse(request.path).query
|
67
|
+
end
|
62
68
|
|
63
|
-
|
64
|
-
|
65
|
-
|
69
|
+
def post_params
|
70
|
+
request.body
|
71
|
+
end
|
66
72
|
|
67
|
-
|
68
|
-
|
69
|
-
|
73
|
+
def auth_header_params
|
74
|
+
return nil unless request["Authorization"] && request["Authorization"][0, 5] == "OAuth"
|
75
|
+
|
76
|
+
request["Authorization"]
|
77
|
+
end
|
78
|
+
end
|
70
79
|
end
|
71
80
|
end
|
72
81
|
end
|
@@ -1,43 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "oauth/request_proxy/base"
|
2
4
|
require "uri"
|
3
5
|
require "rack"
|
4
6
|
|
5
|
-
module OAuth
|
6
|
-
|
7
|
-
|
7
|
+
module OAuth
|
8
|
+
module RequestProxy
|
9
|
+
class RackRequest < OAuth::RequestProxy::Base
|
10
|
+
proxies ::Rack::Request
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
def method
|
13
|
+
request.env["rack.methodoverride.original_method"] || request.request_method
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
def uri
|
17
|
+
request.url
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def parameters
|
21
|
+
if options[:clobber_request]
|
22
|
+
options[:parameters] || {}
|
23
|
+
else
|
24
|
+
params = request_params.merge(query_params).merge(header_params)
|
25
|
+
params.merge(options[:parameters] || {})
|
26
|
+
end
|
23
27
|
end
|
24
|
-
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
def signature
|
30
|
+
parameters["oauth_signature"]
|
31
|
+
end
|
29
32
|
|
30
|
-
|
33
|
+
protected
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
def query_params
|
36
|
+
request.GET
|
37
|
+
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def request_params
|
40
|
+
if request.content_type && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
|
41
|
+
request.POST
|
42
|
+
else
|
43
|
+
{}
|
44
|
+
end
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
@@ -1,62 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "oauth/request_proxy/base"
|
2
4
|
require "rest-client"
|
3
5
|
require "uri"
|
4
6
|
require "cgi"
|
5
7
|
|
6
|
-
module OAuth
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
request.method.to_s.upcase
|
12
|
-
end
|
8
|
+
module OAuth
|
9
|
+
module RequestProxy
|
10
|
+
module RestClient
|
11
|
+
class Request < OAuth::RequestProxy::Base
|
12
|
+
proxies ::RestClient::Request
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def method
|
15
|
+
request.method.to_s.upcase
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
options[:parameters] || {}
|
21
|
-
else
|
22
|
-
post_parameters.merge(query_params).merge(options[:parameters] || {})
|
18
|
+
def uri
|
19
|
+
request.url
|
23
20
|
end
|
24
|
-
end
|
25
21
|
|
26
|
-
|
22
|
+
def parameters
|
23
|
+
if options[:clobber_request]
|
24
|
+
options[:parameters] || {}
|
25
|
+
else
|
26
|
+
post_parameters.merge(query_params).merge(options[:parameters] || {})
|
27
|
+
end
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
query = URI.parse(request.url).query
|
30
|
-
query ? CGI.parse(query) : {}
|
31
|
-
end
|
30
|
+
protected
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
def post_parameters
|
37
|
-
# Post params are only used if posting form data
|
38
|
-
if method == "POST" || method == "PUT"
|
39
|
-
OAuth::Helper.stringify_keys(query_string_to_hash(request.payload.to_s) || {})
|
40
|
-
else
|
41
|
-
{}
|
32
|
+
def query_params
|
33
|
+
query = URI.parse(request.url).query
|
34
|
+
query ? CGI.parse(query) : {}
|
42
35
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if !v.nil?
|
51
|
-
result.merge({k => v})
|
52
|
-
elsif !result.key?(k)
|
53
|
-
result.merge({k => true})
|
36
|
+
|
37
|
+
def request_params; end
|
38
|
+
|
39
|
+
def post_parameters
|
40
|
+
# Post params are only used if posting form data
|
41
|
+
if method == "POST" || method == "PUT"
|
42
|
+
OAuth::Helper.stringify_keys(query_string_to_hash(request.payload.to_s) || {})
|
54
43
|
else
|
55
|
-
|
44
|
+
{}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def query_string_to_hash(query)
|
51
|
+
query.split("&").inject({}) do |result, q|
|
52
|
+
k, v = q.split("=")
|
53
|
+
if !v.nil?
|
54
|
+
result.merge({ k => v })
|
55
|
+
elsif !result.key?(k)
|
56
|
+
result.merge({ k => true })
|
57
|
+
else
|
58
|
+
result
|
59
|
+
end
|
56
60
|
end
|
57
61
|
end
|
58
|
-
keyvals
|
59
62
|
end
|
60
|
-
|
63
|
+
end
|
61
64
|
end
|
62
|
-
end
|
65
|
+
end
|
@@ -1,53 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "oauth/request_proxy/base"
|
2
4
|
require "typhoeus"
|
3
5
|
require "typhoeus/request"
|
4
6
|
require "uri"
|
5
7
|
require "cgi"
|
6
8
|
|
7
|
-
module OAuth
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
request_method = request.options[:method].to_s.upcase
|
23
|
-
request_method.empty? ? "GET" : request_method
|
24
|
-
end
|
9
|
+
module OAuth
|
10
|
+
module RequestProxy
|
11
|
+
module Typhoeus
|
12
|
+
class Request < OAuth::RequestProxy::Base
|
13
|
+
# Proxy for signing Typhoeus::Request requests
|
14
|
+
# Usage example:
|
15
|
+
# oauth_params = {:consumer => oauth_consumer, :token => access_token}
|
16
|
+
# req = Typhoeus::Request.new(uri, options)
|
17
|
+
# oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
|
18
|
+
# req.options[:headers].merge!({"Authorization" => oauth_helper.header})
|
19
|
+
# hydra = Typhoeus::Hydra.new()
|
20
|
+
# hydra.queue(req)
|
21
|
+
# hydra.run
|
22
|
+
# response = req.response
|
23
|
+
proxies ::Typhoeus::Request
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def method
|
26
|
+
request_method = request.options[:method].to_s.upcase
|
27
|
+
request_method.empty? ? "GET" : request_method
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
else
|
34
|
-
post_parameters.merge(query_parameters).merge(options[:parameters] || {})
|
35
|
-
end
|
36
|
-
end
|
30
|
+
def uri
|
31
|
+
options[:uri].to_s
|
32
|
+
end
|
37
33
|
|
38
|
-
|
34
|
+
def parameters
|
35
|
+
if options[:clobber_request]
|
36
|
+
options[:parameters]
|
37
|
+
else
|
38
|
+
post_parameters.merge(query_parameters).merge(options[:parameters] || {})
|
39
|
+
end
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
private
|
43
|
+
|
44
|
+
def query_parameters
|
45
|
+
query = URI.parse(request.url).query
|
46
|
+
query ? CGI.parse(query) : {}
|
47
|
+
end
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def post_parameters
|
50
|
+
# Post params are only used if posting form data
|
51
|
+
if method == "POST"
|
52
|
+
OAuth::Helper.stringify_keys(request.options[:params] || {})
|
53
|
+
else
|
54
|
+
{}
|
55
|
+
end
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
53
59
|
end
|
data/lib/oauth/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.7
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pelle Braendgaard
|
@@ -16,7 +16,7 @@ authors:
|
|
16
16
|
autorequire:
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
|
-
date: 2021-11-
|
19
|
+
date: 2021-11-02 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: actionpack
|
@@ -421,9 +421,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
421
421
|
version: '2.0'
|
422
422
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
423
423
|
requirements:
|
424
|
-
- - "
|
424
|
+
- - ">="
|
425
425
|
- !ruby/object:Gem::Version
|
426
|
-
version:
|
426
|
+
version: '0'
|
427
427
|
requirements: []
|
428
428
|
rubygems_version: 3.0.3.1
|
429
429
|
signing_key:
|