Skip to content

Commit

Permalink
Merge pull request ILIAS-eLearning#8405 from surlabs/ilias9_LTI_003
Browse files Browse the repository at this point in the history
Allow using RSA key when saving LTI Content Selection
  • Loading branch information
Saaweel authored Nov 12, 2024
2 parents fc8905d + a75650c commit 28cf7c0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Modules/LTIConsumer/classes/class.ilObjLTIConsumerGUI.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilObjLTIConsumerGUI
* @author Uwe Kohnle <[email protected]>
Expand Down Expand Up @@ -343,7 +343,7 @@ public function showToolConfig(): void
$provider_id = $this->getRequestValue("provider_id");
$DIC->ctrl()->setParameter($this, "provider_id", $provider_id);
$DIC->language()->loadLanguageModule($new_type);
$form = $this->initShowToolConfig($new_type, (int)$provider_id);
$form = $this->initShowToolConfig($new_type, (int) $provider_id);
$DIC->ui()->mainTemplate()->setContent($form->getHTML());
}

Expand All @@ -360,7 +360,7 @@ public function saveDynReg(): void
$DIC->language()->loadLanguageModule($new_type);
ilSession::clear('lti_dynamic_registration_client_id');
ilSession::clear('lti_dynamic_registration_custom_params');
$form = $this->initShowToolConfig($new_type, (int)$provider_id);
$form = $this->initShowToolConfig($new_type, (int) $provider_id);
$form->setValuesByPost();
if ($form->checkInput()) { // update only overridable fields
$provider = $form->getProvider();
Expand Down Expand Up @@ -477,11 +477,15 @@ public function cancelContentSelection(): void

public function saveContentSelection(ilLTIConsumeProvider $provider, string $token): void
{
//ToDo: fetch with file_get_contents ok? needs caching?
$jwks = file_get_contents($provider->getPublicKeyset());
//ToDo: Errorhandling
$keyset = json_decode($jwks, true);
$keys = Firebase\JWT\JWK::parseKeySet($keyset);
if ($provider->getKeyType() == 'RSA_KEY') {
$key = $provider->getPublicKey();
$keys = new Firebase\JWT\Key($key, "RS256");
} else {
$jwks = file_get_contents($provider->getPublicKeyset());
//ToDo: Errorhandling
$keyset = json_decode($jwks, true);
$keys = Firebase\JWT\JWK::parseKeySet($keyset);
}
$data = Firebase\JWT\JWT::decode($token, $keys);
//ilObjLTIConsumer::getLogger()->debug(var_export($data,TRUE));
$refId = $this->getRequestValue('ref_id');
Expand Down Expand Up @@ -850,7 +854,7 @@ protected function checkContentSelection(): void
$newType = $this->getRequestValue('new_type');
$refId = $this->getRequestValue('ref_id');
if ($providerId !== null && $newType == 'lti' && $refId != null) {
$provider = new ilLTIConsumeProvider((int)$providerId);
$provider = new ilLTIConsumeProvider((int) $providerId);
// check if post variables from contentSelectionResponse
if ($DIC->http()->wrapper()->post()->has('JWT')) {
// ToDo:
Expand Down

0 comments on commit 28cf7c0

Please sign in to comment.