Example #1
0
<?php

$config = SimpleSAML_Configuration::getInstance();
if (!array_key_exists('as', $_REQUEST)) {
    $t = new SimpleSAML_XHTML_Template($config, 'core:authsource_list.tpl.php');
    $t->data['sources'] = SimpleSAML_Auth_Source::getSources();
    $t->show();
    exit;
}
$asId = (string) $_REQUEST['as'];
$as = new SimpleSAML_Auth_Simple($asId);
if (array_key_exists('logout', $_REQUEST)) {
    $as->logout('/' . $config->getBaseURL() . 'logout.php');
}
if (array_key_exists(SimpleSAML_Auth_State::EXCEPTION_PARAM, $_REQUEST)) {
    // This is just a simple example of an error
    $state = SimpleSAML_Auth_State::loadExceptionState();
    assert('array_key_exists(SimpleSAML_Auth_State::EXCEPTION_DATA, $state)');
    $e = $state[SimpleSAML_Auth_State::EXCEPTION_DATA];
    header('Content-Type: text/plain');
    echo "Exception during login:\n";
    foreach ($e->format() as $line) {
        echo $line . "\n";
    }
    exit(0);
}
if (!$as->isAuthenticated()) {
    $url = SimpleSAML_Module::getModuleURL('core/authenticate.php', array('as' => $asId));
    $params = array('ErrorURL' => $url, 'ReturnTo' => $url);
    $as->login($params);
}
Example #2
0
// get all the things that we will need from the SAML authentication
// and then shutdown the session control
SimpleSAML_Configuration::init($samlconfig);
$saml_session = SimpleSAML_Session::getInstance();
// do we have a logout request?
if (param_variable("logout", false)) {
    // logout the saml session
    $sp = $saml_session->getAuthority();
    if (!$sp) {
        $sp = 'default-sp';
    }
    $as = new SimpleSAML_Auth_Simple($sp);
    $as->logout($CFG->wwwroot);
}
$sp = param_alphanumext('as', 'default-sp');
if (!in_array($sp, SimpleSAML_Auth_Source::getSources())) {
    $sp = 'default-sp';
}
$as = new SimpleSAML_Auth_Simple($sp);
// Check the SimpleSAMLphp config is compatible
$saml_config = SimpleSAML_Configuration::getInstance();
$session_handler = $saml_config->getString('session.handler', false);
$store_type = $saml_config->getString('store.type', false);
if ($store_type == 'phpsession' || $session_handler == 'phpsession' || empty($store_type) && empty($session_handler)) {
    throw new AuthInstanceException(get_string('errorbadssphp', 'auth.saml'));
}
// what is the session like?
$valid_saml_session = $saml_session->isValid($sp);
// figure out what the returnto URL should be
$wantsurl = param_variable("wantsurl", false);
if (!$wantsurl) {
        echo $key;
        ?>
</td>
            <td><?php 
        echo $value[0];
        ?>
</td>
          </tr>
	<?php 
    }
    ?>
        </table>
      </div>
    <?php 
} else {
    $sources = SimpleSAML_Auth_Source::getSources();
    ?>
      <p class="lead">Select the IdP you want to use to authenticate:</p>
      <ol>
        <?php 
    foreach ($sources as $source) {
        ?>
        <li><a href="?<?php 
        echo $saml_sso;
        ?>
=<?php 
        echo $source;
        ?>
"><?php 
        echo $source;
        ?>