Minor - Plugin: LTI provider format code #3894

pull/3914/head
Angel Fernando Quiroz Campos 4 years ago committed by Christian
parent 7e8a9b5ccb
commit c794b09bce
  1. 42
      plugin/lti_provider/Entity/Platform.php
  2. 22
      plugin/lti_provider/Entity/PlatformKey.php
  3. 238
      plugin/lti_provider/LtiProviderPlugin.php
  4. 2
      plugin/lti_provider/admin.php
  5. 5
      plugin/lti_provider/create.php
  6. 47
      plugin/lti_provider/db/lti13_cache.php
  7. 12
      plugin/lti_provider/db/lti13_cookie.php
  8. 47
      plugin/lti_provider/db/lti13_database.php
  9. 4
      plugin/lti_provider/delete.php
  10. 5
      plugin/lti_provider/edit.php
  11. 3
      plugin/lti_provider/install.php
  12. 3
      plugin/lti_provider/plugin.php
  13. 2
      plugin/lti_provider/provider_settings.php
  14. 12
      plugin/lti_provider/src/Form/FrmAdd.php
  15. 12
      plugin/lti_provider/src/Form/FrmEdit.php
  16. 51
      plugin/lti_provider/src/LtiProvider.php
  17. 3
      plugin/lti_provider/uninstall.php

@ -71,7 +71,7 @@ class Platform
* *
* @return int * @return int
*/ */
public function getId() public function getId(): int
{ {
return $this->id; return $this->id;
} }
@ -83,7 +83,7 @@ class Platform
* *
* @return Platform * @return Platform
*/ */
public function setId($id) public function setId(int $id): Platform
{ {
$this->id = $id; $this->id = $id;
@ -96,17 +96,27 @@ class Platform
* *
* @return string * @return string
*/ */
public function getKid() public function getKid(): string
{ {
return $this->kid; return $this->kid;
} }
/**
* Set kid.
*
* @param string $kid
*/
public function setKid(string $kid)
{
$this->kid = $kid;
}
/** /**
* Get Issuer * Get Issuer
* *
* @return string * @return string
*/ */
public function getIssuer() public function getIssuer(): string
{ {
return $this->issuer; return $this->issuer;
} }
@ -126,7 +136,7 @@ class Platform
* *
* @return string * @return string
*/ */
public function getClientId() public function getClientId(): string
{ {
return $this->clientId; return $this->clientId;
} }
@ -146,7 +156,7 @@ class Platform
* *
* @return string * @return string
*/ */
public function getAuthLoginUrl() public function getAuthLoginUrl(): string
{ {
return $this->authLoginUrl; return $this->authLoginUrl;
} }
@ -166,7 +176,7 @@ class Platform
* *
* @return string * @return string
*/ */
public function getAuthTokenUrl() public function getAuthTokenUrl(): string
{ {
return $this->authTokenUrl; return $this->authTokenUrl;
} }
@ -183,15 +193,17 @@ class Platform
/** /**
* Get key set URL * Get key set URL
*
* @return string * @return string
*/ */
public function getKeySetUrl() public function getKeySetUrl(): string
{ {
return $this->keySetUrl; return $this->keySetUrl;
} }
/** /**
* Set key set URL * Set key set URL
*
* @param string $keySetUrl * @param string $keySetUrl
*/ */
public function setKeySetUrl(string $keySetUrl) public function setKeySetUrl(string $keySetUrl)
@ -204,7 +216,7 @@ class Platform
* *
* @return string * @return string
*/ */
public function getDeploymentId() public function getDeploymentId(): string
{ {
return $this->deploymentId; return $this->deploymentId;
} }
@ -218,16 +230,4 @@ class Platform
{ {
$this->deploymentId = $deploymentId; $this->deploymentId = $deploymentId;
} }
/**
* Set kid.
*
* @param string $kid
*/
public function setKid($kid)
{
$this->kid = $kid;
}
} }

@ -47,19 +47,15 @@ class PlatformKey
* *
* @return int * @return int
*/ */
public function getId() public function getId(): int
{ {
return $this->id; return $this->id;
} }
/** /**
* Set id. * Set id.
*
* @param int $id
*
* @return Platform
*/ */
public function setId($id) public function setId(int $id): PlatformKey
{ {
$this->id = $id; $this->id = $id;
@ -72,7 +68,7 @@ class PlatformKey
* *
* @return string * @return string
*/ */
public function getKid() public function getKid(): string
{ {
return $this->kid; return $this->kid;
} }
@ -82,7 +78,7 @@ class PlatformKey
* *
* @param string $kid * @param string $kid
*/ */
public function setKid($kid) public function setKid(string $kid)
{ {
$this->kid = $kid; $this->kid = $kid;
} }
@ -92,7 +88,7 @@ class PlatformKey
* *
* @return string * @return string
*/ */
public function getPrivateKey() public function getPrivateKey(): string
{ {
return $this->privateKey; return $this->privateKey;
} }
@ -102,9 +98,9 @@ class PlatformKey
* *
* @param string $privateKey * @param string $privateKey
* *
* @return Platform * @return PlatformKey
*/ */
public function setPrivateKey($privateKey) public function setPrivateKey(string $privateKey): PlatformKey
{ {
$this->privateKey = $privateKey; $this->privateKey = $privateKey;
@ -114,7 +110,7 @@ class PlatformKey
/** /**
* @return string * @return string
*/ */
public function getPublicKey() public function getPublicKey(): string
{ {
return $this->publicKey; return $this->publicKey;
} }
@ -126,6 +122,4 @@ class PlatformKey
{ {
$this->publicKey = $publicKey; $this->publicKey = $publicKey;
} }
} }

@ -3,8 +3,7 @@
use Chamilo\PluginBundle\Entity\LtiProvider\PlatformKey; use Chamilo\PluginBundle\Entity\LtiProvider\PlatformKey;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Schema; use Doctrine\ORM\OptimisticLockException;
use Doctrine\DBAL\Types\Type;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
/** /**
@ -32,7 +31,8 @@ class LtiProviderPlugin extends Plugin
} }
$pkHtml = '<div class="form-group "> $pkHtml = '<div class="form-group ">
<label for="lti_provider_public_key" class="col-sm-2 control-label">'.$this->get_lang('PublicKey').'</label> <label for="lti_provider_public_key" class="col-sm-2 control-label">'
.$this->get_lang('PublicKey').'</label>
<div class="col-sm-8"> <div class="col-sm-8">
<pre>'.$publicKey.'</pre> <pre>'.$publicKey.'</pre>
<p class="help-block"></p> <p class="help-block"></p>
@ -47,28 +47,53 @@ class LtiProviderPlugin extends Plugin
'login_url' => 'text', 'login_url' => 'text',
'redirect_url' => 'text', 'redirect_url' => 'text',
$pkHtml => 'html', $pkHtml => 'html',
'enabled' => 'boolean' 'enabled' => 'boolean',
]; ];
parent::__construct($version, $author, $settings); parent::__construct($version, $author, $settings);
} }
/**
* Get the public key
*
* @return string
*/
public function getPublicKey(): string
{
$publicKey = '';
$platformKey = Database::getManager()
->getRepository('ChamiloPluginBundle:LtiProvider\PlatformKey')
->findOneBy([]);
if ($platformKey) {
$publicKey = $platformKey->getPublicKey();
}
return $publicKey;
}
/** /**
* Get the class instance * Get the class instance
*
* @staticvar LtiProviderPlugin $result * @staticvar LtiProviderPlugin $result
* @return LtiProviderPlugin * @return LtiProviderPlugin
*/ */
public static function create() public static function create(): LtiProviderPlugin
{ {
static $result = null; static $result = null;
return $result ?: $result = new self(); return $result ?: $result = new self();
} }
public static function isInstructor()
{
api_is_allowed_to_edit(false, true);
}
/** /**
* Get the plugin directory name * Get the plugin directory name
*/ */
public function get_name() public function get_name(): string
{ {
return 'lti_provider'; return 'lti_provider';
} }
@ -85,7 +110,7 @@ class LtiProviderPlugin extends Plugin
$message = get_lang('ErrorCreatingDir').': '.$pluginEntityPath; $message = get_lang('ErrorCreatingDir').': '.$pluginEntityPath;
Display::addFlash(Display::return_message($message, 'error')); Display::addFlash(Display::return_message($message, 'error'));
return false; return;
} }
mkdir($pluginEntityPath, api_get_permissions_for_new_directories()); mkdir($pluginEntityPath, api_get_permissions_for_new_directories());
@ -98,78 +123,25 @@ class LtiProviderPlugin extends Plugin
} }
/** /**
* Save configuration for plugin. * @return string
*
* Generate a new key pair for platform when enabling plugin.
*
* @throws \Doctrine\ORM\OptimisticLockException
*
* @return $this|Plugin
*/
public function performActionsAfterConfigure()
{
$em = Database::getManager();
/** @var PlatformKey $platformKey */
$platformKey = $em
->getRepository('ChamiloPluginBundle:LtiProvider\PlatformKey')
->findOneBy([]);
if ($this->get('enabled') === 'true') {
if (!$platformKey) {
$platformKey = new PlatformKey();
}
$keyPair = self::generatePlatformKeys();
$platformKey->setKid($keyPair['kid']);
$platformKey->publicKey = $keyPair['public'];
$platformKey->setPrivateKey($keyPair['private']);
$em->persist($platformKey);
} else {
if ($platformKey) {
$em->remove($platformKey);
}
}
$em->flush();
return $this;
}
/**
* Unistall plugin. Clear the database
*/ */
public function uninstall() public function getEntityPath(): string
{ {
$pluginEntityPath = $this->getEntityPath(); return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
$fs = new Filesystem();
if ($fs->exists($pluginEntityPath)) {
$fs->remove($pluginEntityPath);
}
try {
$this->dropPluginTables();
} catch (DBALException $e) {
error_log('Error while uninstalling IMS/LTI plugin: '.$e->getMessage());
}
} }
/** /**
* Creates the plugin tables on database * Creates the plugin tables on database
* *
* @return boolean * @return void
* @throws DBALException
*/ */
private function createPluginTables() private function createPluginTables(): void
{ {
$entityManager = Database::getManager(); $entityManager = Database::getManager();
$connection = $entityManager->getConnection(); $connection = $entityManager->getConnection();
if ($connection->getSchemaManager()->tablesExist(self::TABLE_PLATFORM)) { if ($connection->getSchemaManager()->tablesExist(self::TABLE_PLATFORM)) {
return true; return;
} }
$queries = [ $queries = [
@ -190,64 +162,55 @@ class LtiProviderPlugin extends Plugin
public_key LONGTEXT NOT NULL, public_key LONGTEXT NOT NULL,
private_key LONGTEXT NOT NULL, private_key LONGTEXT NOT NULL,
PRIMARY KEY(id) PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB" ) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB",
]; ];
foreach ($queries as $query) { foreach ($queries as $query) {
Database::query($query); Database::query($query);
} }
return true;
} }
/** /**
* Drops the plugin tables on database * Save configuration for plugin.
* *
* @return boolean * Generate a new key pair for platform when enabling plugin.
*
* @throws OptimisticLockException
* @throws \Doctrine\ORM\ORMException
*
* @return $this|Plugin
*/ */
private function dropPluginTables() public function performActionsAfterConfigure()
{ {
Database::query("DROP TABLE IF EXISTS plugin_lti_provider_platform"); $em = Database::getManager();
Database::query("DROP TABLE IF EXISTS plugin_lti_provider_platform_key");
return true;
}
/** /** @var PlatformKey $platformKey */
* @return string $platformKey = $em
*/ ->getRepository('ChamiloPluginBundle:LtiProvider\PlatformKey')
public function getEntityPath() ->findOneBy([]);
{
return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
}
public static function isInstructor() if ($this->get('enabled') === 'true') {
{ if (!$platformKey) {
api_is_allowed_to_edit(false, true); $platformKey = new PlatformKey();
} }
/** $keyPair = self::generatePlatformKeys();
* @return null|SimpleXMLElement
*/
private function getRequestXmlElement()
{
$request = file_get_contents("php://input");
if (empty($request)) { $platformKey->setKid($keyPair['kid']);
return null; $platformKey->publicKey = $keyPair['public'];
$platformKey->setPrivateKey($keyPair['private']);
$em->persist($platformKey);
} else {
if ($platformKey) {
$em->remove($platformKey);
}
} }
return new SimpleXMLElement($request); $em->flush();
}
/** return $this;
* @param array $params
*/
public function trimParams(array &$params)
{
foreach ($params as $key => $value) {
$newValue = preg_replace('/\s+/', ' ', $value);
$params[$key] = trim($newValue);
}
} }
/** /**
@ -257,7 +220,7 @@ class LtiProviderPlugin extends Plugin
* *
* @return array * @return array
*/ */
private static function generatePlatformKeys() private static function generatePlatformKeys(): array
{ {
// Create the private and public key // Create the private and public key
$res = openssl_pkey_new( $res = openssl_pkey_new(
@ -283,19 +246,62 @@ class LtiProviderPlugin extends Plugin
} }
/** /**
* Get the public key * Unistall plugin. Clear the database
*/
public function uninstall()
{
$pluginEntityPath = $this->getEntityPath();
$fs = new Filesystem();
if ($fs->exists($pluginEntityPath)) {
$fs->remove($pluginEntityPath);
}
try {
$this->dropPluginTables();
} catch (DBALException $e) {
error_log('Error while uninstalling IMS/LTI plugin: '.$e->getMessage());
}
}
/**
* Drops the plugin tables on database
* *
* @return string * @return boolean
*/ */
public function getPublicKey() { private function dropPluginTables(): bool
$publicKey = ''; {
$platformKey = Database::getManager() Database::query("DROP TABLE IF EXISTS plugin_lti_provider_platform");
->getRepository('ChamiloPluginBundle:LtiProvider\PlatformKey') Database::query("DROP TABLE IF EXISTS plugin_lti_provider_platform_key");
->findOneBy([]);
if ($platformKey) { return true;
$publicKey = $platformKey->getPublicKey(); }
/**
* @param array $params
*/
public function trimParams(array &$params)
{
foreach ($params as $key => $value) {
$newValue = preg_replace('/\s+/', ' ', $value);
$params[$key] = trim($newValue);
} }
return $publicKey; }
/**
* @throws Exception
*
* @return null|SimpleXMLElement
*/
private function getRequestXmlElement(): ?SimpleXMLElement
{
$request = file_get_contents("php://input");
if (empty($request)) {
return null;
}
return new SimpleXMLElement($request);
} }
} }

@ -4,7 +4,7 @@
$cidReset = true; $cidReset = true;
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
require_once __DIR__ . '/LtiProviderPlugin.php'; require_once __DIR__.'/LtiProviderPlugin.php';
api_protect_admin_script(); api_protect_admin_script();

@ -1,12 +1,13 @@
<?php <?php
/* For license terms, see /license.txt */ /* For license terms, see /license.txt */
use Chamilo\PluginBundle\Entity\LtiProvider\Platform; use Chamilo\PluginBundle\Entity\LtiProvider\Platform;
$cidReset = true; $cidReset = true;
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
require_once __DIR__ . '/src/Form/FrmAdd.php'; require_once __DIR__.'/src/Form/FrmAdd.php';
require_once __DIR__ . '/LtiProviderPlugin.php'; require_once __DIR__.'/LtiProviderPlugin.php';
api_protect_admin_script(); api_protect_admin_script();

@ -3,48 +3,57 @@
use Packback\Lti1p3\Interfaces\Cache as Lti1p3Cache; use Packback\Lti1p3\Interfaces\Cache as Lti1p3Cache;
class Lti13Cache implements Lti1p3Cache class Lti13Cache implements Lti1p3Cache
{ {
public const NONCE_PREFIX = 'nonce_'; public const NONCE_PREFIX = 'nonce_';
private $cache; private $cache;
public function getLaunchData($key) { public function getLaunchData($key)
{
$this->loadCache(); $this->loadCache();
return $this->cache[$key]; return $this->cache[$key];
} }
public function cacheLaunchData($key, $jwt_body) { private function loadCache()
$this->cache[$key] = $jwt_body; {
$cache = file_get_contents(sys_get_temp_dir().'/lti_cache.txt');
if (empty($cache)) {
file_put_contents(sys_get_temp_dir().'/lti_cache.txt', '{}');
$this->cache = [];
}
$this->cache = json_decode($cache, true);
}
public function cacheLaunchData($key, $jwtBody): Lti13Cache
{
$this->cache[$key] = $jwtBody;
$this->saveCache(); $this->saveCache();
return $this; return $this;
} }
public function cacheNonce($nonce) { private function saveCache()
{
file_put_contents(sys_get_temp_dir().'/lti_cache.txt', json_encode($this->cache));
}
public function cacheNonce($nonce): Lti13Cache
{
$this->cache['nonce'][$nonce] = true; $this->cache['nonce'][$nonce] = true;
$this->saveCache(); $this->saveCache();
return $this; return $this;
} }
public function checkNonce($nonce) { public function checkNonce($nonce): bool
{
$this->loadCache(); $this->loadCache();
if (!isset($this->cache['nonce'][$nonce])) { if (!isset($this->cache['nonce'][$nonce])) {
return false; return false;
} }
return true;
}
private function loadCache() {
$cache = file_get_contents(sys_get_temp_dir() . '/lti_cache.txt');
if (empty($cache)) {
file_put_contents(sys_get_temp_dir() . '/lti_cache.txt', '{}');
$this->cache = [];
}
$this->cache = json_decode($cache, true);
}
private function saveCache() { return true;
file_put_contents(sys_get_temp_dir() . '/lti_cache.txt', json_encode($this->cache));
} }
} }

@ -11,29 +11,31 @@ class Lti13Cookie implements Lti1p3Cookie
return $_COOKIE[$name]; return $_COOKIE[$name];
} }
// Look for backup cookie if same site is not supported by the user's browser. // Look for backup cookie if same site is not supported by the user's browser.
if (isset($_COOKIE["LEGACY_" . $name])) { if (isset($_COOKIE["LEGACY_".$name])) {
return $_COOKIE["LEGACY_" . $name]; return $_COOKIE["LEGACY_".$name];
} }
return false; return false;
} }
public function setCookie($name, $value, $exp = 3600, $options = []): self public function setCookie($name, $value, $exp = 3600, $options = []): self
{ {
$cookieOptions = [ $cookieOptions = [
'expires' => time() + $exp 'expires' => time() + $exp,
]; ];
// SameSite none and secure will be required for tools to work inside iframes // SameSite none and secure will be required for tools to work inside iframes
$sameSiteOptions = [ $sameSiteOptions = [
'samesite' => 'None', 'samesite' => 'None',
'secure' => false, 'secure' => false,
'httponly' => true 'httponly' => true,
]; ];
setcookie($name, $value, array_merge($cookieOptions, $sameSiteOptions, $options)); setcookie($name, $value, array_merge($cookieOptions, $sameSiteOptions, $options));
// Set a second fallback cookie in the event that "SameSite" is not supported // Set a second fallback cookie in the event that "SameSite" is not supported
setcookie("LEGACY_" . $name, $value, array_merge($cookieOptions, $options)); setcookie("LEGACY_".$name, $value, array_merge($cookieOptions, $options));
return $this; return $this;
} }
} }

@ -1,19 +1,16 @@
<?php <?php
/* For license terms, see /license.txt */ /* For license terms, see /license.txt */
use Chamilo\PluginBundle\Entity\LtiProvider\Platform;
use Chamilo\PluginBundle\Entity\LtiProvider\PlatformKey;
use ChamiloSession as Session; use ChamiloSession as Session;
use Packback\Lti1p3;
use Packback\Lti1p3\Interfaces; use Packback\Lti1p3\Interfaces;
use Packback\Lti1p3\LtiRegistration;
use Packback\Lti1p3\LtiDeployment; use Packback\Lti1p3\LtiDeployment;
use Packback\Lti1p3\OidcException; use Packback\Lti1p3\LtiRegistration;
class Lti13Database implements Interfaces\Database class Lti13Database implements Interfaces\Database
{ {
public function findRegistrationByIssuer($iss, $clientId = null) { public function findRegistrationByIssuer($iss, $clientId = null)
{
$ltiCustomers = $this->getLtiConnection(); $ltiCustomers = $this->getLtiConnection();
if (empty($ltiCustomers[$iss])) { if (empty($ltiCustomers[$iss])) {
return false; return false;
@ -33,16 +30,8 @@ class Lti13Database implements Interfaces\Database
->setToolPrivateKey($this->getPrivateKey()); ->setToolPrivateKey($this->getPrivateKey());
} }
public function findDeployment($iss, $deploymentId, $clientId = null) { private function getLtiConnection(): array
if (!in_array($deploymentId, $_SESSION['iss'][$iss]['deployment'])) { {
return false;
}
return LtiDeployment::new()
->setDeploymentId($deploymentId);
}
private function getLtiConnection() {
$em = Database::getManager(); $em = Database::getManager();
$platforms = $em->getRepository('ChamiloPluginBundle:LtiProvider\Platform')->findAll(); $platforms = $em->getRepository('ChamiloPluginBundle:LtiProvider\Platform')->findAll();
@ -50,19 +39,21 @@ class Lti13Database implements Interfaces\Database
foreach ($platforms as $platform) { foreach ($platforms as $platform) {
$issuer = $platform->getIssuer(); $issuer = $platform->getIssuer();
$ltiCustomers[$issuer] = [ $ltiCustomers[$issuer] = [
'client_id' => $platform->getClientId(), 'client_id' => $platform->getClientId(),
'auth_login_url' => $platform->getAuthLoginUrl(), 'auth_login_url' => $platform->getAuthLoginUrl(),
'auth_token_url' => $platform->getAuthTokenUrl(), 'auth_token_url' => $platform->getAuthTokenUrl(),
'key_set_url' => $platform->getKeySetUrl(), 'key_set_url' => $platform->getKeySetUrl(),
'kid' => $platform->getKid(), 'kid' => $platform->getKid(),
'deployment' => [$platform->getDeploymentId()] 'deployment' => [$platform->getDeploymentId()],
]; ];
} }
Session::write('iss', $ltiCustomers); Session::write('iss', $ltiCustomers);
return $ltiCustomers; return $ltiCustomers;
} }
private function getPrivateKey() { private function getPrivateKey()
{
$privateKey = ''; $privateKey = '';
$platformKey = Database::getManager() $platformKey = Database::getManager()
->getRepository('ChamiloPluginBundle:LtiProvider\PlatformKey') ->getRepository('ChamiloPluginBundle:LtiProvider\PlatformKey')
@ -70,6 +61,16 @@ class Lti13Database implements Interfaces\Database
if ($platformKey) { if ($platformKey) {
$privateKey = $platformKey->getPrivateKey(); $privateKey = $platformKey->getPrivateKey();
} }
return $privateKey; return $privateKey;
} }
public function findDeployment($iss, $deploymentId, $clientId = null)
{
if (!in_array($deploymentId, $_SESSION['iss'][$iss]['deployment'])) {
return false;
}
return LtiDeployment::new()->setDeploymentId($deploymentId);
}
} }

@ -4,8 +4,8 @@
$cidReset = true; $cidReset = true;
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
require_once __DIR__ . '/src/Form/FrmEdit.php'; require_once __DIR__.'/src/Form/FrmEdit.php';
require_once __DIR__ . '/LtiProviderPlugin.php'; require_once __DIR__.'/LtiProviderPlugin.php';
api_protect_admin_script(); api_protect_admin_script();

@ -1,12 +1,13 @@
<?php <?php
/* For license terms, see /license.txt */ /* For license terms, see /license.txt */
use Chamilo\PluginBundle\Entity\LtiProvider\Platform; use Chamilo\PluginBundle\Entity\LtiProvider\Platform;
$cidReset = true; $cidReset = true;
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
require_once __DIR__ . '/src/Form/FrmEdit.php'; require_once __DIR__.'/src/Form/FrmEdit.php';
require_once __DIR__ . '/LtiProviderPlugin.php'; require_once __DIR__.'/LtiProviderPlugin.php';
api_protect_admin_script(); api_protect_admin_script();

@ -3,10 +3,11 @@
/** /**
* Install the Lti/Provider Plugin * Install the Lti/Provider Plugin
*
* @package chamilo.plugin.lti_provider * @package chamilo.plugin.lti_provider
*/ */
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
require_once __DIR__ . '/LtiProviderPlugin.php'; require_once __DIR__.'/LtiProviderPlugin.php';
if (!api_is_platform_admin()) { if (!api_is_platform_admin()) {
die('You must have admin permissions to install plugins'); die('You must have admin permissions to install plugins');

@ -1,5 +1,6 @@
<?php <?php
/* For license terms, see /license.txt */ /* For license terms, see /license.txt */
require_once __DIR__ . '/LtiProviderPlugin.php';
require_once __DIR__.'/LtiProviderPlugin.php';
$plugin_info = LtiProviderPlugin::create()->get_info(); $plugin_info = LtiProviderPlugin::create()->get_info();

@ -7,7 +7,7 @@ use Symfony\Component\HttpFoundation\Response;
$cidReset = true; $cidReset = true;
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
require_once __DIR__ . '/LtiProviderPlugin.php'; require_once __DIR__.'/LtiProviderPlugin.php';
api_block_anonymous_users(false); api_block_anonymous_users(false);

@ -16,16 +16,16 @@ class FrmAdd extends FormValidator
/** /**
* FrmAdd constructor. * FrmAdd constructor.
* *
* @param string $name * @param string $name
* @param array $attributes * @param array $attributes
* @param Platform|null $platform * @param Platform|null $platform
*/ */
public function __construct( public function __construct(
$name, $name,
$attributes = [], $attributes = [],
Platform $platform = null Platform $platform = null
) { ) {
parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true); parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL);
$this->platform = $platform; $this->platform = $platform;
} }
@ -60,7 +60,7 @@ class FrmAdd extends FormValidator
$this->platform = new Platform(); $this->platform = new Platform();
} }
$defaults['issuer'] = $this->platform->getIssuer(); $defaults['issuer'] = $this->platform->getIssuer();
$defaults['auth_login_url'] = $this->platform->getAuthLoginUrl(); $defaults['auth_login_url'] = $this->platform->getAuthLoginUrl();
$defaults['auth_token_url'] = $this->platform->getAuthTokenUrl(); $defaults['auth_token_url'] = $this->platform->getAuthTokenUrl();
$defaults['key_set_url'] = $this->platform->getKeySetUrl(); $defaults['key_set_url'] = $this->platform->getKeySetUrl();
@ -71,7 +71,7 @@ class FrmAdd extends FormValidator
$this->setDefaults($defaults); $this->setDefaults($defaults);
} }
public function returnForm() public function returnForm(): string
{ {
$js = "<script> $js = "<script>
</script>"; </script>";

@ -16,16 +16,16 @@ class FrmEdit extends FormValidator
/** /**
* FrmAdd constructor. * FrmAdd constructor.
* *
* @param string $name * @param string $name
* @param array $attributes * @param array $attributes
* @param Platform|null $platform * @param Platform|null $platform
*/ */
public function __construct( public function __construct(
$name, $name,
$attributes = [], $attributes = [],
Platform $platform = null Platform $platform = null
) { ) {
parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true); parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL);
$this->platform = $platform; $this->platform = $platform;
} }
@ -37,7 +37,7 @@ class FrmEdit extends FormValidator
* *
* @throws Exception * @throws Exception
*/ */
public function build($globalMode = true) public function build(bool $globalMode = true)
{ {
$plugin = LtiProviderPlugin::create(); $plugin = LtiProviderPlugin::create();
$this->addHeader($plugin->get_lang('ConnectionDetails')); $this->addHeader($plugin->get_lang('ConnectionDetails'));
@ -62,7 +62,7 @@ class FrmEdit extends FormValidator
public function setDefaultValues() public function setDefaultValues()
{ {
$defaults = []; $defaults = [];
$defaults['issuer'] = $this->platform->getIssuer(); $defaults['issuer'] = $this->platform->getIssuer();
$defaults['auth_login_url'] = $this->platform->getAuthLoginUrl(); $defaults['auth_login_url'] = $this->platform->getAuthLoginUrl();
$defaults['auth_token_url'] = $this->platform->getAuthTokenUrl(); $defaults['auth_token_url'] = $this->platform->getAuthTokenUrl();
$defaults['key_set_url'] = $this->platform->getKeySetUrl(); $defaults['key_set_url'] = $this->platform->getKeySetUrl();

@ -2,14 +2,12 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Packback\Lti1p3; use Packback\Lti1p3;
require_once __DIR__ . '/../db/lti13_cookie.php';
require_once __DIR__ . '/../db/lti13_cache.php';
require_once __DIR__ . '/../db/lti13_database.php';
use Packback\Lti1p3\LtiOidcLogin;
use Packback\Lti1p3\LtiMessageLaunch; use Packback\Lti1p3\LtiMessageLaunch;
use Packback\Lti1p3\LtiOidcLogin;
require_once __DIR__.'/../db/lti13_cookie.php';
require_once __DIR__.'/../db/lti13_cache.php';
require_once __DIR__.'/../db/lti13_database.php';
/** /**
@ -18,39 +16,50 @@ use Packback\Lti1p3\LtiMessageLaunch;
class LtiProvider class LtiProvider
{ {
/**
* Get the class instance
*
* @staticvar LtiProvider $result
* @return LtiProvider
*/
public static function create()
{
static $result = null;
return $result ?: $result = new self();
}
/** /**
* Oidc login and register * Oidc login and register
*
* @throws Lti1p3\OidcException
*/ */
public function login($request = null) { public function login($request = null)
{
LtiOidcLogin::new(new Lti13Database, new Lti13Cache(), new Lti13Cookie) LtiOidcLogin::new(new Lti13Database, new Lti13Cache(), new Lti13Cookie)
->doOidcLoginRedirect(api_get_path(WEB_PLUGIN_PATH). "lti_provider/web/game.php", $request) ->doOidcLoginRedirect(api_get_path(WEB_PLUGIN_PATH)."lti_provider/web/game.php", $request)
->doRedirect(); ->doRedirect();
} }
/** /**
* Lti Message Launch * Lti Message Launch
*
* @param bool $fromCache * @param bool $fromCache
* @param null $launchId * @param null $launchId
* return $launch *
* @throws Lti1p3\LtiException
*
* @return LtiMessageLaunch
*/ */
public function launch($fromCache = false, $launchId = null) { public function launch(bool $fromCache = false, $launchId = null): LtiMessageLaunch
{
if ($fromCache) { if ($fromCache) {
$launch = LtiMessageLaunch::fromCache($launchId, new Lti13Database(), new Lti13Cache()); $launch = LtiMessageLaunch::fromCache($launchId, new Lti13Database(), new Lti13Cache());
} else { } else {
$launch = LtiMessageLaunch::new(new Lti13Database(), new Lti13Cache(), new Lti13Cookie)->validate(); $launch = LtiMessageLaunch::new(new Lti13Database(), new Lti13Cache(), new Lti13Cookie)->validate();
} }
return $launch;
}
/** return $launch;
* Get the class instance
* @staticvar LtiProvider $result
* @return LtiProvider
*/
public static function create()
{
static $result = null;
return $result ?: $result = new self();
} }
} }

@ -3,10 +3,11 @@
/** /**
* Install the Lti/Provider Plugin * Install the Lti/Provider Plugin
*
* @package chamilo.plugin.lti_provider * @package chamilo.plugin.lti_provider
*/ */
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
require_once __DIR__ . '/LtiProviderPlugin.php'; require_once __DIR__.'/LtiProviderPlugin.php';
if (!api_is_platform_admin()) { if (!api_is_platform_admin()) {
die('You must have admin permissions to install plugins'); die('You must have admin permissions to install plugins');

Loading…
Cancel
Save