Skip to content
Snippets Groups Projects
Commit 439a2124 authored by Olav Morken's avatar Olav Morken
Browse files

Utilities: Add createPostRedirectLink function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1548 44740490-163a-0410-bde0-09ae8108e29a
parent 38f70edd
No related branches found
No related tags found
No related merge requests found
...@@ -1764,6 +1764,32 @@ class SimpleSAML_Utilities { ...@@ -1764,6 +1764,32 @@ class SimpleSAML_Utilities {
exit(0); 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
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment