diff --git a/lib/SimpleSAML/Auth/State.php b/lib/SimpleSAML/Auth/State.php
index c1bfdb6302f4bdad3edccd3c4af4c58518bce697..5eb1b555e8ae01517c31914fdcf008af767b1648 100644
--- a/lib/SimpleSAML/Auth/State.php
+++ b/lib/SimpleSAML/Auth/State.php
@@ -37,6 +37,13 @@ class SimpleSAML_Auth_State {
 	const ID = 'SimpleSAML_Auth_State.id';
 
 
+	/**
+	 * The index in the cloned state array which contains the identifier of the
+	 * original state.
+	 */
+	const CLONE_ORIGINAL_ID = 'SimpleSAML_Auth_State.cloneOriginalId';
+
+
 	/**
 	 * The index in the state array which contains the current stage.
 	 */
@@ -162,6 +169,30 @@ class SimpleSAML_Auth_State {
 	}
 
 
+	/**
+	 * Clone the state.
+	 *
+	 * This function clones and returns the new cloned state.
+	 *
+	 * @param array $state  The original request state.
+	 * @return array  Cloned state data.
+	 */
+	public static function cloneState(array $state) {
+		$clonedState = $state;
+
+		if (array_key_exists(self::ID, $state)) {
+			$clonedState[self::CLONE_ORIGINAL_ID] = $state[self::ID];
+			unset($clonedState[self::ID]);
+
+			SimpleSAML_Logger::debug('Cloned state: ' . var_export($state[self::ID], TRUE));
+		} else {
+			SimpleSAML_Logger::debug('Cloned state with undefined id.');
+		}
+
+		return $clonedState;
+	}
+
+
 	/**
 	 * Retrieve saved state.
 	 *