ajoute Moodle LTI 1.3 (V2), une 6e façon de rejoindre une classe
LTI authentifie l'élève et le fait rejoindre sa classe (même code que le code/QR existant), pas lancer un lab précis - relecture du CLAUDE.md qui liste LTI avec les autres façons d'ajouter des élèves. packbackbooks/lti-1p3-tool (Apache-2.0, recommandé par le CLAUDE.md), trois ponts vers Redis/cookies/MariaDB, élève retrouvé par identité Moodle stable pour ne jamais créer de doublon. Enregistrement d'une plateforme/d'un déploiement par commande Artisan (opération rare, faite à la main par Adam), jamais une page d'administration. Corrige au passage un vrai bug préexistant trouvé en vérifiant en réel sur le serveur : withoutMiddleware(ValidateCsrfToken::class) sur une route ne retire jamais le vrai middleware CSRF (ValidateCsrfToken est un alias déprécié de PreventRequestForgery, pas la classe réellement enregistrée) - /csp-rapport avait le même défaut depuis l'étape 14, invisible faute de surveillance. Corrigé pour les deux par la bonne méthode (validateCsrfTokens except, dans bootstrap/app.php). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
777dd1cbc8
commit
91d7cde4c1
27 changed files with 1293 additions and 9 deletions
69
portail/app/Services/Lti/CacheLti.php
Normal file
69
portail/app/Services/Lti/CacheLti.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Lti;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Packback\Lti1p3\Interfaces\ICache;
|
||||
|
||||
/**
|
||||
* Pont vers le cache Laravel (Redis en production) pour la bibliothèque
|
||||
* LTI 1.3 : nonce OIDC, données d'un lancement en cours, jetons d'accès
|
||||
* aux services LTI (jamais utilisés aujourd'hui, voir ADR).
|
||||
*/
|
||||
class CacheLti implements ICache
|
||||
{
|
||||
private const EXPIRATION_NONCE = 3600;
|
||||
|
||||
private const EXPIRATION_DONNEES_LANCEMENT = 86400;
|
||||
|
||||
private const EXPIRATION_JETON_ACCES = 3600;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function getLaunchData(string $key): ?array
|
||||
{
|
||||
return Cache::get("lti1p3-lancement-{$key}");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $jwtBody
|
||||
*/
|
||||
public function cacheLaunchData(string $key, array $jwtBody): void
|
||||
{
|
||||
Cache::put("lti1p3-lancement-{$key}", $jwtBody, self::EXPIRATION_DONNEES_LANCEMENT);
|
||||
}
|
||||
|
||||
public function cacheNonce(string $nonce, string $state): void
|
||||
{
|
||||
Cache::put("lti1p3-nonce-{$nonce}", $state, self::EXPIRATION_NONCE);
|
||||
}
|
||||
|
||||
public function checkNonceIsValid(string $nonce, string $state): bool
|
||||
{
|
||||
$etatEnCache = Cache::get("lti1p3-nonce-{$nonce}");
|
||||
|
||||
if ($etatEnCache === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Cache::forget("lti1p3-nonce-{$nonce}");
|
||||
|
||||
return $etatEnCache === $state;
|
||||
}
|
||||
|
||||
public function cacheAccessToken(string $key, string $accessToken): void
|
||||
{
|
||||
Cache::put("lti1p3-jeton-{$key}", $accessToken, self::EXPIRATION_JETON_ACCES);
|
||||
}
|
||||
|
||||
public function getAccessToken(string $key): ?string
|
||||
{
|
||||
return Cache::get("lti1p3-jeton-{$key}");
|
||||
}
|
||||
|
||||
public function clearAccessToken(string $key): void
|
||||
{
|
||||
Cache::forget("lti1p3-jeton-{$key}");
|
||||
}
|
||||
}
|
||||
28
portail/app/Services/Lti/CookieLti.php
Normal file
28
portail/app/Services/Lti/CookieLti.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Lti;
|
||||
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Packback\Lti1p3\Interfaces\ICookie;
|
||||
|
||||
/**
|
||||
* Pont vers les cookies Laravel, pour le jeton d'état OIDC du lancement
|
||||
* LTI 1.3. SameSite=None obligatoire : la plateforme (Moodle) renvoie ce
|
||||
* cookie via un POST depuis SON origine, pas la nôtre — un cookie "Lax" ou
|
||||
* "Strict" ne partirait jamais, et chaque lancement échouerait en silence.
|
||||
*/
|
||||
class CookieLti implements ICookie
|
||||
{
|
||||
public function getCookie(string $name): ?string
|
||||
{
|
||||
return Cookie::get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function setCookie(string $name, string $value, int $exp = 3600, array $options = []): void
|
||||
{
|
||||
Cookie::queue($name, $value, (int) ceil($exp / 60), '/', null, true, true, false, 'none');
|
||||
}
|
||||
}
|
||||
61
portail/app/Services/Lti/DatabaseLti.php
Normal file
61
portail/app/Services/Lti/DatabaseLti.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Lti;
|
||||
|
||||
use App\Models\LtiDeploiement;
|
||||
use App\Models\LtiPlateforme;
|
||||
use Packback\Lti1p3\Interfaces\IDatabase;
|
||||
use Packback\Lti1p3\Interfaces\ILtiDeployment;
|
||||
use Packback\Lti1p3\Interfaces\ILtiRegistration;
|
||||
use Packback\Lti1p3\LtiDeployment;
|
||||
use Packback\Lti1p3\LtiRegistration;
|
||||
|
||||
/**
|
||||
* Pont vers les tables lti_plateformes/lti_deploiements : enregistrées à la
|
||||
* main par Adam (`lti:enregistrer-plateforme`, `lti:enregistrer-deploiement`),
|
||||
* jamais devinées ni créées par un lancement lui-même — un lancement dont
|
||||
* la plateforme ou le déploiement est inconnu est refusé.
|
||||
*/
|
||||
class DatabaseLti implements IDatabase
|
||||
{
|
||||
public function findRegistrationByIssuer(string $iss, ?string $clientId = null): ?ILtiRegistration
|
||||
{
|
||||
$requete = LtiPlateforme::where('emetteur', $iss);
|
||||
|
||||
if ($clientId !== null) {
|
||||
$requete->where('client_id', $clientId);
|
||||
}
|
||||
|
||||
$plateforme = $requete->first();
|
||||
|
||||
if ($plateforme === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return LtiRegistration::new([
|
||||
'issuer' => $plateforme->emetteur,
|
||||
'clientId' => $plateforme->client_id,
|
||||
'keySetUrl' => $plateforme->url_jeu_cles,
|
||||
'authTokenUrl' => $plateforme->url_jeton_auth,
|
||||
'authLoginUrl' => $plateforme->url_connexion_auth,
|
||||
'authServer' => $plateforme->serveur_auth,
|
||||
'toolPrivateKey' => $plateforme->cle_privee_outil,
|
||||
'kid' => $plateforme->identifiant_cle,
|
||||
]);
|
||||
}
|
||||
|
||||
public function findDeployment(string $iss, string $deploymentId, ?string $clientId = null): ?ILtiDeployment
|
||||
{
|
||||
$requete = LtiDeploiement::where('deployment_id', $deploymentId)
|
||||
->whereHas('plateforme', function ($q) use ($iss, $clientId) {
|
||||
$q->where('emetteur', $iss);
|
||||
if ($clientId !== null) {
|
||||
$q->where('client_id', $clientId);
|
||||
}
|
||||
});
|
||||
|
||||
$deploiement = $requete->first();
|
||||
|
||||
return $deploiement === null ? null : LtiDeployment::new($deploiement->deployment_id);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue