Skip to content
Snippets Groups Projects
Commit 476fc1a8 authored by Olav Morken's avatar Olav Morken
Browse files

Add support for custom names on authsources in multiauth.

Thanks to Lorenzo Gil Sanchez for implementing this!

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2890 44740490-163a-0410-bde0-09ae8108e29a
parent 5e0cebf0
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,21 @@ authentication source: ...@@ -29,7 +29,21 @@ authentication source:
* The available authentication sources. * The available authentication sources.
* They must be defined in this authsources.php file. * 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( 'example-saml' => array(
...@@ -52,7 +66,30 @@ authentication sources defined in the `config/authsources.php` ...@@ -52,7 +66,30 @@ authentication sources defined in the `config/authsources.php`
file. The order in this array does not matter since the user file. The order in this array does not matter since the user
is the one that decides which one to use. 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 when accessing a service, to allow the user to preselect the
authsource to be used. This can be handy if you support different authsource to be used. This can be handy if you support different
authentication types for differen types of users and you want the authentication types for differen types of users and you want the
......
...@@ -53,7 +53,41 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source { ...@@ -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'); 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,
);
}
} }
/** /**
......
...@@ -11,9 +11,10 @@ $this->includeAtTemplateBase('includes/header.php'); ...@@ -11,9 +11,10 @@ $this->includeAtTemplateBase('includes/header.php');
<ul> <ul>
<?php <?php
foreach($this->data['sources'] as $source) { 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']) . '">' . '&AuthState=' . htmlspecialchars($this->data['authstate']) . '">' .
htmlspecialchars($source) . '</a></li>'; '<span>' . htmlspecialchars($this->t($source['text'])) . '</span></a></li>';
} }
?> ?>
</ul> </ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment