public function test_send_authn_request_profile() { $buildContainer = $this->getBuildContainer(); $idpEntityId = 'https://localhost/lightSAML/lightSAML-IDP'; $builder = new \LightSaml\Builder\Profile\WebBrowserSso\Sp\SsoSpSendAuthnRequestProfileBuilder($buildContainer, $idpEntityId); $context = $builder->buildContext(); $action = $builder->buildAction(); $action->execute($context); $html = $context->getHttpResponseContext()->getResponse()->getContent(); $crawler = new Crawler($html); $code = $crawler->filter('body form input[name="SAMLRequest"]')->first()->attr('value'); $xml = base64_decode($code); $root = new \SimpleXMLElement($xml); $root->registerXPathNamespace('saml', SamlConstants::NS_ASSERTION); $this->assertEquals('AuthnRequest', $root->getName()); $this->assertEquals(self::OWN_ENTITY_ID, (string) $root->children('saml', true)->Issuer); $this->assertEquals('https://localhost/lightsaml/lightSAML-IDP/web/idp/login.php', $root['Destination']); }
<?php $idpEntityId = $_REQUEST['idp']; if (null == $idpEntityId) { header('Location: discovery.php'); exit; } require_once __DIR__ . '/_config.php'; $buildContainer = SpConfig::current()->getBuildContainer(); $builder = new \LightSaml\Builder\Profile\WebBrowserSso\Sp\SsoSpSendAuthnRequestProfileBuilder($buildContainer, $idpEntityId); $buildContainer->getSystemContainer()->getEventDispatcher()->addListener(\LightSaml\Event\Events::BINDING_MESSAGE_SENT, function (\Symfony\Component\EventDispatcher\GenericEvent $event) { //var_dump($event->getSubject()); //exit; }); $buildContainer->getSystemContainer()->getEventDispatcher()->addListener(\LightSaml\Event\Events::BEFORE_ENCRYPT, function (\Symfony\Component\EventDispatcher\GenericEvent $event) { /** @var \LightSaml\Context\Profile\ProfileContext $context */ $context = $event->getSubject(); $context->getOutboundMessage()->setRelayState('relayState'); }); $context = $builder->buildContext(); $action = $builder->buildAction(); $action->map(function (\LightSaml\Action\ActionInterface $action) use($buildContainer) { return new \LightSaml\Action\LoggableAction($action, $buildContainer->getSystemContainer()->getLogger()); }); $action->execute($context); $context->getHttpResponseContext()->getResponse()->send();