From ee7c4a15cca56580ef53b2954f00d433471345c3 Mon Sep 17 00:00:00 2001 From: Mathias Kahl Date: Fri, 17 Nov 2023 16:11:30 +0100 Subject: [PATCH] v1.0.24 send plugin version using standard LTI claim --- CHANGES.md | 4 ++++ classes/lti_flow.php | 22 ++++++++++++++++++++++ openid-configuration.php | 1 + tests/classes/lti_flow_test.php | 9 +++++++++ version.php | 4 ++-- 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 68d6cbe..ce07197 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +### v1.0.24 (Build - 2023111701) + +* Send plugin's version and "platform" information using standard LTI claims. + ### v1.0.23 (Build - 2023102005) * Send plugin version number to Kialo. diff --git a/classes/lti_flow.php b/classes/lti_flow.php index 2ffb869..bc4d158 100644 --- a/classes/lti_flow.php +++ b/classes/lti_flow.php @@ -45,6 +45,19 @@ * Functions implementing the LTI steps. */ class lti_flow { + /** + * The LTI standard requires a stable GUID to be send with the platform information. + * See https://www.imsglobal.org/spec/lti/v1p3#platform-instance-claim. + * We send a value uniqely identifying the Kialo plugin, but it's the same for all instances. + */ + public const PLATFORM_GUID = 'f4be0d51-bf02-5520-b589-8e6d23515876'; + + /** + * The "product_family_code" that the plugin uses to identify itself during LTI requests to tools. + * We send moodle's own product family code because we count the plugin as part of moodle. + */ + public const PRODUCT_FAMILY_CODE = "moodle"; + /** * Can be used to override the default JwksFetcher. Used for testing purposes. * @@ -295,6 +308,8 @@ public static function init_deep_link(int $courseid, string $moodleuserid, strin * @throws \dml_exception */ public static function lti_auth(): LtiMessageInterface { + global $CFG; + $kialoconfig = kialo_config::get_instance(); $registration = $kialoconfig->create_registration(); @@ -311,6 +326,13 @@ public static function lti_auth(): LtiMessageInterface { $payloadbuilder = new MessagePayloadBuilder(new static_nonce_generator($nonce)); $payloadbuilder->withClaim('kialo_plugin_version', kialo_config::get_release()); + // See https://www.imsglobal.org/spec/lti/v1p3#platform-instance-claim. + $payloadbuilder->withClaim('https://purl.imsglobal.org/spec/lti/claim/tool_platform', [ + 'guid' => self::PLATFORM_GUID, + 'product_family_code' => self::PRODUCT_FAMILY_CODE, + 'version' => $CFG->version, + ]); + // Create the OIDC authenticator. $authenticator = new OidcAuthenticator($registrationrepository, $userauthenticator, $payloadbuilder); diff --git a/openid-configuration.php b/openid-configuration.php index 538cb38..b28aa60 100644 --- a/openid-configuration.php +++ b/openid-configuration.php @@ -72,6 +72,7 @@ function lti_get_capabilities() { 'claims_supported' => ['sub', 'iss', 'name', 'given_name', 'middle_name', 'family_name', 'email', 'picture', 'locale', 'zoneinfo', ], + // This is similar to https://www.imsglobal.org/spec/lti/v1p3#platform-instance-claim, but not the same! 'https://purl.imsglobal.org/spec/lti-platform-configuration' => [ 'product_family_code' => 'moodle_kialo_plugin', 'version' => $CFG->release, diff --git a/tests/classes/lti_flow_test.php b/tests/classes/lti_flow_test.php index 217d92f..e5c4056 100644 --- a/tests/classes/lti_flow_test.php +++ b/tests/classes/lti_flow_test.php @@ -399,6 +399,8 @@ private function prepare_lti_auth_request($signer = self::SIGNER_PLATFORM, ?call * @covers \mod_kialo\lti_flow::lti_auth */ public function test_lti_auth(): void { + global $CFG; + // The current user must be at least a student in the course. But this LTI step works the same for students and teachers. $this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, "student"); @@ -430,8 +432,15 @@ public function test_lti_auth(): void { $this->assertEquals($this->user->firstname . " " . $this->user->lastname, $token->claims()->get("name")); $this->assertEquals($this->user->email, $token->claims()->get("email")); $this->assertEquals($this->user->lang, $token->claims()->get("locale")); + $this->assertEquals(kialo_config::get_release(), $token->claims()->get("kialo_plugin_version")); + $this->assertEquals([ + "guid" => lti_flow::PLATFORM_GUID, + "product_family_code" => lti_flow::PRODUCT_FAMILY_CODE, + "version" => $CFG->version, + ], $token->claims()->get("https://purl.imsglobal.org/spec/lti/claim/tool_platform")); + global $PAGE, $USER; $expectedpicture = new \user_picture($USER); $expectedpicture->size = 128; diff --git a/version.php b/version.php index b002fba..4cfb41c 100644 --- a/version.php +++ b/version.php @@ -28,8 +28,8 @@ $plugin->component = 'mod_kialo'; // See https://moodledev.io/docs/apis/commonfiles/version.php. -$plugin->version = 2023102005; // Must be incremented for each new release! -$plugin->release = '1.0.23'; // Semantic version. +$plugin->version = 2023111701; // Must be incremented for each new release! +$plugin->release = '1.0.24'; // Semantic version. // Officially we require PHP 7.4. The first Moodle version that requires this as a minimum is Moodle 4.1. // But technically this plugin also runs on older Moodle versions, as long as they run on PHP 7.4,