Differences Between: [Versions 310 and 400]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 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. 8 // 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. 13 // 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/>. 16 17 /** 18 * Redirect the user to registration with token and openid config url as query params. 19 * 20 * @package mod_lti 21 * @copyright 2020 Cengage 22 * @author Claude Vervoort 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 use Firebase\JWT\JWT; 27 28 use mod_lti\local\ltiopenid\jwks_helper; 29 use mod_lti\local\ltiopenid\registration_helper; 30 31 require_once(__DIR__ . '/../../config.php'); 32 require_once($CFG->libdir.'/weblib.php'); 33 require_once($CFG->dirroot . '/mod/lti/locallib.php'); 34 35 require_login(); 36 $context = context_system::instance(); 37 require_capability('moodle/site:config', $context); 38 39 $starturl = required_param('url', PARAM_URL); 40 $typeid = optional_param('type', -1, PARAM_INT); 41 42 $types = lti_get_tools_by_url($starturl, null); 43 44 if (!empty($types) && $typeid == -1) { 45 // There are matching types for the registration domain, let's prompt the user to upgrade. 46 $pageurl = new moodle_url('/mod/lti/startltiadvregistration.php'); 47 $PAGE->set_context($context); 48 $PAGE->set_url($pageurl); 49 $PAGE->set_pagelayout('maintenance'); 50 $output = $PAGE->get_renderer('mod_lti'); 51 $page = new \mod_lti\output\registration_upgrade_choice_page($types, $starturl); 52 echo $output->header(); 53 echo $output->render($page); 54 echo $output->footer(); 55 } else { 56 // Let's actually start the registration process by launching the tool registration 57 // endpoint with the registration token and the site config url. 58 require_sesskey(); 59 $sub = registration_helper::get()->new_clientid(); 60 $scope = registration_helper::REG_TOKEN_OP_NEW_REG; 61 if ($typeid > 0) { 62 // In the context of an update, the sub is the id of the type. 63 $sub = strval($typeid); 64 $scope = registration_helper::REG_TOKEN_OP_UPDATE_REG; 65 } 66 $now = time(); 67 $token = [ 68 "sub" => $sub, 69 "scope" => $scope, 70 "iat" => $now, 71 "exp" => $now + HOURSECS 72 ]; 73 $privatekey = jwks_helper::get_private_key(); 74 $regtoken = JWT::encode($token, $privatekey['key'], 'RS256', $privatekey['kid']); 75 $confurl = new moodle_url('/mod/lti/openid-configuration.php'); 76 $url = new moodle_url($starturl); 77 $url->param('openid_configuration', $confurl->out(false)); 78 $url->param('registration_token', $regtoken); 79 header("Location: ".$url->out(false)); 80 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body