Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/doorkeeper/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,16 @@ def client_credentials_methods
@client_credentials_methods ||= %i[from_basic from_params]
end

def token_endpoint_auth_methods
return @token_endpoint_auth_methods if instance_variable_defined?(:@token_endpoint_auth_methods)

methods = ['none']
methods << 'client_secret_basic' if client_credentials_methods.include? :from_basic
methods << 'client_secret_post' if client_credentials_methods.include? :from_params

@token_endpoint_auth_methods = methods
end

def access_token_methods
@access_token_methods ||= %i[
from_bearer_authorization
Expand Down
49 changes: 47 additions & 2 deletions spec/lib/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,56 @@
it "can change the value" do
Doorkeeper.configure do
orm DOORKEEPER_ORM
client_credentials :from_digest, :from_params
client_credentials :from_basic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:from_digest was never a "supported" client authentication method, from what I can tell, so instead I've switched this to an actually supported client authentication method. (I looked through the git history for https://github.com/doorkeeper-gem/doorkeeper/blob/main/lib/doorkeeper/oauth/client/credentials.rb )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. We have some longstanding issue for digest auth

#984

end

expect(config.client_credentials_methods)
.to eq(%i[from_digest from_params])
.to eq(%i[from_basic])
end
end

# Returns token endpoint auth methods based on client_credentials per
# https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtml#token-endpoint-auth-method
describe 'token_endpoint_auth_methods' do
it 'returns methods according to defaults' do
expect(config.client_credentials_methods).to eq(%i[from_basic from_params])
expect(config.token_endpoint_auth_methods).to contain_exactly('none', 'client_secret_post', 'client_secret_basic')
end

it "returns none even if no methods are configured" do
Doorkeeper.configure do
orm DOORKEEPER_ORM
client_credentials
end

expect(config.client_credentials_methods)
.to eq([])

expect(config.token_endpoint_auth_methods).to contain_exactly('none')
end

it 'returns client_secret_post if configured' do
Doorkeeper.configure do
orm DOORKEEPER_ORM
client_credentials :from_params
end

expect(config.client_credentials_methods)
.to eq(%i[from_params])

expect(config.token_endpoint_auth_methods).to contain_exactly('none', 'client_secret_post')
end

it 'returns client_secret_basic if configured' do
Doorkeeper.configure do
orm DOORKEEPER_ORM
client_credentials :from_basic
end

expect(config.client_credentials_methods)
.to eq(%i[from_basic])

expect(config.token_endpoint_auth_methods).to contain_exactly('none', 'client_secret_basic')
end
end

Expand Down