1

I'm trying to implement push notification on my pwa app. I use php-web-push library to generate and send notification. Everything is ok on desktop with chrome, edge, or with my samsung on chrome or edge, but when I'm using my iPhone on iOS 16.4 beta 4 I've the following error :

resulted in a 403 Forbidden response: {"reason":"BadJwtToken"} "

You'll find my code below :

use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;
use Minishlink\WebPush\VAPID;

$auth = [
    'VAPID' => [
        'subject' => 'xxx@xxx.xxx',
        'publicKey' =>  trim(
            file_get_contents(
                dirname(__FILE__) . '/../_core/public_key.txt'
            )
        ),
        'privateKey' => trim(
            file_get_contents(
                dirname(__FILE__) . '/../_core/private_key.txt'
            )
        ),

    ],
];

$webPush = new WebPush($auth);

 $notifications = [
        'subscription' => Subscription::create([
            'endpoint' => $t->endpoint,
            'keys' => [
                'p256dh' =>  $t->p256dh,
                'auth' => $t->auth,
            ]
        ]),
        'payload' => json_encode([
            "title" => "Nouvelle réservation",
            "body" => "Tropicana 2 nuit"
        ]),
    ];
    $webPush->setReuseVAPIDHeaders(true);

    $webPush->queueNotification(
        $notifications['subscription'],
        $notifications['payload']
    );

This code works for my computer and my samsung, I can see my notification, but not on my iPhone, I've something else to do ?

I tried to generate VAPID auth by this way too, but it's not working...

$auth = [
    'VAPID' => [
        'subject' => 'mailto:me@website.com', // can be a mailto: or your website address
        'publicKey' => $publicKey, // (recommended) uncompressed public key P-256 encoded in Base64-URL
        'privateKey' => $privateKey, // (recommended) in fact the secret multiplier of the private key encoded in Base64-URL
        'pemFile' => __DIR__ . '/private_key.pem',
    ],
];

Thanks for your help

titome
  • 13
  • 3
  • 1
    Had this exact same thing. This SO post narrowed down the issue to a proper subject value: https://stackoverflow.com/questions/75547851/sending-push-notifications-to-safari-from-java – syciphj Mar 27 '23 at 13:14

0 Answers0