diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 9d9667e730c164a1edb7267d96e351aa9d7309eb..27b4da60057dbab50f40c4d86bf28744c6e99886 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -1764,6 +1764,32 @@ class SimpleSAML_Utilities { exit(0); } + /** + * Create a link which will POST data. + * + * @param string $destination The destination URL. + * @param array $post The name-value pairs which will be posted to the destination. + * @return string An URL which can be accessed to post the data. + */ + public static function createPostRedirectLink($destination, $post) { + assert('is_string($destination)'); + assert('is_array($post)'); + + $id = SimpleSAML_Utilities::generateID(); + $postData = array( + 'post' => $post, + 'url' => $destination, + ); + + $session = SimpleSAML_Session::getInstance(); + $session->setData('core_postdatalink', $id, $postData); + + return SimpleSAML_Utilities::addURLParameter( + SimpleSAML_Module::getModuleURL('core/postredirect.php'), + array('RedirId' => $id) + ); + } + } ?> \ No newline at end of file diff --git a/modules/core/www/postredirect.php b/modules/core/www/postredirect.php new file mode 100644 index 0000000000000000000000000000000000000000..408fe554e65682e339af3120db0f34a5c81eaa7b --- /dev/null +++ b/modules/core/www/postredirect.php @@ -0,0 +1,32 @@ +<?php + +/** + * This page provides a way to create a redirect to a POST request. + * + * @package simpleSAMLphp + * @version $Id$ + */ + +if (!array_key_exists('RedirId', $_REQUEST)) { + throw new SimpleSAML_Error_BadRequest('Missing RedirId parameter.'); +} + +$id = $_REQUEST['RedirId']; + +$session = SimpleSAML_Session::getInstance(); +$postData = $session->getData('core_postdatalink', $id); + +if ($postData === NULL) { + /* The post data is missing, probably because it timed out. */ + throw new Exception('The POST data we should restore was lost.'); +} +assert('is_array($postData)'); +assert('array_key_exists("url", $postData)'); +assert('array_key_exists("post", $postData)'); + +$url = $postData['url']; +$post = $postData['post']; + +SimpleSAML_Utilities::postRedirect($url, $post); + +?> \ No newline at end of file