diff options
| author | Murtaza Sultani <sultani@data-quest.de> | 2026-02-12 15:51:39 +0100 |
|---|---|---|
| committer | Murtaza Sultani <sultani@data-quest.de> | 2026-03-19 17:36:05 +0100 |
| commit | d67057643effcc63a9ab2a20b0469ee3d92ecad1 (patch) | |
| tree | 5fe2c9e264e482bb94a98ff4ec7eb968c762eea9 | |
| parent | d8b845b37be108a5af61c0ed1b5f34ffd315250f (diff) | |
Add LTI 1.3a AGS Server
| -rw-r--r-- | app/controllers/lti/1p3/ags/client.php | 9 | ||||
| -rw-r--r-- | app/controllers/lti/1p3/ags/server.php | 63 | ||||
| -rw-r--r-- | app/controllers/lti/ags.php | 92 | ||||
| -rw-r--r-- | lib/modules/LtiToolModule.php | 2 |
4 files changed, 73 insertions, 93 deletions
diff --git a/app/controllers/lti/1p3/ags/client.php b/app/controllers/lti/1p3/ags/client.php index b3d9bbc..e2076e2 100644 --- a/app/controllers/lti/1p3/ags/client.php +++ b/app/controllers/lti/1p3/ags/client.php @@ -1 +1,10 @@ <?php +use Studip\OAuth2\NegotiatesWithPsr7; + +class Lti_1p3_Ags_ClientController extends AuthenticatedController +{ + protected $allow_nobody = true; + protected $with_session = false; + + use NegotiatesWithPsr7; +} diff --git a/app/controllers/lti/1p3/ags/server.php b/app/controllers/lti/1p3/ags/server.php index b3d9bbc..7ce8679 100644 --- a/app/controllers/lti/1p3/ags/server.php +++ b/app/controllers/lti/1p3/ags/server.php @@ -1 +1,64 @@ <?php + +use Trails\Dispatcher; +use Studip\OAuth2\NegotiatesWithPsr7; +use Studip\Lti\LTI1p3\LineItemRepository; +use Studip\Lti\LTI1p3\RegistrationManager; +use OAT\Library\Lti1p3Core\Service\Server\LtiServiceServer; +use OAT\Library\Lti1p3Ags\Repository\LineItemRepositoryInterface; +use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator; +use OAT\Library\Lti1p3Core\Service\Server\Handler\LtiServiceServerRequestHandlerInterface; +use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\GetLineItemServiceServerRequestHandler; +use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\ListLineItemsServiceServerRequestHandler; +use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\CreateLineItemServiceServerRequestHandler; +use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\DeleteLineItemServiceServerRequestHandler; +use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\UpdateLineItemServiceServerRequestHandler; + +class Lti_1p3_Ags_ServerController extends AuthenticatedController +{ + protected $allow_nobody = true; + protected $with_session = false; + protected LineItemRepositoryInterface $lineItemRepo; + + use NegotiatesWithPsr7; + + public function __construct(Dispatcher $dispatcher) + { + parent::__construct($dispatcher); + + $this->lineItemRepo = new LineItemRepository(); + } + + public function line_item_action(): void + { + $requestHandler = match (Request::method()) { + 'PUT' => new UpdateLineItemServiceServerRequestHandler($this->lineItemRepo), + 'DELETE' => new DeleteLineItemServiceServerRequestHandler($this->lineItemRepo), + 'GET' => new GetLineItemServiceServerRequestHandler($this->lineItemRepo), + default => throw new MethodNotAllowedException() + }; + + $this->renderAgsResponse($requestHandler); + } + + public function line_items_action(): void + { + $requestHandler = match (Request::method()) { + 'POST' => new CreateLineItemServiceServerRequestHandler($this->lineItemRepo), + 'GET' => new ListLineItemsServiceServerRequestHandler($this->lineItemRepo), + default => throw new MethodNotAllowedException() + }; + + $this->renderAgsResponse($requestHandler); + } + + private function renderAgsResponse( + LtiServiceServerRequestHandlerInterface $requestHandler + ): void + { + $requestValidator = new RequestAccessTokenValidator(new RegistrationManager()); + + $server = new LtiServiceServer($requestValidator, $requestHandler); + $this->renderPsrResponse($server->handle($this->getPsrRequest())); + } +} diff --git a/app/controllers/lti/ags.php b/app/controllers/lti/ags.php deleted file mode 100644 index 68ecafb..0000000 --- a/app/controllers/lti/ags.php +++ /dev/null @@ -1,92 +0,0 @@ -<?php - -use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\CreateLineItemServiceServerRequestHandler; -use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\DeleteLineItemServiceServerRequestHandler; -use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\GetLineItemServiceServerRequestHandler; -use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\ListLineItemsServiceServerRequestHandler; -use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\UpdateLineItemServiceServerRequestHandler; -use OAT\Library\Lti1p3Ags\Service\Result\Server\Handler\ResultServiceServerRequestHandler; -use OAT\Library\Lti1p3Ags\Service\Score\Server\Handler\ScoreServiceServerRequestHandler; -use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator; -use OAT\Library\Lti1p3Core\Service\Server\LtiServiceServer; -use Studip\Lti\LTI1p3\LineItemRepository; -use Studip\Lti\LTI1p3\RegistrationManager; -use Studip\OAuth2\NegotiatesWithPsr7; -use Trails\Dispatcher; - -class Lti_AgsController extends StudipController -{ - use NegotiatesWithPsr7; - - public function __construct(Dispatcher $dispatcher) - { - $this->with_session = true; - parent::__construct($dispatcher); - } - - public function before_filter(&$action, &$args) - { - parent::before_filter($action, $args); - - //All the work is done by the OAT-SA library and - //the implementation of its interfaces in Stud.IP. - //Only the handler changes for the endpoints. - $line_item_repo = new LineItemRepository(); - $validator = new RequestAccessTokenValidator(new RegistrationManager()); - $handler = null; - if ($action === 'line_item') { - if (empty($args)) { - if (Request::isPut()) { - //Update a line item: - $handler = new UpdateLineItemServiceServerRequestHandler($line_item_repo); - } elseif (Request::isDelete()) { - //Delete a line item: - $handler = new DeleteLineItemServiceServerRequestHandler($line_item_repo); - } else { - //Get a line item: - $handler = new GetLineItemServiceServerRequestHandler($line_item_repo); - } - } elseif ($args[0] === 'results') { - $handler = new ResultServiceServerRequestHandler($line_item_repo, new \Studip\Lti\LTI1p3\ResultRepository()); - } elseif ($args[0] === 'scores') { - $handler = new ScoreServiceServerRequestHandler($line_item_repo,new \Studip\Lti\LTI1p3\ScoreRepository()); - } - } elseif ($action === 'line_items') { - if (Request::isPost()) { - //Create a line item: - $handler = new CreateLineItemServiceServerRequestHandler($line_item_repo); - } else { - //List line items: - $handler = new ListLineItemsServiceServerRequestHandler($line_item_repo); - } - } else { - //Invalid endpoint. - throw new AccessDeniedException(studip_interpolate('Invalid endpoint: %{endpoint}', ['endpoint' => $action])); - } - if (!$handler) { - throw new \Studip\LTIException('No handler available for this request.'); - } - $server = new LtiServiceServer($validator, $handler); - $this->renderPsrResponse($server->handle($this->getPsrRequest())); - } - - /** - * This is the endpoint for the LTI AGS lineitem service. - * - * @return void - */ - public function line_item_action(): void - { - //Nothing here. All is done in the before_filter. - } - - /** - * This is the endpoint for the LTI AGS lineitems service. - * - * @return void - */ - public function line_items_action(): void - { - //Nothing here. All is done in the before_filter. - } -} diff --git a/lib/modules/LtiToolModule.php b/lib/modules/LtiToolModule.php index a3f2a84..1554eb8 100644 --- a/lib/modules/LtiToolModule.php +++ b/lib/modules/LtiToolModule.php @@ -4,7 +4,7 @@ use Lti\Grade; use Lti\ResourceLink; /** - * LtiToolModule.php - LTI consumer API for Stud.IP + * LtiToolModule.php - LTI consumer and provider API for Stud.IP * * @author Elmar Ludwig * @author Murtaza Sultani <sultani@data-quest.de> |
