From 21ca234aebe391b1ad9e3bbb1fc7ad22144b9b63 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 22 Sep 2009 07:43:48 +0000
Subject: [PATCH] SimpleSAML_Auth_Simple: Make requireAuth accept an array with
 options.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1767 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Auth/Simple.php | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/lib/SimpleSAML/Auth/Simple.php b/lib/SimpleSAML/Auth/Simple.php
index b8041421d..6eba0b73b 100644
--- a/lib/SimpleSAML/Auth/Simple.php
+++ b/lib/SimpleSAML/Auth/Simple.php
@@ -57,9 +57,9 @@ class SimpleSAML_Auth_Simple {
 	 * preserved. If $allowPost is FALSE, the user will be returned to the
 	 * current page with a GET request.
 	 *
-	 * @param bool $allowPost  Whether POST requests will be preserved. The default is to preserve POST requests.
+	 * @param array $options  Various options to the authentication request.
 	 */
-	public function requireAuth($allowPost = TRUE) {
+	public function requireAuth(array $options = array()) {
 		assert('is_bool($allowPost)');
 
 		$session = SimpleSAML_Session::getInstance();
@@ -69,12 +69,23 @@ class SimpleSAML_Auth_Simple {
 			return;
 		}
 
-		$url = SimpleSAML_Utilities::selfURL();
-		if ($allowPost && $_SERVER['REQUEST_METHOD'] === 'POST') {
-			$url = SimpleSAML_Utilities::createPostRedirectLink($url, $_POST);
+		if (array_key_exists('KeepPost', $options)) {
+			$keepPost = (bool)$options['KeepPost'];
+		} else {
+			$keepPost = TRUE;
 		}
 
-		SimpleSAML_Auth_Default::initLogin($this->authSource, $url);
+		if (array_key_exists('ReturnTo', $options)) {
+			$returnTo = (string)$options['ReturnTo'];
+		} else {
+			$returnTo = SimpleSAML_Utilities::selfURL();
+		}
+
+		if ($keepPost && $_SERVER['REQUEST_METHOD'] === 'POST') {
+			$returnTo = SimpleSAML_Utilities::createPostRedirectLink($returnTo, $_POST);
+		}
+
+		SimpleSAML_Auth_Default::initLogin($this->authSource, $returnTo);
 	}
 
 
-- 
GitLab