Skip to content

Commit

Permalink
v1.0.24 send plugin version using standard LTI claim
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-kialo committed Nov 24, 2023
1 parent f595e3f commit ee7c4a1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
22 changes: 22 additions & 0 deletions classes/lti_flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();

Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions openid-configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions tests/classes/lti_flow_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ee7c4a1

Please sign in to comment.