diff options
Diffstat (limited to 'lib/classes')
| -rw-r--r-- | lib/classes/LTI13a/PlatformManager.php | 22 | ||||
| -rw-r--r-- | lib/classes/LTI13a/Registration.php | 43 | ||||
| -rw-r--r-- | lib/classes/LTI13a/RegistrationManager.php | 21 |
3 files changed, 68 insertions, 18 deletions
diff --git a/lib/classes/LTI13a/PlatformManager.php b/lib/classes/LTI13a/PlatformManager.php index 10c7cb1..9017267 100644 --- a/lib/classes/LTI13a/PlatformManager.php +++ b/lib/classes/LTI13a/PlatformManager.php @@ -31,17 +31,20 @@ class PlatformManager * Generates an object containing the settings for using this Stud.IP * as a platform that connects to an LTI tool via Deep Linking. * - * @param string $tool_id An optional LTI tool ID that is used to construct + * @param string $link_id The Stud.IP LTI Resource Link ID that is used to construct * the platform return URL. * + * @param string $course_id An optional Stud.IP course for which to get + * the deep linking configuration. + * * @return DeepLinkingSettings The settings for deep linking. */ - public static function getDeepLinkingConfiguration(string $tool_id = '') : DeepLinkingSettings + public static function getDeepLinkingConfiguration(string $link_id, string $course_id = '') : DeepLinkingSettings { $c = \Config::get(); return new DeepLinkingSettings( - self::getDeepLinkingReturnUrl($tool_id), + self::getDeepLinkingReturnUrl($link_id, $course_id), [LtiResourceLinkInterface::TYPE], ['window', 'iframe'], 'text/html', @@ -85,13 +88,20 @@ class PlatformManager /** * Generates the URL for returning from the tool in an LTI deep linking process. * - * @param string $tool_id The optional LTI Tool-ID to append to the URL. + * @param string $link_id The Stud.IP LTI Resource Link ID to append to the URL. + * + * @param string $course_id An optional Stud.IP course for which to generate + * the deep linking return URL. * * @return string The URL for returning from an LTI deep linking process. */ - public static function getDeepLinkingReturnUrl(string $tool_id = '') : string + public static function getDeepLinkingReturnUrl(string $link_id, string $course_id = '') : string { - return \URLHelper::getURL('dispatch.php/course/lti/save_link/' . $tool_id, null, true); + $params = ['link_id' => $link_id]; + if ($course_id) { + $params['cid'] = $course_id; + } + return \URLHelper::getURL('dispatch.php/course/lti/save_link/' . $link_id, $params, true); } /** diff --git a/lib/classes/LTI13a/Registration.php b/lib/classes/LTI13a/Registration.php index c4b898f..5498ace 100644 --- a/lib/classes/LTI13a/Registration.php +++ b/lib/classes/LTI13a/Registration.php @@ -2,6 +2,7 @@ namespace Studip\LTI13a; +use OAT\Library\Lti1p3Core\Exception\LtiException; use OAT\Library\Lti1p3Core\Registration\RegistrationInterface; use OAT\Library\Lti1p3Core\Tool\ToolInterface; use OAT\Library\Lti1p3Core\Platform\PlatformInterface; @@ -10,7 +11,8 @@ use OAT\Library\Lti1p3Core\Security\Key\KeyChainInterface; class Registration implements RegistrationInterface { public function __construct( - protected ?\LtiTool $tool + protected ?\LtiTool $tool, + protected ?\LtiResourceLink $link = null ) { } @@ -24,13 +26,27 @@ class Registration implements RegistrationInterface return $this->tool; } + public function setLtiResourceLink(\LtiResourceLink $link) + { + $this->link = $link; + } + + public function getLtiResourceLink() : ?\LtiResourceLink + { + return $this->link; + } + #[\Override] public function getIdentifier(): string { if (!$this->tool) { return ''; } - return $this->tool->id; + if ($this->link) { + return $this->tool->id . '_' . $this->link->id; + } else { + return $this->tool->id; + } } #[\Override] @@ -63,7 +79,11 @@ class Registration implements RegistrationInterface if (!$this->tool) { return []; } - return \DBManager::get()->fetchFirst("SELECT `id` FROM `lti_deployments` WHERE `tool_id` = ?", [$this->tool->id]); + if ($this->link) { + return [$this->link->deployment_id]; + } else { + return \DBManager::get()->fetchFirst("SELECT `id` FROM `lti_deployments` WHERE `tool_id` = ?", [$this->tool->id]); + } } #[\Override] @@ -72,10 +92,14 @@ class Registration implements RegistrationInterface if (!$this->tool) { return false; } - return \LtiDeployment::countBySql( - "`tool_id` = :tool_id AND `id` = :deployment_id", - ['tool_id' => $this->tool->id, 'deployment_id' => $deploymentId] - ) > 0; + if ($this->link) { + return $this->link->deployment_id == $deploymentId; + } else { + return \LtiDeployment::countBySql( + "`tool_id` = :tool_id AND `id` = :deployment_id", + ['tool_id' => $this->tool->id, 'deployment_id' => $deploymentId] + ) > 0; + } } #[\Override] @@ -98,12 +122,13 @@ class Registration implements RegistrationInterface #[\Override] public function getToolKeyChain(): ?KeyChainInterface { - if (!$this->tool) { + if (!$this->tool || $this->tool->jwks_url) { return null; } + $keyring = $this->tool->getKeyring(); if (!$keyring) { - $keyring = $this->tool->getKeyring(true); + throw new LtiException('Failed to load public key for tool ' . $this->tool->id); } return $keyring->toKeyChain(); } diff --git a/lib/classes/LTI13a/RegistrationManager.php b/lib/classes/LTI13a/RegistrationManager.php index 922cb58..05bcc2e 100644 --- a/lib/classes/LTI13a/RegistrationManager.php +++ b/lib/classes/LTI13a/RegistrationManager.php @@ -7,15 +7,29 @@ use OAT\Library\Lti1p3Core\Registration\RegistrationInterface; class RegistrationManager implements RegistrationRepositoryInterface { + protected ?\LtiResourceLink $link = null; + + public function setResourceLink(\LtiResourceLink $link) + { + $this->link = $link; + } + #[\Override] public function find(string $identifier): ?RegistrationInterface { //The identifier is the ID of a tool. $tool = \LtiTool::find($identifier); + $link = null; + if (!$tool) { + //Attempt to find the tool and a resource link. + $id_parts = explode('_', $identifier); + $tool = \LtiTool::find($id_parts[0]); + $link = \LtiResourceLink::find($id_parts[1]); + } if (!$tool) { return null; } - return new Registration($tool); + return new Registration($tool, $link); } /** @@ -42,7 +56,7 @@ class RegistrationManager implements RegistrationRepositoryInterface } $tool = \LtiTool::find($clientId); if ($tool) { - return new Registration($tool); + return new Registration($tool, $this->link); } return null; } @@ -51,7 +65,8 @@ class RegistrationManager implements RegistrationRepositoryInterface public function findByPlatformIssuer(string $issuer, string $clientId = null): ?RegistrationInterface { //Only handle requests for registrations of this Stud.IP: - if ($issuer !== \Config::get()->STUDIP_INSTALLATION_ID) { + $platform_config = \Studip\LTI13a\PlatformManager::getPlatformConfiguration(); + if ($issuer !== $platform_config->getAudience()) { //Invalid issuer. return null; } |
