oauth 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -116
- data/CODE_OF_CONDUCT.md +0 -0
- data/CONTRIBUTING.md +0 -0
- data/LICENSE +0 -0
- data/README.md +13 -9
- data/SECURITY.md +0 -0
- data/TODO +0 -0
- data/lib/oauth/cli/authorize_command.rb +8 -10
- data/lib/oauth/cli/base_command.rb +8 -6
- data/lib/oauth/cli/help_command.rb +0 -0
- data/lib/oauth/cli/query_command.rb +3 -3
- data/lib/oauth/cli/sign_command.rb +12 -15
- data/lib/oauth/cli/version_command.rb +0 -0
- data/lib/oauth/cli.rb +2 -2
- data/lib/oauth/client/action_controller_request.rb +14 -15
- data/lib/oauth/client/em_http.rb +28 -28
- data/lib/oauth/client/helper.rb +14 -17
- data/lib/oauth/client/net_http.rb +27 -27
- data/lib/oauth/client.rb +0 -0
- data/lib/oauth/consumer.rb +52 -62
- data/lib/oauth/errors/error.rb +0 -0
- data/lib/oauth/errors/problem.rb +0 -0
- data/lib/oauth/errors/unauthorized.rb +0 -0
- data/lib/oauth/errors.rb +0 -0
- data/lib/oauth/helper.rb +7 -7
- data/lib/oauth/oauth.rb +4 -4
- data/lib/oauth/oauth_test_helper.rb +0 -0
- data/lib/oauth/request_proxy/action_controller_request.rb +0 -0
- data/lib/oauth/request_proxy/action_dispatch_request.rb +0 -0
- data/lib/oauth/request_proxy/base.rb +3 -3
- data/lib/oauth/request_proxy/curb_request.rb +0 -0
- data/lib/oauth/request_proxy/em_http_request.rb +0 -0
- data/lib/oauth/request_proxy/jabber_request.rb +0 -0
- data/lib/oauth/request_proxy/mock_request.rb +0 -0
- data/lib/oauth/request_proxy/net_http.rb +2 -2
- data/lib/oauth/request_proxy/rack_request.rb +0 -0
- data/lib/oauth/request_proxy/rest_client_request.rb +2 -2
- data/lib/oauth/request_proxy/typhoeus_request.rb +0 -0
- data/lib/oauth/request_proxy.rb +3 -3
- data/lib/oauth/server.rb +8 -10
- data/lib/oauth/signature/base.rb +3 -4
- data/lib/oauth/signature/hmac/sha1.rb +1 -1
- data/lib/oauth/signature/hmac/sha256.rb +1 -1
- data/lib/oauth/signature/plaintext.rb +0 -0
- data/lib/oauth/signature/rsa/sha1.rb +3 -3
- data/lib/oauth/signature.rb +5 -5
- data/lib/oauth/token.rb +0 -0
- data/lib/oauth/tokens/access_token.rb +0 -0
- data/lib/oauth/tokens/consumer_token.rb +2 -2
- data/lib/oauth/tokens/request_token.rb +7 -8
- data/lib/oauth/tokens/server_token.rb +0 -1
- data/lib/oauth/tokens/token.rb +0 -0
- data/lib/oauth/version.rb +1 -1
- data/lib/oauth.rb +0 -0
- metadata +8 -7
data/lib/oauth/consumer.rb
CHANGED
@@ -16,8 +16,8 @@ module OAuth
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
CA_FILES = %
|
19
|
+
unless defined?(CA_FILE)
|
20
|
+
CA_FILES = %w[/etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /usr/share/curl/curl-ca-bundle.crt].freeze
|
21
21
|
CA_FILES.each do |ca_file|
|
22
22
|
if File.exist?(ca_file)
|
23
23
|
CA_FILE = ca_file
|
@@ -29,15 +29,15 @@ module OAuth
|
|
29
29
|
|
30
30
|
@@default_options = {
|
31
31
|
# Signature method used by server. Defaults to HMAC-SHA1
|
32
|
-
:
|
32
|
+
signature_method: "HMAC-SHA1",
|
33
33
|
|
34
34
|
# default paths on site. These are the same as the defaults set up by the generators
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
35
|
+
request_token_path: "/oauth/request_token",
|
36
|
+
authenticate_path: "/oauth/authenticate",
|
37
|
+
authorize_path: "/oauth/authorize",
|
38
|
+
access_token_path: "/oauth/access_token",
|
39
39
|
|
40
|
-
:
|
40
|
+
proxy: nil,
|
41
41
|
# How do we send the oauth values to the server see
|
42
42
|
# https://oauth.net/core/1.0/#consumer_req_param for more info
|
43
43
|
#
|
@@ -46,10 +46,10 @@ module OAuth
|
|
46
46
|
# :header - via the Authorize header (Default) ( option 1. in spec)
|
47
47
|
# :body - url form encoded in body of POST request ( option 2. in spec)
|
48
48
|
# :query_string - via the query part of the url ( option 3. in spec)
|
49
|
-
:
|
49
|
+
scheme: :header,
|
50
50
|
|
51
51
|
# Default http method used for OAuth Token Requests (defaults to :post)
|
52
|
-
:
|
52
|
+
http_method: :post,
|
53
53
|
|
54
54
|
# Add a custom ca_file for consumer
|
55
55
|
# :ca_file => '/etc/certs.pem'
|
@@ -59,9 +59,9 @@ module OAuth
|
|
59
59
|
# nil, false - no debug output
|
60
60
|
# true - uses $stdout
|
61
61
|
# some_value - uses some_value
|
62
|
-
:
|
62
|
+
debug_output: nil,
|
63
63
|
|
64
|
-
:
|
64
|
+
oauth_version: "1.0"
|
65
65
|
}
|
66
66
|
|
67
67
|
attr_accessor :options, :key, :secret
|
@@ -94,9 +94,8 @@ module OAuth
|
|
94
94
|
@secret = consumer_secret
|
95
95
|
|
96
96
|
# ensure that keys are symbols
|
97
|
-
@options = @@default_options.merge(options.
|
97
|
+
@options = @@default_options.merge(options.each_with_object({}) do |(key, value), opts|
|
98
98
|
opts[key.to_sym] = value
|
99
|
-
opts
|
100
99
|
end)
|
101
100
|
end
|
102
101
|
|
@@ -127,7 +126,7 @@ module OAuth
|
|
127
126
|
if custom_uri
|
128
127
|
@uri = custom_uri
|
129
128
|
@http = create_http # yike, oh well. less intrusive this way
|
130
|
-
else
|
129
|
+
else # if no custom passed, we use existing, which, if unset, is set to site uri
|
131
130
|
@uri ||= URI.parse(site)
|
132
131
|
end
|
133
132
|
end
|
@@ -156,18 +155,18 @@ module OAuth
|
|
156
155
|
# will be exchanged out of band
|
157
156
|
request_options[:oauth_callback] ||= OAuth::OUT_OF_BAND unless request_options[:exclude_callback]
|
158
157
|
|
159
|
-
if block_given?
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
158
|
+
response = if block_given?
|
159
|
+
token_request(
|
160
|
+
http_method,
|
161
|
+
(request_token_url? ? request_token_url : request_token_path),
|
162
|
+
nil,
|
163
|
+
request_options,
|
164
|
+
*arguments,
|
165
|
+
&block
|
166
|
+
)
|
167
|
+
else
|
168
|
+
token_request(http_method, (request_token_url? ? request_token_url : request_token_path), nil, request_options, *arguments)
|
169
|
+
end
|
171
170
|
OAuth::RequestToken.from_hash(self, response)
|
172
171
|
end
|
173
172
|
|
@@ -190,18 +189,18 @@ module OAuth
|
|
190
189
|
|
191
190
|
# override the request with your own, this is useful for file uploads which Net::HTTP does not do
|
192
191
|
req = create_signed_request(http_method, path, token, request_options, *arguments)
|
193
|
-
return nil if block_given?
|
192
|
+
return nil if block_given? && (yield(req) == :done)
|
194
193
|
rsp = http.request(req)
|
195
194
|
# check for an error reported by the Problem Reporting extension
|
196
195
|
# (https://wiki.oauth.net/ProblemReporting)
|
197
196
|
# note: a 200 may actually be an error; check for an oauth_problem key to be sure
|
198
197
|
if !(headers = rsp.to_hash["www-authenticate"]).nil? &&
|
199
|
-
|
200
|
-
|
198
|
+
(h = headers.select { |hdr| hdr =~ /^OAuth / }).any? &&
|
199
|
+
h.first =~ /oauth_problem/
|
201
200
|
|
202
201
|
# puts "Header: #{h.first}"
|
203
202
|
|
204
|
-
# TODO doesn't handle broken responses from api.login.yahoo.com
|
203
|
+
# TODO: doesn't handle broken responses from api.login.yahoo.com
|
205
204
|
# remove debug code when done
|
206
205
|
params = OAuth::Helper.parse_header(h.first)
|
207
206
|
|
@@ -235,10 +234,9 @@ module OAuth
|
|
235
234
|
# symbolize keys
|
236
235
|
# TODO this could be considered unexpected behavior; symbols or not?
|
237
236
|
# TODO this also drops subsequent values from multi-valued keys
|
238
|
-
CGI.parse(response.body).
|
237
|
+
CGI.parse(response.body).each_with_object({}) do |(k, v), h|
|
239
238
|
h[k.strip.to_sym] = v.first
|
240
239
|
h[k.strip] = v.first
|
241
|
-
h
|
242
240
|
end
|
243
241
|
end
|
244
242
|
when (300..399)
|
@@ -250,11 +248,11 @@ module OAuth
|
|
250
248
|
response.error! if uri.path == path && our_uri.host == uri.host
|
251
249
|
|
252
250
|
if uri.path == path && our_uri.host != uri.host
|
253
|
-
|
254
|
-
|
251
|
+
options[:site] = "#{uri.scheme}://#{uri.host}"
|
252
|
+
@http = create_http
|
255
253
|
end
|
256
254
|
|
257
|
-
|
255
|
+
token_request(http_method, uri.path, token, request_options, arguments)
|
258
256
|
when (400..499)
|
259
257
|
raise OAuth::Unauthorized, response
|
260
258
|
else
|
@@ -301,13 +299,13 @@ module OAuth
|
|
301
299
|
@options[:access_token_path]
|
302
300
|
end
|
303
301
|
|
304
|
-
# TODO this is ugly, rewrite
|
302
|
+
# TODO: this is ugly, rewrite
|
305
303
|
def request_token_url
|
306
304
|
@options[:request_token_url] || site + request_token_path
|
307
305
|
end
|
308
306
|
|
309
307
|
def request_token_url?
|
310
|
-
@options.
|
308
|
+
@options.key?(:request_token_url)
|
311
309
|
end
|
312
310
|
|
313
311
|
def authenticate_url
|
@@ -315,7 +313,7 @@ module OAuth
|
|
315
313
|
end
|
316
314
|
|
317
315
|
def authenticate_url?
|
318
|
-
@options.
|
316
|
+
@options.key?(:authenticate_url)
|
319
317
|
end
|
320
318
|
|
321
319
|
def authorize_url
|
@@ -323,7 +321,7 @@ module OAuth
|
|
323
321
|
end
|
324
322
|
|
325
323
|
def authorize_url?
|
326
|
-
@options.
|
324
|
+
@options.key?(:authorize_url)
|
327
325
|
end
|
328
326
|
|
329
327
|
def access_token_url
|
@@ -331,7 +329,7 @@ module OAuth
|
|
331
329
|
end
|
332
330
|
|
333
331
|
def access_token_url?
|
334
|
-
@options.
|
332
|
+
@options.key?(:access_token_url)
|
335
333
|
end
|
336
334
|
|
337
335
|
def proxy
|
@@ -342,10 +340,7 @@ module OAuth
|
|
342
340
|
|
343
341
|
# Instantiates the http object
|
344
342
|
def create_http(_url = nil)
|
345
|
-
|
346
|
-
if !request_endpoint.nil?
|
347
|
-
_url = request_endpoint
|
348
|
-
end
|
343
|
+
_url = request_endpoint unless request_endpoint.nil?
|
349
344
|
|
350
345
|
our_uri = if _url.nil? || _url[0] =~ /^\//
|
351
346
|
URI.parse(site)
|
@@ -372,10 +367,8 @@ module OAuth
|
|
372
367
|
if @options[:no_verify]
|
373
368
|
http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
374
369
|
else
|
375
|
-
ca_file =
|
376
|
-
if ca_file
|
377
|
-
http_object.ca_file = ca_file
|
378
|
-
end
|
370
|
+
ca_file = @options[:ca_file] || CA_FILE
|
371
|
+
http_object.ca_file = ca_file if ca_file
|
379
372
|
http_object.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
380
373
|
http_object.verify_depth = 5
|
381
374
|
end
|
@@ -394,9 +387,7 @@ module OAuth
|
|
394
387
|
def create_http_request(http_method, path, *arguments)
|
395
388
|
http_method = http_method.to_sym
|
396
389
|
|
397
|
-
if [
|
398
|
-
data = arguments.shift
|
399
|
-
end
|
390
|
+
data = arguments.shift if %i[post put patch].include?(http_method)
|
400
391
|
|
401
392
|
# if the base site contains a path, add it now
|
402
393
|
# only add if the site host matches the current http object's host
|
@@ -408,22 +399,22 @@ module OAuth
|
|
408
399
|
|
409
400
|
case http_method
|
410
401
|
when :post
|
411
|
-
request = Net::HTTP::Post.new(path,headers)
|
402
|
+
request = Net::HTTP::Post.new(path, headers)
|
412
403
|
request["Content-Length"] = "0" # Default to 0
|
413
404
|
when :put
|
414
|
-
request = Net::HTTP::Put.new(path,headers)
|
405
|
+
request = Net::HTTP::Put.new(path, headers)
|
415
406
|
request["Content-Length"] = "0" # Default to 0
|
416
407
|
when :patch
|
417
|
-
request = Net::HTTP::Patch.new(path,headers)
|
408
|
+
request = Net::HTTP::Patch.new(path, headers)
|
418
409
|
request["Content-Length"] = "0" # Default to 0
|
419
410
|
when :get
|
420
|
-
request = Net::HTTP::Get.new(path,headers)
|
411
|
+
request = Net::HTTP::Get.new(path, headers)
|
421
412
|
when :delete
|
422
|
-
request =
|
413
|
+
request = Net::HTTP::Delete.new(path, headers)
|
423
414
|
when :head
|
424
|
-
request = Net::HTTP::Head.new(path,headers)
|
415
|
+
request = Net::HTTP::Head.new(path, headers)
|
425
416
|
else
|
426
|
-
raise ArgumentError, "Don't know how to handle http_method: :#{http_method
|
417
|
+
raise ArgumentError, "Don't know how to handle http_method: :#{http_method}"
|
427
418
|
end
|
428
419
|
|
429
420
|
if data.is_a?(Hash)
|
@@ -448,13 +439,12 @@ module OAuth
|
|
448
439
|
request
|
449
440
|
end
|
450
441
|
|
451
|
-
def marshal_dump(*
|
452
|
-
{:
|
442
|
+
def marshal_dump(*_args)
|
443
|
+
{ key: @key, secret: @secret, options: @options }
|
453
444
|
end
|
454
445
|
|
455
446
|
def marshal_load(data)
|
456
447
|
initialize(data[:key], data[:secret], data[:options])
|
457
448
|
end
|
458
|
-
|
459
449
|
end
|
460
450
|
end
|
data/lib/oauth/errors/error.rb
CHANGED
File without changes
|
data/lib/oauth/errors/problem.rb
CHANGED
File without changes
|
File without changes
|
data/lib/oauth/errors.rb
CHANGED
File without changes
|
data/lib/oauth/helper.rb
CHANGED
@@ -24,11 +24,11 @@ module OAuth
|
|
24
24
|
|
25
25
|
# Generate a random key of up to +size+ bytes. The value returned is Base64 encoded with non-word
|
26
26
|
# characters removed.
|
27
|
-
def generate_key(size=32)
|
27
|
+
def generate_key(size = 32)
|
28
28
|
Base64.encode64(OpenSSL::Random.random_bytes(size)).gsub(/\W/, "")
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
alias generate_nonce generate_key
|
32
32
|
|
33
33
|
def generate_timestamp #:nodoc:
|
34
34
|
Time.now.to_i.to_s
|
@@ -51,13 +51,13 @@ module OAuth
|
|
51
51
|
normalize_nested_query(values, k)
|
52
52
|
else
|
53
53
|
values.sort.collect do |v|
|
54
|
-
[escape(k),escape(v)]
|
54
|
+
[escape(k), escape(v)].join("=")
|
55
55
|
end
|
56
56
|
end
|
57
57
|
elsif values.is_a?(Hash)
|
58
58
|
normalize_nested_query(values, k)
|
59
59
|
else
|
60
|
-
[escape(k),escape(values)]
|
60
|
+
[escape(k), escape(values)].join("=")
|
61
61
|
end
|
62
62
|
end * "&"
|
63
63
|
end
|
@@ -76,7 +76,7 @@ module OAuth
|
|
76
76
|
normalize_nested_query(v, prefix ? "#{prefix}[#{k}]" : k)
|
77
77
|
end.flatten.sort
|
78
78
|
else
|
79
|
-
[escape(prefix), escape(value)]
|
79
|
+
[escape(prefix), escape(value)].join("=")
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -90,10 +90,10 @@ module OAuth
|
|
90
90
|
#
|
91
91
|
def parse_header(header)
|
92
92
|
# decompose
|
93
|
-
params = header[6,header.length].split(/[,=&]/)
|
93
|
+
params = header[6, header.length].split(/[,=&]/)
|
94
94
|
|
95
95
|
# odd number of arguments - must be a malformed header.
|
96
|
-
raise OAuth::Problem
|
96
|
+
raise OAuth::Problem, "Invalid authorization header" if params.size.odd?
|
97
97
|
|
98
98
|
params.map! do |v|
|
99
99
|
# strip and unescape
|
data/lib/oauth/oauth.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module OAuth
|
2
2
|
# request tokens are passed between the consumer and the provider out of
|
3
3
|
# band (i.e. callbacks cannot be used), per section 6.1.1
|
4
|
-
OUT_OF_BAND = "oob"
|
4
|
+
OUT_OF_BAND = "oob".freeze
|
5
5
|
|
6
6
|
# required parameters, per sections 6.1.1, 6.3.1, and 7
|
7
|
-
PARAMETERS = %w
|
8
|
-
|
9
|
-
|
7
|
+
PARAMETERS = %w[oauth_callback oauth_consumer_key oauth_token
|
8
|
+
oauth_signature_method oauth_timestamp oauth_nonce oauth_verifier
|
9
|
+
oauth_version oauth_signature oauth_body_hash].freeze
|
10
10
|
|
11
11
|
# reserved character regexp, per section 5.1
|
12
12
|
RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
|
File without changes
|
File without changes
|
File without changes
|
@@ -79,15 +79,15 @@ module OAuth
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def parameters_for_signature
|
82
|
-
parameters.
|
82
|
+
parameters.reject { |k, _v| signature_and_unsigned_parameters.include?(k) }
|
83
83
|
end
|
84
84
|
|
85
85
|
def oauth_parameters
|
86
|
-
parameters.select { |k, _v| OAuth::PARAMETERS.include?(k) }.
|
86
|
+
parameters.select { |k, _v| OAuth::PARAMETERS.include?(k) }.reject { |_k, v| v == "" }
|
87
87
|
end
|
88
88
|
|
89
89
|
def non_oauth_parameters
|
90
|
-
parameters.
|
90
|
+
parameters.reject { |k, _v| OAuth::PARAMETERS.include?(k) }
|
91
91
|
end
|
92
92
|
|
93
93
|
def signature_and_unsigned_parameters
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -39,8 +39,8 @@ module OAuth
|
|
39
39
|
# request_params.each{|k,v| request_params[k] = [nil] if v == []}
|
40
40
|
|
41
41
|
if options[:parameters]
|
42
|
-
options[:parameters].each do |k,v|
|
43
|
-
if request_params.
|
42
|
+
options[:parameters].each do |k, v|
|
43
|
+
if request_params.key?(k) && v
|
44
44
|
request_params[k] << v
|
45
45
|
else
|
46
46
|
request_params[k] = [v]
|
File without changes
|
@@ -51,9 +51,9 @@ module OAuth
|
|
51
51
|
query.split("&").inject({}) do |result, q|
|
52
52
|
k, v = q.split("=")
|
53
53
|
if !v.nil?
|
54
|
-
result.merge(
|
54
|
+
result.merge(k => v)
|
55
55
|
elsif !result.key?(k)
|
56
|
-
result.merge(
|
56
|
+
result.merge(k => true)
|
57
57
|
else
|
58
58
|
result
|
59
59
|
end
|
File without changes
|
data/lib/oauth/request_proxy.rb
CHANGED
@@ -5,13 +5,13 @@ module OAuth
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.proxy(request, options = {})
|
8
|
-
return request if request.
|
8
|
+
return request if request.is_a?(OAuth::RequestProxy::Base)
|
9
9
|
|
10
10
|
klass = available_proxies[request.class]
|
11
11
|
|
12
12
|
# Search for possible superclass matches.
|
13
13
|
if klass.nil?
|
14
|
-
request_parent = available_proxies.keys.find { |rc| request.
|
14
|
+
request_parent = available_proxies.keys.find { |rc| request.is_a?(rc) }
|
15
15
|
klass = available_proxies[request_parent]
|
16
16
|
end
|
17
17
|
|
@@ -19,6 +19,6 @@ module OAuth
|
|
19
19
|
klass.new(request, options)
|
20
20
|
end
|
21
21
|
|
22
|
-
class UnknownRequestType <
|
22
|
+
class UnknownRequestType < RuntimeError; end
|
23
23
|
end
|
24
24
|
end
|
data/lib/oauth/server.rb
CHANGED
@@ -8,9 +8,9 @@ module OAuth
|
|
8
8
|
attr_accessor :base_url
|
9
9
|
|
10
10
|
@@server_paths = {
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
11
|
+
request_token_path: "/oauth/request_token",
|
12
|
+
authorize_path: "/oauth/authorize",
|
13
|
+
access_token_path: "/oauth/access_token"
|
14
14
|
}
|
15
15
|
|
16
16
|
# Create a new server instance
|
@@ -23,7 +23,7 @@ module OAuth
|
|
23
23
|
[generate_key(16), generate_key]
|
24
24
|
end
|
25
25
|
|
26
|
-
def generate_consumer_credentials(
|
26
|
+
def generate_consumer_credentials(_params = {})
|
27
27
|
Consumer.new(*generate_credentials)
|
28
28
|
end
|
29
29
|
|
@@ -31,12 +31,10 @@ module OAuth
|
|
31
31
|
def create_consumer
|
32
32
|
creds = generate_credentials
|
33
33
|
Consumer.new(creds[0], creds[1],
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
:access_token_path => access_token_path
|
39
|
-
})
|
34
|
+
site: base_url,
|
35
|
+
request_token_path: request_token_path,
|
36
|
+
authorize_path: authorize_path,
|
37
|
+
access_token_path: access_token_path)
|
40
38
|
end
|
41
39
|
|
42
40
|
def request_token_path
|
data/lib/oauth/signature/base.rb
CHANGED
@@ -17,7 +17,7 @@ module OAuth::Signature
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def initialize(request, options = {}, &block)
|
20
|
-
raise TypeError unless request.
|
20
|
+
raise TypeError unless request.is_a?(OAuth::RequestProxy::Base)
|
21
21
|
@request = request
|
22
22
|
@options = options
|
23
23
|
|
@@ -47,7 +47,7 @@ module OAuth::Signature
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def signature
|
50
|
-
Base64.encode64(digest).chomp.
|
50
|
+
Base64.encode64(digest).chomp.delete("\n")
|
51
51
|
end
|
52
52
|
|
53
53
|
def ==(cmp_signature)
|
@@ -57,7 +57,7 @@ module OAuth::Signature
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def verify
|
60
|
-
self ==
|
60
|
+
self == request.signature
|
61
61
|
end
|
62
62
|
|
63
63
|
def signature_base_string
|
@@ -93,6 +93,5 @@ module OAuth::Signature
|
|
93
93
|
def raise_instantiation_error
|
94
94
|
raise NotImplementedError, "Cannot instantiate #{self.class.name} class directly."
|
95
95
|
end
|
96
|
-
|
97
96
|
end
|
98
97
|
end
|
@@ -5,7 +5,7 @@ module OAuth::Signature::HMAC
|
|
5
5
|
implements "hmac-sha1"
|
6
6
|
|
7
7
|
def body_hash
|
8
|
-
Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || "")).chomp.
|
8
|
+
Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || "")).chomp.delete("\n")
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -5,7 +5,7 @@ module OAuth::Signature::HMAC
|
|
5
5
|
implements "hmac-sha256"
|
6
6
|
|
7
7
|
def body_hash
|
8
|
-
Base64.encode64(OpenSSL::Digest::SHA256.digest(request.body || "")).chomp.
|
8
|
+
Base64.encode64(OpenSSL::Digest::SHA256.digest(request.body || "")).chomp.delete("\n")
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
File without changes
|
@@ -19,7 +19,7 @@ module OAuth::Signature::RSA
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def body_hash
|
22
|
-
Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || "")).chomp.
|
22
|
+
Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || "")).chomp.delete("\n")
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
@@ -27,9 +27,9 @@ module OAuth::Signature::RSA
|
|
27
27
|
def decode_public_key
|
28
28
|
case consumer_secret
|
29
29
|
when /-----BEGIN CERTIFICATE-----/
|
30
|
-
OpenSSL::X509::Certificate.new(
|
30
|
+
OpenSSL::X509::Certificate.new(consumer_secret).public_key
|
31
31
|
else
|
32
|
-
OpenSSL::PKey::RSA.new(
|
32
|
+
OpenSSL::PKey::RSA.new(consumer_secret)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
data/lib/oauth/signature.rb
CHANGED
@@ -20,26 +20,26 @@ module OAuth
|
|
20
20
|
|
21
21
|
# Sign a +request+
|
22
22
|
def self.sign(request, options = {}, &block)
|
23
|
-
|
23
|
+
build(request, options, &block).signature
|
24
24
|
end
|
25
25
|
|
26
26
|
# Verify the signature of +request+
|
27
27
|
def self.verify(request, options = {}, &block)
|
28
|
-
|
28
|
+
build(request, options, &block).verify
|
29
29
|
end
|
30
30
|
|
31
31
|
# Create the signature base string for +request+. This string is the normalized parameter information.
|
32
32
|
#
|
33
33
|
# See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
|
34
34
|
def self.signature_base_string(request, options = {}, &block)
|
35
|
-
|
35
|
+
build(request, options, &block).signature_base_string
|
36
36
|
end
|
37
37
|
|
38
38
|
# Create the body hash for a request
|
39
39
|
def self.body_hash(request, options = {}, &block)
|
40
|
-
|
40
|
+
build(request, options, &block).body_hash
|
41
41
|
end
|
42
42
|
|
43
|
-
class UnknownSignatureMethod <
|
43
|
+
class UnknownSignatureMethod < RuntimeError; end
|
44
44
|
end
|
45
45
|
end
|
data/lib/oauth/token.rb
CHANGED
File without changes
|
File without changes
|
@@ -5,12 +5,12 @@ module OAuth
|
|
5
5
|
attr_reader :response
|
6
6
|
|
7
7
|
def self.from_hash(consumer, hash)
|
8
|
-
token =
|
8
|
+
token = new(consumer, hash[:oauth_token], hash[:oauth_token_secret])
|
9
9
|
token.params = hash
|
10
10
|
token
|
11
11
|
end
|
12
12
|
|
13
|
-
def initialize(consumer, token="", secret="")
|
13
|
+
def initialize(consumer, token = "", secret = "")
|
14
14
|
super(token, secret)
|
15
15
|
@consumer = consumer
|
16
16
|
@params = {}
|
@@ -2,19 +2,18 @@ module OAuth
|
|
2
2
|
# The RequestToken is used for the initial Request.
|
3
3
|
# This is normally created by the Consumer object.
|
4
4
|
class RequestToken < ConsumerToken
|
5
|
-
|
6
5
|
# Generate an authorization URL for user authorization
|
7
6
|
def authorize_url(params = nil)
|
8
|
-
return nil if
|
7
|
+
return nil if token.nil?
|
9
8
|
|
10
|
-
params = (params || {}).merge(:
|
9
|
+
params = (params || {}).merge(oauth_token: token)
|
11
10
|
build_url(consumer.authorize_url, params)
|
12
11
|
end
|
13
12
|
|
14
13
|
def authenticate_url(params = nil)
|
15
|
-
return nil if
|
14
|
+
return nil if token.nil?
|
16
15
|
|
17
|
-
params = (params || {}).merge(:
|
16
|
+
params = (params || {}).merge(oauth_token: token)
|
18
17
|
build_url(consumer.authenticate_url, params)
|
19
18
|
end
|
20
19
|
|
@@ -28,16 +27,16 @@ module OAuth
|
|
28
27
|
OAuth::AccessToken.from_hash(consumer, response)
|
29
28
|
end
|
30
29
|
|
31
|
-
|
30
|
+
protected
|
32
31
|
|
33
32
|
# construct an authorization or authentication url
|
34
33
|
def build_url(base_url, params)
|
35
34
|
uri = URI.parse(base_url.to_s)
|
36
35
|
queries = {}
|
37
36
|
queries = Hash[URI.decode_www_form(uri.query)] if uri.query
|
38
|
-
# TODO doesn't handle array values correctly
|
37
|
+
# TODO: doesn't handle array values correctly
|
39
38
|
queries.merge!(params) if params
|
40
|
-
uri.query = URI.encode_www_form(queries)
|
39
|
+
uri.query = URI.encode_www_form(queries) unless queries.empty?
|
41
40
|
uri.to_s
|
42
41
|
end
|
43
42
|
end
|