- Author: Luuk Verhoeven, MFreak.nl
- Min. required: Moodle 3.6.x
- Supports PHP: 7.0 | 7.1 | 7.2
- Shared key encryption.
- Authenticate a user with a direct link.
- Redirect after login to a redirect url.
- Allow locking userfields.
- Copy this plugin to the
auth\cfour
folder on the server - Login as administrator
- Go to Site Administrator > Notification
- Install the plugin
- Add the correct AUTHENTICATION key to the settings
/admin/settings.php?section=authsettingcfour
. - Enable the authentication module
/admin/category.php?category=authsettings
.
- A user should already be created in Moodle. You can add a new user with the API, make sure auth property must have the value
cfour
for security reasons. - Build a link on a external system, see the example below.
<?php
#External system, samplecode
define('SHARED_AUTHENTICION_KEY' , 'LONG_KEY_HERE');
/**
* Get a authentication code
*
* @param int $userid
* @param string $username
* @return string
*/
function get_code(int $userid , string $username ){
return hash('sha256', SHARED_AUTHENTICION_KEY . '|' . $userid . '|' . $username);
}
// Building the link.
$domain = 'https://moodle.test.domain.com/';
$plugin = 'auth/cfour/login.php?';
// The user that exists in Moodle and has `cfour` auth property in there account.
$moodleusername = 'student1';
$moodleuserid = 2;
$params = [
'sso_username' => $moodleusername,
'sso_code' => get_code($moodleuserid , $moodleusername),
'wantsurl' => '/course/view.php?id=2'
];
// Make sure all params get urlencoded!
$url = $domain . $plugin . http_build_query($params);
// https://moodle.test.domain.com/auth/cfour/login.php?sso_username=student1&sso_code=&wantsurl=%2Fcourse%2Fview.php%3Fid%3D2
header('Location: ' . $url);
die;
- Use the link where you want. Keep in mind there is no expiry date implemented.
If you discover any security related issues, please email luuk@MFreak.nl instead of using the issue tracker.
The GNU GENERAL PUBLIC LICENSE. Please see License File for more information.
See version control for the complete history. Major changes in this version will be listed below.