pushok
pushok copied to clipboard
Support for creating WeatherKit JWT tokens
The WeatherKit REST interface requires JWT tokens, similar to to those required for push notifications. I was wondering if a class for generating those could be added to this package without too much difficulty.
While this should be easily possible, it has nothing really in common with this library.
You could write an implementation like this:
...
$privateKey = file_get_contents(realpath(dirname(__FILE__)).'/your_cert.p8');
$keyId = 'YOUR_KEY_ID';
$time = time();
$expires = $time + 3600;
// Create a token
$payload = [
'iss' => $teamId, // Team ID
'iat' => $time, // Issued-at time
'exp' => $expires, // Expiration time
'sub' => $serviceId, // Service ID
];
// Create the header
$header = [
'alg' => 'ES256', // Algorithm (ES256)
'kid' => $keyId,
'id' => $teamId.'.'.$serviceId, // 10-character key identifier
];
$token = \Firebase\JWT\JWT::encode($payload, $privateKey, 'ES256', null, $header);