From 3dd293950a009bef66a163e4b023811b298655da Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Thu, 24 Sep 2009 11:54:17 +0000
Subject: [PATCH] SimpleSAML_Auth_Default: Add handleUnsolicedAuth().

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1783 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Auth/Default.php | 38 +++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/lib/SimpleSAML/Auth/Default.php b/lib/SimpleSAML/Auth/Default.php
index a71358c96..18df3b49e 100644
--- a/lib/SimpleSAML/Auth/Default.php
+++ b/lib/SimpleSAML/Auth/Default.php
@@ -178,6 +178,44 @@ class SimpleSAML_Auth_Default {
 		$session->doLogout();
 	}
 
+
+	/**
+	 * Handle a unsoliced login operations.
+	 *
+	 * This function creates a session from the received information. It
+	 * will then redirect to the given URL.
+	 *
+	 * This is used to handle IdP initiated SSO.
+	 *
+	 * @param string $authId  The id of the authentication source that received the request.
+	 * @param array $state  A state array.
+	 * @param string $redirectTo  The URL we should redirect the user to after
+	 *                            updating the session.
+	 */
+	public static function handleUnsolicedAuth($authId, array $state, $redirectTo) {
+		assert('is_string($authId)');
+		assert('is_string($redirectTo)');
+
+		$session = SimpleSAML_Session::getInstance();
+		$session->doLogin($authId);
+
+		if (array_key_exists('Attributes', $state)) {
+			$session->setAttributes($state['Attributes']);
+		} else {
+			$session->setAttributes(array());
+		}
+
+		if(array_key_exists('Expires', $state)) {
+			$session->setSessionDuration($state['Expires'] - time());
+		}
+
+		if (array_key_exists('LogoutState', $state)) {
+			$session->setLogoutState($state['LogoutState']);
+		}
+
+		SimpleSAML_Utilities::redirect($redirectTo);
+	}
+
 }
 
 ?>
\ No newline at end of file
-- 
GitLab