Skip to content

Commit

Permalink
fix(saml): add setup route to OmniauthRegistrationsController
Browse files Browse the repository at this point in the history
  • Loading branch information
moustachu committed Jun 5, 2024
1 parent b498a63 commit 042bb49
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
8 changes: 1 addition & 7 deletions config/initializers/omniauth_saml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions lib/omniauth/strategies/imt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 042bb49

Please sign in to comment.