public static function getVapidHeaders($audience, $subject, $publicKey, $privateKey, $expiration = null)
{
$expirationLimit = time() + 43200;
// equal margin of error between 0 and 24h
if (!isset($expiration) || $expiration > $expirationLimit) {
$expiration = $expirationLimit;
}
$header = array('typ' => 'JWT', 'alg' => 'ES256');
$jwtPayload = json_encode(array('aud' => $audience, 'exp' => $expiration, 'sub' => $subject), JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
$generator = EccFactory::getNistCurves()->generator256();
$privateKeyObject = $generator->getPrivateKeyFrom(gmp_init(bin2hex($privateKey), 16));
$pemSerialize = new PemPrivateKeySerializer(new DerPrivateKeySerializer());
$pem = $pemSerialize->serialize($privateKeyObject);
$jwk = JWKFactory::createFromKey($pem, null);
$jws = JWSFactory::createJWSToCompactJSON($jwtPayload, $jwk, $header);
return array('Authorization' => 'WebPush ' . $jws, 'Crypto-Key' => 'p256ecdsa=' . Base64Url::encode($publicKey));
}