Skip to content

Commit ec9e7ea

Browse files
authored
Merge pull request #1400 from aclemons/client_credentials_validation
Yield application to allow_grant_flow_for_client? client credentials …
2 parents 7f6d449 + 4bcf3ee commit ec9e7ea

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ User-visible changes worth mentioning.
1010
- [#1395] Fix `NameError: uninitialized constant Doorkeeper::AccessToken` for Rake tasks.
1111
- [#1397] Add `as: :doorkeeper_application` on Doorkeeper application form in order to support
1212
custom configured application model.
13+
- [#1400] Correctly yield the application to allow_grant_flow_for_client? (Fixes #1398)
1314

1415
## 5.4.0.rc1
1516
- [#1366] Sets expiry of token generated using `refresh_token` to that of original token. (Fixes #1364)

lib/doorkeeper/oauth/client_credentials/validator.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ def validate_client
2626
end
2727

2828
def validate_client_supports_grant_flow
29+
return if @client.blank?
30+
2931
Doorkeeper.config.allow_grant_flow_for_client?(
3032
Doorkeeper::OAuth::CLIENT_CREDENTIALS,
31-
@client,
33+
@client.application,
3234
)
3335
end
3436

spec/lib/oauth/client_credentials/validation_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,33 @@
1919
expect(subject).not_to be_valid
2020
end
2121

22+
context "when a grant flow check is configured" do
23+
let(:callback) { double("callback") }
24+
25+
before do
26+
allow(Doorkeeper.config).to receive(:option_defined?).with(:allow_grant_flow_for_client).and_return(true)
27+
allow(Doorkeeper.config).to receive(:allow_grant_flow_for_client).and_return(callback)
28+
29+
expect(callback).to receive(:call).twice.with(Doorkeeper::OAuth::CLIENT_CREDENTIALS, application).and_return(callback_response)
30+
end
31+
32+
context "when the callback rejects the grant flow" do
33+
let(:callback_response) { false }
34+
35+
it "is invalid" do
36+
expect(subject).not_to be_valid
37+
end
38+
end
39+
40+
context "when the callback allows the grant flow" do
41+
let(:callback_response) { true }
42+
43+
it "is invalid" do
44+
expect(subject).to be_valid
45+
end
46+
end
47+
end
48+
2249
context "with scopes" do
2350
it "is invalid when scopes are not included in the server" do
2451
server_scopes = Doorkeeper::OAuth::Scopes.from_string "email"

spec/lib/oauth/client_credentials_integration_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let(:server) { Doorkeeper.configuration }
77

88
context "with a valid request" do
9-
let(:client) { FactoryBot.create :application }
9+
let(:client) { Doorkeeper::OAuth::Client.new(FactoryBot.build_stubbed(:application)) }
1010

1111
it "issues an access token" do
1212
request = Doorkeeper::OAuth::ClientCredentialsRequest.new(server, client, {})

0 commit comments

Comments
 (0)