moodle单点登陆

在moodle/login添加sso.php



require('../config.php');
require_once('lib.php');

if($_SERVER['REQUEST_METHOD']=='GET'){
    $tokenId=$_GET['tokenId'];
}else{
    $tokenId="fail";
}
echo $tokenId;
$url="authurl".$tokenId;
$ch= curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close($ch);

$result1=(array)json_decode($result);
$message=(array)$result1["data"];
$userid=$message["登陆id"];
echo $userid;
if($userid){
    $name=$userid;
    $dashboard = $CFG->wwwroot;
    $user = authenticate_user_login($name, null,true);

    if(complete_user_login($user))
    {
        redirect(new moodle_url("moodle url?sesskey=".$user->sesskey));
    }
    else
    {
        echo "not login"; die;
    }
}

moodle\lib\moodlelib.php
if($ignorelockout){

} 加入 return $user语句

 if ($ignorelockout) {
        // Some other mechanism protects against brute force password guessing, for example login form might include reCAPTCHA
        // or this function is called from a SSO script.
        return $user; 
    } 

你可能感兴趣的:(moodle)