Skip to content

Commit 7e2a392

Browse files
authored
Merge pull request #656 from srook/urlencoded-params-token-revocation
2 parents 44a9b17 + dddc568 commit 7e2a392

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

.rubocop_gradual.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
[69, 15, 38, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1480816240],
3838
[79, 13, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2314399065]
3939
],
40-
"spec/oauth2/client_spec.rb:3334307042": [
40+
"spec/oauth2/client_spec.rb:292714281": [
4141
[6, 1, 29, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/client*_spec.rb`.", 439549885],
4242
[175, 7, 492, "RSpec/NoExpectationExample: No expectation found in this example.", 1272021224],
4343
[194, 7, 592, "RSpec/NoExpectationExample: No expectation found in this example.", 3428877205],

lib/oauth2/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ def get_token(params, access_token_opts = {}, extract_access_token = nil, &block
256256
# @see https://datatracker.ietf.org/doc/html/rfc7009#section-2.1
257257
def revoke_token(token, token_type_hint = nil, params = {}, &block)
258258
params[:token_method] ||= :post_with_query_string
259+
params[:token] = token
260+
params[:token_type_hint] = token_type_hint if token_type_hint
261+
259262
req_opts = params_to_req_opts(params)
260-
req_opts[:params] ||= {}
261-
req_opts[:params][:token] = token
262-
req_opts[:params][:token_type_hint] = token_type_hint if token_type_hint
263263

264264
request(http_method, revoke_url, req_opts, &block)
265265
end

spec/oauth2/client_spec.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,13 +1216,6 @@ def self.contains_token?(hash)
12161216
}.not_to raise_error
12171217
end
12181218
end
1219-
1220-
def stubbed_client(params = {}, &stubs)
1221-
params = {site: "https://api.example.com"}.merge(params)
1222-
OAuth2::Client.new("abc", "def", params) do |builder|
1223-
builder.adapter :test, &stubs
1224-
end
1225-
end
12261219
end
12271220

12281221
describe "#revoke_token" do
@@ -1259,6 +1252,19 @@ def stubbed_client(params = {}, &stubs)
12591252
}.not_to raise_error
12601253
end
12611254

1255+
it "submits params in request body" do
1256+
client = stubbed_client do |stub|
1257+
stub.post("/oauth/revoke") do |req|
1258+
expect(req.body[:token]).to eq(token)
1259+
expect(req.params).to be_empty
1260+
1261+
[200, {"Content-Type" => "application/json"}, ""]
1262+
end
1263+
end
1264+
1265+
client.revoke_token(token, "access_token", token_method: :post)
1266+
end
1267+
12621268
it "has status 200" do
12631269
expect(instance.revoke_token(token, nil, extra: "param").status).to eq(200)
12641270
end
@@ -1332,4 +1338,11 @@ def stubbed_client(params = {}, &stubs)
13321338
expect(subject.inspect).to include("@secret=[FILTERED]")
13331339
end
13341340
end
1341+
1342+
def stubbed_client(params = {}, &stubs)
1343+
params = {site: "https://api.example.com"}.merge(params)
1344+
OAuth2::Client.new("abc", "def", params) do |builder|
1345+
builder.adapter :test, &stubs
1346+
end
1347+
end
13351348
end

0 commit comments

Comments
 (0)