A platform for community discussion. Free, open, simple.
FEATURE: Automatically redirect to authenticator when there is only one
David Taylor0a14b9b42a2f
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex 3c19910598f..1fdd6027aec 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -722,6 +722,10 @@ class ApplicationController < ActionController::Basesession[:destination_url] = destination_urlredirect_to path('/session/sso')return+ elsif !SiteSetting.enable_local_logins && Discourse.enabled_authenticators.length == 1+ # Only one authentication provider, direct straight to it+ cookies[:destination_url] = destination_url+ redirect_to path("/auth/#{Discourse.enabled_authenticators.first.name}")else# save original URL in a cookie (javascript redirects after login in this case)cookies[:destination_url] = destination_urldiff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rbindex c762fb070b1..03fc4caf8ac 100644--- a/spec/requests/application_controller_spec.rb+++ b/spec/requests/application_controller_spec.rb@@ -15,6 +15,35 @@ RSpec.describe ApplicationController doget "/"expect(response.headers["Cache-Control"]).to eq("no-cache, no-store")end++ it "should redirect to login normally" do+ get "/"+ expect(response).to redirect_to("/login")+ end++ it "should redirect to SSO if enabled" do+ SiteSetting.sso_url = 'http://someurl.com'+ SiteSetting.enable_sso = true+ get "/"+ expect(response).to redirect_to("/session/sso")+ end++ it "should redirect to authenticator if only one, and local logins disabled" do+ # Local logins and google enabled, direct to login UI+ SiteSetting.enable_google_oauth2_logins = true+ get "/"+ expect(response).to redirect_to("/login")++ # Only google enabled, login immediately+ SiteSetting.enable_local_logins = false+ get "/"+ expect(response).to redirect_to("/auth/google_oauth2")++ # Google and GitHub enabled, direct to login UI+ SiteSetting.enable_github_logins = true+ get "/"+ expect(response).to redirect_to("/login")+ endenddescribe '#redirect_to_second_factor_if_required' do