MDL-84173 libraries: upgrade lti1p3 to v6.2.0

This commit is contained in:
rajutm25
2025-10-24 12:49:28 +05:30
parent c39b6a6751
commit ccc02084ad
22 changed files with 94 additions and 45 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ A library used for building IMS-certified LTI 1.3 tool providers in PHP.
This library is a fork of the [packbackbooks/lti-1-3-php-library](https://github.com/packbackbooks/lti-1-3-php-library), patched specifically for use in [Moodle](https://github.com/moodle/moodle).
It is currently based on version [6.0.0 of the packbackbooks/lti-1-3-php-library](https://github.com/packbackbooks/lti-1-3-php-library/releases/tag/v6.0.0) library.
It is currently based on version [6.2.0 of the packbackbooks/lti-1-3-php-library](https://github.com/packbackbooks/lti-1-3-php-library/releases/tag/v6.2.0) library.
The following changes are included so that the library may be used with Moodle:
+2 -1
View File
@@ -21,13 +21,14 @@
}
],
"require": {
"php": "^8.1",
"firebase/php-jwt": "^6.6",
"guzzlehttp/guzzle": "^7.0",
"phpseclib/phpseclib": "^3.0"
},
"require-dev": {
"mockery/mockery": "^1.4",
"nesbot/carbon": "^2.43",
"nesbot/carbon": "^2.43 || ^3.0",
"laravel/pint": "^1.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.0|^10.0"
@@ -21,7 +21,7 @@ class DateTimeInterval
public static function new(): self
{
return new DateTimeInterval();
return new DateTimeInterval;
}
public function getArray(): array
@@ -12,8 +12,7 @@ class Icon
private string $url,
private int $width,
private int $height
) {
}
) {}
public static function new(string $url, int $width, int $height): self
{
@@ -12,12 +12,11 @@ class Iframe
private ?string $src = null,
private ?int $width = null,
private ?int $height = null
) {
}
) {}
public static function new(): self
{
return new Iframe();
return new Iframe;
}
public function getArray(): array
@@ -25,7 +25,7 @@ class Resource
public static function new(): self
{
return new Resource();
return new Resource;
}
public function getArray(): array
@@ -51,6 +51,8 @@ class Resource
$resource['lineItem'] = [
'scoreMaximum' => $this->line_item->getScoreMaximum(),
'label' => $this->line_item->getLabel(),
'resourceId' => $this->line_item->getResourceId(),
'tag' => $this->line_item->getTag(),
];
}
@@ -13,12 +13,11 @@ class Window
private ?int $width = null,
private ?int $height = null,
private ?string $window_features = null
) {
}
) {}
public static function new(): self
{
return new Window();
return new Window;
}
public function getArray(): array
+1 -3
View File
@@ -8,9 +8,7 @@ use Packback\Lti1p3\Interfaces\ILtiRegistration;
class JwksEndpoint
{
public function __construct(private array $keys)
{
}
public function __construct(private array $keys) {}
public static function new(array $keys): self
{
+1 -2
View File
@@ -12,8 +12,7 @@ abstract class LtiAbstractService
private ILtiServiceConnector $serviceConnector,
private ILtiRegistration $registration,
private array $serviceData
) {
}
) {}
public function getServiceData(): array
{
+1 -1
View File
@@ -21,7 +21,7 @@ class LtiConstants
public const LAUNCH_PRESENTATION = 'https://purl.imsglobal.org/spec/lti/claim/launch_presentation';
public const LIS = 'https://purl.imsglobal.org/spec/lti/claim/lis';
public const LTI1P1 = 'https://purl.imsglobal.org/spec/lti/claim/lti1p1';
public const ROLE_SCOPE_MENTOR = 'https://purlimsglobal.org/spec/lti/claim/role_scope_mentor';
public const ROLE_SCOPE_MENTOR = 'https://purl.imsglobal.org/spec/lti/claim/role_scope_mentor';
public const TOOL_PLATFORM = 'https://purl.imsglobal.org/spec/lti/claim/tool_platform';
// LTI DL
+64 -4
View File
@@ -11,8 +11,7 @@ class LtiDeepLink
private ILtiRegistration $registration,
private string $deployment_id,
private array $deep_link_settings
) {
}
) {}
public function getResponseJwt(array $resources): string
{
@@ -32,10 +31,71 @@ class LtiDeepLink
// https://www.imsglobal.org/spec/lti-dl/v2p0/#deep-linking-request-message
// 'data' is an optional property which, if it exists, must be returned by the tool
if (isset($this->deep_link_settings['data'])) {
$message_jwt[LtiConstants::DL_DATA] = $this->deep_link_settings['data'];
if (isset($this->settings()['data'])) {
$message_jwt[LtiConstants::DL_DATA] = $this->settings()['data'];
}
return JWT::encode($message_jwt, $this->registration->getToolPrivateKey(), 'RS256', $this->registration->getKid());
}
public function settings(): array
{
return $this->deep_link_settings;
}
public function returnUrl(): string
{
return $this->settings()['deep_link_return_url'];
}
public function acceptTypes(): array
{
return $this->settings()['accept_types'];
}
public function canAcceptType(string $acceptType): bool
{
return in_array($acceptType, $this->acceptTypes());
}
public function acceptPresentationDocumentTargets(): array
{
return $this->settings()['accept_presentation_document_targets'];
}
public function canAcceptPresentationDocumentTarget(string $target): bool
{
return in_array($target, $this->acceptPresentationDocumentTargets());
}
public function acceptMediaTypes(): ?string
{
return $this->settings()['accept_media_types'] ?? null;
}
public function canAcceptMultiple(): bool
{
return $this->settings()['accept_multiple'] ?? false;
}
public function canAcceptLineitem(): bool
{
return $this->settings()['accept_lineitem'] ?? false;
}
public function canAutoCreate(): bool
{
return $this->settings()['auto_create'] ?? false;
}
public function title(): ?string
{
return $this->settings()['title'] ?? null;
}
public function text(): ?string
{
return $this->settings()['text'] ?? null;
}
}
+1 -2
View File
@@ -8,8 +8,7 @@ class LtiDeployment implements ILtiDeployment
{
public function __construct(
private $deployment_id
) {
}
) {}
public static function new($deployment_id): self
{
+1 -3
View File
@@ -4,6 +4,4 @@ namespace Packback\Lti1p3;
use Exception;
class LtiException extends Exception
{
}
class LtiException extends Exception {}
+1 -1
View File
@@ -50,7 +50,7 @@ class LtiGrade
*/
public static function new(): self
{
return new LtiGrade();
return new LtiGrade;
}
public function getScoreGiven()
@@ -35,7 +35,7 @@ class LtiGradeSubmissionReview
*/
public static function new(): self
{
return new LtiGradeSubmissionReview();
return new LtiGradeSubmissionReview;
}
public function getReviewableStatus()
+5 -5
View File
@@ -27,9 +27,9 @@ class LtiMessageLaunch
public const ERR_FETCH_PUBLIC_KEY = 'Failed to fetch public key.';
public const ERR_NO_PUBLIC_KEY = 'Unable to find public key.';
public const ERR_NO_MATCHING_PUBLIC_KEY = 'Unable to find a public key which matches your JWT.';
public const ERR_STATE_NOT_FOUND = 'Please make sure you have cookies enabled in this browser and that you are not in private or incognito mode';
public const ERR_STATE_NOT_FOUND = 'Please make sure you have cookies and cross-site tracking enabled in the privacy and security settings of your browser.';
public const ERR_MISSING_ID_TOKEN = 'Missing id_token.';
public const ERR_INVALID_ID_TOKEN = 'Invalid id_token, JWT must contain 3 parts';
public const ERR_INVALID_ID_TOKEN = 'Invalid id_token, JWT must contain 3 parts.';
public const ERR_MISSING_NONCE = 'Missing Nonce.';
public const ERR_INVALID_NONCE = 'Invalid Nonce.';
@@ -304,7 +304,7 @@ class LtiMessageLaunch
try {
$response = $this->serviceConnector->makeRequest($request);
} catch (TransferException $e) {
throw new LtiException(static::ERR_NO_PUBLIC_KEY);
throw new LtiException(static::ERR_NO_PUBLIC_KEY, previous: $e);
}
$publicKeySet = $this->serviceConnector->getResponseBody($response);
@@ -438,11 +438,11 @@ class LtiMessageLaunch
// Validate JWT signature
try {
$headers = new \stdClass();
$headers = new \stdClass;
JWT::decode($this->request['id_token'], $public_key, $headers);
} catch (ExpiredException $e) {
// Error validating signature.
throw new LtiException(static::ERR_INVALID_SIGNATURE);
throw new LtiException(static::ERR_INVALID_SIGNATURE, previous: $e);
}
return $this;
+1 -2
View File
@@ -19,8 +19,7 @@ class LtiOidcLogin
public IDatabase $db,
public ICache $cache,
public ICookie $cookie
) {
}
) {}
/**
* Static function to allow for method chaining without having to assign to a variable first.
@@ -20,8 +20,7 @@ class LtiServiceConnector implements ILtiServiceConnector
public function __construct(
private ICache $cache,
private Client $client
) {
}
) {}
public function setDebuggingMode(bool $enable): self
{
+1 -3
View File
@@ -4,6 +4,4 @@ namespace Packback\Lti1p3;
use Exception;
class OidcException extends Exception
{
}
class OidcException extends Exception {}
+1 -2
View File
@@ -47,8 +47,7 @@ class ServiceRequest implements IServiceRequest
private string $method,
private string $url,
private string $type = self::TYPE_UNSUPPORTED
) {
}
) {}
public function getMethod(): string
{
+1 -1
View File
@@ -2,7 +2,7 @@ Description of php-jwt library import into Moodle
Dependencies
------------
- The lib/lti1p3 library currently depends on version 6.0 of php-jwt.
- The lib/lti1p3 library currently depends on version 6.2.0 of php-jwt.
- There are usages of this library in mod/lti too. Please check these.
Instructions
+1 -1
View File
@@ -452,7 +452,7 @@ All rights reserved.</copyright>
<location>lti1p3</location>
<name>LTI 1.3 Tool Library</name>
<description>A library used for building IMS-certified LTI 1.3 tool providers in PHP.</description>
<version>6.0.0</version>
<version>6.2.0</version>
<license>Apache</license>
<licenseversion>2.0</licenseversion>
<repository>https://github.com/packbackbooks/lti-1-3-php-library</repository>