Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function doAuthentication(\ilAuthStatus $status): bool
$lti_provider->rsaKey = $pk['key'];
$lti_provider->kid = $pk['kid'];
$lti_provider->signatureMethod = 'RS256';
$lti_provider->handleRequest();
$lti_provider->processRequest();
$this->provider = $lti_provider;
$this->messageParameters = $this->provider->getMessageParameters();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

/**
* Thrown by the LTI library instead of terminating the request on its own.
*
* The library is designed to be the only thing handling an LTI request, so it ends the request
* itself once the message has been processed. ILIAS still has to authenticate the user and send
* them to the requested object afterwards, so it asks the library to throw this exception rather
* than to exit, and regains control in ilLTITool::processRequest().
*/
class ilLTIExitException extends ilException
{
public function __construct(string $message = '', int $code = 0)
{
parent::__construct($message, $code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use ceLTIc\LTI\ResourceLink;
use ceLTIc\LTI\Tool;
use ceLTIc\LTI\User;
use ceLTIc\LTI\Util;
use ILIAS\HTTP\Wrapper\ArrayBasedRequestWrapper;

/**
Expand Down Expand Up @@ -87,7 +88,13 @@ public function parsePostBody(ArrayBasedRequestWrapper $postData): array
return $res;
}

public function handleRequest(?bool $strictMode = null, bool $disableCookieCheck = false, bool $generateWarnings = false): void
/**
* Process the LTI request and return to ILIAS once the message has been accepted.
*
* This does not override handleRequest(): the library declares that method as never returning,
* while ILIAS needs control back to authenticate the user.
*/
public function processRequest(): void
{
global $DIC;

Expand All @@ -100,6 +107,35 @@ public function handleRequest(?bool $strictMode = null, bool $disableCookieCheck

self::$authenticateUsingGet = true;

parent::handleRequest($strictMode, $disableCookieCheck, $generateWarnings);
// The LTI library ends the request itself once the message has been processed. ILIAS still
// has to authenticate the user and forward them to the requested object, so the library is
// asked to throw instead of exiting.
$this->onExitExceptionClass = ilLTIExitException::class;

try {
$this->handleRequest();
} catch (ilLTIExitException $e) {
$this->sendPendingResponse();
}
}

/**
* Send whatever the LTI library prepared for the platform before it tried to end the request.
*
* A redirect back to the platform carries an error message, an output body is either an error
* page or one of the self submitting forms used for the browser storage and cookie checks. A
* successfully processed launch leaves both of them empty, which is the only case where the
* control flow returns to ILIAS.
*/
private function sendPendingResponse(): void
{
if (!is_null($this->redirectUrl)) {
Util::redirect($this->redirectUrl);
}

if (!is_null($this->output)) {
echo $this->output;
exit;
}
}
}
Loading