// Only show the proxy if the token parameter is correct. // If we do not compare with a shared secret, someone could very easily // guess an id for the enrolment. if (!\enrol_lti\helper::verify_proxy_token($toolid, $token)) { throw new \moodle_exception('incorrecttoken', 'enrol_lti'); } $tool = \enrol_lti\helper::get_lti_tool($toolid); if (!is_enabled_auth('lti')) { print_error('pluginnotenabled', 'auth', '', get_string('pluginname', 'auth_lti')); exit; } // Check if the enrolment plugin is disabled. if (!enrol_is_enabled('lti')) { print_error('enrolisdisabled', 'enrol_lti'); exit; } // Check if the enrolment instance is disabled. if ($tool->status != ENROL_INSTANCE_ENABLED) { print_error('enrolisdisabled', 'enrol_lti'); exit; } $messagetype = required_param('lti_message_type', PARAM_TEXT); // Only accept proxy registration requests from this endpoint. if ($messagetype != "ToolProxyRegistrationRequest") { print_error('invalidrequest', 'enrol_lti'); exit; } $toolprovider = new \enrol_lti\tool_provider($toolid); $toolprovider->handleRequest(); echo $OUTPUT->header(); echo $OUTPUT->footer();
} // Check if the enrolment instance is disabled. if ($tool->status != ENROL_INSTANCE_ENABLED) { print_error('enrolisdisabled', 'enrol_lti'); exit; } $consumerkey = required_param('oauth_consumer_key', PARAM_TEXT); $ltiversion = optional_param('lti_version', null, PARAM_TEXT); $messagetype = required_param('lti_message_type', PARAM_TEXT); // Only accept launch requests from this endpoint. if ($messagetype != "basic-lti-launch-request") { print_error('invalidrequest', 'enrol_lti'); exit; } // Initialise tool provider. $toolprovider = new \enrol_lti\tool_provider($toolid); // Special handling for LTIv1 launch requests. if ($ltiversion === \IMSGlobal\LTI\ToolProvider\ToolProvider::LTI_VERSION1) { $dataconnector = new \enrol_lti\data_connector(); $consumer = new \IMSGlobal\LTI\ToolProvider\ToolConsumer($consumerkey, $dataconnector); // Check if the consumer has already been registered to the enrol_lti_lti2_consumer table. Register if necessary. $consumer->ltiVersion = \IMSGlobal\LTI\ToolProvider\ToolProvider::LTI_VERSION1; // For LTIv1, set the tool secret as the consumer secret. $consumer->secret = $tool->secret; $consumer->name = optional_param('tool_consumer_instance_name', null, PARAM_TEXT); $consumer->consumerName = $consumer->name; $consumer->consumerGuid = optional_param('tool_consumer_instance_guid', null, PARAM_TEXT); $consumer->consumerVersion = optional_param('tool_consumer_info_version', null, PARAM_TEXT); $consumer->enabled = true; $consumer->protected = true; $consumer->save();
/** * Test for data_connector::get_consumers_mapped_to_tool(). */ public function test_get_consumers_mapped_to_tool() { $generator = $this->getDataGenerator(); // Create two tools belonging to the same course. $course1 = $generator->create_course(); $data = new stdClass(); $data->courseid = $course1->id; $tool = $generator->create_lti_tool($data); $tool2 = $generator->create_lti_tool($data); $dc = new data_connector(); $consumer = new ToolConsumer('key1', $dc); $consumer->name = 'testconsumername'; $consumer->secret = 'testsecret'; $consumer->save(); $tp = new \enrol_lti\tool_provider($tool->id); $tp->consumer = $consumer; $tp->map_tool_to_consumer(); $consumer2 = new ToolConsumer('key2', $dc); $consumer2->name = 'testconsumername2'; $consumer2->secret = 'testsecret2'; $consumer2->save(); $tp2 = new \enrol_lti\tool_provider($tool2->id); $tp2->consumer = $consumer2; $tp2->map_tool_to_consumer(); $consumers = $dc->get_consumers_mapped_to_tool($tool->id); $this->assertCount(1, $consumers); $this->assertEquals($consumer, $consumers[0]); $consumers2 = $dc->get_consumers_mapped_to_tool($tool2->id); $this->assertCount(1, $consumers2); $this->assertEquals($consumer2, $consumers2[0]); }