Skip to content

Commit

Permalink
fix display of SP name in selectidp-links template
Browse files Browse the repository at this point in the history
  • Loading branch information
briskt committed Jul 9, 2024
1 parent 8d4adb1 commit 27b6c1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions modules/material/themes/material/default/selectidp-links.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<span class="mdl-layout-title scale-to-parent">
{% if spName ?? '' is empty %}
{% if sp|entityDisplayName is empty %}
{{ '{selectidp-links:header}'|trans }}
{% else %}
{{ '{selectidp-links:header-for-sp}'|trans({'%spName%': spName})|e }}
{{ '{selectidp-links:header-for-sp}'|trans({'%spName%': sp|entityDisplayName})|e }}
{% endif %}
</span>

Expand Down
36 changes: 14 additions & 22 deletions modules/sildisco/src/IdPDisco.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Sil\SspUtils\AnnouncementUtils;
use Sil\SspUtils\DiscoUtils;
use Sil\SspUtils\Metadata;
use SimpleSAML\Utils\Arrays;
use SimpleSAML\Auth;
use SimpleSAML\Utils\HTTP;

/**
Expand All @@ -31,14 +31,6 @@ class IdPDisco extends \SimpleSAML\XHTML\IdPDisco
/* The idp metadata key that says whether an IDP is enabled */
public static string $enabledMdKey = 'enabled';

/* The sp metadata key that gives the name of the SP */
public static string $spNameMdKey = 'name';

/* Used to get the SP Entity ID, e.g. $spEntityId = $this->session->getData($sessionDataType, $sessionKeyForSP); */
public static string $sessionDataType = 'sildisco:authentication';
public static string $sessionKeyForSP = 'spentityid';


/**
* @inheritDoc
*/
Expand All @@ -59,7 +51,16 @@ private function getSPEntityIDAndReducedIdpList(): array
$idpList = $this->getIdPList();
$idpList = $this->filterList($idpList);

$spEntityId = $this->session->getData(self::$sessionDataType, self::$sessionKeyForSP);
// Creative solution for getting the EntityID from the SPMetadata entry in the state
// Source: https://github.com/simplesamlphp/simplesamlphp-module-discopower/blob/5e2e5e9da751104d1553d273cfb2d0bd1e2b57df/src/PowerIdPDisco.php#L231
// Before the SimpleSAMLphp 2 upgrade, we added it to the state ourselves by overriding the SAML2.php file
parse_str(parse_url($_GET['return'], PHP_URL_QUERY), $returnState);
$state = Auth\State::loadState($returnState['AuthID'], 'saml:sp:sso');
if ($state && array_key_exists('SPMetadata', $state)) {
$spmd = $state['SPMetadata'];
$this->log('Updated SP metadata from ' . $this->spEntityId . ' to ' . $spmd['entityid']);
}
$spEntityId = $spmd['entityid'];

if (!empty($spEntityId)) {
$idpList = DiscoUtils::getReducedIdpList(
Expand Down Expand Up @@ -99,21 +100,12 @@ public function handleRequest(): void
}
}

// Get the SP's name
// Get the SP metadata entry
$spEntries = Metadata::getSpMetadataEntries($this->getMetadataPath());
$sp = $spEntries[$spEntityId];

$t = new \SimpleSAML\XHTML\Template($this->config, 'selectidp-links', 'disco');

$spName = null;

$rawSPName = $spEntries[$spEntityId][self::$spNameMdKey] ?? null;
if ($rawSPName !== null) {
$arrayUtils = new Arrays();
$spName = htmlspecialchars($t->getTranslator()->getPreferredTranslation(
$arrayUtils->arrayize($rawSPName, 'en')
));
}

// in order to bypass some built-in simplesaml behavior, an extra idp
// might've been added. It's not meant to be displayed.
unset($idpList['dummy']);
Expand All @@ -132,7 +124,7 @@ public function handleRequest(): void
$t->data['return'] = $this->returnURL;
$t->data['returnIDParam'] = $this->returnIdParam;
$t->data['entityID'] = $this->spEntityId;
$t->data['spName'] = $spName;
$t->data['sp'] = $sp;
$t->data['urlpattern'] = htmlspecialchars($httpUtils->getSelfURLNoQuery());
$t->data['announcement'] = AnnouncementUtils::getAnnouncement();
$t->data['helpCenterUrl'] = $this->config->getOptionalString('helpCenterUrl', '');
Expand Down

0 comments on commit 27b6c1a

Please sign in to comment.