在 moodle angular 中登录 API 8
Login API in moodle angular 8
我需要将我的用户从我的网站登录到 moodle page.I 具有创建用户和注册课程的构建功能,现在我需要进行自动登录。
我已经设置了 "moodle_mobile_app",它有 return 我的用户令牌,但我可以找到任何可以登录的服务。
我的一切都在我身边UserName,Password,Token
我只需要一些来自moodle的网络服务可以接收这些数据和return登录Url
"/login/token.php?username=YOUR_FORM_USERNAME&password=YOUR_FORM_PASSWORD&service=moodle_mobile_app"
有谁知道 trick/way 我怎样才能让用户从我的网站登录到 mooble?
我找到了这个插件
https://moodle.org/plugins/auth_userkey
https://github.com/catalyst/moodle-auth_userkey/blob/MOODLE_33PLUS/README.md
下载并安装
首页 -> 站点管理 -> 插件 -> 安装插件
只需将您下载的带有插件的 zip 文件拖入
设置你的插件步骤:你有完整的描述here
> 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.
解压并添加到你的根文件夹,然后我添加了名为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);
我需要将我的用户从我的网站登录到 moodle page.I 具有创建用户和注册课程的构建功能,现在我需要进行自动登录。
我已经设置了 "moodle_mobile_app",它有 return 我的用户令牌,但我可以找到任何可以登录的服务。
我的一切都在我身边UserName,Password,Token
我只需要一些来自moodle的网络服务可以接收这些数据和return登录Url
"/login/token.php?username=YOUR_FORM_USERNAME&password=YOUR_FORM_PASSWORD&service=moodle_mobile_app"
有谁知道 trick/way 我怎样才能让用户从我的网站登录到 mooble?
我找到了这个插件
https://moodle.org/plugins/auth_userkey
https://github.com/catalyst/moodle-auth_userkey/blob/MOODLE_33PLUS/README.md
下载并安装
首页 -> 站点管理 -> 插件 -> 安装插件
只需将您下载的带有插件的 zip 文件拖入
设置你的插件步骤:你有完整的描述here
> 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.
解压并添加到你的根文件夹,然后我添加了名为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);