web-push-libs / web-push-php

Web Push library for PHP
MIT License
1.69k stars 295 forks source link

Uncaught TypeError: Argument 1 passed to Jose\Component\Signature\JWSBuilder #332

Closed musaffar-patel closed 3 years ago

musaffar-patel commented 3 years ago

Getting the following error:

Fatal error: Uncaught TypeError: Argument 1 passed to Jose\Component\Signature\JWSBuilder::construct() must be an instance of Jose\Component\Core\Converter\JsonConverter or null, instance of Jose\Component\Core\AlgorithmManager given, called in E:\websites\test\push\vendor\minishlink\web-push\src\VAPID.php on line 136 and defined in E:\websites\test\push\vendor\web-token\jwt-signature\JWSBuilder.php:58 Stack trace: #0 E:\websites\test\push\vendor\minishlink\web-push\src\VAPID.php(136): Jose\Component\Signature\JWSBuilder->construct(Object(Jose\Component\Core\AlgorithmManager)) #1 E:\websites\test\push\vendor\minishlink\web-push\src\WebPush.php(404): Minishlink\WebPush\VAPID::getVapidHeaders('https://fcm.goo...', 'mailto:musaffar...', '\x04\x11p\xB7\x89uf\xF2(\nA\xF6\n\x9FC...', '\x95im\xBDAk\x8D\xAE\x15\x9E\x01\xEE.\e\x83...', 'aesgcm') #2 E:\websites\test\push\vendor\minishlink\web-push\src\WebPush.php(273): Minishlink\WebPush\WebPush->getVAPIDHeaders('https://fcm.goo...', 'aesgcm', Array) #3 E:\websites\test\push\ve in E:\websites\test\push\vendor\web-token\jwt-signature\JWSBuilder.php on line 58

With the following code:

$notifications = [
    'endpoint' => 'https://fcm.googleapis.com/fcm/send/f1azG0YpefY:APA91bEgPUCksrDdHc3vpd8JZUsiLnf6sphqgw8TdyPVyTMaviZGvBY76RPJ2zFmMFpvhxoL3hvbvMSJ_O8Ct5nqKmDYozsZh-IU-gm2DWqeTVRRgW9k6Hq58vxnYi75RehmdXbEr_yb', // Chrome
    'contentEncoding' => 'aesgcm',
];

$auth = [
    'VAPID' => [
        'subject' => 'mailto:xx@gmail.com',
        'publicKey' => 'BBFwt4l1ZvIoCkH2Cp9DSQKGN6MUQ5mFXrT3OLKNsoqSTweloz87hZtIA64Zgx2zROgxPWN1l61q8ezM0QkD2Dg',
        'privateKey' => '',
    ],
];

$webPush = new WebPush($auth);
$report = $webPush->sendOneNotification(
    Subscription::create($notifications),
    '{"msg":"Hello World!"}' // optional (defaults null)
);

Any guidance would be appreciated here.

musaffar-patel commented 3 years ago

Hi

Solved this by changing the line of code to:

$jwsBuilder = new JWSBuilder(null, new AlgorithmManager([new ES256()]));

in \vendor\minishlink\web-push\src\VAPID.php