PHP code example of karanshukla / php-atproto-identity

1. Go to this page and download the library: Download karanshukla/php-atproto-identity 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/ */

    

karanshukla / php-atproto-identity example snippets


use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use KaranShukla\PhpAtprotoIdentity\Resolution\Cache\Psr6DidDocumentCache;
use KaranShukla\PhpAtprotoIdentity\Resolution\HttpDidDocumentResolver;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$resolver = new HttpDidDocumentResolver(
    httpClient: new Client(),
    requestFactory: new HttpFactory(),
    cache: new Psr6DidDocumentCache(new FilesystemAdapter()),
);

$document = $resolver->resolve('did:plc:z72i7hdynmk6r22z27h6tvur');

$resolver = new HttpDidDocumentResolver(
    httpClient: $client,
    requestFactory: $factory,
    allowedHosts: ['feed.example.com', 'pds.example.com:8443'],
);

use KaranShukla\PhpAtprotoIdentity\Key\SigningKeys;

$keys = SigningKeys::atproto($document);   // every #atproto key, in order
$key = $keys[0];

$key->curve;        // 'secp256k1'
$key->algorithm();  // 'ES256K', the JWS alg a token signed by it must declare
$key->pem();        // a PEM any JWT library or openssl_verify() will accept
$key->der();        // the same key as a DER SubjectPublicKeyInfo

$document = $resolver->resolve($issuerDid);

foreach (SigningKeys::atproto($document) as $key) {
    // ... hand $key->pem() and $key->algorithm() to your verifier
}
bash
composer install
composer qa        # php-cs-fixer, phpstan (level max), phpunit