oauth2 2.0.9 → 2.0.10
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 +0 -0
- data/CHANGELOG.md +301 -168
- data/CODE_OF_CONDUCT.md +0 -0
- data/CONTRIBUTING.md +126 -31
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.md +619 -245
- data/SECURITY.md +2 -2
- data/lib/oauth2/access_token.rb +186 -32
- data/lib/oauth2/authenticator.rb +9 -6
- data/lib/oauth2/client.rb +291 -96
- data/lib/oauth2/error.rb +14 -14
- data/lib/oauth2/filtered_attributes.rb +31 -0
- data/lib/oauth2/response.rb +17 -13
- data/lib/oauth2/strategy/assertion.rb +4 -4
- data/lib/oauth2/strategy/auth_code.rb +3 -3
- data/lib/oauth2/strategy/base.rb +0 -0
- data/lib/oauth2/strategy/client_credentials.rb +2 -2
- data/lib/oauth2/strategy/implicit.rb +3 -3
- data/lib/oauth2/strategy/password.rb +6 -4
- data/lib/oauth2/version.rb +1 -1
- data/lib/oauth2.rb +23 -18
- data.tar.gz.sig +0 -0
- metadata +188 -67
- metadata.gz.sig +0 -0
data/lib/oauth2/response.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "json"
|
4
|
+
require "multi_xml"
|
5
|
+
require "rack"
|
6
6
|
|
7
7
|
module OAuth2
|
8
8
|
# OAuth2::Response class
|
@@ -23,8 +23,8 @@ module OAuth2
|
|
23
23
|
|
24
24
|
# Content type assignments for various potential HTTP content types.
|
25
25
|
@@content_types = {
|
26
|
-
|
27
|
-
|
26
|
+
"application/x-www-form-urlencoded" => :query,
|
27
|
+
"text/plain" => :text,
|
28
28
|
}
|
29
29
|
|
30
30
|
# Adds a new content type parser.
|
@@ -68,7 +68,7 @@ module OAuth2
|
|
68
68
|
|
69
69
|
# The HTTP response body
|
70
70
|
def body
|
71
|
-
response.body ||
|
71
|
+
response.body || ""
|
72
72
|
end
|
73
73
|
|
74
74
|
# The {#response} {#body} as parsed by {#parser}.
|
@@ -90,16 +90,19 @@ module OAuth2
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
|
93
|
+
if options[:snaky] && @parsed.is_a?(Hash)
|
94
|
+
parsed = SnakyHash::StringKeyed.new(@parsed)
|
95
|
+
@parsed = parsed.to_h
|
96
|
+
end
|
94
97
|
|
95
98
|
@parsed
|
96
99
|
end
|
97
100
|
|
98
101
|
# Attempts to determine the content type of the response.
|
99
102
|
def content_type
|
100
|
-
return
|
103
|
+
return unless response.headers
|
101
104
|
|
102
|
-
((response.headers.values_at(
|
105
|
+
((response.headers.values_at("content-type", "Content-Type").compact.first || "").split(";").first || "").strip.downcase
|
103
106
|
end
|
104
107
|
|
105
108
|
# Determines the parser (a Proc or other Object which responds to #call)
|
@@ -133,16 +136,17 @@ module OAuth2
|
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
136
|
-
OAuth2::Response.register_parser(:xml, [
|
139
|
+
OAuth2::Response.register_parser(:xml, ["text/xml", "application/rss+xml", "application/rdf+xml", "application/atom+xml", "application/xml"]) do |body|
|
137
140
|
next body unless body.respond_to?(:to_str)
|
138
141
|
|
139
142
|
MultiXml.parse(body)
|
140
143
|
end
|
141
144
|
|
142
|
-
OAuth2::Response.register_parser(:json, [
|
145
|
+
OAuth2::Response.register_parser(:json, ["application/json", "text/javascript", "application/hal+json", "application/vnd.collection+json", "application/vnd.api+json", "application/problem+json"]) do |body|
|
143
146
|
next body unless body.respond_to?(:to_str)
|
144
147
|
|
145
|
-
body = body.dup.force_encoding(
|
148
|
+
body = body.dup.force_encoding(Encoding::ASCII_8BIT) if body.respond_to?(:force_encoding)
|
149
|
+
next body if body.respond_to?(:empty?) && body.empty?
|
146
150
|
|
147
|
-
|
151
|
+
JSON.parse(body)
|
148
152
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "jwt"
|
4
4
|
|
5
5
|
module OAuth2
|
6
6
|
module Strategy
|
@@ -34,7 +34,7 @@ module OAuth2
|
|
34
34
|
#
|
35
35
|
# @raise [NotImplementedError]
|
36
36
|
def authorize_url
|
37
|
-
raise(NotImplementedError,
|
37
|
+
raise(NotImplementedError, "The authorization endpoint is not used in this strategy")
|
38
38
|
end
|
39
39
|
|
40
40
|
# Retrieve an access token given the specified client.
|
@@ -87,13 +87,13 @@ module OAuth2
|
|
87
87
|
|
88
88
|
def build_request(assertion, request_opts = {})
|
89
89
|
{
|
90
|
-
grant_type:
|
90
|
+
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
91
91
|
assertion: assertion,
|
92
92
|
}.merge(request_opts)
|
93
93
|
end
|
94
94
|
|
95
95
|
def build_assertion(claims, encoding_opts)
|
96
|
-
raise ArgumentError.new(message:
|
96
|
+
raise ArgumentError.new(message: "Please provide an encoding_opts hash with :algorithm and :key") if !encoding_opts.is_a?(Hash) || (%i[algorithm key] - encoding_opts.keys).any?
|
97
97
|
|
98
98
|
JWT.encode(claims, encoding_opts[:key], encoding_opts[:algorithm])
|
99
99
|
end
|
@@ -10,7 +10,7 @@ module OAuth2
|
|
10
10
|
#
|
11
11
|
# @param [Hash] params additional query parameters
|
12
12
|
def authorize_params(params = {})
|
13
|
-
params.merge(
|
13
|
+
params.merge("response_type" => "code", "client_id" => @client.id)
|
14
14
|
end
|
15
15
|
|
16
16
|
# The authorization URL endpoint of the provider
|
@@ -28,7 +28,7 @@ module OAuth2
|
|
28
28
|
# @param [Hash] opts access_token_opts, @see Client#get_token
|
29
29
|
# @note that you must also provide a :redirect_uri with most OAuth 2.0 providers
|
30
30
|
def get_token(code, params = {}, opts = {})
|
31
|
-
params = {
|
31
|
+
params = {"grant_type" => "authorization_code", "code" => code}.merge(@client.redirection_params).merge(params)
|
32
32
|
params_dup = params.dup
|
33
33
|
params.each_key do |key|
|
34
34
|
params_dup[key.to_s] = params_dup.delete(key) if key.is_a?(Symbol)
|
@@ -40,7 +40,7 @@ module OAuth2
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def assert_valid_params(params)
|
43
|
-
raise(ArgumentError,
|
43
|
+
raise(ArgumentError, "client_secret is not allowed in authorize URL query params") if params.key?(:client_secret) || params.key?("client_secret")
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/lib/oauth2/strategy/base.rb
CHANGED
File without changes
|
@@ -10,7 +10,7 @@ module OAuth2
|
|
10
10
|
#
|
11
11
|
# @raise [NotImplementedError]
|
12
12
|
def authorize_url
|
13
|
-
raise(NotImplementedError,
|
13
|
+
raise(NotImplementedError, "The authorization endpoint is not used in this strategy")
|
14
14
|
end
|
15
15
|
|
16
16
|
# Retrieve an access token given the specified client.
|
@@ -18,7 +18,7 @@ module OAuth2
|
|
18
18
|
# @param [Hash] params additional params
|
19
19
|
# @param [Hash] opts options
|
20
20
|
def get_token(params = {}, opts = {})
|
21
|
-
params = params.merge(
|
21
|
+
params = params.merge("grant_type" => "client_credentials")
|
22
22
|
@client.get_token(params, opts)
|
23
23
|
end
|
24
24
|
end
|
@@ -10,7 +10,7 @@ module OAuth2
|
|
10
10
|
#
|
11
11
|
# @param [Hash] params additional query parameters
|
12
12
|
def authorize_params(params = {})
|
13
|
-
params.merge(
|
13
|
+
params.merge("response_type" => "token", "client_id" => @client.id)
|
14
14
|
end
|
15
15
|
|
16
16
|
# The authorization URL endpoint of the provider
|
@@ -25,13 +25,13 @@ module OAuth2
|
|
25
25
|
#
|
26
26
|
# @raise [NotImplementedError]
|
27
27
|
def get_token(*)
|
28
|
-
raise(NotImplementedError,
|
28
|
+
raise(NotImplementedError, "The token is accessed differently in this strategy")
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def assert_valid_params(params)
|
34
|
-
raise(ArgumentError,
|
34
|
+
raise(ArgumentError, "client_secret is not allowed in authorize URL query params") if params.key?(:client_secret) || params.key?("client_secret")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -10,7 +10,7 @@ module OAuth2
|
|
10
10
|
#
|
11
11
|
# @raise [NotImplementedError]
|
12
12
|
def authorize_url
|
13
|
-
raise(NotImplementedError,
|
13
|
+
raise(NotImplementedError, "The authorization endpoint is not used in this strategy")
|
14
14
|
end
|
15
15
|
|
16
16
|
# Retrieve an access token given the specified End User username and password.
|
@@ -19,9 +19,11 @@ module OAuth2
|
|
19
19
|
# @param [String] password the End User password
|
20
20
|
# @param [Hash] params additional params
|
21
21
|
def get_token(username, password, params = {}, opts = {})
|
22
|
-
params = {
|
23
|
-
|
24
|
-
|
22
|
+
params = {
|
23
|
+
"grant_type" => "password",
|
24
|
+
"username" => username,
|
25
|
+
"password" => password,
|
26
|
+
}.merge(params)
|
25
27
|
@client.get_token(params, opts)
|
26
28
|
end
|
27
29
|
end
|
data/lib/oauth2/version.rb
CHANGED
data/lib/oauth2.rb
CHANGED
@@ -1,33 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# includes modules from stdlib
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "cgi"
|
5
|
+
require "time"
|
6
6
|
|
7
7
|
# third party gems
|
8
|
-
require
|
9
|
-
require
|
8
|
+
require "snaky_hash"
|
9
|
+
require "version_gem"
|
10
10
|
|
11
11
|
# includes gem files
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
require_relative "oauth2/version"
|
13
|
+
require_relative "oauth2/filtered_attributes"
|
14
|
+
require_relative "oauth2/error"
|
15
|
+
require_relative "oauth2/authenticator"
|
16
|
+
require_relative "oauth2/client"
|
17
|
+
require_relative "oauth2/strategy/base"
|
18
|
+
require_relative "oauth2/strategy/auth_code"
|
19
|
+
require_relative "oauth2/strategy/implicit"
|
20
|
+
require_relative "oauth2/strategy/password"
|
21
|
+
require_relative "oauth2/strategy/client_credentials"
|
22
|
+
require_relative "oauth2/strategy/assertion"
|
23
|
+
require_relative "oauth2/access_token"
|
24
|
+
require_relative "oauth2/response"
|
24
25
|
|
25
26
|
# The namespace of this library
|
26
27
|
module OAuth2
|
27
|
-
|
28
|
+
OAUTH_DEBUG = ENV.fetch("OAUTH_DEBUG", "false").casecmp("true").zero?
|
29
|
+
DEFAULT_CONFIG = SnakyHash::SymbolKeyed.new(
|
30
|
+
silence_extra_tokens_warning: true,
|
31
|
+
silence_no_tokens_warning: true,
|
32
|
+
)
|
28
33
|
@config = DEFAULT_CONFIG.dup
|
29
34
|
class << self
|
30
|
-
|
35
|
+
attr_reader :config
|
31
36
|
end
|
32
37
|
def configure
|
33
38
|
yield @config
|
data.tar.gz.sig
ADDED
Binary file
|