diff --git a/modules/multiauth/docs/multiauth.txt b/modules/multiauth/docs/multiauth.txt index 4c0f52be251beedf8c5f90ede310930e2581d83b..347b2c242498fce1c6fc04d733425e9e6ca9edb0 100644 --- a/modules/multiauth/docs/multiauth.txt +++ b/modules/multiauth/docs/multiauth.txt @@ -29,7 +29,21 @@ authentication source: * The available authentication sources. * They must be defined in this authsources.php file. */ - 'sources' => array('example-saml', 'example-admin'), + 'sources' => array( + 'example-saml' => array( + 'text' => array( + 'en' => 'Log in using a SAML SP', + 'es' => 'Entrar usando un SP SAML', + ), + 'css-class' => 'SAML', + ), + 'example-admin' => array( + 'text' => array( + 'en' => 'Log in using the admin password', + 'es' => 'Entrar usando la contraseña de administrador', + ), + ), + ), ), 'example-saml' => array( @@ -52,7 +66,30 @@ authentication sources defined in the `config/authsources.php` file. The order in this array does not matter since the user is the one that decides which one to use. -I is possible to add the parameter `source` to the calling URL, +The keys of the sources array are the identifiers of authentication +sources defined in the authsources.php configuration file. The +values are arrays with information used to create the user +interface that will let the user select the authentication source +he wants. Older versions of the multiauth module did not have +this structure and just have the authsources identifiers as the +values of the sources array. It has been improved in a backwards +compatibility fashion so both cases should work. + +So each source in the sources array has a key and a value. As +mentioned above the key is the authsource identifier and the value +is another array with two optional keys: 'text' and 'css-class'. +The text element is another array with localized strings for one +or more languages. These texts will be shown in the selectsource.php +view. Note that you should at least enter the text in the default +language as specified in your config.php file. The css-class +element is a string with the css class that will be applied to +the <li> element in the selectsource.php view. By default the +authtype of the authsource is used as the css class with colons +replaced by dashes. So in the previous example, the css class used +in the 'example-admin' authentication source would be +'core-AdminPassword'. + +It is possible to add the parameter `source` to the calling URL, when accessing a service, to allow the user to preselect the authsource to be used. This can be handy if you support different authentication types for differen types of users and you want the diff --git a/modules/multiauth/lib/Auth/Source/MultiAuth.php b/modules/multiauth/lib/Auth/Source/MultiAuth.php index d54ee15c85769f9bd522e96df5e113a2347bb0ca..d613564493e95ac6adbd56de664bfb12593af3e3 100644 --- a/modules/multiauth/lib/Auth/Source/MultiAuth.php +++ b/modules/multiauth/lib/Auth/Source/MultiAuth.php @@ -53,7 +53,41 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source { throw new Exception('The required "sources" config option was not found'); } - $this->sources = $config['sources']; + $globalConfiguration = SimpleSAML_Configuration::getInstance(); + $defaultLanguage = $globalConfiguration->getString('language.default', 'en'); + $authsources = SimpleSAML_Configuration::getConfig('authsources.php'); + $this->sources = array(); + foreach($config['sources'] as $source => $info) { + + if (is_int($source)) { // Backwards compatibility + $source = $info; + $info = array(); + } + + if (array_key_exists('text', $info)) { + $text = $info['text']; + } else { + $text = array($defaultLanguage => $source); + } + + if (array_key_exists('css-class', $info)) { + $css_class = $info['css-class']; + } else { + /* Use the authtype as the css class */ + $authconfig = $authsources->getArray($source, NULL); + if (!array_key_exists(0, $authconfig) || !is_string($authconfig[0])) { + $css_class = ""; + } else { + $css_class = str_replace(":", "-", $authconfig[0]); + } + } + + $this->sources[] = array( + 'source' => $source, + 'text' => $text, + 'css_class' => $css_class, + ); + } } /** diff --git a/modules/multiauth/templates/selectsource.php b/modules/multiauth/templates/selectsource.php index 5d5290cd1c40af9fb16d35a22da6fadaccfaaf4f..135a43a2f1c180d95dd381d6f9b97eb10ee0e4fe 100644 --- a/modules/multiauth/templates/selectsource.php +++ b/modules/multiauth/templates/selectsource.php @@ -11,9 +11,10 @@ $this->includeAtTemplateBase('includes/header.php'); <ul> <?php foreach($this->data['sources'] as $source) { - echo '<li><a href="?source=' . htmlspecialchars($source) . + echo '<li class="' . htmlspecialchars($source['css_class']) . ' authsource">' . + '<a href="?source=' . htmlspecialchars($source['source']) . '&AuthState=' . htmlspecialchars($this->data['authstate']) . '">' . - htmlspecialchars($source) . '</a></li>'; + '<span>' . htmlspecialchars($this->t($source['text'])) . '</span></a></li>'; } ?> </ul>