diff --git a/lib/Auth/Source/Campusidp.php b/lib/Auth/Source/Campusidp.php index 009e8280e07d13bd7d43294219dcc11f2cfb3e47..4534c0ea8d1f1f2d3047f17a7f8026d676aa1777 100644 --- a/lib/Auth/Source/Campusidp.php +++ b/lib/Auth/Source/Campusidp.php @@ -217,6 +217,17 @@ class Campusidp extends Source } } + public static function isIdpInCookie($idps, $entityid) + { + foreach ($idps as $idp) { + if ($idp['entityid'] === $entityid) { + return true; + } + } + + return false; + } + public function logout(&$state) { assert(is_array($state)); diff --git a/www/selectsource.php b/www/selectsource.php index 9c0354be7d5d7abbfe0be87a0e954da4657f48fb..a0de84f086084b03f028cd64926dbaae98cf6d9a 100644 --- a/www/selectsource.php +++ b/www/selectsource.php @@ -47,21 +47,27 @@ if (array_key_exists('source', $_POST)) { !empty($wayfConfig['components'][$_POST['componentIndex']]) && $wayfConfig['components'][$_POST['componentIndex']]['name'] === 'searchbox') { - $chosenIdp = []; - $chosenIdp['entityid'] = $_POST['searchbox']; - $chosenIdp['name'] = $metadata[$_POST['searchbox']]['name']; - $chosenIdp['img'] = $wayfConfig['components'][$_POST['componentIndex']]['logos'][$_POST['searchbox']] - ?? Campusidp::getMostSquareLikeImg($metadata[$_POST['searchbox']]); - $chosenIdp['index'] = $_POST['componentIndex']; - - $prevIdps = Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS) === null ? [] : json_decode(gzinflate(base64_decode(Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS)))); - $prevIdps[] = $chosenIdp; - - while (strlen(base64_encode(gzdeflate(json_encode($prevIdps)))) > 4093) { - array_shift($prevIdps); - } + $prevIdps = Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS) === null ? + [] : + json_decode(gzinflate(base64_decode(Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS))), true); + + if (!Campusidp::isIdpInCookie($prevIdps, $_POST['searchbox'])) { + $chosenIdp = []; + $chosenIdp['entityid'] = $_POST['searchbox']; + $chosenIdp['name'] = $metadata[$_POST['searchbox']]['name']; + $chosenIdp['img'] = $wayfConfig['components'][$_POST['componentIndex']]['logos'][$_POST['searchbox']] + ?? Campusidp::getMostSquareLikeImg($metadata[$_POST['searchbox']]); + $chosenIdp['index'] = $_POST['componentIndex']; + - Campusidp::setCookie(Campusidp::COOKIE_PREVIOUS_IDPS, base64_encode(gzdeflate(json_encode($prevIdps)))); + $prevIdps[] = $chosenIdp; + + while (strlen(base64_encode(gzdeflate(json_encode($prevIdps)))) > 4093) { + array_shift($prevIdps); + } + + Campusidp::setCookie(Campusidp::COOKIE_PREVIOUS_IDPS, base64_encode(gzdeflate(json_encode($prevIdps)))); + } } Campusidp::delegateAuthentication($_POST['source'], $state);