/**
* 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.
*/
public function getRedirectURL(Message $message)
{
if ($this->destination === null) {
$destination = $message->getDestination();
} else {
$destination = $this->destination;
}
$relayState = $message->getRelayState();
$key = $message->getSignatureKey();
$msgStr = $message->toUnsignedXML();
$msgStr = $msgStr->ownerDocument->saveXML($msgStr);
Utils::getContainer()->debugMessage($msgStr, 'out');
$msgStr = gzdeflate($msgStr);
$msgStr = base64_encode($msgStr);
/* Build the query string. */
if ($message instanceof Request) {
$msg = 'SAMLRequest=';
} else {
$msg = 'SAMLResponse=';
}
$msg .= urlencode($msgStr);
if ($relayState !== null) {
$msg .= '&RelayState=' . urlencode($relayState);
}
if ($key !== null) {
/* Add the signature. */
$msg .= '&SigAlg=' . urlencode($key->type);
$signature = $key->signData($msg);
$msg .= '&Signature=' . urlencode(base64_encode($signature));
}
if (strpos($destination, '?') === false) {
$destination .= '?' . $msg;
} else {
$destination .= '&' . $msg;
}
return $destination;
}