catalyst / moodle-auth_userkey

Log in to Moodle using one time user key based login URL. Auth plugin for organising simple SSO (single sign on) between moodle and your external web application.
https://moodle.org/plugins/auth_userkey
83 stars 53 forks source link

Timeout error 30 seconds #41

Closed danielddltellez closed 5 years ago

danielddltellez commented 5 years ago

Because it takes to enter moodle, it shows error after 30 seconds. How can I solve it, will it be the curl?

/**

function getloginurl($useremail, $firstname, $lastname, $username, $courseid = null, $modname = null, $activityid = null) { require_once('curl.php');

$token        = 'mytoken';//editar token que generamos
$domainname   = 'myurl';//colocar la url de la plataforma
$functionname = 'auth_userkey_request_login_url';

$params = Array('user' => Array('email' => $useremail) );

/ $param = [ 'user' => [ 'email' => $useremail ] ]; /

$serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname . '&moodlewsrestformat=json';

// $serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname; // echo $serverurl; $curl = new curl; // The required library curl can be obtained from https://github.com/moodlehq/sample-ws-clients

try {

$resp = $curl->post($serverurl, $params);

    echo $resp."<br><br>";
    $resp     = json_decode($resp);
    print_r($resp);

    if ($resp && !empty($resp->loginurl)) {
        $loginurl = $resp->loginurl;
        echo "<br><br>$loginurl<br><br>";
     //   exit;
    }

} catch (Exception $ex) {
    return false;
}

if (!isset($loginurl)) {
    return false;
}

$path = '';
if (isset($courseid)) {
    $path = '&wantsurl=' . urlencode("$domainname/course/view.php?id=$courseid");

    $path=str_replace("%3A", ":", "$path");
    $path=str_replace("%2F", "/", "$path");
    $path=str_replace("//course", "/course", "$path");
    $path=str_replace("%3F", "?", "$path");
    $path=str_replace("%3D", "=", "$path");

// echo "$path

"; } /* if (isset($modname) && isset($activityid)) { $path = '&wantsurl=' . urlencode("$domainname/mod/$modname/view.php?id=$activityid"); }

echo "$path<br><br>";
echo $loginurl.$path;

*/ return $loginurl.$path; }

$mail=$_GET['email']; $cid=$_GET['courseid']; $url = getloginurl("$mail", 'Carlos', 'Legorreta Garcia', 'carlos.legorreta', $cid, null, null);

header('Location: '.$url); die();

dmitriim commented 5 years ago

Hi @danielddltellez Thank you for using this plugin. First of all you should figure out why your request takes 30 seconds. It shouldn't be that long on normally working moodle instances.

dmitriim commented 5 years ago

closing this one as I can't replicate it. Most likely the issue in the moodle instance itself.