PHP code example of tecsafe / jwt-sdk

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

    

tecsafe / jwt-sdk example snippets




use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Component\HttpClient\Psr18Client;
use Tecsafe\OFCP\JWT\SDK\JWKLoader;
use Tecsafe\OFCP\JWT\SDK\JWTParser;

/* Load JWKS from URL */
$jwkUri = "https://api-gateway.tecsafe.example.com/.well-known/jwks";

$jwkLoader = new JWKLoader(new Psr18Client(), new Psr17Factory());
$jwk = $jwkLoader->getJWK($jwkUri);


/* Optional: Decorate JWKLoader with Cache */
use Tecsafe\OFCP\JWT\SDK\CachedJWKLoader;
use Symfony\Component\Cache\Psr16Cache;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

$cachedLoader = new CachedJWKLoader($jwkLoader, new Psr16Cache(new ArrayAdapter()));
$jwk = $cachedLoader->getJWK($jwkUri);
$jwk = $cachedLoader->getJWK($jwkUri); // Loaded from cache


/* Parse and validate tokens */
$TOKEN = 'eyJhbGci...';

$body = JWTParser::parseCustomerJwt($TOKEN, $jwk);
// same as above, if you don't want to validate the signature
$body = JWTParser::parseCustomerJwt($TOKEN);