Merge branch 'MDL-81409-403' of https://github.com/snake/moodle into MOODLE_403_STABLE

This commit is contained in:
Ilya Tregubov
2024-04-08 12:45:18 +08:00
+14 -11
View File
@@ -52,11 +52,8 @@ $PAGE->set_pagelayout('popup');
// URL to the platform's OpenID configuration.
$openidconfigurl = required_param('openid_configuration', PARAM_URL);
// Token generated by the platform, which must be sent back in registration request.
$regtoken = required_param('registration_token', PARAM_RAW);
if (!preg_match('/[a-zA-Z0-9-_.]+/', $regtoken)) { // 0 on no match, FALSE on error.
throw new coding_exception('Invalid registration_token.');
}
// Token generated by the platform, which must be sent back in registration request. This is opaque to the tool.
$regtoken = optional_param('registration_token', null, PARAM_RAW);
// Moodle-specific token used to secure the dynamic registration URL.
$token = required_param('token', PARAM_ALPHANUM);
@@ -122,7 +119,6 @@ $regrequest = (object) [
'https://purl.imsglobal.org/spec/lti-tool-configuration' => [
'domain' => $parsed['host'],
'target_link_uri' => $CFG->wwwroot . '/enrol/lti/launch.php',
'custom_parameters' => [],
'claims' => [
'iss',
'sub',
@@ -157,7 +153,10 @@ $regrequest = (object) [
]
];
$curl->setHeader(['Authorization: Bearer ' . $regtoken]);
if (!is_null($regtoken)) {
$curl->setHeader(['Authorization: Bearer ' . $regtoken]);
}
$curl->setHeader('Content-Type: application/json');
$regrequest = json_encode($regrequest);
$regresponse = $curl->post($regendpoint, $regrequest);
$errno = $curl->get_errno();
@@ -184,12 +183,16 @@ if ($regresponse) {
$draftreg->complete_registration();
$appreg = $appregrepo->save($draftreg);
$deployment = $appreg->add_tool_deployment($toolconfig->deployment_id, $toolconfig->deployment_id);
$deploymentrepo = new deployment_repository();
$deploymentrepo->save($deployment);
// Deployment id is optional.
// If this isn't provided by the platform at this time, it must be manually set in Site admin before launches can happen.
if (!empty($toolconfig->deployment_id)) {
$deployment = $appreg->add_tool_deployment($toolconfig->deployment_id, $toolconfig->deployment_id);
$deploymentrepo = new deployment_repository();
$deploymentrepo->save($deployment);
}
}
}
echo "<script>
(window.opener || window.parent).postMessage({subject: 'org.imsglobal.lti.close'}, '$openidconfig->issuer');
(window.opener || window.parent).postMessage({subject: 'org.imsglobal.lti.close'}, '*');
</script>";