From 9ca7540fee064e8e24cd3cd43d86e42c63fd3d75 Mon Sep 17 00:00:00 2001 From: Janos Pribelszki Date: Wed, 6 Mar 2024 15:47:33 +0100 Subject: [PATCH 1/5] feature: add userpilot to TAO 3.x, save tenant id as session context --- models/classes/LtiService.php | 9 ++++- models/classes/TaoLtiSession.php | 8 ++-- .../classes/TenantDataLtiSessionContext.php | 39 +++++++++++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 models/classes/TenantDataLtiSessionContext.php diff --git a/models/classes/LtiService.php b/models/classes/LtiService.php index 192fbfc0..dfc976b2 100644 --- a/models/classes/LtiService.php +++ b/models/classes/LtiService.php @@ -111,10 +111,17 @@ public function createLti1p3Session( $ltiUser->setRegistrationId($registration->getIdentifier()); - $session = TaoLtiSession::fromVersion1p3($ltiUser); + $clientId = $messagePayload->getClaim(MessagePayloadInterface::CLAIM_AUD)[0] ?? null; + $contexts = null; + if ($clientId !== null) { + $contexts = [new TenantDataLtiSessionContext($clientId)]; + } + + $session = TaoLtiSession::fromVersion1p3($ltiUser, $contexts); $this->getServiceLocator()->propagate($session); + return $session; } catch (LtiInvalidVariableException $e) { $this->logInfo($e->getMessage()); diff --git a/models/classes/TaoLtiSession.php b/models/classes/TaoLtiSession.php index 063dcf33..21b6d9a0 100644 --- a/models/classes/TaoLtiSession.php +++ b/models/classes/TaoLtiSession.php @@ -37,14 +37,14 @@ class TaoLtiSession extends common_session_DefaultSession /** @var string */ private $version = self::VERSION_LTI_1P1; - public function __construct(LtiUserInterface $user) + public function __construct(LtiUserInterface $user, array $contexts = []) { - parent::__construct($user); + parent::__construct($user, $contexts); } - public static function fromVersion1p3(LtiUserInterface $user): self + public static function fromVersion1p3(LtiUserInterface $user, array $contexts = []): self { - $session = new self($user); + $session = new self($user, $contexts); $session->version = self::VERSION_LTI_1P3; diff --git a/models/classes/TenantDataLtiSessionContext.php b/models/classes/TenantDataLtiSessionContext.php new file mode 100644 index 00000000..b2f54011 --- /dev/null +++ b/models/classes/TenantDataLtiSessionContext.php @@ -0,0 +1,39 @@ +tenantId = $tenantId; + } + + public function getTenantId(): string + { + return $this->tenantId; + } +} From 2d23362c27f735b226e97dd9363842294f9e918c Mon Sep 17 00:00:00 2001 From: Janos Pribelszki Date: Wed, 6 Mar 2024 17:49:49 +0100 Subject: [PATCH 2/5] feature: refactor TenantDataSessionContext class --- composer.json | 2 +- models/classes/LtiService.php | 3 +- .../classes/TenantDataLtiSessionContext.php | 39 ------------------- 3 files changed, 3 insertions(+), 41 deletions(-) delete mode 100644 models/classes/TenantDataLtiSessionContext.php diff --git a/composer.json b/composer.json index d15c2e4d..1f3b6760 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "oat-sa/lib-lti1p3-ags": "^1.2", "oat-sa/lib-lti1p3-core": "^6.0.0", "oat-sa/generis" : ">=15.22", - "oat-sa/tao-core" : ">=50.24.6" + "oat-sa/tao-core" : "dev-feature/MS-2756/add-userpilot-to-tao-3.x" }, "autoload" : { "psr-4" : { diff --git a/models/classes/LtiService.php b/models/classes/LtiService.php index dfc976b2..825409d7 100644 --- a/models/classes/LtiService.php +++ b/models/classes/LtiService.php @@ -35,6 +35,7 @@ use oat\oatbox\service\ConfigurableService; use oat\oatbox\service\ServiceManager; use oat\oatbox\session\SessionService; +use oat\tao\model\session\Context\TenantDataSessionContext; use oat\tao\model\TaoOntology; use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage; use oat\taoLti\models\classes\user\Lti1p3User; @@ -114,7 +115,7 @@ public function createLti1p3Session( $clientId = $messagePayload->getClaim(MessagePayloadInterface::CLAIM_AUD)[0] ?? null; $contexts = null; if ($clientId !== null) { - $contexts = [new TenantDataLtiSessionContext($clientId)]; + $contexts = [new TenantDataSessionContext($clientId)]; } $session = TaoLtiSession::fromVersion1p3($ltiUser, $contexts); diff --git a/models/classes/TenantDataLtiSessionContext.php b/models/classes/TenantDataLtiSessionContext.php deleted file mode 100644 index b2f54011..00000000 --- a/models/classes/TenantDataLtiSessionContext.php +++ /dev/null @@ -1,39 +0,0 @@ -tenantId = $tenantId; - } - - public function getTenantId(): string - { - return $this->tenantId; - } -} From 25cadbf7f0ec10d2184ccde038ba1d069337a2e8 Mon Sep 17 00:00:00 2001 From: Janos Pribelszki Date: Fri, 8 Mar 2024 21:33:11 +0100 Subject: [PATCH 3/5] feature: separated session contexts for user and tenant data. --- models/classes/LtiService.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/models/classes/LtiService.php b/models/classes/LtiService.php index 825409d7..d7bf16f4 100644 --- a/models/classes/LtiService.php +++ b/models/classes/LtiService.php @@ -36,6 +36,7 @@ use oat\oatbox\service\ServiceManager; use oat\oatbox\session\SessionService; use oat\tao\model\session\Context\TenantDataSessionContext; +use oat\tao\model\session\Context\UserDataSessionContext; use oat\tao\model\TaoOntology; use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage; use oat\taoLti\models\classes\user\Lti1p3User; @@ -112,11 +113,20 @@ public function createLti1p3Session( $ltiUser->setRegistrationId($registration->getIdentifier()); - $clientId = $messagePayload->getClaim(MessagePayloadInterface::CLAIM_AUD)[0] ?? null; - $contexts = null; - if ($clientId !== null) { - $contexts = [new TenantDataSessionContext($clientId)]; - } + $userId = $messagePayload->getUserIdentity(); + $contexts = [ + new UserDataSessionContext( + $userId->getIdentifier(), + $userId->getIdentifier(), + $userId->getName(), + $userId->getEmail(), + $userId->getLocale() + ), + new TenantDataSessionContext( + $clientId, + $clientId + ) + ]; $session = TaoLtiSession::fromVersion1p3($ltiUser, $contexts); From 199f09c39123ef68aaf31c9699286f674e86198f Mon Sep 17 00:00:00 2001 From: Janos Pribelszki Date: Thu, 14 Mar 2024 16:15:45 +0100 Subject: [PATCH 4/5] feature: remove tenant name, do not add user pilot context data if client id is not available --- models/classes/LtiService.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/models/classes/LtiService.php b/models/classes/LtiService.php index d7bf16f4..968a8491 100644 --- a/models/classes/LtiService.php +++ b/models/classes/LtiService.php @@ -113,20 +113,21 @@ public function createLti1p3Session( $ltiUser->setRegistrationId($registration->getIdentifier()); - $userId = $messagePayload->getUserIdentity(); - $contexts = [ - new UserDataSessionContext( - $userId->getIdentifier(), - $userId->getIdentifier(), - $userId->getName(), - $userId->getEmail(), - $userId->getLocale() - ), - new TenantDataSessionContext( - $clientId, - $clientId - ) - ]; + $contexts = []; + if ($clientId) { + $userId = $messagePayload->getUserIdentity(); + $clientIdParts = explode('-', $clientId); + $contexts = [ + new UserDataSessionContext( + $userId->getIdentifier(), + $userId->getIdentifier(), + $userId->getName(), + $userId->getEmail(), + $userId->getLocale() + ), + new TenantDataSessionContext(end($clientIdParts)) + ]; + } $session = TaoLtiSession::fromVersion1p3($ltiUser, $contexts); From 72f43fa06f1582ccc0e13229c336810248afefc0 Mon Sep 17 00:00:00 2001 From: Janos Pribelszki Date: Tue, 19 Mar 2024 09:52:00 +0100 Subject: [PATCH 5/5] feature: Update tao-core version requirements --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1f3b6760..d5c0e2ed 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "oat-sa/lib-lti1p3-ags": "^1.2", "oat-sa/lib-lti1p3-core": "^6.0.0", "oat-sa/generis" : ">=15.22", - "oat-sa/tao-core" : "dev-feature/MS-2756/add-userpilot-to-tao-3.x" + "oat-sa/tao-core" : ">=54.8.0" }, "autoload" : { "psr-4" : {