diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fda95a..2f05400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/app/controllers/doorkeeper/openid_connect/discovery_controller.rb b/app/controllers/doorkeeper/openid_connect/discovery_controller.rb index 5b2bbaa..606b842 100644 --- a/app/controllers/doorkeeper/openid_connect/discovery_controller.rb +++ b/app/controllers/doorkeeper/openid_connect/discovery_controller.rb @@ -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, @@ -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), diff --git a/spec/controllers/discovery_controller_spec.rb b/spec/controllers/discovery_controller_spec.rb index 887a802..ac738de 100644 --- a/spec/controllers/discovery_controller_spec.rb +++ b/spec/controllers/discovery_controller_spec.rb @@ -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', @@ -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 }