PHP code example of edu-sharing / auth-plugin

1. Go to this page and download the library: Download edu-sharing/auth-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

edu-sharing / auth-plugin example snippets




use EduSharingApiClient\EduSharingNodeHelper;
use EduSharingApiClient\SignatureHandler;

class MySignatureHandler implements SignatureHandler
{
    private EduSharingNodeHelper $nodeHelper;

    public function __construct(EduSharingNodeHelper $nodeHelper) {
        $this->nodeHelper = $nodeHelper;
    }

    public function getAlgorithm(): string {
        try {
            $about = $this->nodeHelper->base->getAbout();
            if (isset($about['defaultSignatureAlgorithm'])) {
                return $about['defaultSignatureAlgorithm'];
            }
        } catch (Exception) {
            // Do nothing. Just use default
        }
        return $this->nodeHelper->base->defaultAlgorithm;
    }
}

$nodeHelper->base->setSignatureHandler(new MySignatureHandler($nodeHelper));

$nodeHelper = new EduSharingNodeHelper($base,
    new EduSharingNodeHelperConfig(
        new UrlHandling(true, 'my/api/redirect/endpoint')
    )
);

        $about = $nodeHelper->base->getAbout();
        $useRendering2 =  isset ($about['renderingService2']['url']);
        $url = $nodeHelper->getRedirectUrl(
            mode: $_GET['mode'],
            usage: new Usage(
                $_GET['nodeId'],
                $_GET['nodeVersion'] ?? null,
                $_GET['containerId'],
                $_GET['resourceId'],
                $_GET['usageId'],
            ),
            rendering2: $useRendering2
        );
        header("Location: $url");

$base->registerCurlHandler(new class extends CurlHandler {

    public function handleCurlRequest(string $url, array $curlOptions): CurlResult
    {
       return new CurlResult('', 0, []);
    }
});

$privateKeyId = openssl_get_privatekey($privateKey);
openssl_sign($toSign, $signature, $privateKeyId);
return base64_encode($signature);