From aa73df768a8bce4362b2ffcbf07ebbfd9711d1b7 Mon Sep 17 00:00:00 2001
From: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Date: Mon, 16 Dec 2019 12:33:24 +0100
Subject: [PATCH] DEV: improves error message when sso param is not passed
 (#8549)

SingleSignOnProvider is expecting a sso param later in the chain. If sso param is not found it will cause a 500 with the following exception: `NoMethodError (undefined method `unpack1' for nil:NilClass)` as `set_return_sso_url` is attempting to decode it: https://github.com/discourse/discourse/blob/master/lib/single_sign_on_provider.rb#L19
---
 app/controllers/session_controller.rb | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb
index b0687625209..8b51a339c29 100644
--- a/app/controllers/session_controller.rb
+++ b/app/controllers/session_controller.rb
@@ -41,10 +41,12 @@ class SessionController < ApplicationController
   end
 
   def sso_provider(payload = nil)
-    payload ||= request.query_string
-
     if SiteSetting.enable_sso_provider
       begin
+        if !payload
+          params.require(:sso)
+          payload = request.query_string
+        end
         sso = SingleSignOnProvider.parse(payload)
       rescue SingleSignOnProvider::BlankSecret
         render plain: I18n.t("sso.missing_secret"), status: 400