diff --git a/auth/shibboleth/auth.php b/auth/shibboleth/auth.php index fe6244c8c8a..39ca032b44e 100644 --- a/auth/shibboleth/auth.php +++ b/auth/shibboleth/auth.php @@ -277,6 +277,32 @@ class auth_plugin_shibboleth extends auth_plugin_base { return; } } + + /** + * Return a list of identity providers to display on the login page. + * + * @param string $wantsurl The requested URL. + * @return array List of arrays with keys url, iconurl and name. + */ + public function loginpage_idp_list($wantsurl) { + $config = get_config('auth_shibboleth'); + $result = []; + + // Before displaying the button check that Shibboleth is set-up correctly. + if (empty($config->user_attribute)) { + return $result; + } + + $url = new moodle_url('/auth/shibboleth/index.php'); + $iconurl = moodle_url::make_pluginfile_url(context_system::instance()->id, + 'auth_shibboleth', + 'logo', + null, + '/', + $config->auth_logo); + $result[] = ['url' => $url, 'iconurl' => $iconurl, 'name' => $config->login_name]; + return $result; + } } diff --git a/auth/shibboleth/lang/en/auth_shibboleth.php b/auth/shibboleth/lang/en/auth_shibboleth.php index 659e4d1a1e9..8ef9ec1b2bc 100644 --- a/auth/shibboleth/lang/en/auth_shibboleth.php +++ b/auth/shibboleth/lang/en/auth_shibboleth.php @@ -25,6 +25,8 @@ $string['auth_shib_auth_method'] = 'Authentication method name'; $string['auth_shib_auth_method_description'] = 'Provide a name for the Shibboleth authentication method that is familiar to your users. This could be the name of your Shibboleth federation, e.g. SWITCHaai Login or InCommon Login or similar.'; +$string['auth_shib_auth_logo'] = 'Authentication method logo'; +$string['auth_shib_auth_logo_description'] = 'Provide a logo for the Shibboleth authentication method that is familiar to your users. This could be the logo of your Shibboleth federation, e.g. SWITCHaai Login or InCommon Login or similar.'; $string['auth_shib_contact_administrator'] = 'In case you are not associated with the given organizations and you need access to a course on this server, please contact the Moodle Administrator.'; $string['auth_shibbolethdescription'] = 'Using this method users are created and authenticated using Shibboleth.
Be sure to read the README for Shibboleth on how to set up your Moodle with Shibboleth'; $string['auth_shibboleth_errormsg'] = 'Please select the organization you are member of!'; diff --git a/auth/shibboleth/lib.php b/auth/shibboleth/lib.php new file mode 100644 index 00000000000..f8ac7573984 --- /dev/null +++ b/auth/shibboleth/lib.php @@ -0,0 +1,64 @@ +. + +/** + * This file contains the hooks for the Shibboleth authentication module. + * + * @package auth_shibboleth + * @copyright 2018 Fabrice Ménard + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +/** + * Serves the logo file settings. + * + * @param stdClass $course course object + * @param stdClass $cm course module object + * @param stdClass $context context object + * @param string $filearea file area + * @param array $args extra arguments + * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving + * @return bool false if file not found, does not return if found - justsend the file + */ +function auth_shibboleth_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { + if ($context->contextlevel != CONTEXT_SYSTEM) { + return false; + } + + if ($filearea !== 'logo' ) { + return false; + } + + $itemid = 0; + + $filename = array_pop($args); + if (!$args) { + $filepath = '/'; + } else { + $filepath = '/'.implode('/', $args).'/'; + } + + $fs = get_file_storage(); + $file = $fs->get_file($context->id, 'auth_shibboleth', $filearea, $itemid, $filepath, $filename); + if (!$file) { + return false; + } + + send_stored_file($file, null, 0, $forcedownload, $options); +} diff --git a/auth/shibboleth/settings.php b/auth/shibboleth/settings.php index c9013783bfe..e4b4c3a9f86 100644 --- a/auth/shibboleth/settings.php +++ b/auth/shibboleth/settings.php @@ -63,6 +63,11 @@ if ($ADMIN->fulltree) { get_string('auth_shib_auth_method', 'auth_shibboleth'), get_string('auth_shib_auth_method_description', 'auth_shibboleth'), 'Shibboleth Login', PARAM_RAW_TRIMMED)); + // Authentication method logo. + $settings->add(new admin_setting_configstoredfile('auth_shibboleth/auth_logo', + get_string('auth_shib_auth_logo', 'auth_shibboleth'), + get_string('auth_shib_auth_logo_description', 'auth_shibboleth'), 'logo', 0, ['accepted_types' => ['image']])); + // Login directions. $settings->add(new admin_setting_configtextarea('auth_shibboleth/auth_instructions', get_string('auth_shib_instructions_key', 'auth_shibboleth'),