diff --git a/mod/lti/classes/local/ltiservice/service_base.php b/mod/lti/classes/local/ltiservice/service_base.php index 234b558f1da..e37990d74f3 100644 --- a/mod/lti/classes/local/ltiservice/service_base.php +++ b/mod/lti/classes/local/ltiservice/service_base.php @@ -336,6 +336,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 84c175d87ff..15deb8dbc31 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -125,7 +125,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', @@ -436,74 +441,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 e51e41f2355..98b98f4f701 100644 --- a/mod/lti/service/gradebookservices/classes/local/service/gradebookservices.php +++ b/mod/lti/service/gradebookservices/classes/local/service/gradebookservices.php @@ -143,6 +143,57 @@ class gradebookservices extends service_base { $mform->addHelpButton($selectelementname, $identifier, $this->get_component_id()); } + /** + * 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 97efc05a5b7..93bc88274b2 100644 --- a/mod/lti/service/memberships/classes/local/service/memberships.php +++ b/mod/lti/service/memberships/classes/local/service/memberships.php @@ -551,4 +551,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 a9697fe9fb1..98cf37e82b5 100644 --- a/mod/lti/tests/locallib_test.php +++ b/mod/lti/tests/locallib_test.php @@ -1006,8 +1006,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 318c625ce78..77ea8d3711a 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.0.7 === + +* 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. + === 3.10 === * Select Content supports multiple, allowing a tool to return more than one link at a time.