Skip to content

Commit f2c129b

Browse files
committed
accept local_http_config on Rack::OAuth2::Client#access_token! & revoke!
close #80
1 parent 7c4ab57 commit f2c129b

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

lib/rack/oauth2/client.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def force_token_type!(token_type)
6868
@forced_token_type = token_type.to_s
6969
end
7070

71-
def access_token!(*args)
72-
headers, params, http_client, options = authenticated_context_from(*args)
71+
def access_token!(*args, &local_http_config)
72+
headers, params, http_client, options = authenticated_context_from(*args, &local_http_config)
7373
params[:scope] = Array(options.delete(:scope)).join(' ') if options[:scope].present?
7474
params.merge! @grant.as_json
7575
params.merge! options
@@ -82,8 +82,8 @@ def access_token!(*args)
8282
end
8383
end
8484

85-
def revoke!(*args)
86-
headers, params, http_client, options = authenticated_context_from(*args)
85+
def revoke!(*args, &local_http_config)
86+
headers, params, http_client, options = authenticated_context_from(*args, &local_http_config)
8787

8888
params.merge! case
8989
when access_token = options.delete(:access_token)
@@ -126,9 +126,9 @@ def absolute_uri_for(endpoint)
126126
_endpoint_.to_s
127127
end
128128

129-
def authenticated_context_from(*args)
129+
def authenticated_context_from(*args, &local_http_config)
130130
headers, params = {}, {}
131-
http_client = Rack::OAuth2.http_client
131+
http_client = Rack::OAuth2.http_client(&local_http_config)
132132

133133
# NOTE:
134134
# Using Array#extract_options! for backward compatibility.

spec/rack/oauth2/client_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,23 @@
309309
end
310310
end
311311

312+
context 'local_http_config handling' do
313+
it do
314+
mock_response(
315+
:post,
316+
'https://server.example.com/oauth2/token',
317+
'tokens/bearer.json',
318+
request_header: {
319+
'Authorization' => 'Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=',
320+
'X-Foo' => 'bar'
321+
}
322+
)
323+
client.access_token! do |request|
324+
request.headers.merge! 'X-Foo' => 'bar'
325+
end
326+
end
327+
end
328+
312329
context 'when bearer token is given' do
313330
before do
314331
client.authorization_code = 'code'
@@ -433,6 +450,28 @@
433450
end
434451

435452
describe '#revoke!' do
453+
context 'local_http_config handling' do
454+
it do
455+
mock_response(
456+
:post,
457+
'https://server.example.com/oauth2/revoke',
458+
'blank',
459+
status: 200,
460+
body: {
461+
token: 'access_token',
462+
token_type_hint: 'access_token'
463+
},
464+
request_header: {
465+
'Authorization' => 'Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=',
466+
'X-Foo' => 'bar'
467+
}
468+
)
469+
client.revoke!(access_token: 'access_token') do |request|
470+
request.headers.merge! 'X-Foo' => 'bar'
471+
end
472+
end
473+
end
474+
436475
context 'when access_token given' do
437476
before do
438477
mock_response(

0 commit comments

Comments
 (0)