mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
DEV: Add helper method for repeated sso logging pattern (#16749)
This commit is contained in:

committed by
GitHub

parent
ce8dd8810e
commit
6a4696eec8
@ -30,9 +30,7 @@ class SessionController < ApplicationController
|
|||||||
|
|
||||||
if SiteSetting.enable_discourse_connect?
|
if SiteSetting.enable_discourse_connect?
|
||||||
sso = DiscourseConnect.generate_sso(return_path, secure_session: secure_session)
|
sso = DiscourseConnect.generate_sso(return_path, secure_session: secure_session)
|
||||||
if SiteSetting.verbose_discourse_connect_logging
|
connect_verbose_warn { "Verbose SSO log: Started SSO process\n\n#{sso.diagnostics}" }
|
||||||
Rails.logger.warn("Verbose SSO log: Started SSO process\n\n#{sso.diagnostics}")
|
|
||||||
end
|
|
||||||
redirect_to sso_url(sso), allow_other_host: true
|
redirect_to sso_url(sso), allow_other_host: true
|
||||||
else
|
else
|
||||||
render body: nil, status: 404
|
render body: nil, status: 404
|
||||||
@ -131,25 +129,19 @@ class SessionController < ApplicationController
|
|||||||
begin
|
begin
|
||||||
sso = DiscourseConnect.parse(request.query_string, secure_session: secure_session)
|
sso = DiscourseConnect.parse(request.query_string, secure_session: secure_session)
|
||||||
rescue DiscourseConnect::ParseError => e
|
rescue DiscourseConnect::ParseError => e
|
||||||
if SiteSetting.verbose_discourse_connect_logging
|
connect_verbose_warn { "Verbose SSO log: Signature parse error\n\n#{e.message}\n\n#{sso&.diagnostics}" }
|
||||||
Rails.logger.warn("Verbose SSO log: Signature parse error\n\n#{e.message}\n\n#{sso&.diagnostics}")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Do NOT pass the error text to the client, it would give them the correct signature
|
# Do NOT pass the error text to the client, it would give them the correct signature
|
||||||
return render_sso_error(text: I18n.t("discourse_connect.login_error"), status: 422)
|
return render_sso_error(text: I18n.t("discourse_connect.login_error"), status: 422)
|
||||||
end
|
end
|
||||||
|
|
||||||
if !sso.nonce_valid?
|
if !sso.nonce_valid?
|
||||||
if SiteSetting.verbose_discourse_connect_logging
|
connect_verbose_warn { "Verbose SSO log: #{sso.nonce_error}\n\n#{sso.diagnostics}" }
|
||||||
Rails.logger.warn("Verbose SSO log: #{sso.nonce_error}\n\n#{sso.diagnostics}")
|
|
||||||
end
|
|
||||||
return render_sso_error(text: I18n.t("discourse_connect.timeout_expired"), status: 419)
|
return render_sso_error(text: I18n.t("discourse_connect.timeout_expired"), status: 419)
|
||||||
end
|
end
|
||||||
|
|
||||||
if ScreenedIpAddress.should_block?(request.remote_ip)
|
if ScreenedIpAddress.should_block?(request.remote_ip)
|
||||||
if SiteSetting.verbose_discourse_connect_logging
|
connect_verbose_warn { "Verbose SSO log: IP address is blocked #{request.remote_ip}\n\n#{sso.diagnostics}" }
|
||||||
Rails.logger.warn("Verbose SSO log: IP address is blocked #{request.remote_ip}\n\n#{sso.diagnostics}")
|
|
||||||
end
|
|
||||||
return render_sso_error(text: I18n.t("discourse_connect.unknown_error"), status: 500)
|
return render_sso_error(text: I18n.t("discourse_connect.unknown_error"), status: 500)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -227,8 +219,7 @@ class SessionController < ApplicationController
|
|||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
|
|
||||||
if SiteSetting.verbose_discourse_connect_logging
|
connect_verbose_warn { <<~TEXT }
|
||||||
Rails.logger.warn(<<~TEXT)
|
|
||||||
Verbose SSO log: Record was invalid: #{e.record.class.name} #{e.record.id}
|
Verbose SSO log: Record was invalid: #{e.record.class.name} #{e.record.id}
|
||||||
#{e.record.errors.to_h}
|
#{e.record.errors.to_h}
|
||||||
|
|
||||||
@ -237,8 +228,7 @@ class SessionController < ApplicationController
|
|||||||
|
|
||||||
SSO Diagnostics:
|
SSO Diagnostics:
|
||||||
#{sso.diagnostics}
|
#{sso.diagnostics}
|
||||||
TEXT
|
TEXT
|
||||||
end
|
|
||||||
|
|
||||||
text = nil
|
text = nil
|
||||||
|
|
||||||
@ -274,9 +264,7 @@ class SessionController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def login_sso_user(sso, user)
|
def login_sso_user(sso, user)
|
||||||
if SiteSetting.verbose_discourse_connect_logging
|
connect_verbose_warn { "Verbose SSO log: User was logged on #{user.username}\n\n#{sso.diagnostics}" }
|
||||||
Rails.logger.warn("Verbose SSO log: User was logged on #{user.username}\n\n#{sso.diagnostics}")
|
|
||||||
end
|
|
||||||
log_on_user(user) if user.id != current_user&.id
|
log_on_user(user) if user.id != current_user&.id
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -634,6 +622,12 @@ class SessionController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def connect_verbose_warn(&blk)
|
||||||
|
if SiteSetting.verbose_discourse_connect_logging
|
||||||
|
Rails.logger.warn(blk.call)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def authenticate_second_factor(user)
|
def authenticate_second_factor(user)
|
||||||
second_factor_authentication_result = user.authenticate_second_factor(params, secure_session)
|
second_factor_authentication_result = user.authenticate_second_factor(params, secure_session)
|
||||||
if !second_factor_authentication_result.ok
|
if !second_factor_authentication_result.ok
|
||||||
|
Reference in New Issue
Block a user