NRPS Platform - Membership service server
How to use the MembershipServiceServerRequestHandler (with the core LtiServiceServer) to serve authenticated NRPS service calls as a platform.
Features
This library provides a MembershipServiceServerRequestHandler ready to be use with the core LtiServiceServer to handle context and resource link membership requests.
- it accepts a PSR7 ServerRequestInterface,
- leverages the required IMS LTI 1.3 service authentication,
- and returns a PSR7 ResponseInterface containing the
membership
representation
Usage
First, you need to provide a MembershipServiceServerBuilderInterface implementation, in charge to build memberships on tools context or resource link requests.
<?php
use OAT\Library\Lti1p3Core\Registration\RegistrationInterface;
use OAT\Library\Lti1p3Nrps\Model\Membership\MembershipInterface;
use OAT\Library\Lti1p3Nrps\Service\Server\Builder\MembershipServiceServerBuilderInterface;
/** @var MembershipServiceServerBuilderInterface $builder */
$builder = new class() implements MembershipServiceServerBuilderInterface
{
public function buildContextMembership(
RegistrationInterface $registration,
?string $role = null,
?int $limit = null,
?int $offset = null
): MembershipInterface {
// Logic for building context membership for a given registration
}
public function buildResourceLinkMembership(
RegistrationInterface $registration,
string $resourceLinkIdentifier,
?string $role = null,
?int $limit = null,
?int $offset = null
): MembershipInterface {
// Logic for building resource link membership for a given registration and resource link identifier
}
};
Then:
- you can construct the MembershipServiceServerRequestHandler (constructed with your MembershipServiceServerBuilderInterface implementation)
- to finally expose it to requests using the core LtiServiceServer (constructed with the RequestAccessTokenValidator, from core library)
<?php
use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator;
use OAT\Library\Lti1p3Core\Service\Server\LtiServiceServer;
use OAT\Library\Lti1p3Nrps\Service\Server\Builder\MembershipServiceServerBuilderInterface;
use OAT\Library\Lti1p3Nrps\Service\Server\Handler\MembershipServiceServerRequestHandler;
use Psr\Http\Message\ServerRequestInterface;
/** @var ServerRequestInterface $request */
$request = ...
/** @var RegistrationRepositoryInterface $repository */
$repository = ...
/** @var MembershipServiceServerBuilderInterface $builder */
$builder = ...
$validator = new RequestAccessTokenValidator($repository);
$handler = new MembershipServiceServerRequestHandler($builder);
$server = new LtiServiceServer($validator, $handler);
// Generates an authenticated response containing the built membership representation
$response = $server->handle($request);