oauth2 1.4.7 → 1.4.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
- data/CHANGELOG.md +36 -3
- data/CONTRIBUTING.md +18 -0
- data/LICENSE +1 -1
- data/README.md +301 -116
- data/SECURITY.md +20 -0
- data/lib/oauth2/access_token.rb +4 -2
- data/lib/oauth2/authenticator.rb +3 -1
- data/lib/oauth2/client.rb +91 -56
- data/lib/oauth2/error.rb +3 -1
- data/lib/oauth2/mac_token.rb +19 -19
- data/lib/oauth2/response.rb +2 -0
- data/lib/oauth2/strategy/assertion.rb +3 -1
- data/lib/oauth2/strategy/auth_code.rb +3 -1
- data/lib/oauth2/strategy/base.rb +2 -0
- data/lib/oauth2/strategy/client_credentials.rb +3 -1
- data/lib/oauth2/strategy/implicit.rb +3 -1
- data/lib/oauth2/strategy/password.rb +3 -1
- data/lib/oauth2/version.rb +1 -1
- data/lib/oauth2.rb +2 -0
- metadata +50 -87
- data/spec/helper.rb +0 -37
- data/spec/oauth2/access_token_spec.rb +0 -216
- data/spec/oauth2/authenticator_spec.rb +0 -84
- data/spec/oauth2/client_spec.rb +0 -506
- data/spec/oauth2/mac_token_spec.rb +0 -117
- data/spec/oauth2/response_spec.rb +0 -90
- data/spec/oauth2/strategy/assertion_spec.rb +0 -58
- data/spec/oauth2/strategy/auth_code_spec.rb +0 -107
- data/spec/oauth2/strategy/base_spec.rb +0 -5
- data/spec/oauth2/strategy/client_credentials_spec.rb +0 -69
- data/spec/oauth2/strategy/implicit_spec.rb +0 -26
- data/spec/oauth2/strategy/password_spec.rb +0 -55
- data/spec/oauth2/version_spec.rb +0 -23
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: 1.4.
|
4
|
+
version: 1.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
8
|
-
- Michael Bleigh
|
9
8
|
- Erik Michaels-Ober
|
10
|
-
|
9
|
+
- Michael Bleigh
|
10
|
+
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-07-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -18,20 +18,20 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 0.17.3
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
24
|
+
version: '3.0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version:
|
31
|
+
version: 0.17.3
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '3.0'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: jwt
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,20 +114,6 @@ dependencies:
|
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '2.3'
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: backports
|
119
|
-
requirement: !ruby/object:Gem::Requirement
|
120
|
-
requirements:
|
121
|
-
- - "~>"
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: '3.11'
|
124
|
-
type: :development
|
125
|
-
prerelease: false
|
126
|
-
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
requirements:
|
128
|
-
- - "~>"
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: '3.11'
|
131
117
|
- !ruby/object:Gem::Dependency
|
132
118
|
name: bundler
|
133
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,54 +128,34 @@ dependencies:
|
|
142
128
|
- - ">="
|
143
129
|
- !ruby/object:Gem::Version
|
144
130
|
version: '1.16'
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: coveralls
|
147
|
-
requirement: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - "~>"
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: '0.8'
|
152
|
-
type: :development
|
153
|
-
prerelease: false
|
154
|
-
version_requirements: !ruby/object:Gem::Requirement
|
155
|
-
requirements:
|
156
|
-
- - "~>"
|
157
|
-
- !ruby/object:Gem::Version
|
158
|
-
version: '0.8'
|
159
131
|
- !ruby/object:Gem::Dependency
|
160
132
|
name: rake
|
161
133
|
requirement: !ruby/object:Gem::Requirement
|
162
134
|
requirements:
|
163
|
-
- - "
|
135
|
+
- - ">="
|
164
136
|
- !ruby/object:Gem::Version
|
165
137
|
version: '12.3'
|
166
138
|
type: :development
|
167
139
|
prerelease: false
|
168
140
|
version_requirements: !ruby/object:Gem::Requirement
|
169
141
|
requirements:
|
170
|
-
- - "
|
142
|
+
- - ">="
|
171
143
|
- !ruby/object:Gem::Version
|
172
144
|
version: '12.3'
|
173
145
|
- !ruby/object:Gem::Dependency
|
174
|
-
name:
|
146
|
+
name: rexml
|
175
147
|
requirement: !ruby/object:Gem::Requirement
|
176
148
|
requirements:
|
177
|
-
- - "
|
178
|
-
- !ruby/object:Gem::Version
|
179
|
-
version: '5.0'
|
180
|
-
- - "<"
|
149
|
+
- - "~>"
|
181
150
|
- !ruby/object:Gem::Version
|
182
|
-
version: '
|
151
|
+
version: '3.2'
|
183
152
|
type: :development
|
184
153
|
prerelease: false
|
185
154
|
version_requirements: !ruby/object:Gem::Requirement
|
186
155
|
requirements:
|
187
|
-
- - "
|
188
|
-
- !ruby/object:Gem::Version
|
189
|
-
version: '5.0'
|
190
|
-
- - "<"
|
156
|
+
- - "~>"
|
191
157
|
- !ruby/object:Gem::Version
|
192
|
-
version: '
|
158
|
+
version: '3.2'
|
193
159
|
- !ruby/object:Gem::Dependency
|
194
160
|
name: rspec
|
195
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -247,21 +213,27 @@ dependencies:
|
|
247
213
|
- !ruby/object:Gem::Version
|
248
214
|
version: '0'
|
249
215
|
- !ruby/object:Gem::Dependency
|
250
|
-
name:
|
216
|
+
name: rubocop-lts
|
251
217
|
requirement: !ruby/object:Gem::Requirement
|
252
218
|
requirements:
|
253
219
|
- - ">="
|
254
220
|
- !ruby/object:Gem::Version
|
255
|
-
version:
|
221
|
+
version: 2.0.3
|
222
|
+
- - "~>"
|
223
|
+
- !ruby/object:Gem::Version
|
224
|
+
version: '2.0'
|
256
225
|
type: :development
|
257
226
|
prerelease: false
|
258
227
|
version_requirements: !ruby/object:Gem::Requirement
|
259
228
|
requirements:
|
260
229
|
- - ">="
|
261
230
|
- !ruby/object:Gem::Version
|
262
|
-
version:
|
231
|
+
version: 2.0.3
|
232
|
+
- - "~>"
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '2.0'
|
263
235
|
- !ruby/object:Gem::Dependency
|
264
|
-
name:
|
236
|
+
name: silent_stream
|
265
237
|
requirement: !ruby/object:Gem::Requirement
|
266
238
|
requirements:
|
267
239
|
- - ">="
|
@@ -284,8 +256,10 @@ extra_rdoc_files: []
|
|
284
256
|
files:
|
285
257
|
- CHANGELOG.md
|
286
258
|
- CODE_OF_CONDUCT.md
|
259
|
+
- CONTRIBUTING.md
|
287
260
|
- LICENSE
|
288
261
|
- README.md
|
262
|
+
- SECURITY.md
|
289
263
|
- lib/oauth2.rb
|
290
264
|
- lib/oauth2/access_token.rb
|
291
265
|
- lib/oauth2/authenticator.rb
|
@@ -300,29 +274,31 @@ files:
|
|
300
274
|
- lib/oauth2/strategy/implicit.rb
|
301
275
|
- lib/oauth2/strategy/password.rb
|
302
276
|
- lib/oauth2/version.rb
|
303
|
-
- spec/helper.rb
|
304
|
-
- spec/oauth2/access_token_spec.rb
|
305
|
-
- spec/oauth2/authenticator_spec.rb
|
306
|
-
- spec/oauth2/client_spec.rb
|
307
|
-
- spec/oauth2/mac_token_spec.rb
|
308
|
-
- spec/oauth2/response_spec.rb
|
309
|
-
- spec/oauth2/strategy/assertion_spec.rb
|
310
|
-
- spec/oauth2/strategy/auth_code_spec.rb
|
311
|
-
- spec/oauth2/strategy/base_spec.rb
|
312
|
-
- spec/oauth2/strategy/client_credentials_spec.rb
|
313
|
-
- spec/oauth2/strategy/implicit_spec.rb
|
314
|
-
- spec/oauth2/strategy/password_spec.rb
|
315
|
-
- spec/oauth2/version_spec.rb
|
316
277
|
homepage: https://github.com/oauth-xx/oauth2
|
317
278
|
licenses:
|
318
279
|
- MIT
|
319
280
|
metadata:
|
320
281
|
bug_tracker_uri: https://github.com/oauth-xx/oauth2/issues
|
321
|
-
changelog_uri: https://github.com/oauth-xx/oauth2/blob/v1.4.
|
322
|
-
documentation_uri: https://www.rubydoc.info/gems/oauth2/1.4.
|
323
|
-
source_code_uri: https://github.com/oauth-xx/oauth2/tree/v1.4.
|
282
|
+
changelog_uri: https://github.com/oauth-xx/oauth2/blob/v1.4.10/CHANGELOG.md
|
283
|
+
documentation_uri: https://www.rubydoc.info/gems/oauth2/1.4.10
|
284
|
+
source_code_uri: https://github.com/oauth-xx/oauth2/tree/v1.4.10
|
324
285
|
wiki_uri: https://github.com/oauth-xx/oauth2/wiki
|
325
|
-
|
286
|
+
funding_uri: https://github.com/sponsors/pboling
|
287
|
+
rubygems_mfa_required: 'true'
|
288
|
+
post_install_message: |2+
|
289
|
+
|
290
|
+
You have installed oauth2 version 1.4.10, which is EOL.
|
291
|
+
No further support is anticipated for the 1.4.x series.
|
292
|
+
|
293
|
+
OAuth2 version 2 is released.
|
294
|
+
There are BREAKING changes, but most will not encounter them, and upgrading should be easy!
|
295
|
+
|
296
|
+
Please see:
|
297
|
+
• https://github.com/oauth-xx/oauth2#what-is-new-for-v20
|
298
|
+
• https://github.com/oauth-xx/oauth2/blob/master/CHANGELOG.md
|
299
|
+
|
300
|
+
Please upgrade, report issues, and support the project! Thanks, |7eter l-|. l3oling
|
301
|
+
|
326
302
|
rdoc_options: []
|
327
303
|
require_paths:
|
328
304
|
- lib
|
@@ -335,23 +311,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
335
311
|
requirements:
|
336
312
|
- - ">="
|
337
313
|
- !ruby/object:Gem::Version
|
338
|
-
version:
|
314
|
+
version: '0'
|
339
315
|
requirements: []
|
340
|
-
rubygems_version: 3.
|
341
|
-
signing_key:
|
316
|
+
rubygems_version: 3.3.16
|
317
|
+
signing_key:
|
342
318
|
specification_version: 4
|
343
319
|
summary: A Ruby wrapper for the OAuth 2.0 protocol.
|
344
|
-
test_files:
|
345
|
-
- spec/helper.rb
|
346
|
-
- spec/oauth2/client_spec.rb
|
347
|
-
- spec/oauth2/version_spec.rb
|
348
|
-
- spec/oauth2/authenticator_spec.rb
|
349
|
-
- spec/oauth2/mac_token_spec.rb
|
350
|
-
- spec/oauth2/access_token_spec.rb
|
351
|
-
- spec/oauth2/response_spec.rb
|
352
|
-
- spec/oauth2/strategy/password_spec.rb
|
353
|
-
- spec/oauth2/strategy/client_credentials_spec.rb
|
354
|
-
- spec/oauth2/strategy/assertion_spec.rb
|
355
|
-
- spec/oauth2/strategy/implicit_spec.rb
|
356
|
-
- spec/oauth2/strategy/auth_code_spec.rb
|
357
|
-
- spec/oauth2/strategy/base_spec.rb
|
320
|
+
test_files: []
|
data/spec/helper.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
DEBUG = ENV['DEBUG'] == 'true'
|
2
|
-
|
3
|
-
ruby_version = Gem::Version.new(RUBY_VERSION)
|
4
|
-
|
5
|
-
if ruby_version >= Gem::Version.new('2.7')
|
6
|
-
require 'simplecov'
|
7
|
-
require 'coveralls'
|
8
|
-
|
9
|
-
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
|
10
|
-
|
11
|
-
SimpleCov.start do
|
12
|
-
add_filter '/spec'
|
13
|
-
minimum_coverage(95)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
require 'byebug' if DEBUG && ruby_version >= Gem::Version.new('2.4')
|
18
|
-
|
19
|
-
require 'oauth2'
|
20
|
-
require 'addressable/uri'
|
21
|
-
require 'rspec'
|
22
|
-
require 'rspec/stubbed_env'
|
23
|
-
require 'silent_stream'
|
24
|
-
|
25
|
-
RSpec.configure do |config|
|
26
|
-
config.expect_with :rspec do |c|
|
27
|
-
c.syntax = :expect
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
Faraday.default_adapter = :test
|
32
|
-
|
33
|
-
RSpec.configure do |conf|
|
34
|
-
conf.include SilentStream
|
35
|
-
end
|
36
|
-
|
37
|
-
VERBS = [:get, :post, :put, :delete].freeze
|
@@ -1,216 +0,0 @@
|
|
1
|
-
describe OAuth2::AccessToken do
|
2
|
-
subject { described_class.new(client, token) }
|
3
|
-
|
4
|
-
let(:token) { 'monkey' }
|
5
|
-
let(:refresh_body) { MultiJson.encode(:access_token => 'refreshed_foo', :expires_in => 600, :refresh_token => 'refresh_bar') }
|
6
|
-
let(:client) do
|
7
|
-
OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com') do |builder|
|
8
|
-
builder.request :url_encoded
|
9
|
-
builder.adapter :test do |stub|
|
10
|
-
VERBS.each do |verb|
|
11
|
-
stub.send(verb, '/token/header') { |env| [200, {}, env[:request_headers]['Authorization']] }
|
12
|
-
stub.send(verb, "/token/query?access_token=#{token}") { |env| [200, {}, Addressable::URI.parse(env[:url]).query_values['access_token']] }
|
13
|
-
stub.send(verb, '/token/query_string') { |env| [200, {}, CGI.unescape(Addressable::URI.parse(env[:url]).query)] }
|
14
|
-
stub.send(verb, '/token/body') { |env| [200, {}, env[:body]] }
|
15
|
-
end
|
16
|
-
stub.post('/oauth/token') { |env| [200, {'Content-Type' => 'application/json'}, refresh_body] }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#initialize' do
|
22
|
-
it 'assigns client and token' do
|
23
|
-
expect(subject.client).to eq(client)
|
24
|
-
expect(subject.token).to eq(token)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'assigns extra params' do
|
28
|
-
target = described_class.new(client, token, 'foo' => 'bar')
|
29
|
-
expect(target.params).to include('foo')
|
30
|
-
expect(target.params['foo']).to eq('bar')
|
31
|
-
end
|
32
|
-
|
33
|
-
def assert_initialized_token(target) # rubocop:disable Metrics/AbcSize
|
34
|
-
expect(target.token).to eq(token)
|
35
|
-
expect(target).to be_expires
|
36
|
-
expect(target.params.keys).to include('foo')
|
37
|
-
expect(target.params['foo']).to eq('bar')
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'initializes with a Hash' do
|
41
|
-
hash = {:access_token => token, :expires_at => Time.now.to_i + 200, 'foo' => 'bar'}
|
42
|
-
target = described_class.from_hash(client, hash)
|
43
|
-
assert_initialized_token(target)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'from_hash does not modify opts hash' do
|
47
|
-
hash = {:access_token => token, :expires_at => Time.now.to_i}
|
48
|
-
hash_before = hash.dup
|
49
|
-
described_class.from_hash(client, hash)
|
50
|
-
expect(hash).to eq(hash_before)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'initializes with a form-urlencoded key/value string' do
|
54
|
-
kvform = "access_token=#{token}&expires_at=#{Time.now.to_i + 200}&foo=bar"
|
55
|
-
target = described_class.from_kvform(client, kvform)
|
56
|
-
assert_initialized_token(target)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'sets options' do
|
60
|
-
target = described_class.new(client, token, :param_name => 'foo', :header_format => 'Bearer %', :mode => :body)
|
61
|
-
expect(target.options[:param_name]).to eq('foo')
|
62
|
-
expect(target.options[:header_format]).to eq('Bearer %')
|
63
|
-
expect(target.options[:mode]).to eq(:body)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'does not modify opts hash' do
|
67
|
-
opts = {:param_name => 'foo', :header_format => 'Bearer %', :mode => :body}
|
68
|
-
opts_before = opts.dup
|
69
|
-
described_class.new(client, token, opts)
|
70
|
-
expect(opts).to eq(opts_before)
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'expires_at' do
|
74
|
-
let(:expires_at) { 1_361_396_829 }
|
75
|
-
let(:hash) do
|
76
|
-
{
|
77
|
-
:access_token => token,
|
78
|
-
:expires_at => expires_at.to_s,
|
79
|
-
'foo' => 'bar',
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'initializes with an integer timestamp expires_at' do
|
84
|
-
target = described_class.from_hash(client, hash.merge(:expires_at => expires_at))
|
85
|
-
assert_initialized_token(target)
|
86
|
-
expect(target.expires_at).to eql(expires_at)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'initializes with a string timestamp expires_at' do
|
90
|
-
target = described_class.from_hash(client, hash)
|
91
|
-
assert_initialized_token(target)
|
92
|
-
expect(target.expires_at).to eql(expires_at)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'initializes with a string time expires_at' do
|
96
|
-
target = described_class.from_hash(client, hash.merge(:expires_at => Time.at(expires_at).iso8601))
|
97
|
-
assert_initialized_token(target)
|
98
|
-
expect(target.expires_at).to eql(expires_at)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe '#request' do
|
104
|
-
context 'with :mode => :header' do
|
105
|
-
before do
|
106
|
-
subject.options[:mode] = :header
|
107
|
-
end
|
108
|
-
|
109
|
-
VERBS.each do |verb|
|
110
|
-
it "sends the token in the Authorization header for a #{verb.to_s.upcase} request" do
|
111
|
-
expect(subject.post('/token/header').body).to include(token)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'with :mode => :query' do
|
117
|
-
before do
|
118
|
-
subject.options[:mode] = :query
|
119
|
-
end
|
120
|
-
|
121
|
-
VERBS.each do |verb|
|
122
|
-
it "sends the token in the Authorization header for a #{verb.to_s.upcase} request" do
|
123
|
-
expect(subject.post('/token/query').body).to eq(token)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "sends a #{verb.to_s.upcase} request and options[:param_name] include [number]." do
|
127
|
-
subject.options[:param_name] = 'auth[1]'
|
128
|
-
expect(subject.__send__(verb, '/token/query_string').body).to include("auth[1]=#{token}")
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context 'with :mode => :body' do
|
134
|
-
before do
|
135
|
-
subject.options[:mode] = :body
|
136
|
-
end
|
137
|
-
|
138
|
-
VERBS.each do |verb|
|
139
|
-
it "sends the token in the Authorization header for a #{verb.to_s.upcase} request" do
|
140
|
-
expect(subject.post('/token/body').body.split('=').last).to eq(token)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'params include [number]' do
|
146
|
-
VERBS.each do |verb|
|
147
|
-
it "sends #{verb.to_s.upcase} correct query" do
|
148
|
-
expect(subject.__send__(verb, '/token/query_string', :params => {'foo[bar][1]' => 'val'}).body).to include('foo[bar][1]=val')
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe '#expires?' do
|
155
|
-
it 'is false if there is no expires_at' do
|
156
|
-
expect(described_class.new(client, token)).not_to be_expires
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'is true if there is an expires_in' do
|
160
|
-
expect(described_class.new(client, token, :refresh_token => 'abaca', :expires_in => 600)).to be_expires
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'is true if there is an expires_at' do
|
164
|
-
expect(described_class.new(client, token, :refresh_token => 'abaca', :expires_in => Time.now.getutc.to_i + 600)).to be_expires
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe '#expired?' do
|
169
|
-
it 'is false if there is no expires_in or expires_at' do
|
170
|
-
expect(described_class.new(client, token)).not_to be_expired
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'is false if expires_in is in the future' do
|
174
|
-
expect(described_class.new(client, token, :refresh_token => 'abaca', :expires_in => 10_800)).not_to be_expired
|
175
|
-
end
|
176
|
-
|
177
|
-
it 'is true if expires_at is in the past' do
|
178
|
-
access = described_class.new(client, token, :refresh_token => 'abaca', :expires_in => 600)
|
179
|
-
@now = Time.now + 10_800
|
180
|
-
allow(Time).to receive(:now).and_return(@now)
|
181
|
-
expect(access).to be_expired
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe '#refresh!' do
|
186
|
-
let(:access) do
|
187
|
-
described_class.new(client, token, :refresh_token => 'abaca',
|
188
|
-
:expires_in => 600,
|
189
|
-
:param_name => 'o_param')
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'returns a refresh token with appropriate values carried over' do
|
193
|
-
refreshed = access.refresh!
|
194
|
-
expect(access.client).to eq(refreshed.client)
|
195
|
-
expect(access.options[:param_name]).to eq(refreshed.options[:param_name])
|
196
|
-
end
|
197
|
-
|
198
|
-
context 'with a nil refresh_token in the response' do
|
199
|
-
let(:refresh_body) { MultiJson.encode(:access_token => 'refreshed_foo', :expires_in => 600, :refresh_token => nil) }
|
200
|
-
|
201
|
-
it 'copies the refresh_token from the original token' do
|
202
|
-
refreshed = access.refresh!
|
203
|
-
|
204
|
-
expect(refreshed.refresh_token).to eq(access.refresh_token)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe '#to_hash' do
|
210
|
-
it 'return a hash equals to the hash used to initialize access token' do
|
211
|
-
hash = {:access_token => token, :refresh_token => 'foobar', :expires_at => Time.now.to_i + 200, 'foo' => 'bar'}
|
212
|
-
access_token = described_class.from_hash(client, hash.clone)
|
213
|
-
expect(access_token.to_hash).to eq(hash)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
describe OAuth2::Authenticator do
|
2
|
-
subject do
|
3
|
-
described_class.new(client_id, client_secret, mode)
|
4
|
-
end
|
5
|
-
|
6
|
-
let(:client_id) { 'foo' }
|
7
|
-
let(:client_secret) { 'bar' }
|
8
|
-
let(:mode) { :undefined }
|
9
|
-
|
10
|
-
it 'raises NotImplementedError for unknown authentication mode' do
|
11
|
-
expect { subject.apply({}) }.to raise_error(NotImplementedError)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#apply' do
|
15
|
-
context 'with parameter-based authentication' do
|
16
|
-
let(:mode) { :request_body }
|
17
|
-
|
18
|
-
it 'adds client_id and client_secret to params' do
|
19
|
-
output = subject.apply({})
|
20
|
-
expect(output).to eq('client_id' => 'foo', 'client_secret' => 'bar')
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'does not overwrite existing credentials' do
|
24
|
-
input = {'client_secret' => 's3cr3t'}
|
25
|
-
output = subject.apply(input)
|
26
|
-
expect(output).to eq('client_id' => 'foo', 'client_secret' => 's3cr3t')
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'preserves other parameters' do
|
30
|
-
input = {'state' => '42', :headers => {'A' => 'b'}}
|
31
|
-
output = subject.apply(input)
|
32
|
-
expect(output).to eq(
|
33
|
-
'client_id' => 'foo',
|
34
|
-
'client_secret' => 'bar',
|
35
|
-
'state' => '42',
|
36
|
-
:headers => {'A' => 'b'}
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'using tls client authentication' do
|
41
|
-
let(:mode) { :tls_client_auth }
|
42
|
-
|
43
|
-
it 'does not add client_secret' do
|
44
|
-
output = subject.apply({})
|
45
|
-
expect(output).to eq('client_id' => 'foo')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'using private key jwt authentication' do
|
50
|
-
let(:mode) { :private_key_jwt }
|
51
|
-
|
52
|
-
it 'does not add client_secret or client_id' do
|
53
|
-
output = subject.apply({})
|
54
|
-
expect(output).to eq({})
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'with Basic authentication' do
|
60
|
-
let(:mode) { :basic_auth }
|
61
|
-
let(:header) { 'Basic ' + Base64.encode64("#{client_id}:#{client_secret}").delete("\n") }
|
62
|
-
|
63
|
-
it 'encodes credentials in headers' do
|
64
|
-
output = subject.apply({})
|
65
|
-
expect(output).to eq(:headers => {'Authorization' => header})
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'does not overwrite existing credentials' do
|
69
|
-
input = {:headers => {'Authorization' => 'Bearer abc123'}}
|
70
|
-
output = subject.apply(input)
|
71
|
-
expect(output).to eq(:headers => {'Authorization' => 'Bearer abc123'})
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'does not overwrite existing params or headers' do
|
75
|
-
input = {'state' => '42', :headers => {'A' => 'b'}}
|
76
|
-
output = subject.apply(input)
|
77
|
-
expect(output).to eq(
|
78
|
-
'state' => '42',
|
79
|
-
:headers => {'A' => 'b', 'Authorization' => header}
|
80
|
-
)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|