PHP code example of koh / poppy

1. Go to this page and download the library: Download koh/poppy 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/ */

    

koh / poppy example snippets


use Koh\Poppy\Discovery\Api;
use Koh\Poppy\Discovery\PoppyDocument;
use Koh\Poppy\PoppyServer;
use Koh\Poppy\Server\Endpoints;
use Koh\Poppy\Server\ServerConfiguration;

$configuration = new ServerConfiguration(
    issuer: 'https://shop.example/poppy',
    domains: ['shop.example'],
    endpoints: Endpoints::below('https://shop.example/poppy'),
    directScopes: ['poppy:read', 'poppy:write'],
    deviceScopes: ['poppy:read'],
    apis: [Api::openApi('https://shop.example/openapi.json', 'Orders and returns')],
);

$server = new PoppyServer(
    $configuration,
    $storage,        // PoppyStorage — your persistence
    $replayGuard,    // ReplayGuard — atomic set-if-absent, e.g. Redis SET NX or a unique key
    $clientPolicy,   // ClientPolicy — e.g. new ListClientPolicy(block: [...])
    $jsonFetcher,    // JsonFetcher over a PSR-18 client that does not follow redirects
    $clock,          // PSR-20
    $responseFactory,
    $streamFactory,
);

// GET /.well-known/poppy.json
$document = new PoppyDocument('Example Shop', 'shop.example', $configuration, $configuration->apis);

// GET /.well-known/oauth-authorization-server/poppy
$metadata = $server->metadata();

// POST /poppy/token, /poppy/revoke, /poppy/device_authorization
$response = $server->tokenEndpoint()->handle($request);

// An API endpoint
$session = $server->resourceGuard()->authenticate($request, 'https://shop.example/api/orders');
$accountId = $session->