$authId, 'SimpleSAML_Auth_Default.ReturnURL' => $returnURL, 'SimpleSAML_Auth_Default.ErrorURL' => $errorURL, 'LoginCompletedHandler' => array(get_class(), 'loginCompleted'), 'LoginFailedHandler' => array(get_class(), 'loginFailed'), ); if (array_key_exists('SPMetadata', $hints)) { $state['SPMetadata'] = $hints['SPMetadata']; } if (array_key_exists('IdPMetadata', $hints)) { $state['IdPMetadata'] = $hints['IdPMetadata']; } $as = SimpleSAML_Auth_Source::getById($authId); if ($as === NULL) { throw new Exception('Invalid authentication source: ' . $authId); } $as->authenticate($state); self::loginCompleted($state); } /** * Called when a login operation has finished. * * @param array $state The state after the login. */ public static function loginCompleted($state) { assert('is_array($state)'); assert('array_key_exists("SimpleSAML_Auth_Default.ReturnURL", $state)'); assert('array_key_exists("SimpleSAML_Auth_Default.id", $state)'); assert('array_key_exists("Attributes", $state)'); $returnURL = $state['SimpleSAML_Auth_Default.ReturnURL']; /* Save session state. */ $session = SimpleSAML_Session::getInstance(); $session->doLogin($state['SimpleSAML_Auth_Default.id']); $session->setAttributes($state['Attributes']); if(array_key_exists('Expires', $state)) { $session->setSessionDuration($state['Expires'] - time()); } /* Redirect... */ SimpleSAML_Utilities::redirect($returnURL); } /** * Called when a login operation fails. * * @param array $state The state array. * @param string $statusCode A status code, in the form of an URI, which indicates why the login failed. * @param string $statusMessage A text which describes why the login failed. */ public static function loginFailed($state, $statusCode, $statusMessage) { assert('is_array($state)'); assert('array_key_exists("SimpleSAML_Auth_Default.ErrorURL", $state)'); assert('is_string($statusCode)'); assert('is_string($statusMessage)'); $url = $state['SimpleSAML_Auth_Default.ErrorURL']; if ($url === NULL) { /* We don't have an error handler. Show an error page. */ SimpleSAML_Utilities::fatalError($session->getTrackID(), 'RESPONSESTATUSNOSUCCESS', new Exception('StatusCode = \'' . $statusCode . '\'; StatusMessage = \'' . $statusMessage . '\';')); } $info = array('StatusCode' => $statusCode, 'StatusMessage' => $statusMessage); /* Redirect... */ SimpleSAML_Utilities::redirect($url, $info); } } ?>