Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 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 ResourceMessageValidator implements IMessageValidator
  10  {
  11      public function canValidate(array $jwtBody)
  12      {
  13          return $jwtBody[LtiConstants::MESSAGE_TYPE] === 'LtiResourceLinkRequest';
  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 (!isset($jwtBody[LtiConstants::VERSION])) {
  22              throw new LtiException('Missing LTI Version');
  23          }
  24          if ($jwtBody[LtiConstants::VERSION] !== LtiConstants::V1_3) {
  25              throw new LtiException('Incorrect version, expected 1.3.0');
  26          }
  27          if (!isset($jwtBody[LtiConstants::ROLES])) {
  28              throw new LtiException('Missing Roles Claim');
  29          }
  30          if (empty($jwtBody[LtiConstants::RESOURCE_LINK]['id'])) {
  31              throw new LtiException('Missing Resource Link Id');
  32          }
  33  
  34          return true;
  35      }
  36  }