Я нашел этот плагин, который делает работу
https://moodle.org/plugins/auth_userkey
https://github.com/catalyst/moodle-auth_userkey/blob/MOODLE_33PLUS/README.md
Загрузите и установите его
Главная страница -> Администрирование сайта -> Плагины -> Установить плагины
Просто перетащите свой zip-файл с загруженным плагином
Установите шаги своего плагина: у вас есть полное описание здесь
> 1.Install the plugin as usual.
> 2.Enable and configure just installed plugin. Set required Mapping field, User key life time, IP restriction and Logout redirect URL.
> 3.Enable web service advance feature (Admin > Advanced features), more info http://docs.moodle.org/en/Web_services
> 4.Enable one of the supported protocols (Admin > Plugins > Web services > Manage protocols)
> 5.Create a token for a specific user and for the service 'User key authentication web service' (Admin > Plugins > Web services > Manage
> tokens)
> 6.Make sure that the "web service" user has 'auth/userkey:generatekey' capability.
> 7.Configure your external application to make a web call to get login URL.
> 8.Redirect your users to this URL to be logged in to Moodle.
Затем загрузите sample-ws-clients
Распакуйте и добавьте его в корневую папку, затем я добавлю файл с именем sso.php в папку Online.mydomain.com\sample-ws-clients-master\PHP-REST\sso.php
Мой код sso.php, получающий электронную почту, и повторный URL для входа в систему
<?php
/**
* @param string $useremail Email address of user to create token for.
* @param string $firstname First name of user (used to update/create user).
* @param string $lastname Last name of user (used to update/create user).
* @param string $username Username of user (used to update/create user).
* @param string $ipaddress IP address of end user that login request will come from (probably $_SERVER['REMOTE_ADDR']).
* @param int $courseid Course id to send logged in users to, defaults to site home.
* @param int $modname Name of course module to send users to, defaults to none.
* @param int $activityid cmid to send logged in users to, defaults to site home.
* @return bool|string
*/
$userEmail = $_GET["email"];
$courseid = $_GET["id"];
function getloginurl($useremail, $courseid) {
require_once('./curl.php');
$token = 'your token';
$domainname = 'your domain';
$functionname = 'auth_userkey_request_login_url';
$param = [
'user' => [
'username' => $useremail
]
];
$serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname . '&moodlewsrestformat=json';
$curl = new curl; // The required library curl can be obtained from https://github.com/moodlehq/sample-ws-clients
try {
$resp = $curl->post($serverurl, $param);
$resp = json_decode($resp);
if ($resp && !empty($resp->loginurl)) {
$loginurl = $resp->loginurl;
}
} catch (Exception $ex) {
return false;
}
if (!isset($loginurl)) {
return false;
}
$path = '';
if (isset($courseid)) {
$path = '&wantsurl=' . $domainname . '/course/view.php?id=' . $courseid;
}
if (isset($modname) && isset($activityid)) {
$path = '&wantsurl=' . urlencode("$domainname/mod/$modname/view.php?id=$activityid");
}
echo $loginurl . $path;
header('Location:' . $loginurl . $path);
return $loginurl . $path;
}
getloginurl($userEmail, $courseid);