diff options
| author | Murtaza Sultani <sultani@data-quest.de> | 2026-01-19 12:11:08 +0100 |
|---|---|---|
| committer | Murtaza Sultani <sultani@data-quest.de> | 2026-01-19 12:11:08 +0100 |
| commit | 0d8b969f29e484c28516d23a5edf22fe9d04a74c (patch) | |
| tree | f34f57ca071a4ccc8645c07e65099d547795da00 | |
| parent | 1f45a5b9b6fb8e3c24d29c225315ce619f3ea4bb (diff) | |
Resolve "Die LTI-1.1-Integration funktioniert seit 6.0 nicht mehr."
Closes #6174
Merge request studip/studip!4676
| -rw-r--r-- | app/controllers/course/lti.php | 71 | ||||
| -rw-r--r-- | app/controllers/courseware/lti.php | 2 | ||||
| -rw-r--r-- | app/views/course/lti/iframe.php | 13 | ||||
| -rw-r--r-- | lib/classes/LtiLink.php | 18 |
4 files changed, 55 insertions, 49 deletions
diff --git a/app/controllers/course/lti.php b/app/controllers/course/lti.php index 172461f..8dfdff0 100644 --- a/app/controllers/course/lti.php +++ b/app/controllers/course/lti.php @@ -14,6 +14,7 @@ use Studip\LTI13a\PlatformManager; use Studip\LTI13a\Registration; use Studip\LTI13a\RegistrationManager; use OAT\Library\Lti1p3Core\Message\Payload\MessagePayloadInterface\MessagePayloadInterface; +use LtiResourceLink as LtiResourceLinkModel; /** * course/lti.php - LTI consumer API for Stud.IP @@ -274,12 +275,10 @@ class Course_LtiController extends StudipController if (!$this->show_data_protection_info) { //Redirect to the tool. - $this->lti13a_mode = false; - $lti_version = $this->resource_link->deployment->getToolLtiVersion(); - if ($lti_version === '1.3a') { - //LTI 1.3a - $this->lti13a_mode = true; + $this->version = $this->resource_link->deployment->getToolLtiVersion(); + //LTI 1.3a + if ($this->version === '1.3a') { $return_url = URLHelper::getURL($GLOBALS['ABSOLUTE_URI_STUDIP'] . 'dispatch.php/course/lti', ['deployment_id' => $this->resource_link->deployment_id]); $document_target = 'window'; if (!empty($this->resource_link->options['document_target'])) { @@ -336,14 +335,17 @@ class Course_LtiController extends StudipController $this->resource_link->getCustomLtiParameterArray(), ) ); - } else { - //LTI 1.0/1.1 + } + + //LTI 1.0/1.1 + if ($this->version === '1.1') { $this->deployment = $this->resource_link->deployment; - $lti_link = $this->getLtiLink($this->deployment); + $lti_link = $this->getLtiLink($this->deployment, $this->resource_link); $this->launch_url = $this->deployment->getLaunchURL(); $this->launch_data = $lti_link->getBasicLaunchData(); $this->signature = $lti_link->getLaunchSignature($this->launch_data); } + $this->set_layout(null); } } @@ -544,7 +546,7 @@ class Course_LtiController extends StudipController // set up ContentItemSelectionRequest $lti_link = new LtiLink($this->tool->launch_url, $this->tool->consumer_key, $this->tool->consumer_secret, $this->tool->oauth_signature_method); - $lti_link->setUser($GLOBALS['user']->id, 'Instructor', $this->tool->send_lis_person); + $lti_link->setUser(User::findCurrent(), 'Instructor', $this->tool->send_lis_person); $lti_link->setCourse($this->course_id); $lti_link->addLaunchParameters([ 'lti_message_type' => 'ContentItemSelectionRequest', @@ -691,44 +693,47 @@ class Course_LtiController extends StudipController /** * Return an LtiLink object for the configured LTI content block. * - * @param LtiDeployment $lti_data data of LTI content block + * @param LtiDeployment $ltiDeployment data of LTI content block + * @param LtiResourceLinkModel $resourceLink * - * @return LtiLink LTI link representation + * @return LtiLink LTI link representation */ - public function getLtiLink($lti_data) + public function getLtiLink(LtiDeployment $ltiDeployment, LtiResourceLinkModel $resourceLink): LtiLink { - $launch_url = $lti_data->getLaunchURL(); - $consumer_key = $lti_data->getConsumerKey(); - $consumer_secret = $lti_data->getConsumerSecret(); - $oauth_signature_method = $lti_data->getOauthSignatureMethod(); + $authUser = User::findCurrent(); + $ltiRole = $this->edit_perm ? 'Instructor' : 'Learner'; - $roles = $this->edit_perm ? 'Instructor' : 'Learner'; - $custom_parameters = explode("\n", $lti_data->getCustomParameters()); - $description = kill_format($lti_data->description); - $lis_outcome_service_url = $this->url_for('course/lti/outcome/' . $lti_data->id, ['cid' => null]); - $tc_profile_url = $this->url_for('course/lti/profile/' . $lti_data->id, ['cid' => null]); + $customParameters = explode("\n", $ltiDeployment->getCustomParameters()); + $lisOutcomeServiceUrl = $this->url_for('course/lti/outcome/' . $ltiDeployment->id, ['cid' => null]); + $tcProfileUrl = $this->url_for('course/lti/profile/' . $ltiDeployment->id, ['cid' => null]); // set up launch request - $lti_link = new LtiLink($launch_url, $consumer_key, $consumer_secret, $oauth_signature_method); - $lti_link->setResource($lti_data->id, $lti_data->title, $description); - $lti_link->setUser($GLOBALS['user']->id, $roles, $lti_data->getSendLisPerson()); - $lti_link->setCourse($lti_data->course_id); - $lti_link->addVariable('ToolConsumerProfile.url', $tc_profile_url); - $lti_link->addLaunchParameters([ + $ltiLink = new LtiLink( + $ltiDeployment->getLaunchURL(), + $ltiDeployment->getConsumerKey(), + $ltiDeployment->getConsumerSecret(), + $ltiDeployment->getOauthSignatureMethod() + ); + + $ltiLink->setResource($ltiDeployment->id, $resourceLink->title, kill_format($resourceLink->description)); + $ltiLink->setUser($authUser, $ltiRole, $ltiDeployment->getSendLisPerson()); + $ltiLink->setCourse($resourceLink->course_id); + $ltiLink->addVariable('ToolConsumerProfile.url', $tcProfileUrl); + $ltiLink->addLaunchParameters([ 'launch_presentation_locale' => str_replace('_', '-', $_SESSION['_language']), - 'launch_presentation_document_target' => $lti_data->options['document_target'], - 'lis_outcome_service_url' => $lis_outcome_service_url, - 'lis_result_sourcedid' => $GLOBALS['user']->id + 'launch_presentation_document_target' => $resourceLink->options['document_target'], + 'lis_outcome_service_url' => $lisOutcomeServiceUrl, + 'lis_result_sourcedid' => $authUser->id ]); - foreach ($custom_parameters as $param) { + foreach ($customParameters as $param) { if (strpos($param, '=') !== false) { [$key, $value] = explode('=', $param, 2); - $lti_link->addCustomParameter(trim($key), trim($value)); + $ltiLink->addCustomParameter(trim($key), trim($value)); } } - return $lti_link; + return $ltiLink; } /** diff --git a/app/controllers/courseware/lti.php b/app/controllers/courseware/lti.php index 93159cc..53ec44b 100644 --- a/app/controllers/courseware/lti.php +++ b/app/controllers/courseware/lti.php @@ -79,7 +79,7 @@ class Courseware_LtiController extends AuthenticatedController // Create LTI Link for setting up launch request $lti_link = new LtiLink($launch_url, $consumer_key, $consumer_secret, $oauth_signature_method); $lti_link->setResource($id, $title); - $lti_link->setUser($GLOBALS['user']->id, $roles, $send_lis_person); + $lti_link->setUser(User::findCurrent(), $roles, $send_lis_person); $lti_link->setCourse($range_id); $lti_link->addLaunchParameters([ 'launch_presentation_locale' => str_replace('_', '-', $_SESSION['_language']), diff --git a/app/views/course/lti/iframe.php b/app/views/course/lti/iframe.php index 79cbd60..777cd78 100644 --- a/app/views/course/lti/iframe.php +++ b/app/views/course/lti/iframe.php @@ -4,7 +4,7 @@ * @var ?LtiResourceLink $resource_link * @var array $launch_data * @var string $signature - * @var bool $lti13a_mode + * @var string $version * @var \OAT\Library\Lti1p3Core\Message\LtiMessage $message */ ?> @@ -13,20 +13,23 @@ <html> <head> <meta charset="UTF-8"> - <? if (!$lti13a_mode) : ?> + <? if ($version === '1.1') : ?> <script type="text/javascript"> - window.onload=document.ltiLaunchForm.submit(); + document.addEventListener("DOMContentLoaded", function () { + document.ltiLaunchForm.submit(); + }); </script> <? endif ?> </head> <body> - <? if ($lti13a_mode) : ?> + <? if ($version === '1.3a'): ?> <? if ($message) : ?> <?= $message->toHtmlRedirectForm(Request::submitted('do_not_send') ? false : true) ?> <? else: ?> <?= _('Das LTI-Tool kann nicht aufgerufen werden.') ?> <? endif ?> - <? else : ?> + <? endif ?> + <? if ($version === '1.1'): ?> <form name="ltiLaunchForm" method="post" action="<?= htmlReady($resource_link->deployment->getLaunchUrl()) ?>"> <? foreach ($launch_data as $key => $value): ?> <input type="hidden" name="<?= htmlReady($key) ?>" value="<?= htmlReady($value, false) ?>"> diff --git a/lib/classes/LtiLink.php b/lib/classes/LtiLink.php index 193487e..5f2afd3 100644 --- a/lib/classes/LtiLink.php +++ b/lib/classes/LtiLink.php @@ -137,20 +137,18 @@ class LtiLink * is used to set up the user and LIS person parameters and variables. * If send_lis_person is true, the user's name and e-mail is included. * - * @param string $user_id id of associated course - * @param string $roles roles of this user (defaults to 'Learner') + * @param User $user + * @param string $role roles of this user (defaults to 'Learner') * @param bool $send_lis_person include additional user information */ - public function setUser($user_id, $roles = 'Learner', $send_lis_person = false) + public function setUser(User $user, string $role = 'Learner', $sendLisPerson = false): void { - $user = User::find($user_id); - $avatar = Avatar::getAvatar($user_id); + $avatar = Avatar::getAvatar($user->id); + $this->addVariable('User.id', $user->id); + $this->addLaunchParameter('user_id', $user->id); + $this->addLaunchParameter('roles', $role); - $this->addVariable('User.id', $user_id); - $this->addLaunchParameter('user_id', $user_id); - $this->addLaunchParameter('roles', $roles); - - if ($user && $send_lis_person) { + if ($user && $sendLisPerson) { $this->addVariables([ 'User.image' => $avatar->getURL(Avatar::NORMAL), 'User.username' => $user->username, |
