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\DefaultSignatureHandler;

class MySignatureHandler extends DefaultSignatureHandler
{
    public function getAlgorithm(): string {
        // Reuse a previously resolved algorithm from the session / global storage.
        if (!empty($_SESSION['edusharing_signature_algorithm'])) {
            return $_SESSION['edusharing_signature_algorithm'];
        }
        // Resolve via the About endpoint (with built-in fallback) and persist it.
        $algorithm = parent::getAlgorithm();
        $_SESSION['edusharing_signature_algorithm'] = $algorithm;
        return $algorithm;
    }
}

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

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