From ba8c0f2b283eba01ca7cb4f6ae59beaebe1806a4 Mon Sep 17 00:00:00 2001 From: Paul Nicholls Date: Wed, 25 May 2016 09:37:59 +1200 Subject: [PATCH 1/2] Initialise $error_message in seamless login function $error_message was undefined if there was no error, as it wasn't being initialised. Later in the function, it's compared to an empty string, so should be initialised to that value. --- locallib.php | 1 + 1 file changed, 1 insertion(+) diff --git a/locallib.php b/locallib.php index 4f51df1..e873798 100644 --- a/locallib.php +++ b/locallib.php @@ -390,6 +390,7 @@ function echolink_ess_oauth_seamless_login($echolink) { // we want to test for a 404 $curl = $essSSOLogin->get_curl_with_defaults(); $headers = $essSSOLogin->get_headers($curl, $ssoResponse['url'], 1); + $error_message = ''; if (!strstr($headers[0]['http'], "302")) { $error_message = 'unexpected_response'; From fe85bf4eeade3954dd52499be7eb3c70f1600d20 Mon Sep 17 00:00:00 2001 From: Paul Nicholls Date: Wed, 25 May 2016 09:40:54 +1200 Subject: [PATCH 2/2] Make indentation consistent in seamless login function The indentation in the echolink_ess_oauth_seamless_login function was inconsistent (a mix of tabs and spaces, as well as different amounts of indentation on different lines), which made it hard to read. --- locallib.php | 92 ++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/locallib.php b/locallib.php index e873798..19318f0 100644 --- a/locallib.php +++ b/locallib.php @@ -373,54 +373,54 @@ function convertXMLtoJSON($xml, $encode, $decode) { //------------------------------------------------------------- function echolink_ess_oauth_seamless_login($echolink) { - global $USER; + global $USER; + + $config = get_config('echolink'); + $essURL = $config->ESS_URL; + $essConsumerKey = $config->ESS_Consumer_Key; + $essConsumerSecret = $config->ESS_Consumer_Secret; + $realm = ""; + + $isInstructor = true; + + $essSSOLogin = new EchoSystemSeamlessLogin($essURL, $essConsumerKey, $essConsumerSecret, $realm); + $ssoResponse = $essSSOLogin->generate_sso_url($echolink, $USER, $isInstructor, true); + + if($ssoResponse['success'] == true) { + // we want to test for a 404 + $curl = $essSSOLogin->get_curl_with_defaults(); + $headers = $essSSOLogin->get_headers($curl, $ssoResponse['url'], 1); + $error_message = ''; + + if (!strstr($headers[0]['http'], "302")) { + $error_message = 'unexpected_response'; + $e = explode(" ", $headers[0]['http'], 3); + $error_detail = $e[2]; + } else if (strstr($headers[1]['http'], "404")) { + $error_message = 'not_found_response'; + $e = explode(" ", $headers[1]['http'], 3); + $error_detail = $e[2]; + } else if (strstr($headers[1]['http'], "403")) { + $error_message = 'forbidden_response'; + $e = explode(" ", $headers[1]['http'], 3); + $error_detail = $e[2]; + } else if (!strstr($headers[1]['http'], "200")) { + $error_message = 'unexpected_response'; + $e = explode(" ", $headers[1]['http'], 3); + $error_detail = $e[2]; + } + curl_close($curl); - $config = get_config('echolink'); - $essURL = $config->ESS_URL; - $essConsumerKey = $config->ESS_Consumer_Key; - $essConsumerSecret = $config->ESS_Consumer_Secret; - $realm = ""; - - $isInstructor = true; - - $essSSOLogin = new EchoSystemSeamlessLogin($essURL, $essConsumerKey, $essConsumerSecret, $realm); - $ssoResponse = $essSSOLogin->generate_sso_url($echolink, $USER, $isInstructor, true); - - if($ssoResponse['success'] == true) { - // we want to test for a 404 - $curl = $essSSOLogin->get_curl_with_defaults(); - $headers = $essSSOLogin->get_headers($curl, $ssoResponse['url'], 1); - $error_message = ''; - - if (!strstr($headers[0]['http'], "302")) { - $error_message = 'unexpected_response'; - $e = explode(" ", $headers[0]['http'], 3); - $error_detail = $e[2]; - } else if (strstr($headers[1]['http'], "404")) { - $error_message = 'not_found_response'; - $e = explode(" ", $headers[1]['http'], 3); - $error_detail = $e[2]; - } else if (strstr($headers[1]['http'], "403")) { - $error_message = 'forbidden_response'; - $e = explode(" ", $headers[1]['http'], 3); - $error_detail = $e[2]; - } else if (!strstr($headers[1]['http'], "200")) { - $error_message = 'unexpected_response'; - $e = explode(" ", $headers[1]['http'], 3); - $error_detail = $e[2]; - } - curl_close($curl); - - if ($error_message == "") { - // All good - but we already used the request - need to sign again (generate a new nonce) - $ssoResponse = $essSSOLogin->generate_sso_url($echolink, $USER, $isInstructor, true); - header("Location:" . $ssoResponse['url']); - } else { - print_error($error_message, 'mod_echolink', '', $error_detail); - } - } + if ($error_message == "") { + // All good - but we already used the request - need to sign again (generate a new nonce) + $ssoResponse = $essSSOLogin->generate_sso_url($echolink, $USER, $isInstructor, true); + header("Location:" . $ssoResponse['url']); + } else { + print_error($error_message, 'mod_echolink', '', $error_detail); + } + } - return; + return; }// end of echolink_ess_oauth_seamless_login function //-------------------------------------------------------------