八角的登录API

问题描述 投票:1回答:1

我需要从我的网站登录到我的用户页面。我具有创建用户并进行课程注册的构建功能,现在我需要进行自动登录。

我已经设置了返回用户令牌的“ moodle_mobile_app”,但是我可以找到进行登录的任何服务。

我全都在我身边UserName,Password,Token我只需要穆德的一些Web服务就可以接收此数据并返回登录网址

"/login/token.php?username=YOUR_FORM_USERNAME&password=YOUR_FORM_PASSWORD&service=moodle_mobile_app"

有人知道这个技巧/方式如何使用户从我的网站登录到Mooble吗?

angular moodle moodle-api moodle-mobile
1个回答
0
投票

我已经找到了可以正常工作的插件

https://moodle.org/plugins/auth_userkey

https://github.com/catalyst/moodle-auth_userkey/blob/MOODLE_33PLUS/README.md

下载并安装它

主页->站点管理->插件->安装插件

只需使用已下载的插件拖动zip文件Plugin install

设置插件步骤:您的完整说明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.

然后下载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);
© www.soinside.com 2019 - 2024. All rights reserved.