From 439a2124ed23c9b44c30a50aec36718acba0fff7 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Fri, 3 Jul 2009 13:21:51 +0000 Subject: [PATCH] Utilities: Add createPostRedirectLink function. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1548 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Utilities.php | 26 +++++++++++++++++++++++++ modules/core/www/postredirect.php | 32 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 modules/core/www/postredirect.php diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 9d9667e73..27b4da600 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 000000000..408fe554e --- /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 -- GitLab