diff --git a/enrol/lti/register.php b/enrol/lti/register.php index b5e3bf34830..cda46d1f2bc 100644 --- a/enrol/lti/register.php +++ b/enrol/lti/register.php @@ -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 "";