Skip to content

Latest commit

 

History

History
44 lines (30 loc) · 1.91 KB

service-client.md

File metadata and controls

44 lines (30 loc) · 1.91 KB

LTI service client

How to use the LtiServiceClient to perform authenticated LTI service calls as a tool.

Table of contents

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', [...]);

Note: the client decorates by default a guzzle client, but you can provide your own by implementing LtiServiceClientInterface