Skip to content

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.

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:

<?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);