oauth2 1.4.11 → 2.0.0.rc1
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
- data/CHANGELOG.md +133 -75
- data/CONTRIBUTING.md +1 -27
- data/LICENSE +1 -1
- data/README.md +128 -100
- data/SECURITY.md +5 -17
- data/lib/oauth2/access_token.rb +28 -19
- data/lib/oauth2/authenticator.rb +9 -4
- data/lib/oauth2/client.rb +74 -60
- data/lib/oauth2/error.rb +27 -18
- data/lib/oauth2/response.rb +61 -19
- data/lib/oauth2/snaky_hash.rb +8 -0
- data/lib/oauth2/strategy/assertion.rb +63 -38
- data/lib/oauth2/strategy/auth_code.rb +12 -1
- data/lib/oauth2/strategy/implicit.rb +7 -0
- data/lib/oauth2/version.rb +17 -19
- data/lib/oauth2.rb +14 -1
- metadata +55 -61
- data/lib/oauth2/mac_token.rb +0 -130
data/lib/oauth2/version.rb
CHANGED
@@ -2,36 +2,43 @@
|
|
2
2
|
|
3
3
|
module OAuth2
|
4
4
|
module Version
|
5
|
-
VERSION =
|
5
|
+
VERSION = '2.0.0.rc1'.freeze
|
6
6
|
|
7
7
|
module_function
|
8
8
|
|
9
|
+
# The version number as a string
|
10
|
+
#
|
11
|
+
# @return [String]
|
12
|
+
def to_s
|
13
|
+
VERSION
|
14
|
+
end
|
15
|
+
|
9
16
|
# The major version
|
10
17
|
#
|
11
18
|
# @return [Integer]
|
12
19
|
def major
|
13
|
-
|
20
|
+
to_a[0].to_i
|
14
21
|
end
|
15
22
|
|
16
23
|
# The minor version
|
17
24
|
#
|
18
25
|
# @return [Integer]
|
19
26
|
def minor
|
20
|
-
|
27
|
+
to_a[1].to_i
|
21
28
|
end
|
22
29
|
|
23
30
|
# The patch version
|
24
31
|
#
|
25
32
|
# @return [Integer]
|
26
33
|
def patch
|
27
|
-
|
34
|
+
to_a[2].to_i
|
28
35
|
end
|
29
36
|
|
30
37
|
# The pre-release version, if any
|
31
38
|
#
|
32
39
|
# @return [String, NilClass]
|
33
40
|
def pre
|
34
|
-
|
41
|
+
to_a[3]
|
35
42
|
end
|
36
43
|
|
37
44
|
# The version number as a hash
|
@@ -39,10 +46,10 @@ module OAuth2
|
|
39
46
|
# @return [Hash]
|
40
47
|
def to_h
|
41
48
|
{
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
49
|
+
major: major,
|
50
|
+
minor: minor,
|
51
|
+
patch: patch,
|
52
|
+
pre: pre,
|
46
53
|
}
|
47
54
|
end
|
48
55
|
|
@@ -50,16 +57,7 @@ module OAuth2
|
|
50
57
|
#
|
51
58
|
# @return [Array]
|
52
59
|
def to_a
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
# The version number as a string
|
57
|
-
#
|
58
|
-
# @return [String]
|
59
|
-
def to_s
|
60
|
-
v = [major, minor, patch].compact.join('.')
|
61
|
-
v += "-#{pre}" if pre
|
62
|
-
v
|
60
|
+
VERSION.split('.')
|
63
61
|
end
|
64
62
|
end
|
65
63
|
end
|
data/lib/oauth2.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# includes modules from stdlib
|
4
|
+
require 'cgi'
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
# third party gems
|
8
|
+
require 'rash'
|
9
|
+
|
10
|
+
# includes gem files
|
11
|
+
require 'oauth2/version'
|
3
12
|
require 'oauth2/error'
|
13
|
+
require 'oauth2/snaky_hash'
|
4
14
|
require 'oauth2/authenticator'
|
5
15
|
require 'oauth2/client'
|
6
16
|
require 'oauth2/strategy/base'
|
@@ -10,5 +20,8 @@ require 'oauth2/strategy/password'
|
|
10
20
|
require 'oauth2/strategy/client_credentials'
|
11
21
|
require 'oauth2/strategy/assertion'
|
12
22
|
require 'oauth2/access_token'
|
13
|
-
require 'oauth2/mac_token'
|
14
23
|
require 'oauth2/response'
|
24
|
+
|
25
|
+
# The namespace of this library
|
26
|
+
module OAuth2
|
27
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
8
|
-
- Erik Michaels-Ober
|
9
8
|
- Michael Bleigh
|
10
|
-
|
9
|
+
- Erik Michaels-Ober
|
10
|
+
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-06-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -53,53 +53,59 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: multi_xml
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0.5'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rack
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.2'
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '3'
|
76
79
|
type: :runtime
|
77
80
|
prerelease: false
|
78
81
|
version_requirements: !ruby/object:Gem::Requirement
|
79
82
|
requirements:
|
80
|
-
- - "
|
83
|
+
- - ">="
|
81
84
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
85
|
+
version: '1.2'
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
90
|
+
name: rash_alt
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
93
|
- - ">="
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
95
|
+
version: '0.4'
|
90
96
|
- - "<"
|
91
97
|
- !ruby/object:Gem::Version
|
92
|
-
version: '
|
98
|
+
version: '1'
|
93
99
|
type: :runtime
|
94
100
|
prerelease: false
|
95
101
|
version_requirements: !ruby/object:Gem::Requirement
|
96
102
|
requirements:
|
97
103
|
- - ">="
|
98
104
|
- !ruby/object:Gem::Version
|
99
|
-
version: '
|
105
|
+
version: '0.4'
|
100
106
|
- - "<"
|
101
107
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
108
|
+
version: '1'
|
103
109
|
- !ruby/object:Gem::Dependency
|
104
110
|
name: addressable
|
105
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,20 +120,34 @@ dependencies:
|
|
114
120
|
- - ">="
|
115
121
|
- !ruby/object:Gem::Version
|
116
122
|
version: '2'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: backports
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '3'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '3'
|
117
137
|
- !ruby/object:Gem::Dependency
|
118
138
|
name: bundler
|
119
139
|
requirement: !ruby/object:Gem::Requirement
|
120
140
|
requirements:
|
121
141
|
- - ">="
|
122
142
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
143
|
+
version: '2'
|
124
144
|
type: :development
|
125
145
|
prerelease: false
|
126
146
|
version_requirements: !ruby/object:Gem::Requirement
|
127
147
|
requirements:
|
128
148
|
- - ">="
|
129
149
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
150
|
+
version: '2'
|
131
151
|
- !ruby/object:Gem::Dependency
|
132
152
|
name: rake
|
133
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -216,22 +236,16 @@ dependencies:
|
|
216
236
|
name: rubocop-lts
|
217
237
|
requirement: !ruby/object:Gem::Requirement
|
218
238
|
requirements:
|
219
|
-
- - ">="
|
220
|
-
- !ruby/object:Gem::Version
|
221
|
-
version: 2.0.3
|
222
239
|
- - "~>"
|
223
240
|
- !ruby/object:Gem::Version
|
224
|
-
version: '
|
241
|
+
version: '8.0'
|
225
242
|
type: :development
|
226
243
|
prerelease: false
|
227
244
|
version_requirements: !ruby/object:Gem::Requirement
|
228
245
|
requirements:
|
229
|
-
- - ">="
|
230
|
-
- !ruby/object:Gem::Version
|
231
|
-
version: 2.0.3
|
232
246
|
- - "~>"
|
233
247
|
- !ruby/object:Gem::Version
|
234
|
-
version: '
|
248
|
+
version: '8.0'
|
235
249
|
- !ruby/object:Gem::Dependency
|
236
250
|
name: silent_stream
|
237
251
|
requirement: !ruby/object:Gem::Requirement
|
@@ -265,8 +279,8 @@ files:
|
|
265
279
|
- lib/oauth2/authenticator.rb
|
266
280
|
- lib/oauth2/client.rb
|
267
281
|
- lib/oauth2/error.rb
|
268
|
-
- lib/oauth2/mac_token.rb
|
269
282
|
- lib/oauth2/response.rb
|
283
|
+
- lib/oauth2/snaky_hash.rb
|
270
284
|
- lib/oauth2/strategy/assertion.rb
|
271
285
|
- lib/oauth2/strategy/auth_code.rb
|
272
286
|
- lib/oauth2/strategy/base.rb
|
@@ -274,37 +288,18 @@ files:
|
|
274
288
|
- lib/oauth2/strategy/implicit.rb
|
275
289
|
- lib/oauth2/strategy/password.rb
|
276
290
|
- lib/oauth2/version.rb
|
277
|
-
homepage: https://
|
291
|
+
homepage: https://github.com/oauth-xx/oauth2
|
278
292
|
licenses:
|
279
293
|
- MIT
|
280
294
|
metadata:
|
281
|
-
homepage_uri: https://
|
282
|
-
source_code_uri: https://
|
283
|
-
changelog_uri: https://
|
284
|
-
bug_tracker_uri: https://
|
285
|
-
documentation_uri: https://www.rubydoc.info/gems/oauth2/
|
286
|
-
wiki_uri: https://
|
287
|
-
funding_uri: https://liberapay.com/pboling
|
295
|
+
homepage_uri: https://github.com/oauth-xx/oauth2
|
296
|
+
source_code_uri: https://github.com/oauth-xx/oauth2/tree/v2.0.0.rc1
|
297
|
+
changelog_uri: https://github.com/oauth-xx/oauth2/blob/v2.0.0.rc1/CHANGELOG.md
|
298
|
+
bug_tracker_uri: https://github.com/oauth-xx/oauth2/issues
|
299
|
+
documentation_uri: https://www.rubydoc.info/gems/oauth2/2.0.0.rc1
|
300
|
+
wiki_uri: https://github.com/oauth-xx/oauth2/wiki
|
288
301
|
rubygems_mfa_required: 'true'
|
289
|
-
post_install_message:
|
290
|
-
|
291
|
-
You have installed oauth2 version 1.4.11, which is EOL.
|
292
|
-
No further support is anticipated for the 1.4.x series.
|
293
|
-
|
294
|
-
OAuth2 version 2 is released.
|
295
|
-
There are BREAKING changes, but most will not encounter them, and upgrading should be easy!
|
296
|
-
|
297
|
-
We have made two other major migrations:
|
298
|
-
1. master branch renamed to main
|
299
|
-
2. Github has been replaced with Gitlab
|
300
|
-
|
301
|
-
Please see:
|
302
|
-
• https://gitlab.com/oauth-xx/oauth2#what-is-new-for-v20
|
303
|
-
• https://gitlab.com/oauth-xx/oauth2/-/blob/main/CHANGELOG.md
|
304
|
-
• https://groups.google.com/g/oauth-ruby/c/QA_dtrXWXaE
|
305
|
-
|
306
|
-
Please upgrade, report issues, and support the project! Thanks, |7eter l-|. l3oling
|
307
|
-
|
302
|
+
post_install_message:
|
308
303
|
rdoc_options: []
|
309
304
|
require_paths:
|
310
305
|
- lib
|
@@ -312,16 +307,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
312
307
|
requirements:
|
313
308
|
- - ">="
|
314
309
|
- !ruby/object:Gem::Version
|
315
|
-
version:
|
310
|
+
version: 2.2.0
|
316
311
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
317
312
|
requirements:
|
318
|
-
- - "
|
313
|
+
- - ">"
|
319
314
|
- !ruby/object:Gem::Version
|
320
|
-
version:
|
315
|
+
version: 1.3.1
|
321
316
|
requirements: []
|
322
|
-
rubygems_version: 3.3.
|
323
|
-
signing_key:
|
317
|
+
rubygems_version: 3.3.15
|
318
|
+
signing_key:
|
324
319
|
specification_version: 4
|
325
320
|
summary: A Ruby wrapper for the OAuth 2.0 protocol.
|
326
321
|
test_files: []
|
327
|
-
...
|
data/lib/oauth2/mac_token.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'base64'
|
4
|
-
require 'digest'
|
5
|
-
require 'openssl'
|
6
|
-
require 'securerandom'
|
7
|
-
|
8
|
-
module OAuth2
|
9
|
-
class MACToken < AccessToken
|
10
|
-
# Generates a MACToken from an AccessToken and secret
|
11
|
-
#
|
12
|
-
# @param [AccessToken] token the OAuth2::Token instance
|
13
|
-
# @option [String] secret the secret key value
|
14
|
-
# @param [Hash] opts the options to create the Access Token with
|
15
|
-
# @see MACToken#initialize
|
16
|
-
def self.from_access_token(token, secret, options = {})
|
17
|
-
new(token.client, token.token, secret, token.params.merge(:refresh_token => token.refresh_token, :expires_in => token.expires_in, :expires_at => token.expires_at).merge(options))
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :secret, :algorithm
|
21
|
-
|
22
|
-
# Initalize a MACToken
|
23
|
-
#
|
24
|
-
# @param [Client] client the OAuth2::Client instance
|
25
|
-
# @param [String] token the Access Token value
|
26
|
-
# @option [String] secret the secret key value
|
27
|
-
# @param [Hash] opts the options to create the Access Token with
|
28
|
-
# @option opts [String] :refresh_token (nil) the refresh_token value
|
29
|
-
# @option opts [FixNum, String] :expires_in (nil) the number of seconds in which the AccessToken will expire
|
30
|
-
# @option opts [FixNum, String] :expires_at (nil) the epoch time in seconds in which AccessToken will expire
|
31
|
-
# @option opts [FixNum, String] :algorithm (hmac-sha-256) the algorithm to use for the HMAC digest (one of 'hmac-sha-256', 'hmac-sha-1')
|
32
|
-
def initialize(client, token, secret, opts = {})
|
33
|
-
@secret = secret
|
34
|
-
self.algorithm = opts.delete(:algorithm) || 'hmac-sha-256'
|
35
|
-
|
36
|
-
super(client, token, opts)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Make a request with the MAC Token
|
40
|
-
#
|
41
|
-
# @param [Symbol] verb the HTTP request method
|
42
|
-
# @param [String] path the HTTP URL path of the request
|
43
|
-
# @param [Hash] opts the options to make the request with
|
44
|
-
# @see Client#request
|
45
|
-
def request(verb, path, opts = {}, &block)
|
46
|
-
url = client.connection.build_url(path, opts[:params]).to_s
|
47
|
-
|
48
|
-
opts[:headers] ||= {}
|
49
|
-
opts[:headers]['Authorization'] = header(verb, url)
|
50
|
-
|
51
|
-
@client.request(verb, path, opts, &block)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Get the headers hash (always an empty hash)
|
55
|
-
def headers
|
56
|
-
{}
|
57
|
-
end
|
58
|
-
|
59
|
-
# Generate the MAC header
|
60
|
-
#
|
61
|
-
# @param [Symbol] verb the HTTP request method
|
62
|
-
# @param [String] url the HTTP URL path of the request
|
63
|
-
def header(verb, url)
|
64
|
-
timestamp = Time.now.utc.to_i
|
65
|
-
nonce = Digest::SHA256.hexdigest([timestamp, SecureRandom.hex].join(':'))
|
66
|
-
|
67
|
-
uri = URI.parse(url)
|
68
|
-
|
69
|
-
raise(ArgumentError, "could not parse \"#{url}\" into URI") unless uri.is_a?(URI::HTTP)
|
70
|
-
|
71
|
-
mac = signature(timestamp, nonce, verb, uri)
|
72
|
-
|
73
|
-
"MAC id=\"#{token}\", ts=\"#{timestamp}\", nonce=\"#{nonce}\", mac=\"#{mac}\""
|
74
|
-
end
|
75
|
-
|
76
|
-
# Generate the Base64-encoded HMAC digest signature
|
77
|
-
#
|
78
|
-
# @param [Fixnum] timestamp the timestamp of the request in seconds since epoch
|
79
|
-
# @param [String] nonce the MAC header nonce
|
80
|
-
# @param [Symbol] verb the HTTP request method
|
81
|
-
# @param [String] url the HTTP URL path of the request
|
82
|
-
def signature(timestamp, nonce, verb, uri)
|
83
|
-
signature = [
|
84
|
-
timestamp,
|
85
|
-
nonce,
|
86
|
-
verb.to_s.upcase,
|
87
|
-
uri.request_uri,
|
88
|
-
uri.host,
|
89
|
-
uri.port,
|
90
|
-
'', nil
|
91
|
-
].join("\n")
|
92
|
-
|
93
|
-
strict_encode64(OpenSSL::HMAC.digest(@algorithm, secret, signature))
|
94
|
-
end
|
95
|
-
|
96
|
-
# Set the HMAC algorithm
|
97
|
-
#
|
98
|
-
# @param [String] alg the algorithm to use (one of 'hmac-sha-1', 'hmac-sha-256')
|
99
|
-
def algorithm=(alg)
|
100
|
-
@algorithm = case alg.to_s
|
101
|
-
when 'hmac-sha-1'
|
102
|
-
begin
|
103
|
-
OpenSSL::Digest('SHA1').new
|
104
|
-
rescue StandardError
|
105
|
-
OpenSSL::Digest.new('SHA1')
|
106
|
-
end
|
107
|
-
when 'hmac-sha-256'
|
108
|
-
begin
|
109
|
-
OpenSSL::Digest('SHA256').new
|
110
|
-
rescue StandardError
|
111
|
-
OpenSSL::Digest.new('SHA256')
|
112
|
-
end
|
113
|
-
else
|
114
|
-
raise(ArgumentError, 'Unsupported algorithm')
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
private
|
119
|
-
|
120
|
-
# No-op since we need the verb and path
|
121
|
-
# and the MAC always goes in a header
|
122
|
-
def token=(_noop)
|
123
|
-
end
|
124
|
-
|
125
|
-
# Base64.strict_encode64 is not available on Ruby 1.8.7
|
126
|
-
def strict_encode64(str)
|
127
|
-
Base64.encode64(str).delete("\n")
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|