Skip to content

Commit

Permalink
Merge pull request #112 from linhdangduy/add_grant_types_supported_to…
Browse files Browse the repository at this point in the history
…_discovery

Add grant_types_supported to discovery response
  • Loading branch information
nbulaj committed May 25, 2020
2 parents e8ce8fa + c5b4d31 commit 3930ae6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

- [#114] Fix user_info endpoint when used in api mode
- [#112] Add grant_types_supported to discovery response

## v1.7.2 (2020-05-20)

Expand Down
21 changes: 12 additions & 9 deletions app/controllers/doorkeeper/openid_connect/discovery_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ def provider_response

# TODO: support id_token response type
response_types_supported: doorkeeper.authorization_response_types,
response_modes_supported: ['query', 'fragment'],
response_modes_supported: %w[query fragment],
grant_types_supported: grant_types_supported(doorkeeper),

token_endpoint_auth_methods_supported: [
'client_secret_basic',
'client_secret_post',

# TODO: look into doorkeeper-jwt_assertion for these
# 'client_secret_jwt',
# 'private_key_jwt'
],
# TODO: look into doorkeeper-jwt_assertion for these
# 'client_secret_jwt',
# 'private_key_jwt'
token_endpoint_auth_methods_supported: %w[client_secret_basic client_secret_post],

subject_types_supported: openid_connect.subject_types_supported,

Expand All @@ -73,6 +70,12 @@ def provider_response
}.compact
end

def grant_types_supported(doorkeeper)
grant_types_supported = doorkeeper.grant_flows
grant_types_supported << 'refresh_token' if doorkeeper.refresh_token_enabled?
grant_types_supported
end

def webfinger_response
{
subject: params.require(:resource),
Expand Down
19 changes: 14 additions & 5 deletions spec/controllers/discovery_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
'scopes_supported' => ['openid'],

'response_types_supported' => ['code'],
'response_modes_supported' => ['query', 'fragment'],
'response_modes_supported' => %w[query fragment],
'grant_types_supported' => %w[authorization_code client_credentials],

'token_endpoint_auth_methods_supported' => [
'client_secret_basic',
'client_secret_post',
],
'token_endpoint_auth_methods_supported' => %w[client_secret_basic client_secret_post],

'subject_types_supported' => [
'public',
Expand Down Expand Up @@ -57,6 +55,17 @@
}.sort)
end

context 'when refresh_token grant type is enabled' do
before { Doorkeeper.configure { use_refresh_token } }

it 'add refresh_token to grant_types_supported' do
get :provider
data = JSON.parse(response.body)

expect(data['grant_types_supported']).to eq %w[authorization_code client_credentials refresh_token]
end
end

it 'uses the protocol option for generating URLs' do
Doorkeeper::OpenidConnect.configure do
protocol { :testing }
Expand Down

0 comments on commit 3930ae6

Please sign in to comment.