LTI service client
How to use the LtiServiceClient to perform authenticated LTI service calls as a tool.
Features
You may need to perform authenticated service calls from your registered tool to a platform (ex: LTI Advantage Services)
To do so, you can use the LtiServiceClient that permits:
- to call platform endpoints, returning a PSR7 response
- to perform automatically the required OAuth2 authentication to get an access token
- to handle automatically the access token caching if you provide an optional PSR6 cache instance
Usage
To use it, you can simply do by example:
<?php
use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
use OAT\Library\Lti1p3Core\Service\Client\LtiServiceClient;
use Psr\Http\Message\ResponseInterface;
use Psr\Cache\CacheItemPoolInterface;
// Get related registration of the launch
/** @var RegistrationRepositoryInterface $registrationRepository */
$registration = $registrationRepository->find(...);
// Optional but HIGHLY RECOMMENDED cache for access tokens
/** @var CacheItemPoolInterface $cache */
$cache = ...
$client = new LtiServiceClient($cache);
/** @var ResponseInterface $response */
$response = $client->request($registration, 'GET', 'https://platform.com/some-service-url', [...]);