bpolaszek / webpush-bundle

Symfony Bundle: Send WebPush Notifications to your users.
MIT License
66 stars 40 forks source link

Error 400 thrown when sending push notification to Windows devices #48

Open ignasdamunskis opened 7 months ago

ignasdamunskis commented 7 months ago

First of all, very good package, love it! I use version 0.9 since my PHP is version 7.4.

Most of the times it works as expected. Push notifications to Android Chrome and iOS Safari (90% of user devices) are sending without any issues, I had some issues with Android Firefox, it was throwing 413, but resolved decreasing the max padding length to 2847.

The issue I don't know how to resolve is sending push notifications to my clients using Windows devices, I always get an error 400 for endpoints: https://wns2-par02p.notify.windows.com/w/?token=...

I usualy log the notification errors as it happens, but since PushResponse class has no message property I can't properly debug the issue. Anyone else facing the issue, or knows how o resolve it?

bbehrendt-mm commented 7 months ago

Hi! I just had the same problem myself, and found out that Microsoft requires a TTL header to be set when pushing notifications. The easiest way to fix this is by setting a default TTL for the bundle to use inside your services.yaml:

Minimal example:

    BenTools\WebPushBundle\Sender\PushMessageSender:
      arguments:
        $defaultOptions:
          TTL: 2419200

What you will likely need (to include the default VAPID params):

    BenTools\WebPushBundle\Sender\PushMessageSender:
      arguments:
        $auth:
          VAPID:
            subject: '%bentools_webpush.vapid_subject%'
            publicKey: '%bentools_webpush.vapid_public_key%'
            privateKey: '%bentools_webpush.vapid_private_key%'
        $defaultOptions:
          TTL: 2419200