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 abstract class AbstractMessageValidator implements IMessageValidator 10 { 11 abstract public static function getMessageType(): string; 12 13 public static function canValidate(array $jwtBody): bool 14 { 15 return $jwtBody[LtiConstants::MESSAGE_TYPE] === static::getMessageType(); 16 } 17 18 abstract public static function validate(array $jwtBody): void; 19 20 public static function validateGenericMessage(array $jwtBody): void 21 { 22 if (empty($jwtBody['sub'])) { 23 throw new LtiException('Must have a user (sub)'); 24 } 25 if (!isset($jwtBody[LtiConstants::VERSION])) { 26 throw new LtiException('Missing LTI Version'); 27 } 28 if ($jwtBody[LtiConstants::VERSION] !== LtiConstants::V1_3) { 29 throw new LtiException('Incorrect version, expected 1.3.0'); 30 } 31 if (!isset($jwtBody[LtiConstants::ROLES])) { 32 throw new LtiException('Missing Roles Claim'); 33 } 34 } 35 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body