2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Authentication Plugin: Moodle Network Authentication
19 * Multiple host authentication support for Moodle Network.
22 * @author Martin Dougiamas
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
26 require_once dirname(dirname(dirname(__FILE__
))) . '/config.php';
27 require_once $CFG->dirroot
. '/mnet/xmlrpc/client.php';
29 // grab the GET params
30 $token = required_param('token', PARAM_BASE64
);
31 $remotewwwroot = required_param('idp', PARAM_URL
);
32 $wantsurl = required_param('wantsurl', PARAM_LOCALURL
);
33 $wantsremoteurl = optional_param('remoteurl', false, PARAM_BOOL
);
35 $url = new moodle_url('/auth/mnet/jump.php', array('token'=>$token, 'idp'=>$remotewwwroot, 'wantsurl'=>$wantsurl));
36 if ($wantsremoteurl !== false) $url->param('remoteurl', $wantsremoteurl);
41 if (!is_enabled_auth('mnet')) {
42 print_error('mnetdisable');
45 // confirm the MNET session
46 $mnetauth = get_auth_plugin('mnet');
47 $remotepeer = new mnet_peer();
48 $remotepeer->set_wwwroot($remotewwwroot);
49 // this creates the local user account if necessary, or updates it if it already exists
50 $localuser = $mnetauth->confirm_mnet_session($token, $remotepeer);
53 $user = get_complete_user_data('id', $localuser->id
, $localuser->mnethostid
);
54 complete_user_login($user);
55 // now that we've logged in, set up the mnet session properly
56 $mnetauth->update_mnet_session($user, $token, $remotepeer);
58 if (!empty($localuser->mnet_foreign_host_array
)) {
59 $USER->mnet_foreign_host_array
= $localuser->mnet_foreign_host_array
;
63 if ($wantsremoteurl) {
64 redirect($remotewwwroot . $wantsurl);
66 redirect($CFG->wwwroot
. $wantsurl);