I am trying to produce a JWT from the instructions on this site https://web-token.spomky-labs.com.
All dependencies that I know of have been installed. My code is below. I get the 30 sec time out. What's missing? The RSA key was generated on 8x8 website. Even if I generate my own key. I get the same 30 sec time out.
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Signature\Algorithm\RS256;
use Jose\Component\Signature\JWSBuilder;
use Jose\Component\KeyManagement\JWKFactory;
// The algorithm manager with the HS256 algorithm.
$algorithmManager = new AlgorithmManager([
new RS256(),
]);
// Our key.
$keyFile = dirname(__FILE__, 6) . "/sites/RsaPrivateKey.pk";
$contents = file_get_contents($keyFile);
$jwk = JWKFactory::createFromKeyFile(
$keyFile,
'',
[
'use' => 'sig',
]
);
// We instantiate our JWS Builder.
$jwsBuilder = new JWSBuilder($algorithmManager);
// The payload we want to sign. The payload MUST be a string hence we use our JSON Converter.
$payload = json_encode([
'iat' => time(),
'nbf' => time(),
'exp' => time() + 3600,
'iss' => 'My service',
'aud' => 'Your application',
]);
//Never makes it to here
$jws = $jwsBuilder
->create() // We want to create a new JWS
->withPayload($payload) // We set the payload
->addSignature($jwk, ['alg' => 'RS256']) // We add a signature with a simple protected header
->build(); // We build it