FEATURE: Automatically redirect to authenticator when there is only one

This brings the behavior in line with native Discourse SSO. If login is required, and a user tries to visit the forum, they will be directed straight to the external login page without requiring any clicks.
This commit is contained in:
David Taylor
2019-11-13 17:28:12 +00:00
parent 3c5df82590
commit 0a14b9b42a
2 changed files with 33 additions and 0 deletions

View File

@ -722,6 +722,10 @@ class ApplicationController < ActionController::Base
session[:destination_url] = destination_url
redirect_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_url