diff --git a/mod/lti/classes/local/ltiservice/service_base.php b/mod/lti/classes/local/ltiservice/service_base.php index 9f45235c164..ecaf2c7f08c 100644 --- a/mod/lti/classes/local/ltiservice/service_base.php +++ b/mod/lti/classes/local/ltiservice/service_base.php @@ -353,6 +353,16 @@ abstract class service_base { return array(); } + /** + * Return an array of key/claim mapping allowing LTI 1.1 custom parameters + * to be transformed to LTI 1.3 claims. + * + * @return array Key/value pairs of params to claim mapping. + */ + public function get_jwt_claim_mappings(): array { + return array(); + } + /** * Get the path for service requests. * diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index b83b7c5909b..b1339a68152 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -126,7 +126,12 @@ function lti_get_jwt_message_type_mapping() { * @return array */ function lti_get_jwt_claim_mapping() { - return array( + $mapping = []; + $services = lti_get_services(); + foreach ($services as $service) { + $mapping = array_merge($mapping, $service->get_jwt_claim_mappings()); + } + $mapping = array_merge($mapping, array( 'accept_copy_advice' => [ 'suffix' => 'dl', 'group' => 'deep_linking_settings', @@ -443,74 +448,9 @@ function lti_get_jwt_claim_mapping() { 'group' => 'tool_platform', 'claim' => 'url', 'isarray' => false - ], - 'custom_context_memberships_v2_url' => [ - 'suffix' => 'nrps', - 'group' => 'namesroleservice', - 'claim' => 'context_memberships_url', - 'isarray' => false - ], - 'custom_context_memberships_versions' => [ - 'suffix' => 'nrps', - 'group' => 'namesroleservice', - 'claim' => 'service_versions', - 'isarray' => true - ], - 'custom_gradebookservices_scope' => [ - 'suffix' => 'ags', - 'group' => 'endpoint', - 'claim' => 'scope', - 'isarray' => true - ], - 'custom_lineitems_url' => [ - 'suffix' => 'ags', - 'group' => 'endpoint', - 'claim' => 'lineitems', - 'isarray' => false - ], - 'custom_lineitem_url' => [ - 'suffix' => 'ags', - 'group' => 'endpoint', - 'claim' => 'lineitem', - 'isarray' => false - ], - 'custom_results_url' => [ - 'suffix' => 'ags', - 'group' => 'endpoint', - 'claim' => 'results', - 'isarray' => false - ], - 'custom_result_url' => [ - 'suffix' => 'ags', - 'group' => 'endpoint', - 'claim' => 'result', - 'isarray' => false - ], - 'custom_scores_url' => [ - 'suffix' => 'ags', - 'group' => 'endpoint', - 'claim' => 'scores', - 'isarray' => false - ], - 'custom_score_url' => [ - 'suffix' => 'ags', - 'group' => 'endpoint', - 'claim' => 'score', - 'isarray' => false - ], - 'lis_outcome_service_url' => [ - 'suffix' => 'bo', - 'group' => 'basicoutcome', - 'claim' => 'lis_outcome_service_url', - 'isarray' => false - ], - 'lis_result_sourcedid' => [ - 'suffix' => 'bo', - 'group' => 'basicoutcome', - 'claim' => 'lis_result_sourcedid', - 'isarray' => false - ], - ); + ] + )); + return $mapping; } /** diff --git a/mod/lti/service/basicoutcomes/classes/local/service/basicoutcomes.php b/mod/lti/service/basicoutcomes/classes/local/service/basicoutcomes.php index bfc6420609a..d25d2e8f813 100644 --- a/mod/lti/service/basicoutcomes/classes/local/service/basicoutcomes.php +++ b/mod/lti/service/basicoutcomes/classes/local/service/basicoutcomes.php @@ -90,4 +90,25 @@ class basicoutcomes extends \mod_lti\local\ltiservice\service_base { return [self::SCOPE_BASIC_OUTCOMES]; } + /** + * Return an array of key/claim mapping allowing LTI 1.1 custom parameters + * to be transformed to LTI 1.3 claims. + * + * @return array Key/value pairs of params to claim mapping. + */ + public function get_jwt_claim_mappings(): array { + return array('lis_outcome_service_url' => [ + 'suffix' => 'bo', + 'group' => 'basicoutcome', + 'claim' => 'lis_outcome_service_url', + 'isarray' => false + ], + 'lis_result_sourcedid' => [ + 'suffix' => 'bo', + 'group' => 'basicoutcome', + 'claim' => 'lis_result_sourcedid', + 'isarray' => false + ]); + } + } diff --git a/mod/lti/service/gradebookservices/classes/local/service/gradebookservices.php b/mod/lti/service/gradebookservices/classes/local/service/gradebookservices.php index 3dc691e035b..12cb8b38b75 100644 --- a/mod/lti/service/gradebookservices/classes/local/service/gradebookservices.php +++ b/mod/lti/service/gradebookservices/classes/local/service/gradebookservices.php @@ -183,6 +183,58 @@ class gradebookservices extends service_base { return [$targetlinkuri, $customstr]; } + /** + * Return an array of key/claim mapping allowing LTI 1.1 custom parameters + * to be transformed to LTI 1.3 claims. + * + * @return array Key/value pairs of params to claim mapping. + */ + public function get_jwt_claim_mappings(): array { + return array('custom_gradebookservices_scope' => [ + 'suffix' => 'ags', + 'group' => 'endpoint', + 'claim' => 'scope', + 'isarray' => true + ], + 'custom_lineitems_url' => [ + 'suffix' => 'ags', + 'group' => 'endpoint', + 'claim' => 'lineitems', + 'isarray' => false + ], + 'custom_lineitem_url' => [ + 'suffix' => 'ags', + 'group' => 'endpoint', + 'claim' => 'lineitem', + 'isarray' => false + ], + 'custom_results_url' => [ + 'suffix' => 'ags', + 'group' => 'endpoint', + 'claim' => 'results', + 'isarray' => false + ], + 'custom_result_url' => [ + 'suffix' => 'ags', + 'group' => 'endpoint', + 'claim' => 'result', + 'isarray' => false + ], + 'custom_scores_url' => [ + 'suffix' => 'ags', + 'group' => 'endpoint', + 'claim' => 'scores', + 'isarray' => false + ], + 'custom_score_url' => [ + 'suffix' => 'ags', + 'group' => 'endpoint', + 'claim' => 'score', + 'isarray' => false + ]); + } + + /** * Return an array of key/values to add to the launch parameters. * diff --git a/mod/lti/service/memberships/classes/local/service/memberships.php b/mod/lti/service/memberships/classes/local/service/memberships.php index 538c228786e..d9c747064c5 100644 --- a/mod/lti/service/memberships/classes/local/service/memberships.php +++ b/mod/lti/service/memberships/classes/local/service/memberships.php @@ -554,4 +554,24 @@ class memberships extends \mod_lti\local\ltiservice\service_base { return $launchparameters; } + /** + * Return an array of key/claim mapping allowing LTI 1.1 custom parameters + * to be transformed to LTI 1.3 claims. + * + * @return array Key/value pairs of params to claim mapping. + */ + public function get_jwt_claim_mappings(): array { + return array('custom_context_memberships_v2_url' => [ + 'suffix' => 'nrps', + 'group' => 'namesroleservice', + 'claim' => 'context_memberships_url', + 'isarray' => false + ], + 'custom_context_memberships_versions' => [ + 'suffix' => 'nrps', + 'group' => 'namesroleservice', + 'claim' => 'service_versions', + 'isarray' => true + ]); + } } diff --git a/mod/lti/tests/locallib_test.php b/mod/lti/tests/locallib_test.php index 83a39c066b3..3a04c21f6eb 100644 --- a/mod/lti/tests/locallib_test.php +++ b/mod/lti/tests/locallib_test.php @@ -1026,8 +1026,8 @@ class locallib_test extends mod_lti_testcase { 'isarray' => false ], ]; - - $this->assertEquals($mapping, lti_get_jwt_claim_mapping()); + $actual = lti_get_jwt_claim_mapping(); + $this->assertEquals($mapping, $actual); } /** diff --git a/mod/lti/upgrade.txt b/mod/lti/upgrade.txt index 503089d29f5..a6b71d25639 100644 --- a/mod/lti/upgrade.txt +++ b/mod/lti/upgrade.txt @@ -1,5 +1,10 @@ This files describes API changes in the lti code. +=== 4.1.2 === + +* get_jwt_claim_mappings() function has been added to service_base class. It allows a service subplugin to be + compatible with LTI 1.3 by exposing its 1.1 custom parameters to LTI 1.3 claim mapping. + === 4.1 === * The callback get_shortcuts() is now removed. Please use get_course_content_items and get_all_content_items instead.