validateRequest($request); $this->validateRole($ltiMessagePayload); } catch (Lti1p3Exception $exception) { throw new LtiException($exception->getMessage()); } return $ltiMessagePayload; } /** * @throws Lti1p3Exception */ public function validateRequest(ServerRequestInterface $request): LtiMessagePayloadInterface { $validator = new ToolLaunchValidator( $this->getServiceLocator()->get(Lti1p3RegistrationRepository::SERVICE_ID), new NonceRepository($this->getServiceLocator()->get(ItemPoolSimpleCacheAdapter::class)) ); $result = $validator->validatePlatformOriginatingLaunch($request); if ($result->hasError()) { throw new Lti1p3Exception($result->getError()); } $ltiMessagePayload = $result->getPayload(); if ($ltiMessagePayload === null) { throw new Lti1p3Exception('No LTI message payload received.'); } return $ltiMessagePayload; } /** * @throws LtiException */ public function validateRole(LtiMessagePayloadInterface $ltiMessagePayload): void { $roles = $ltiMessagePayload->getValidatedRoleCollection(); if (!$roles->canFindBy(RoleInterface::TYPE_CONTEXT)) { throw new LtiException('No valid IMS context role has been provided.'); } } }