Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  
   3  namespace Packback\Lti1p3\MessageValidators;
   4  
   5  use Packback\Lti1p3\Interfaces\IMessageValidator;
   6  use Packback\Lti1p3\LtiConstants;
   7  use Packback\Lti1p3\LtiException;
   8  
   9  class DeepLinkMessageValidator implements IMessageValidator
  10  {
  11      public function canValidate(array $jwtBody)
  12      {
  13          return $jwtBody[LtiConstants::MESSAGE_TYPE] === 'LtiDeepLinkingRequest';
  14      }
  15  
  16      public function validate(array $jwtBody)
  17      {
  18          if (empty($jwtBody['sub'])) {
  19              throw new LtiException('Must have a user (sub)');
  20          }
  21          if ($jwtBody[LtiConstants::VERSION] !== LtiConstants::V1_3) {
  22              throw new LtiException('Incorrect version, expected 1.3.0');
  23          }
  24          if (!isset($jwtBody[LtiConstants::ROLES])) {
  25              throw new LtiException('Missing Roles Claim');
  26          }
  27          if (empty($jwtBody[LtiConstants::DL_DEEP_LINK_SETTINGS])) {
  28              throw new LtiException('Missing Deep Linking Settings');
  29          }
  30          $deep_link_settings = $jwtBody[LtiConstants::DL_DEEP_LINK_SETTINGS];
  31          if (empty($deep_link_settings['deep_link_return_url'])) {
  32              throw new LtiException('Missing Deep Linking Return URL');
  33          }
  34          if (empty($deep_link_settings['accept_types']) || !in_array('ltiResourceLink', $deep_link_settings['accept_types'])) {
  35              throw new LtiException('Must support resource link placement types');
  36          }
  37          if (empty($deep_link_settings['accept_presentation_document_targets'])) {
  38              throw new LtiException('Must support a presentation type');
  39          }
  40  
  41          return true;
  42      }
  43  }