Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for creating WeatherKit JWT tokens #153

Open
NPAssoc opened this issue Jul 22, 2022 · 1 comment
Open

Support for creating WeatherKit JWT tokens #153

NPAssoc opened this issue Jul 22, 2022 · 1 comment

Comments

@NPAssoc
Copy link

NPAssoc commented Jul 22, 2022

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.

@nikischin
Copy link

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants