rack-oauth2 2.0.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/VERSION +1 -1
- data/lib/rack/oauth2/access_token/mtls.rb +2 -2
- data/lib/rack/oauth2/access_token.rb +3 -4
- data/lib/rack/oauth2/client.rb +15 -12
- data/lib/rack/oauth2/server/extension/pkce.rb +1 -1
- data/lib/rack/oauth2.rb +1 -0
- data/spec/helpers/webmock_helper.rb +8 -2
- data/spec/mock_response/{blank → blank.txt} +0 -0
- data/spec/rack/oauth2/access_token/authenticator_spec.rb +0 -9
- data/spec/rack/oauth2/client_spec.rb +58 -64
- metadata +4 -13
- data/lib/rack/oauth2/access_token/legacy.rb +0 -19
- data/spec/mock_response/tokens/legacy.json +0 -5
- data/spec/mock_response/tokens/legacy.txt +0 -1
- data/spec/mock_response/tokens/legacy_without_expires_in.txt +0 -1
- data/spec/rack/oauth2/access_token/legacy_spec.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45ba67ac4566f374465673cc5711e71c15006bbe966531a4c1de2473206879b2
|
4
|
+
data.tar.gz: 56f8718f283533c369b1743dfd86499e49e5d828a83ac060fa919fac57a935d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63316467536c2c98cddea9b2b7907b3ff5fd6b53b892bd338709e1f7a6b014aa4dc20d71b12cd01ffac502c1ab0964218aac7ff6a0e81141ff8aa10e80557cdd
|
7
|
+
data.tar.gz: 97e685531853c4837a0e86636c865827033e25f646c4572d254e2584a811f937faa6dc7fe780742814bd9657066c9fc16394723ba87029605761d5acf2d490f7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [2.1.0] - 2022-10-10
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- accept local_http_config on Rack::OAuth2::Client#access_token! & revoke! to support custom headers etc. by @nov in https://github.com/nov/rack-oauth2/pull/93
|
8
|
+
|
9
|
+
## [2.0.1] - 2022-10-09
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
- changes for mTLS on faraday by @nov in https://github.com/nov/rack-oauth2/pull/92
|
14
|
+
|
3
15
|
## [2.0.0] - 2022-10-09
|
4
16
|
|
5
17
|
### Added
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0
|
1
|
+
2.2.0
|
@@ -7,8 +7,8 @@ module Rack
|
|
7
7
|
def initialize(attributes = {})
|
8
8
|
super
|
9
9
|
self.token_type = :bearer
|
10
|
-
|
11
|
-
|
10
|
+
http_client.ssl.client_key = private_key
|
11
|
+
http_client.ssl.client_cert = certificate
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -5,7 +5,7 @@ module Rack
|
|
5
5
|
attr_required :access_token, :token_type
|
6
6
|
attr_optional :refresh_token, :expires_in, :scope
|
7
7
|
attr_accessor :raw_attributes
|
8
|
-
delegate :get, :patch, :post, :put, :delete, to: :
|
8
|
+
delegate :get, :patch, :post, :put, :delete, to: :http_client
|
9
9
|
|
10
10
|
alias_method :to_s, :access_token
|
11
11
|
|
@@ -18,8 +18,8 @@ module Rack
|
|
18
18
|
attr_missing!
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
@
|
21
|
+
def http_client
|
22
|
+
@http_client ||= Rack::OAuth2.http_client("#{self.class} (#{VERSION})") do |faraday|
|
23
23
|
Authenticator.new(self).authenticate(faraday)
|
24
24
|
end
|
25
25
|
end
|
@@ -39,5 +39,4 @@ end
|
|
39
39
|
|
40
40
|
require 'rack/oauth2/access_token/authenticator'
|
41
41
|
require 'rack/oauth2/access_token/bearer'
|
42
|
-
require 'rack/oauth2/access_token/legacy'
|
43
42
|
require 'rack/oauth2/access_token/mtls'
|
data/lib/rack/oauth2/client.rb
CHANGED
@@ -74,7 +74,13 @@ module Rack
|
|
74
74
|
params.merge! @grant.as_json
|
75
75
|
params.merge! options
|
76
76
|
handle_response do
|
77
|
-
http_client.post(
|
77
|
+
http_client.post(
|
78
|
+
absolute_uri_for(token_endpoint),
|
79
|
+
Util.compact_hash(params),
|
80
|
+
headers
|
81
|
+
) do |req|
|
82
|
+
yield req if block_given?
|
83
|
+
end
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|
@@ -107,7 +113,9 @@ module Rack
|
|
107
113
|
absolute_uri_for(revocation_endpoint),
|
108
114
|
Util.compact_hash(params),
|
109
115
|
headers
|
110
|
-
)
|
116
|
+
) do |req|
|
117
|
+
yield req if block_given?
|
118
|
+
end
|
111
119
|
end
|
112
120
|
end
|
113
121
|
|
@@ -130,7 +138,7 @@ module Rack
|
|
130
138
|
# Using Array#extract_options! for backward compatibility.
|
131
139
|
# Until v1.0.5, the first argument was 'client_auth_method' in scalar.
|
132
140
|
options = args.extract_options!
|
133
|
-
client_auth_method = args.first || options.delete(:client_auth_method)
|
141
|
+
client_auth_method = args.first || options.delete(:client_auth_method)&.to_sym || :basic
|
134
142
|
|
135
143
|
case client_auth_method
|
136
144
|
when :basic
|
@@ -205,24 +213,19 @@ module Rack
|
|
205
213
|
end
|
206
214
|
|
207
215
|
def handle_success_response(response)
|
208
|
-
token_hash =
|
209
|
-
case (@forced_token_type || token_hash[:token_type])
|
216
|
+
token_hash = response.body.with_indifferent_access
|
217
|
+
case (@forced_token_type || token_hash[:token_type])&.downcase
|
210
218
|
when 'bearer'
|
211
219
|
AccessToken::Bearer.new(token_hash)
|
212
|
-
when nil
|
213
|
-
AccessToken::Legacy.new(token_hash)
|
214
220
|
else
|
215
221
|
raise 'Unknown Token Type'
|
216
222
|
end
|
217
|
-
rescue JSON::ParserError
|
218
|
-
# NOTE: Facebook support (They don't use JSON as token response)
|
219
|
-
AccessToken::Legacy.new Rack::Utils.parse_nested_query(response.body).with_indifferent_access
|
220
223
|
end
|
221
224
|
|
222
225
|
def handle_error_response(response)
|
223
|
-
error =
|
226
|
+
error = response.body.with_indifferent_access
|
224
227
|
raise Error.new(response.status, error)
|
225
|
-
rescue
|
228
|
+
rescue Faraday::ParsingError, NoMethodError
|
226
229
|
raise Error.new(response.status, error: 'Unknown', error_description: response.body)
|
227
230
|
end
|
228
231
|
end
|
@@ -27,7 +27,7 @@ module Rack
|
|
27
27
|
|
28
28
|
def verify_code_verifier!(code_challenge, code_challenge_method = :S256)
|
29
29
|
if code_verifier.present? || code_challenge.present?
|
30
|
-
case code_challenge_method
|
30
|
+
case code_challenge_method&.to_sym
|
31
31
|
when :S256
|
32
32
|
code_challenge == Util.urlsafe_base64_encode(
|
33
33
|
OpenSSL::Digest::SHA256.digest(code_verifier.to_s)
|
data/lib/rack/oauth2.rb
CHANGED
@@ -44,6 +44,7 @@ module Rack
|
|
44
44
|
Faraday.new(headers: {user_agent: agent_name}) do |faraday|
|
45
45
|
faraday.request :url_encoded
|
46
46
|
faraday.request :json
|
47
|
+
faraday.response :json
|
47
48
|
faraday.response :logger, Rack::OAuth2.logger, {bodies: true} if debugging?
|
48
49
|
faraday.adapter Faraday.default_adapter
|
49
50
|
local_http_config&.call(faraday)
|
@@ -13,7 +13,7 @@ module WebMockHelper
|
|
13
13
|
|
14
14
|
def request_for(method, options = {})
|
15
15
|
request = {}
|
16
|
-
params = options
|
16
|
+
params = options&.[](:params) || {}
|
17
17
|
case method
|
18
18
|
when :post, :put, :delete
|
19
19
|
request[:body] = params
|
@@ -28,7 +28,13 @@ module WebMockHelper
|
|
28
28
|
|
29
29
|
def response_for(response_file, options = {})
|
30
30
|
response = {}
|
31
|
-
|
31
|
+
format = options[:format] || :json
|
32
|
+
if format == :json
|
33
|
+
response[:headers] = {
|
34
|
+
'Content-Type': 'application/json'
|
35
|
+
}
|
36
|
+
end
|
37
|
+
response[:body] = File.new(File.join(File.dirname(__FILE__), '../mock_response', "#{response_file}.#{format}"))
|
32
38
|
if options[:status]
|
33
39
|
response[:status] = options[:status]
|
34
40
|
end
|
File without changes
|
@@ -12,15 +12,6 @@ describe Rack::OAuth2::AccessToken::Authenticator do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context 'when Legacy token is given' do
|
16
|
-
let(:token) do
|
17
|
-
Rack::OAuth2::AccessToken::Legacy.new(
|
18
|
-
access_token: 'access_token'
|
19
|
-
)
|
20
|
-
end
|
21
|
-
it_behaves_like :authenticator
|
22
|
-
end
|
23
|
-
|
24
15
|
context 'when Bearer token is given' do
|
25
16
|
let(:token) do
|
26
17
|
Rack::OAuth2::AccessToken::Bearer.new(
|
@@ -93,7 +93,7 @@ describe Rack::OAuth2::Client do
|
|
93
93
|
mock_response(
|
94
94
|
:post,
|
95
95
|
'https://server.example.com/oauth2/token',
|
96
|
-
'tokens/bearer
|
96
|
+
'tokens/bearer',
|
97
97
|
request_header: {
|
98
98
|
'Authorization' => 'Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ='
|
99
99
|
}
|
@@ -109,7 +109,7 @@ describe Rack::OAuth2::Client do
|
|
109
109
|
mock_response(
|
110
110
|
:post,
|
111
111
|
'https://server.example.com/oauth2/token',
|
112
|
-
'tokens/bearer
|
112
|
+
'tokens/bearer',
|
113
113
|
request_header: {
|
114
114
|
'Authorization' => 'Basic aHR0cHMlM0ElMkYlMkZjbGllbnQuZXhhbXBsZS5jb206Y2xpZW50X3NlY3JldA=='
|
115
115
|
}
|
@@ -127,7 +127,7 @@ describe Rack::OAuth2::Client do
|
|
127
127
|
mock_response(
|
128
128
|
:post,
|
129
129
|
'https://server.example.com/oauth2/token',
|
130
|
-
'tokens/bearer
|
130
|
+
'tokens/bearer',
|
131
131
|
request_header: {
|
132
132
|
'Authorization' => 'Basic aHR0cHM6Ly9jbGllbnQuZXhhbXBsZS5jb206Y2xpZW50X3NlY3JldA=='
|
133
133
|
}
|
@@ -143,7 +143,7 @@ describe Rack::OAuth2::Client do
|
|
143
143
|
mock_response(
|
144
144
|
:post,
|
145
145
|
'https://server.example.com/oauth2/token',
|
146
|
-
'tokens/bearer
|
146
|
+
'tokens/bearer',
|
147
147
|
params: {
|
148
148
|
client_assertion: /^eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9\..+/, # NOTE: HS256
|
149
149
|
client_assertion_type: Rack::OAuth2::URN::ClientAssertionType::JWT_BEARER,
|
@@ -171,7 +171,7 @@ describe Rack::OAuth2::Client do
|
|
171
171
|
mock_response(
|
172
172
|
:post,
|
173
173
|
'https://server.example.com/oauth2/token',
|
174
|
-
'tokens/bearer
|
174
|
+
'tokens/bearer',
|
175
175
|
params: {
|
176
176
|
client_assertion: /^eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9\..+/, # NOTE: RS256
|
177
177
|
client_assertion_type: Rack::OAuth2::URN::ClientAssertionType::JWT_BEARER,
|
@@ -198,7 +198,7 @@ describe Rack::OAuth2::Client do
|
|
198
198
|
mock_response(
|
199
199
|
:post,
|
200
200
|
'https://server.example.com/oauth2/token',
|
201
|
-
'tokens/bearer
|
201
|
+
'tokens/bearer',
|
202
202
|
params: {
|
203
203
|
client_assertion: /^eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9\..+/, # NOTE: ES256
|
204
204
|
client_assertion_type: Rack::OAuth2::URN::ClientAssertionType::JWT_BEARER,
|
@@ -225,7 +225,7 @@ describe Rack::OAuth2::Client do
|
|
225
225
|
mock_response(
|
226
226
|
:post,
|
227
227
|
'https://server.example.com/oauth2/token',
|
228
|
-
'tokens/bearer
|
228
|
+
'tokens/bearer',
|
229
229
|
params: {
|
230
230
|
client_assertion: 'any.jwt.assertion',
|
231
231
|
client_assertion_type: Rack::OAuth2::URN::ClientAssertionType::JWT_BEARER,
|
@@ -244,7 +244,7 @@ describe Rack::OAuth2::Client do
|
|
244
244
|
mock_response(
|
245
245
|
:post,
|
246
246
|
'https://server.example.com/oauth2/token',
|
247
|
-
'tokens/bearer
|
247
|
+
'tokens/bearer',
|
248
248
|
params: {
|
249
249
|
client_id: 'client_id',
|
250
250
|
client_secret: 'client_secret',
|
@@ -262,7 +262,7 @@ describe Rack::OAuth2::Client do
|
|
262
262
|
mock_response(
|
263
263
|
:post,
|
264
264
|
'https://server.example.com/oauth2/token',
|
265
|
-
'tokens/bearer
|
265
|
+
'tokens/bearer',
|
266
266
|
params: {
|
267
267
|
client_id: 'client_id',
|
268
268
|
client_secret: 'client_secret',
|
@@ -282,7 +282,7 @@ describe Rack::OAuth2::Client do
|
|
282
282
|
mock_response(
|
283
283
|
:post,
|
284
284
|
'https://server.example.com/oauth2/token',
|
285
|
-
'tokens/bearer
|
285
|
+
'tokens/bearer',
|
286
286
|
params: {
|
287
287
|
grant_type: 'client_credentials',
|
288
288
|
scope: 'a b'
|
@@ -298,7 +298,7 @@ describe Rack::OAuth2::Client do
|
|
298
298
|
mock_response(
|
299
299
|
:post,
|
300
300
|
'https://server.example.com/oauth2/token',
|
301
|
-
'tokens/bearer
|
301
|
+
'tokens/bearer',
|
302
302
|
params: {
|
303
303
|
grant_type: 'client_credentials',
|
304
304
|
resource: 'something'
|
@@ -309,81 +309,49 @@ describe Rack::OAuth2::Client do
|
|
309
309
|
end
|
310
310
|
end
|
311
311
|
|
312
|
-
context '
|
313
|
-
|
314
|
-
client.authorization_code = 'code'
|
312
|
+
context 'local_http_config handling' do
|
313
|
+
it do
|
315
314
|
mock_response(
|
316
315
|
:post,
|
317
316
|
'https://server.example.com/oauth2/token',
|
318
|
-
'tokens/bearer
|
317
|
+
'tokens/bearer',
|
318
|
+
request_header: {
|
319
|
+
'Authorization' => 'Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=',
|
320
|
+
'X-Foo' => 'bar'
|
321
|
+
}
|
319
322
|
)
|
320
|
-
|
321
|
-
|
322
|
-
its(:token_type) { should == :bearer }
|
323
|
-
its(:access_token) { should == 'access_token' }
|
324
|
-
its(:refresh_token) { should == 'refresh_token' }
|
325
|
-
its(:expires_in) { should == 3600 }
|
326
|
-
|
327
|
-
context 'when token type is "Bearer", not "bearer"' do
|
328
|
-
before do
|
329
|
-
client.authorization_code = 'code'
|
330
|
-
mock_response(
|
331
|
-
:post,
|
332
|
-
'https://server.example.com/oauth2/token',
|
333
|
-
'tokens/_Bearer.json'
|
334
|
-
)
|
323
|
+
client.access_token! do |request|
|
324
|
+
request.headers['X-Foo'] = 'bar'
|
335
325
|
end
|
336
|
-
it { should be_instance_of Rack::OAuth2::AccessToken::Bearer }
|
337
|
-
its(:token_type) { should == :bearer }
|
338
326
|
end
|
339
327
|
end
|
340
328
|
|
341
|
-
context 'when
|
329
|
+
context 'when bearer token is given' do
|
342
330
|
before do
|
343
331
|
client.authorization_code = 'code'
|
344
332
|
mock_response(
|
345
333
|
:post,
|
346
334
|
'https://server.example.com/oauth2/token',
|
347
|
-
'tokens/
|
335
|
+
'tokens/bearer'
|
348
336
|
)
|
349
337
|
end
|
350
|
-
it { should be_instance_of Rack::OAuth2::AccessToken::
|
351
|
-
its(:token_type) { should == :
|
338
|
+
it { should be_instance_of Rack::OAuth2::AccessToken::Bearer }
|
339
|
+
its(:token_type) { should == :bearer }
|
352
340
|
its(:access_token) { should == 'access_token' }
|
353
341
|
its(:refresh_token) { should == 'refresh_token' }
|
354
342
|
its(:expires_in) { should == 3600 }
|
355
343
|
|
356
|
-
context 'when
|
357
|
-
before do
|
358
|
-
client.force_token_type! :bearer
|
359
|
-
end
|
360
|
-
it { should be_instance_of Rack::OAuth2::AccessToken::Bearer }
|
361
|
-
its(:token_type) { should == :bearer }
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
context 'when no-type token is given (key-value)' do
|
366
|
-
before do
|
367
|
-
mock_response(
|
368
|
-
:post,
|
369
|
-
'https://server.example.com/oauth2/token',
|
370
|
-
'tokens/legacy.txt'
|
371
|
-
)
|
372
|
-
end
|
373
|
-
it { should be_instance_of Rack::OAuth2::AccessToken::Legacy }
|
374
|
-
its(:token_type) { should == :legacy }
|
375
|
-
its(:access_token) { should == 'access_token' }
|
376
|
-
its(:expires_in) { should == 3600 }
|
377
|
-
|
378
|
-
context 'when expires_in is not given' do
|
344
|
+
context 'when token type is "Bearer", not "bearer"' do
|
379
345
|
before do
|
346
|
+
client.authorization_code = 'code'
|
380
347
|
mock_response(
|
381
348
|
:post,
|
382
349
|
'https://server.example.com/oauth2/token',
|
383
|
-
'tokens/
|
350
|
+
'tokens/_Bearer'
|
384
351
|
)
|
385
352
|
end
|
386
|
-
|
353
|
+
it { should be_instance_of Rack::OAuth2::AccessToken::Bearer }
|
354
|
+
its(:token_type) { should == :bearer }
|
387
355
|
end
|
388
356
|
end
|
389
357
|
|
@@ -393,7 +361,7 @@ describe Rack::OAuth2::Client do
|
|
393
361
|
mock_response(
|
394
362
|
:post,
|
395
363
|
'https://server.example.com/oauth2/token',
|
396
|
-
'tokens/unknown
|
364
|
+
'tokens/unknown'
|
397
365
|
)
|
398
366
|
end
|
399
367
|
it do
|
@@ -406,7 +374,7 @@ describe Rack::OAuth2::Client do
|
|
406
374
|
mock_response(
|
407
375
|
:post,
|
408
376
|
'https://server.example.com/oauth2/token',
|
409
|
-
'errors/invalid_request
|
377
|
+
'errors/invalid_request',
|
410
378
|
status: 400
|
411
379
|
)
|
412
380
|
end
|
@@ -422,6 +390,7 @@ describe Rack::OAuth2::Client do
|
|
422
390
|
:post,
|
423
391
|
'https://server.example.com/oauth2/token',
|
424
392
|
'blank',
|
393
|
+
format: 'txt',
|
425
394
|
status: 400
|
426
395
|
)
|
427
396
|
end
|
@@ -433,12 +402,36 @@ describe Rack::OAuth2::Client do
|
|
433
402
|
end
|
434
403
|
|
435
404
|
describe '#revoke!' do
|
405
|
+
context 'local_http_config handling' do
|
406
|
+
it do
|
407
|
+
mock_response(
|
408
|
+
:post,
|
409
|
+
'https://server.example.com/oauth2/revoke',
|
410
|
+
'blank',
|
411
|
+
format: 'txt',
|
412
|
+
status: 200,
|
413
|
+
body: {
|
414
|
+
token: 'access_token',
|
415
|
+
token_type_hint: 'access_token'
|
416
|
+
},
|
417
|
+
request_header: {
|
418
|
+
'Authorization' => 'Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=',
|
419
|
+
'X-Foo' => 'bar'
|
420
|
+
}
|
421
|
+
)
|
422
|
+
client.revoke!(access_token: 'access_token') do |request|
|
423
|
+
request.headers['X-Foo'] = 'bar'
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
436
428
|
context 'when access_token given' do
|
437
429
|
before do
|
438
430
|
mock_response(
|
439
431
|
:post,
|
440
432
|
'https://server.example.com/oauth2/revoke',
|
441
433
|
'blank',
|
434
|
+
format: 'txt',
|
442
435
|
status: 200,
|
443
436
|
body: {
|
444
437
|
token: 'access_token',
|
@@ -457,6 +450,7 @@ describe Rack::OAuth2::Client do
|
|
457
450
|
:post,
|
458
451
|
'https://server.example.com/oauth2/revoke',
|
459
452
|
'blank',
|
453
|
+
format: 'txt',
|
460
454
|
status: 200,
|
461
455
|
body: {
|
462
456
|
token: 'refresh_token',
|
@@ -484,7 +478,7 @@ describe Rack::OAuth2::Client do
|
|
484
478
|
mock_response(
|
485
479
|
:post,
|
486
480
|
'https://server.example.com/oauth2/revoke',
|
487
|
-
'errors/invalid_request
|
481
|
+
'errors/invalid_request',
|
488
482
|
status: 400
|
489
483
|
)
|
490
484
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov matake
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -201,7 +201,6 @@ files:
|
|
201
201
|
- lib/rack/oauth2/access_token.rb
|
202
202
|
- lib/rack/oauth2/access_token/authenticator.rb
|
203
203
|
- lib/rack/oauth2/access_token/bearer.rb
|
204
|
-
- lib/rack/oauth2/access_token/legacy.rb
|
205
204
|
- lib/rack/oauth2/access_token/mtls.rb
|
206
205
|
- lib/rack/oauth2/client.rb
|
207
206
|
- lib/rack/oauth2/client/error.rb
|
@@ -250,18 +249,14 @@ files:
|
|
250
249
|
- rack-oauth2.gemspec
|
251
250
|
- spec/helpers/time.rb
|
252
251
|
- spec/helpers/webmock_helper.rb
|
253
|
-
- spec/mock_response/blank
|
252
|
+
- spec/mock_response/blank.txt
|
254
253
|
- spec/mock_response/errors/invalid_request.json
|
255
254
|
- spec/mock_response/resources/fake.txt
|
256
255
|
- spec/mock_response/tokens/_Bearer.json
|
257
256
|
- spec/mock_response/tokens/bearer.json
|
258
|
-
- spec/mock_response/tokens/legacy.json
|
259
|
-
- spec/mock_response/tokens/legacy.txt
|
260
|
-
- spec/mock_response/tokens/legacy_without_expires_in.txt
|
261
257
|
- spec/mock_response/tokens/unknown.json
|
262
258
|
- spec/rack/oauth2/access_token/authenticator_spec.rb
|
263
259
|
- spec/rack/oauth2/access_token/bearer_spec.rb
|
264
|
-
- spec/rack/oauth2/access_token/legacy_spec.rb
|
265
260
|
- spec/rack/oauth2/access_token_spec.rb
|
266
261
|
- spec/rack/oauth2/client/error_spec.rb
|
267
262
|
- spec/rack/oauth2/client/grant/authorization_code_spec.rb
|
@@ -321,18 +316,14 @@ summary: OAuth 2.0 Server & Client Library - Both Bearer token type are supporte
|
|
321
316
|
test_files:
|
322
317
|
- spec/helpers/time.rb
|
323
318
|
- spec/helpers/webmock_helper.rb
|
324
|
-
- spec/mock_response/blank
|
319
|
+
- spec/mock_response/blank.txt
|
325
320
|
- spec/mock_response/errors/invalid_request.json
|
326
321
|
- spec/mock_response/resources/fake.txt
|
327
322
|
- spec/mock_response/tokens/_Bearer.json
|
328
323
|
- spec/mock_response/tokens/bearer.json
|
329
|
-
- spec/mock_response/tokens/legacy.json
|
330
|
-
- spec/mock_response/tokens/legacy.txt
|
331
|
-
- spec/mock_response/tokens/legacy_without_expires_in.txt
|
332
324
|
- spec/mock_response/tokens/unknown.json
|
333
325
|
- spec/rack/oauth2/access_token/authenticator_spec.rb
|
334
326
|
- spec/rack/oauth2/access_token/bearer_spec.rb
|
335
|
-
- spec/rack/oauth2/access_token/legacy_spec.rb
|
336
327
|
- spec/rack/oauth2/access_token_spec.rb
|
337
328
|
- spec/rack/oauth2/client/error_spec.rb
|
338
329
|
- spec/rack/oauth2/client/grant/authorization_code_spec.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Rack
|
2
|
-
module OAuth2
|
3
|
-
class AccessToken
|
4
|
-
class Legacy < AccessToken
|
5
|
-
def initialize(attributes = {})
|
6
|
-
super
|
7
|
-
self.expires_in = (
|
8
|
-
self.expires_in ||
|
9
|
-
attributes[:expires]
|
10
|
-
).try(:to_i)
|
11
|
-
end
|
12
|
-
|
13
|
-
def authenticate(request)
|
14
|
-
request.headers["Authorization"] = "OAuth #{access_token}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
access_token=access_token&expires=3600
|
@@ -1 +0,0 @@
|
|
1
|
-
access_token=access_token
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Rack::OAuth2::AccessToken::Legacy do
|
4
|
-
let :token do
|
5
|
-
Rack::OAuth2::AccessToken::Legacy.new(
|
6
|
-
access_token: 'access_token'
|
7
|
-
)
|
8
|
-
end
|
9
|
-
let(:resource_endpoint) { 'https://server.example.com/resources/fake' }
|
10
|
-
let(:request) { Faraday::Request.new(:post, URI.parse(resource_endpoint), '', {hello: "world"}, {}) }
|
11
|
-
|
12
|
-
describe '#to_s' do
|
13
|
-
subject { token }
|
14
|
-
its(:to_s) { should == token.access_token }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '.authenticate' do
|
18
|
-
it 'should set Authorization header' do
|
19
|
-
expect(request.headers).to receive(:[]=).with('Authorization', 'OAuth access_token')
|
20
|
-
token.authenticate(request)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|