kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
992 stars 163 forks source link

Sending notification to tokens of iOS devices gives error #164

Closed Xoshbin closed 1 year ago

Xoshbin commented 1 year ago

Describe the bug

Hi, When trying to send a notification to an individual FCM token that's grabbed from any iOS device, gives the error below. The same process is working for Android devices's FCM tokens. Auth error from APNS or Web Push Service {"userId":"********","exception":"[object] (Kreait\\Firebase\\Exception\\Messaging\\AuthenticationError(code: 0): Auth error from APNS or Web Push Service at /project/vendor/kreait/firebase-php/src/Firebase/Exception/Messaging/AuthenticationError.php:22)

The error looks like and authentication issue, but I checked it and found no issue with authentications. and another proof is that it's working for Android devices.

Installed packages

"require": {
        "php": "^8.0.2",
        "embed/embed": "^4.4",
        "filament/filament": "^2.0",
        "filament/forms": "^2.0",
        "filament/spatie-laravel-media-library-plugin": "^2.0",
        "filament/tables": "^2.0",
        "flowframe/laravel-trend": "^0.1.1",
        "guzzlehttp/guzzle": "^7.2",
        "http-interop/http-factory-guzzle": "^1.2",
        "kreait/laravel-firebase": "^4.2",
        "laravel/framework": "^9.19",
        "laravel/helpers": "^1.5",
        "laravel/horizon": "^5.10",
        "laravel/jetstream": "^2.10",
        "laravel/scout": "^9.4",
        "laravel/socialite": "^5.5",
        "laravel/tinker": "^2.7",
        "livewire/livewire": "^2.5",
        "opcodesio/log-viewer": "^1.4",

PHP version and extensions

PHP: 8.0.2

Steps to reproduce the issue.

# Insert the commands issued in the terminal if they are needed
# to reproduce the issue. Otherwise, delete this code block.
// Insert the PHP code to reproduce the issue. Please ensure that it is code that
// can be copy pasted to reproduce it.

Error message/Stack trace

Auth error from APNS or Web Push Service {"userId":"********","exception":"[object] (Kreait\\Firebase\\Exception\\Messaging\\AuthenticationError(code: 0): Auth error from APNS or Web Push Service at /project/vendor/kreait/firebase-php/src/Firebase/Exception/Messaging/AuthenticationError.php:22)

Additional information

One of the FCM tokens that make the error:

fKGNv-pJtU53mX7BaLImqt:APA91bFyKK_PlaMy93FIPXZWQHHSSDQWa-KSdwXIwx9gcEl5-rJkVOkj1Bwb51hm81WvFlyLlxnd2u2c3pixd-V9HGa2UKiSA45OiyKM02PQHZ9bwmD5SlO1qbY5OJUbw8UaDlzlO-by

jeromegamez commented 1 year ago

Unfortunately this is not an error that can be fixed within the SDK, it's most likely a configuration issue in the Firebase console, see, for example https://stackoverflow.com/a/56045461

Another possible/related reason could be that you try to send the notification to a device that is not registered with your Firebase application. This can happen when you work with multiple environments: a device could be registered with a production project, but the message is sent from an QA environment.

jeromegamez commented 1 year ago

I'm going to close the issue because it's most likely not directly related to the SDK, but feel free to add further comments with your findings so that others might benefit from them when they face the same issue.

Xoshbin commented 1 year ago

For some reason, the APNS key is revoked in Apple developer keys (maybe I did it in mistake). So Firebase didn't have access to APNS. After creating a new key and uploading it to Firebase, the error solved. Thank you

jeromegamez commented 1 year ago

Good to hear! Thank you for coming back and describing the root and solution to the problem! 🙏🏻