diff --git a/config/initializers/omniauth_saml.rb b/config/initializers/omniauth_saml.rb index 42ed44f7..a04e0bd8 100644 --- a/config/initializers/omniauth_saml.rb +++ b/config/initializers/omniauth_saml.rb @@ -14,7 +14,7 @@ idp_metadata_url = provider_config[:idp_metadata_url] - if env["omniauth.strategy"].on_setup_path? && request.params["action"] == "idp_entity_selector_url" + if env["omniauth.strategy"].on_setup_path? && request.params["setup_action"] == "idp_entity_selector_url" env["omniauth.strategy"].idp_entity_setup idp_metadata_url = env["omniauth.strategy"].options[:idp_metadata_url] end @@ -88,12 +88,6 @@ Rails.logger.debug v end Rails.logger.debug "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" - - if env["omniauth.strategy"].on_setup_path? && request.params["action"] == "idp_entity_selector_url" - Rails.logger.debug "(#{env["omniauth.strategy"].name}) Setup phase redirected to Request call" - env["omniauth.strategy"].skip_setup - return env["omniauth.strategy"].request_call - end } ) end diff --git a/config/routes.rb b/config/routes.rb index a87f61ad..6831b419 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,4 +13,8 @@ mount Decidim::Core::Engine => "/" # mount Decidim::Map::Engine => '/map' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + devise_scope :user do + get "/users/auth/:provider/setup" => "decidim/devise/omniauth_registrations#setup" + end end diff --git a/lib/extends/controllers/decidim/devise/omniauth_registrations_controller_extends.rb b/lib/extends/controllers/decidim/devise/omniauth_registrations_controller_extends.rb index 2ec5f643..e0a14a20 100644 --- a/lib/extends/controllers/decidim/devise/omniauth_registrations_controller_extends.rb +++ b/lib/extends/controllers/decidim/devise/omniauth_registrations_controller_extends.rb @@ -7,6 +7,15 @@ module OmniauthRegistrationsControllerExtends skip_before_action :verify_authenticity_token, only: [:imt, :failure] skip_after_action :verify_same_origin_request, only: [:imt, :failure] end + + def setup + Rails.logger.debug "Decidim::Devise::OmniauthRegistrationsController#setup" + if request.env["omniauth.strategy"].on_setup_path? && request.params["setup_action"] == "idp_entity_selector_url" + Rails.logger.debug "(#{request.env["omniauth.strategy"].name}) Setup phase redirected to Request call" + request.env["omniauth.strategy"].skip_setup + redirect_to request.env["omniauth.strategy"].request_call + end + end end Decidim::Devise::OmniauthRegistrationsController.class_eval do diff --git a/lib/omniauth/strategies/imt.rb b/lib/omniauth/strategies/imt.rb index e66c3c50..6b16254d 100644 --- a/lib/omniauth/strategies/imt.rb +++ b/lib/omniauth/strategies/imt.rb @@ -43,7 +43,6 @@ def skip_setup end def redirect_to_entity_selector - @skip_request_phase = true Rails.logger.debug "Redirecting to entity selector URL : #{entity_selector_url}" redirect(entity_selector_url) end @@ -64,7 +63,7 @@ def entity_selector_url def entity_selector_callback_url uri = URI.parse(full_host + setup_path) uri.query = { - action: "idp_entity_selector_url", + setup_action: "idp_entity_selector_url", state: new_state }.to_query uri.to_s @@ -97,7 +96,11 @@ def request_phase if options[:idp_entity_selector_url].present? && !@skip_idp_entity_setup redirect_to_entity_selector else - super + authn_request = OneLogin::RubySaml::Authrequest.new + + with_settings do |settings| + return authn_request.create(settings, additional_params_for_authn_request) + end end end