1. Go to this page and download the library: Download swanflutter/native-jwt 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/ */
// Same key format as RS* — just change the algorithm name.
$token = JWT::encode($payload, $privateKey, 'PS256');
$decoded = JWT::decode($token, new Key($publicKey, 'PS256'));
// Keys are base64url-encoded raw bytes (compatible with sodium_crypto_sign_*).
$keyPair = sodium_crypto_sign_keypair();
$privKey = base64_encode(sodium_crypto_sign_secretkey($keyPair));
$pubKey = base64_encode(sodium_crypto_sign_publickey($keyPair));
$token = JWT::encode($payload, $privKey, 'EdDSA');
$decoded = JWT::decode($token, new Key($pubKey, 'EdDSA'));
$keys = [
'key-2024' => new Key($publicKeyOld, 'RS256'),
'key-2025' => new Key($publicKeyNew, 'RS256'),
];
$decoded = JWT::decode($token, $keys);
JWT::$leeway = 60; // tolerate up to 60 seconds of clock skew
$decoded = JWT::decode($token, new Key($publicKey, 'RS256'));
use SwanFlutter\NativeJwt\JWK;
// $jwks is the decoded JSON from a JWKS endpoint (e.g. Google, Firebase).
$keys = JWK::parseKeySet($jwks); // returns array<kid, Key>
$decoded = JWT::decode($token, $keys);
use SwanFlutter\NativeJwt\CachedKeySet;
$keySet = new CachedKeySet(
jwksUri: 'https://www.googleapis.com/oauth2/v3/certs',
httpClient: $psrHttpClient, // PSR-18 ClientInterface
requestFactory: $psrRequestFactory, // PSR-17 RequestFactoryInterface
cache: $psrCachePool, // PSR-6 CacheItemPoolInterface
expiresAfter: 3600, // TTL in seconds (null = use Cache-Control)
rateLimit: true, // max 10 refreshes/second
);
$decoded = JWT::decode($token, $keySet);
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use SwanFlutter\NativeJwt\CachedKeySet;
$keySet = new CachedKeySet(
jwksUri: 'https://www.googleapis.com/oauth2/v3/certs',
httpClient: new Client(),
requestFactory: new HttpFactory(),
cache: new FilesystemAdapter(),
expiresAfter: 3600,
);