From 5b5b4695229b1d878c50b00a1b510fcae69ce262 Mon Sep 17 00:00:00 2001 From: linhdangduy Date: Fri, 12 Mar 2021 10:39:08 +0900 Subject: [PATCH] get response_modes_supported when discovery --- .../openid_connect/discovery_controller.rb | 6 +++- spec/controllers/discovery_controller_spec.rb | 35 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/controllers/doorkeeper/openid_connect/discovery_controller.rb b/app/controllers/doorkeeper/openid_connect/discovery_controller.rb index c6fa4c3..5726996 100644 --- a/app/controllers/doorkeeper/openid_connect/discovery_controller.rb +++ b/app/controllers/doorkeeper/openid_connect/discovery_controller.rb @@ -38,7 +38,7 @@ def provider_response # TODO: support id_token response type response_types_supported: doorkeeper.authorization_response_types, - response_modes_supported: %w[query fragment], + response_modes_supported: response_modes_supported(doorkeeper), grant_types_supported: grant_types_supported(doorkeeper), # TODO: look into doorkeeper-jwt_assertion for these @@ -76,6 +76,10 @@ def grant_types_supported(doorkeeper) grant_types_supported end + def response_modes_supported(doorkeeper) + doorkeeper.authorization_response_flows.flat_map(&:response_mode_matches).uniq + 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 8fd48d0..97d6248 100644 --- a/spec/controllers/discovery_controller_spec.rb +++ b/spec/controllers/discovery_controller_spec.rb @@ -19,7 +19,7 @@ 'scopes_supported' => ['openid'], 'response_types_supported' => ['code', 'token', 'id_token', 'id_token token'], - 'response_modes_supported' => %w[query fragment], + 'response_modes_supported' => %w[query fragment form_post], 'grant_types_supported' => %w[authorization_code client_credentials implicit_oidc], 'token_endpoint_auth_methods_supported' => %w[client_secret_basic client_secret_post], @@ -65,6 +65,39 @@ end end + context 'when grant_flows is configed with only client_credentials' do + before { Doorkeeper.configure { grant_flows %w[client_credentials] } } + + it 'return empty response_modes_supported' do + get :provider + data = JSON.parse(response.body) + + expect(data['response_modes_supported']).to eq [] + end + end + + context 'when grant_flows is configed only implicit flow' do + before { Doorkeeper.configure { grant_flows %w[implicit_oidc] } } + + it 'return fragment and form_post as response_modes_supported' do + get :provider + data = JSON.parse(response.body) + + expect(data['response_modes_supported']).to eq %w[fragment form_post] + end + end + + context 'when grant_flows is configed with authorization_code and implicit flow' do + before { Doorkeeper.configure { grant_flows %w[authorization_code implicit_oidc] } } + + it 'return query, fragment and form_post as response_modes_supported' do + get :provider + data = JSON.parse(response.body) + + expect(data['response_modes_supported']).to eq %w[query fragment form_post] + end + end + it 'uses the protocol option for generating URLs' do Doorkeeper::OpenidConnect.configure do protocol { :testing }