Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
discourse sso auto
diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb
index e96566f..f5f63be 100644
--- a/app/controllers/session_controller.rb
+++ b/app/controllers/session_controller.rb
@@ -9,7 +9,7 @@ class SessionController < ApplicationController
before_action :check_local_login_allowed, only: %i(create forgot_password)
skip_before_action :redirect_to_login_if_required
- skip_before_action :preload_json, :check_xhr, only: ['sso', 'sso_login', 'become', 'sso_provider', 'destroy']
+ skip_before_action :preload_json, :check_xhr, only: ['sso', 'sso_dry', 'sso_login', 'become', 'sso_provider', 'destroy']
ACTIVATE_USER_KEY = "activate_user"
@@ -40,6 +40,30 @@ class SessionController < ApplicationController
end
end
+ def sso_dry
+ destination_url = cookies[:destination_url] || session[:destination_url]
+ return_path = params[:return_path] || path('/')
+
+ if destination_url && return_path == path('/')
+ uri = URI::parse(destination_url)
+ return_path = "#{uri.path}#{uri.query ? "?" << uri.query : ""}"
+ end
+
+ session.delete(:destination_url)
+ cookies.delete(:destination_url)
+
+ if SiteSetting.enable_sso?
+ sso = DiscourseSingleSignOn.generate_sso(return_path)
+ if SiteSetting.verbose_sso_logging
+ Rails.logger.warn("Verbose SSO log: Started Dry SSO process\n\n#{sso.diagnostics}")
+ end
+ redirect_to "#{sso.to_url}&dry_return=#{return_path}"
+ else
+ render body: nil, status: 404
+ end
+ end
+
+
def sso_provider(payload = nil)
payload ||= request.query_string
if SiteSetting.enable_sso_provider
diff --git a/config/routes.rb b/config/routes.rb
index f3cb50b..82c9bd0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -297,6 +297,7 @@ Discourse::Application.routes.draw do
end
get "session/sso" => "session#sso"
+ get "session/sso_dry" => "session#sso_dry"
get "session/sso_login" => "session#sso_login"
get "session/sso_provider" => "session#sso_provider"
get "session/current" => "session#current"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment