我无法使用authsources。php,但还是设法用我需要的samlp:extensions authnrequest重新创建了它。
我创建了一个php应用程序,并将其连接到Simplesaml服务提供商,以便使用samlp:Extensions发送请求,下面是针对那些有相同问题的人的代码:
应用程序/应用程序。php
<?php
//Load SimpleSAMLphp.
require_once('/var/www/simplesamlphp/lib/_autoload.php');
//Initiate a SimpleSAML_Auth_Simple object.
$as = new SimpleSAML_Auth_Simple('name-of-sp');
//Standard PHP lib more info at -> http://php.net/manual/en/domdocument.createelementns.phphttp://php.net/manual/en/domdocument.createelementns.php
$dom = SAML2_DOMDocumentFactory::create();
$attributes_ext = $dom->createElementNS('namespace-uri', 'fa:RequestedAttributes');
$item = $dom->createElementNS('namespace-uri', 'fa:RequestedAttribute');
$attrName = $dom->createAttribute('Name');
$attrName->value = 'attributeName';
$attrNameFormat = $dom->createAttribute('NameFormat');
$attrNameFormat->value = "urn:oasis:names:tc:SAML:2.0:attrname-format:uri";
$attrRequirement = $dom->createAttribute('isRequired');
$attrRequirement->value = "true";
$item->appendChild($attrName);
$item->appendChild($attrNameFormat);
$item->appendChild($attrRequirement);
$attributes_ext->appendChild($item);
$ext[] = new SAML2_XML_Chunk($attributes_ext);
$as->login(array(
'saml:Extensions' => $ext,
));
//If the user is not authenticated, authenticate the user
$as->requireAuth();
//Get the users attributes and print them.
$attributes = $as->getAttributes();
print_r($attributes);
//Output the attributes to a file
$myFile = "/tmp/attributes.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = print_r($attributes, true);
fwrite($fh, $stringData);
fclose($fh);
//Displays a Login and Logout link
$url_in = $as->getLoginURL();
$url_out = $as->getLogoutURL();
print('<br><a href="' . htmlspecialchars($url_in) . '">Login</a>');
print('<br><a href="' . htmlspecialchars($url_out) . '">Logout</a><br>');
//If using PHP sessions in SimpleSAMLphp cleanup the SimpleSAMLphp session to be able to use $_SESSION
$session = SimpleSAML_Session::getSessionFromRequest();
$session->cleanup();
//Display PHP information
phpinfo()
?>
</body>
</html>
将其设置为运行以进行实验
php-S 0.0.0.0:5000-t应用程序/
导航到localhost:5000/app。php,这将使用SP配置自动将您发送到IDP的登录。您可以尝试使用authsources。simplesamlphp提供的php示例