Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Use RelayState in discoveryAction
Browse files Browse the repository at this point in the history
  • Loading branch information
Mael LE GUEN committed Sep 16, 2019
1 parent e7204aa commit 6c6ca2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/LightSaml/SpBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,41 @@ public function metadataAction()
return $context->getHttpResponseContext()->getResponse();
}

public function discoveryAction()
public function discoveryAction(Request $request)
{
$params = array();
$relayState = $request->get('RelayState');
if (null !== $relayState) {
$params['RelayState'] = $relayState;
}

$parties = $this->get('lightsaml.container.build')->getPartyContainer()->getIdpEntityDescriptorStore()->all();

if (1 == count($parties)) {
return $this->redirect($this->generateUrl('lightsaml_sp.login', ['idp' => $parties[0]->getEntityID()]));
return $this->redirect($this->generateUrl('lightsaml_sp.login', array_merge($params, ['idp' => $parties[0]->getEntityID()])));
}

return $this->render('LightSamlSpBundle::discovery.html.twig', [
'parties' => $parties,
'params' => $params
]);
}

public function loginAction(Request $request)
{
$relayState = $request->get('RelayState');
$idpEntityId = $request->get('idp');
if (null === $idpEntityId) {
return $this->redirect($this->generateUrl($this->container->getParameter('lightsaml_sp.route.discovery')));
$params = array();
if (null !== $relayState) {
$params['RelayState'] = $relayState;
}
return $this->redirect($this->generateUrl($this->container->getParameter('lightsaml_sp.route.discovery'), $params));
}

$profile = $this->get('ligthsaml.profile.login_factory')->get($idpEntityId);
$context = $profile->buildContext();

$relayState = $request->get('RelayState');
if (null !== $relayState) {
$context->setRelayState($relayState);
}
Expand Down
2 changes: 1 addition & 1 deletion src/LightSaml/SpBundle/Resources/views/discovery.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<p><small>Choose one</small></p>
{% for idp in parties %}
{% if idp.allIdpSsoDescriptors %}
<p><a data-idp="{{ idp.entityID }}" href="{{ path('lightsaml_sp.login', {idp: idp.entityID}) }}">{{ idp.entityID }}</a></p>
<p><a data-idp="{{ idp.entityID }}" href="{{ path('lightsaml_sp.login', params|merge({idp: idp.entityID})) }}">{{ idp.entityID }}</a></p>
{% endif %}
{% else %}
<p>There is no IDP configured</p>
Expand Down

0 comments on commit 6c6ca2f

Please sign in to comment.