diff --git a/modules/core/templates/login.twig b/modules/core/templates/login.twig new file mode 100644 index 0000000000000000000000000000000000000000..c86235b4c4b59d220193cdc84f0e9b3a30013313 --- /dev/null +++ b/modules/core/templates/login.twig @@ -0,0 +1,20 @@ +{% set pagetitle = 'Authenticate'|trans %} +{% extends "@core/base.twig" %} + +{% block content %} +<h1>{{ pagetitle }}</h1> + <p>Please choose one of the following authentication methods: </p> + +{%- if sources is empty %} + <p>Please check your SimpleSAML configuration.<br> + Follow the link and log in with administrator credentials. <a href="{{ loginurl }}">Admin login.</a></p> + +{%- else %} + <ul> + {% for id, config in sources -%} + <li><a href="?as={{ id|url_encode }}">{{ config.name|translateFromArray|default(id) }}</a></li> + + {% endfor -%} + </ul> +{% endif %} +{% endblock %} \ No newline at end of file diff --git a/modules/core/www/login.php b/modules/core/www/login.php new file mode 100644 index 0000000000000000000000000000000000000000..283950d6c6d6bef6742e514cfb34882278ea78fa --- /dev/null +++ b/modules/core/www/login.php @@ -0,0 +1,63 @@ +<?php + +$config = SimpleSAML_Configuration::getInstance(); +$sources = SimpleSAML_Configuration::getOptionalConfig('authsources.php')->toArray(); + +//delete admin +if (isset($sources['admin'])) { + unset($sources['admin']); +} + +//if only 1 auth +if (count($sources)==1) { + $_REQUEST['as'] = key(end($sources)); +} + +if (!array_key_exists('as', $_REQUEST)) { + $t = new SimpleSAML_XHTML_Template($config, 'core:login.twig'); + + $t->data['loginurl'] = SimpleSAML\Utils\Auth::getAdminLoginURL(); + $t->data['sources'] = $sources; + $t->show(); + exit(); +} + +$asId = (string) $_REQUEST['as']; +$as = new \SimpleSAML\Auth\Simple($asId); + +if (array_key_exists('logout', $_REQUEST)) { + $as->logout($config->getBasePath().'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]; + + throw $e; +} + +if (!$as->isAuthenticated()) { + $url = SimpleSAML\Module::getModuleURL('core/login.php', array('as' => $asId)); + $params = array( + 'ErrorURL' => $url, + 'ReturnTo' => $url, + ); + $as->login($params); +} + +$attributes = $as->getAttributes(); +$session = SimpleSAML_Session::getSessionFromRequest(); + +$t = new SimpleSAML_XHTML_Template($config, 'auth_status.twig', 'attributes'); + + +$t->data['header'] = '{status:header_saml20_sp}'; +$t->data['attributes'] = $attributes; +$t->data['nameid'] = !is_null($as->getAuthData('saml:sp:NameID')) ? $as->getAuthData('saml:sp:NameID') : false; +$t->data['logouturl'] = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery().'?as='.urlencode($asId).'&logout'; +$t->data['remaining'] = $session->getAuthData($asId, 'Expire')-time(); + +$t->show();