diff --git a/lib/SimpleSAML/Auth/Default.php b/lib/SimpleSAML/Auth/Default.php
index 33b20cb84834d7c7461856b75d528bb5f27bc3a2..5f620a341e69261e2c697188f38ea88b8c16456d 100644
--- a/lib/SimpleSAML/Auth/Default.php
+++ b/lib/SimpleSAML/Auth/Default.php
@@ -66,6 +66,7 @@ class SimpleSAML_Auth_Default {
 		assert('array_key_exists("SimpleSAML_Auth_Default.ReturnURL", $state)');
 		assert('array_key_exists("SimpleSAML_Auth_Default.id", $state)');
 		assert('array_key_exists("Attributes", $state)');
+		assert('!array_key_exists("LogoutState", $state) || is_array($state["LogoutState"])');
 
 		$returnURL = $state['SimpleSAML_Auth_Default.ReturnURL'];
 
@@ -77,6 +78,10 @@ class SimpleSAML_Auth_Default {
 			$session->setSessionDuration($state['Expires'] - time());
 		}
 
+		if (array_key_exists('LogoutState', $state)) {
+			$session->setLogoutState($state['LogoutState']);
+		}
+
 		/* Redirect... */
 		SimpleSAML_Utilities::redirect($returnURL);
 	}
@@ -121,15 +126,15 @@ class SimpleSAML_Auth_Default {
 	public static function initLogout($returnURL) {
 		assert('is_string($returnURL)');
 
-		$state = array(
-			'SimpleSAML_Auth_Default.ReturnURL' => $returnURL,
-			'LogoutCompletedHandler' => array(get_class(), 'logoutCompleted'),
-			);
-
 		$session = SimpleSAML_Session::getInstance();
+
+		$state = $session->getLogoutState();
 		$authId = $session->getAuthority();
 		$session->doLogout();
 
+		$state['SimpleSAML_Auth_Default.ReturnURL'] = $returnURL;
+		$state['LogoutCompletedHandler'] = array(get_class(), 'logoutCompleted');
+
 		$as = SimpleSAML_Auth_Source::getById($authId);
 		if ($as === NULL) {
 			/* The authority wasn't an authentication source... */
diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php
index 19a18b3622606f7afdce4193c6918b37d3908355..4dc3ef24ea891b06505cf26d44ad8ea92b6149b5 100644
--- a/lib/SimpleSAML/Session.php
+++ b/lib/SimpleSAML/Session.php
@@ -76,6 +76,12 @@ class SimpleSAML_Session {
 	private $sessionNameId;
 
 
+	/**
+	 * Logout state when authenticated with authentication sources.
+	 */
+	private $logoutState;
+
+
 	/**
 	 * private constructor restricts instantiaton to getInstance()
 	 */
@@ -405,6 +411,7 @@ class SimpleSAML_Session {
 		$this->authenticated = FALSE;
 		$this->authority = NULL;
 		$this->attributes = NULL;
+		$this->logoutState = NULL;
 	}
 
 
@@ -816,6 +823,34 @@ class SimpleSAML_Session {
 		register_shutdown_function(array($this, 'saveSession'));
 	}
 
+
+	/**
+	 * Set the logout state for this session.
+	 *
+	 * @param array $state  The state array.
+	 */
+	public function setLogoutState($state) {
+		assert('is_array($state)');
+
+		$this->dirty = TRUE;
+		$this->logoutState = $state;
+	}
+
+
+	/**
+	 * Retrieve the logout state for this session.
+	 *
+	 * @return array  The logout state. If no logout state is set, an empty array will be returned.
+	 */
+	public function getLogoutState() {
+
+		if ($this->logoutState === NULL) {
+			return array();
+		}
+
+		return $this->logoutState;
+	}
+
 }
 
 ?>
\ No newline at end of file