/**
* Create the redirect URL for a message.
*
* @param \SAML2\Message $message The message.
* @return string The URL the user should be redirected to in order to send a message.
* @throws \Exception
*/
public function getRedirectURL(Message $message)
{
$store = SimpleSAML_Store::getInstance();
if ($store === false) {
throw new \Exception('Unable to send artifact without a datastore configured.');
}
$generatedId = pack('H*', (string) SimpleSAML_Utilities::stringToHex(SimpleSAML_Utilities::generateRandomBytes(20)));
$artifact = base64_encode("" . sha1($message->getIssuer(), true) . $generatedId);
$artifactData = $message->toUnsignedXML();
$artifactDataString = $artifactData->ownerDocument->saveXML($artifactData);
$store->set('artifact', $artifact, $artifactDataString, Temporal::getTime() + 15 * 60);
$params = array('SAMLart' => $artifact);
$relayState = $message->getRelayState();
if ($relayState !== null) {
$params['RelayState'] = $relayState;
}
return SimpleSAML_Utilities::addURLparameter($message->getDestination(), $params);
}