better logs when an error happens in SSO
This commit is contained in:
parent
f7432d8ec9
commit
97c7b894ce
|
@ -117,7 +117,14 @@ class SessionController < ApplicationController
|
||||||
SingleSignOn::ACCESSORS.each do |a|
|
SingleSignOn::ACCESSORS.each do |a|
|
||||||
details[a] = sso.send(a)
|
details[a] = sso.send(a)
|
||||||
end
|
end
|
||||||
Rails.logger.error "Failed to create or lookup user: #{e}\n\n#{details.map{|k,v| "#{k}: #{v}"}.join("\n")}"
|
|
||||||
|
message = "Failed to create or lookup user: #{e}."
|
||||||
|
message << "\n\n" << "-" * 100
|
||||||
|
message << details.map { |k,v| "#{k}: #{v}" }.join("\n")
|
||||||
|
message << "\n\n" << "-" * 100
|
||||||
|
message << e.backtrace.join("\n")
|
||||||
|
|
||||||
|
Rails.logger.error(message)
|
||||||
|
|
||||||
render text: I18n.t("sso.unknown_error"), status: 500
|
render text: I18n.t("sso.unknown_error"), status: 500
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,19 +81,21 @@ class DiscourseSingleSignOn < SingleSignOn
|
||||||
private
|
private
|
||||||
|
|
||||||
def match_email_or_create_user(ip_address)
|
def match_email_or_create_user(ip_address)
|
||||||
user = User.find_by_email(email)
|
unless user = User.find_by_email(email)
|
||||||
|
try_name = name.presence
|
||||||
|
try_username = username.presence
|
||||||
|
|
||||||
try_name = name.blank? ? nil : name
|
user_params = {
|
||||||
try_username = username.blank? ? nil : username
|
email: email,
|
||||||
|
name: try_name || User.suggest_name(try_username || email),
|
||||||
|
username: UserNameSuggester.suggest(try_username || try_name || email),
|
||||||
|
ip_address: ip_address
|
||||||
|
}
|
||||||
|
|
||||||
user_params = {
|
user = User.create!(user_params)
|
||||||
email: email,
|
end
|
||||||
name: try_name || User.suggest_name(try_username || email),
|
|
||||||
username: UserNameSuggester.suggest(try_username || try_name || email),
|
|
||||||
ip_address: ip_address
|
|
||||||
}
|
|
||||||
|
|
||||||
if user || user = User.create!(user_params)
|
if user
|
||||||
if sso_record = user.single_sign_on_record
|
if sso_record = user.single_sign_on_record
|
||||||
sso_record.last_payload = unsigned_payload
|
sso_record.last_payload = unsigned_payload
|
||||||
sso_record.external_id = external_id
|
sso_record.external_id = external_id
|
||||||
|
|
Loading…
Reference in New Issue