oauth 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +4 -0
- data/CHANGELOG.md +317 -41
- data/CITATION.cff +20 -0
- data/CODE_OF_CONDUCT.md +79 -29
- data/CONTRIBUTING.md +213 -24
- data/FUNDING.md +77 -0
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.md +543 -275
- data/REEK +0 -0
- data/RUBOCOP.md +71 -0
- data/SECURITY.md +27 -11
- data/lib/oauth/client/action_controller_request.rb +14 -9
- data/lib/oauth/client/em_http.rb +106 -99
- data/lib/oauth/client/helper.rb +15 -11
- data/lib/oauth/client/net_http.rb +39 -13
- data/lib/oauth/consumer.rb +105 -54
- data/lib/oauth/errors/problem.rb +1 -1
- data/lib/oauth/helper.rb +25 -3
- data/lib/oauth/oauth.rb +28 -6
- data/lib/oauth/optional.rb +20 -0
- data/lib/oauth/request_proxy/action_controller_request.rb +11 -7
- data/lib/oauth/request_proxy/action_dispatch_request.rb +41 -0
- data/lib/oauth/request_proxy/base.rb +15 -12
- data/lib/oauth/request_proxy/em_http_request.rb +53 -52
- data/lib/oauth/request_proxy/jabber_request.rb +9 -2
- data/lib/oauth/request_proxy/net_http.rb +1 -1
- data/lib/oauth/request_proxy/rest_client_request.rb +4 -3
- data/lib/oauth/server.rb +12 -8
- data/lib/oauth/signature/base.rb +1 -1
- data/lib/oauth/signature/rsa/sha1.rb +11 -4
- data/lib/oauth/tokens/access_token.rb +1 -1
- data/lib/oauth/tokens/consumer_token.rb +2 -2
- data/lib/oauth/tokens/request_token.rb +9 -4
- data/lib/oauth/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +246 -81
- metadata.gz.sig +3 -0
- data/TODO +0 -32
@@ -18,8 +18,15 @@ module OAuth
|
|
18
18
|
oauth = @request.get_elements("//oauth").first
|
19
19
|
return @params unless oauth
|
20
20
|
|
21
|
-
%w[
|
22
|
-
|
21
|
+
%w[
|
22
|
+
oauth_token
|
23
|
+
oauth_consumer_key
|
24
|
+
oauth_signature_method
|
25
|
+
oauth_signature
|
26
|
+
oauth_timestamp
|
27
|
+
oauth_nonce
|
28
|
+
oauth_version
|
29
|
+
].each do |param|
|
23
30
|
next unless (element = oauth.first_element(param))
|
24
31
|
|
25
32
|
@params[param] = element.text
|
@@ -69,7 +69,7 @@ module OAuth
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def auth_header_params
|
72
|
-
return
|
72
|
+
return unless request["Authorization"] && request["Authorization"][0, 5] == "OAuth"
|
73
73
|
|
74
74
|
request["Authorization"]
|
75
75
|
end
|
@@ -34,7 +34,8 @@ module OAuth
|
|
34
34
|
query ? CGI.parse(query) : {}
|
35
35
|
end
|
36
36
|
|
37
|
-
def request_params
|
37
|
+
def request_params
|
38
|
+
end
|
38
39
|
|
39
40
|
def post_parameters
|
40
41
|
# Post params are only used if posting form data
|
@@ -52,9 +53,9 @@ module OAuth
|
|
52
53
|
query.split("&").inject({}) do |result, q|
|
53
54
|
k, v = q.split("=")
|
54
55
|
if !v.nil?
|
55
|
-
result.merge({
|
56
|
+
result.merge({k => v})
|
56
57
|
elsif !result.key?(k)
|
57
|
-
result.merge({
|
58
|
+
result.merge({k => true})
|
58
59
|
else
|
59
60
|
result
|
60
61
|
end
|
data/lib/oauth/server.rb
CHANGED
@@ -7,12 +7,13 @@ module OAuth
|
|
7
7
|
# This is mainly used to create consumer credentials and can pretty much be ignored if you want to create your own
|
8
8
|
class Server
|
9
9
|
include OAuth::Helper
|
10
|
+
|
10
11
|
attr_accessor :base_url
|
11
12
|
|
12
13
|
@@server_paths = {
|
13
14
|
request_token_path: "/oauth/request_token",
|
14
15
|
authorize_path: "/oauth/authorize",
|
15
|
-
access_token_path: "/oauth/access_token"
|
16
|
+
access_token_path: "/oauth/access_token",
|
16
17
|
}
|
17
18
|
|
18
19
|
# Create a new server instance
|
@@ -32,13 +33,16 @@ module OAuth
|
|
32
33
|
# mainly for testing purposes
|
33
34
|
def create_consumer
|
34
35
|
creds = generate_credentials
|
35
|
-
Consumer.new(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
Consumer.new(
|
37
|
+
creds[0],
|
38
|
+
creds[1],
|
39
|
+
{
|
40
|
+
site: base_url,
|
41
|
+
request_token_path: request_token_path,
|
42
|
+
authorize_path: authorize_path,
|
43
|
+
access_token_path: access_token_path,
|
44
|
+
},
|
45
|
+
)
|
42
46
|
end
|
43
47
|
|
44
48
|
def request_token_path
|
data/lib/oauth/signature/base.rb
CHANGED
@@ -43,7 +43,7 @@ module OAuth
|
|
43
43
|
# override secrets based on the values returned from the block (if any)
|
44
44
|
if block
|
45
45
|
# consumer secret and token secret need to be looked up based on pieces of the request
|
46
|
-
secrets = yield block.arity == 1 ? request : [token, consumer_key, nonce, request.timestamp]
|
46
|
+
secrets = yield (block.arity == 1) ? request : [token, consumer_key, nonce, request.timestamp]
|
47
47
|
if secrets.is_a?(Array) && secrets.size == 2
|
48
48
|
@token_secret = secrets[0]
|
49
49
|
@consumer_secret = secrets[1]
|
@@ -9,8 +9,8 @@ module OAuth
|
|
9
9
|
implements "rsa-sha1"
|
10
10
|
|
11
11
|
def ==(other)
|
12
|
-
|
13
|
-
|
12
|
+
decoded = Base64.decode64(other.is_a?(Array) ? other.first : other)
|
13
|
+
public_key.verify(OpenSSL::Digest.new("SHA1"), decoded, signature_base_string)
|
14
14
|
end
|
15
15
|
|
16
16
|
def public_key
|
@@ -25,7 +25,14 @@ module OAuth
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def body_hash
|
28
|
-
|
28
|
+
# Use SHA1 body hash with compatibility across OpenSSL versions
|
29
|
+
data = request.body || ""
|
30
|
+
begin
|
31
|
+
digest_bytes = OpenSSL::Digest.digest("SHA1", data)
|
32
|
+
rescue StandardError
|
33
|
+
digest_bytes = ::Digest::SHA1.digest(data)
|
34
|
+
end
|
35
|
+
Base64.encode64(digest_bytes).chomp.delete("\n")
|
29
36
|
end
|
30
37
|
|
31
38
|
private
|
@@ -47,7 +54,7 @@ module OAuth
|
|
47
54
|
options[:private_key]
|
48
55
|
else
|
49
56
|
consumer_secret
|
50
|
-
end
|
57
|
+
end,
|
51
58
|
)
|
52
59
|
|
53
60
|
private_key.sign(OpenSSL::Digest.new("SHA1"), signature_base_string)
|
@@ -8,7 +8,7 @@ module OAuth
|
|
8
8
|
def request(http_method, path, *arguments)
|
9
9
|
request_uri = URI.parse(path)
|
10
10
|
site_uri = consumer.uri
|
11
|
-
is_service_uri_different =
|
11
|
+
is_service_uri_different = request_uri.absolute? && request_uri != site_uri
|
12
12
|
begin
|
13
13
|
consumer.uri(request_uri) if is_service_uri_different
|
14
14
|
@response = super(http_method, path, *arguments)
|
@@ -4,7 +4,7 @@ module OAuth
|
|
4
4
|
# Superclass for tokens used by OAuth Clients
|
5
5
|
class ConsumerToken < Token
|
6
6
|
attr_accessor :consumer, :params
|
7
|
-
attr_reader
|
7
|
+
attr_reader :response
|
8
8
|
|
9
9
|
def self.from_hash(consumer, hash)
|
10
10
|
token = new(consumer, hash[:oauth_token], hash[:oauth_token_secret])
|
@@ -15,7 +15,7 @@ module OAuth
|
|
15
15
|
def initialize(consumer, token = "", secret = "")
|
16
16
|
super(token, secret)
|
17
17
|
@consumer = consumer
|
18
|
-
@params
|
18
|
+
@params = {}
|
19
19
|
end
|
20
20
|
|
21
21
|
# Make a signed request using given http_method to the path
|
@@ -6,14 +6,14 @@ module OAuth
|
|
6
6
|
class RequestToken < ConsumerToken
|
7
7
|
# Generate an authorization URL for user authorization
|
8
8
|
def authorize_url(params = nil)
|
9
|
-
return
|
9
|
+
return if token.nil?
|
10
10
|
|
11
11
|
params = (params || {}).merge(oauth_token: token)
|
12
12
|
build_url(consumer.authorize_url, params)
|
13
13
|
end
|
14
14
|
|
15
15
|
def authenticate_url(params = nil)
|
16
|
-
return
|
16
|
+
return if token.nil?
|
17
17
|
|
18
18
|
params = (params || {}).merge(oauth_token: token)
|
19
19
|
build_url(consumer.authenticate_url, params)
|
@@ -25,8 +25,13 @@ module OAuth
|
|
25
25
|
|
26
26
|
# exchange for AccessToken on server
|
27
27
|
def get_access_token(options = {}, *arguments)
|
28
|
-
response = consumer.token_request(
|
29
|
-
|
28
|
+
response = consumer.token_request(
|
29
|
+
consumer.http_method,
|
30
|
+
(consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path),
|
31
|
+
self,
|
32
|
+
options,
|
33
|
+
*arguments,
|
34
|
+
)
|
30
35
|
OAuth::AccessToken.from_hash(consumer, response)
|
31
36
|
end
|
32
37
|
|
data/lib/oauth/version.rb
CHANGED
data.tar.gz.sig
ADDED
Binary file
|