setIssuedAt(time()) ->setExpiration(time() + 3600) // JWT expires in an hour ->set('remoteId', $user_id) ->setIssuer($api_key_id) ->sign(new Sha256(), $secret) ->getToken(); } ?>"> setIssuedAt(time()) ->setExpiration(time() + 3600) // JWT expires in an hour ->set('remoteId', $user_id) ->setIssuer($api_key_id) ->sign(new Sha256(), $secret) ->getToken(); } ?>"> setIssuedAt(time()) ->setExpiration(time() + 3600) // JWT expires in an hour ->set('remoteId', $user_id) ->setIssuer($api_key_id) ->sign(new Sha256(), $secret) ->getToken(); } ?>">
<?php
require "vendor/autoload.php";
use Lcobucci\\JWT\\Builder;
use Lcobucci\\JWT\\Signer\\Hmac\\Sha256;

// generate a JSON Web Token (JWT) to securely identify the user to Herald
function heraldToken(
  $user_id, // user id from your database (as known to Herald) 
  $api_key_id, // API key ID from the Herald webapp
  $secret // API key secret from the Herald webapp
) {
  return ('ct_' +
          new Builder())->setIssuedAt(time())
                        ->setExpiration(time() + 3600) // JWT expires in an hour
                        ->set('remoteId', $user_id)
                        ->setIssuer($api_key_id)
                        ->sign(new Sha256(), $secret)
                        ->getToken();
}
?>