mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: For a single authenticator, do not interrupt registration flow
Followup to 0a14b9b42a2f597f5df26be97296a4d6909f6a34
This commit is contained in:
@ -722,8 +722,9 @@ class ApplicationController < ActionController::Base
|
|||||||
session[:destination_url] = destination_url
|
session[:destination_url] = destination_url
|
||||||
redirect_to path('/session/sso')
|
redirect_to path('/session/sso')
|
||||||
return
|
return
|
||||||
elsif !SiteSetting.enable_local_logins && Discourse.enabled_authenticators.length == 1
|
elsif !SiteSetting.enable_local_logins && Discourse.enabled_authenticators.length == 1 && !cookies[:authentication_data]
|
||||||
# Only one authentication provider, direct straight to it
|
# Only one authentication provider, direct straight to it.
|
||||||
|
# If authentication_data is present, then we are halfway though registration. Don't redirect offsite
|
||||||
cookies[:destination_url] = destination_url
|
cookies[:destination_url] = destination_url
|
||||||
redirect_to path("/auth/#{Discourse.enabled_authenticators.first.name}")
|
redirect_to path("/auth/#{Discourse.enabled_authenticators.first.name}")
|
||||||
else
|
else
|
||||||
|
@ -44,6 +44,46 @@ RSpec.describe ApplicationController do
|
|||||||
get "/"
|
get "/"
|
||||||
expect(response).to redirect_to("/login")
|
expect(response).to redirect_to("/login")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with omniauth in test mode" do
|
||||||
|
before do
|
||||||
|
OmniAuth.config.test_mode = true
|
||||||
|
OmniAuth.config.add_mock(:google_oauth2,
|
||||||
|
info: OmniAuth::AuthHash::InfoHash.new(
|
||||||
|
email: "address@example.com",
|
||||||
|
),
|
||||||
|
extra: {
|
||||||
|
raw_info: OmniAuth::AuthHash.new(
|
||||||
|
email_verified: true,
|
||||||
|
email: "address@example.com",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2]
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2] = nil
|
||||||
|
OmniAuth.config.test_mode = false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not redirect to authenticator if registration in progress" do
|
||||||
|
SiteSetting.enable_local_logins = false
|
||||||
|
SiteSetting.enable_google_oauth2_logins = true
|
||||||
|
|
||||||
|
get "/"
|
||||||
|
expect(response).to redirect_to("/auth/google_oauth2")
|
||||||
|
|
||||||
|
expect(cookies[:authentication_data]).to eq(nil)
|
||||||
|
|
||||||
|
get "/auth/google_oauth2/callback.json"
|
||||||
|
expect(response).to redirect_to("/")
|
||||||
|
expect(cookies[:authentication_data]).not_to eq(nil)
|
||||||
|
|
||||||
|
get "/"
|
||||||
|
expect(response).to redirect_to("/login")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#redirect_to_second_factor_if_required' do
|
describe '#redirect_to_second_factor_if_required' do
|
||||||
|
Reference in New Issue
Block a user