2017-09-24 17:27:23 +02:00
|
|
|
class DiscourseSsoController < DiscourseController
|
2019-10-28 21:11:35 +01:00
|
|
|
before_action -> { require_config_enabled :discourse_sso }
|
2017-09-24 17:27:23 +02:00
|
|
|
|
|
|
|
def sso
|
|
|
|
raise I18n.t('discourse.sso.invalid_signature') unless valid_signature?
|
|
|
|
|
|
|
|
payload = parse_payload
|
|
|
|
nonce = payload[:nonce]
|
|
|
|
return_sso_url = payload[:return_sso_url] || "#{discourse_url}/session/sso_login"
|
|
|
|
|
|
|
|
raise I18n.t('discourse.sso.nonce_missing') if nonce.blank?
|
|
|
|
|
|
|
|
redirect_to_with_payload return_sso_url,
|
2021-03-01 15:27:26 +01:00
|
|
|
nonce: nonce,
|
|
|
|
email: current_user.email,
|
|
|
|
require_activation: true,
|
|
|
|
external_id: "#{FoodsoftConfig.scope}/#{current_user.id}",
|
|
|
|
username: current_user.nick,
|
|
|
|
name: current_user.name
|
2023-05-12 13:01:12 +02:00
|
|
|
rescue StandardError => e
|
|
|
|
redirect_to root_url, alert: e.to_s
|
2017-09-24 17:27:23 +02:00
|
|
|
end
|
|
|
|
end
|