firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.63k stars 371 forks source link

Firebase Messaging returning "Invalid registration token" when sending silent APNs notification #1224

Closed gdieguez closed 3 years ago

gdieguez commented 3 years ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

FCM started responding with INVALID_ARGUMENT with a description of Invalid registration token to any calls for sending APNs silent notifications. We've verified that the tokens are actually valid. This happens in the node client, and also when calling directly the HTTP v1 send endpoint.

We started noticing this behavior roughly on 2021-04-08 14:30:00 ET, which suspiciously coincides with a deploy of our production functions. Note that this deploy didn't include any updates to the relevant codepaths nor libraries involved.

We also found someone with the very same problem on Stack Overflow: https://stackoverflow.com/questions/67051941/fcm-throwing-invalid-argument-for-ios-notifications

Steps to reproduce:

Call the HTTP v1 send endpoint:

POST https://fcm.googleapis.com/v1/{parent=projects/*}/messages:send

with the following payload:

{
  "validate_only": false,
  "message": {
    "token": <FCM TOKEN>,
    "apns": {
        "payload": {
            "aps": {
              "content-available": 1
            }
        }
    }
  }
}

with a valid FCM token and you should receive the following response:

{
    "error": {
        "code": 400,
        "message": "Request contains an invalid argument.",
        "status": "INVALID_ARGUMENT",
        "details": [
            {
                "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
                "errorCode": "INVALID_ARGUMENT"
            },
            {
                "@type": "type.googleapis.com/google.rpc.BadRequest",
                "fieldViolations": [
                    {
                        "field": "message.token",
                        "description": "Invalid registration token"
                    }
                ]
            }
        ]
    }
}

But if you replace content-available with badge, the notification is sent correctly:

{
    "name": "projects/<PROJECT_ID>/messages/<MESSAGE_ID>"
}

We've also tried sending content_available and contentAvailable as keys, and true as value, to no avail.

gdieguez commented 3 years ago

@hiranya911 please take a look when you can

hiranya911 commented 3 years ago

This has been forwarded to the FCM backend team. They are looking into it. We'll post an update when new information is available.

frenberg commented 3 years ago

@hiranya911 Sweet, we're seeing this too. Is there somewhere we can follow the progress over at the FCM backend team?

ssprang commented 3 years ago

Hi! We are using the java version of this library and we're not getting any exceptions but our APNs silent notifications stopped working at about the same time on 2021-04-08. @hiranya911 it sounds like a backend release of FCM caused this, would it be possible to rollback that change? APNs silent notifications not working is affecting our end users.

chong-shao commented 3 years ago

FCM backend team has identified the issue, expect to have it fixed within a week. I'll post more updates on timelines, etc.

gdieguez commented 3 years ago

Thanks for the update. For all of you who are waiting for this to be fixed, we were able to send silent notifications using the legacy API. I left some details on the stack overflow post I linked before.

ssprang commented 3 years ago

FCM backend team has identified the issue, expect to have it fixed within a week.

That is great! But a week is a very long time.. Especially since it's been broken for almost a week already. @chong-shao or @hiranya911 could you confirm if this issue is affecting all FCM APNs silent notifications (including those of us using the java version of this library)? Can't the FCM backend team rollback the release that caused the issue to begin with?

viktorvoltaire commented 3 years ago

If this is a FCM backend problem, shouldn't there be any mention of it at https://status.firebase.google.com/ ?

gdieguez commented 3 years ago

They actually put a message on the status website a couple hours ago but now it's gone, so I tested and it seems to be fixed. @hiranya911 @chong-shao can you confirm?

chong-shao commented 3 years ago

Latest update: FCM backend performed a fast rollback today. The backend should be at the good version without this issue now.

viktorvoltaire commented 3 years ago

Latest update: FCM backend performed a fast rollback today. The backend should be at the good version without this issue now.

@chong-shao Even though it was never confirmed that this affected the firebase-admin-java library, we can say that after the rollback it is also functioning again. Whats scary is that we saw no errors on our end, suddenly silent notifications just stopped occurring in our app and the graph for sending messages went down to 0 at https://console.firebase.google.com/u/0/project/PROJECT/notification/reporting but we saw 0 increase in errors towards the API

I hope this could be forwarded to the team that it would be nice if we at least got a status error in the library when such an important feature stopps working :)

Cheers for the rollback!

marcelsalej commented 3 years ago

We still have the problem here in our project. Reports show that not a single push from background came to client. We also tried examples in your docs: concept options via OAuth2 playground. Same thing happens.

If we try via legacy system, pushes are working as they should.

Screenshot 2021-04-15 at 13 09 21

Matoz commented 3 years ago

Works for us again. Thanks for the rollback

chong-shao commented 3 years ago

@salkovich Hello, did you observe "invalid_argument_error"/"invalid registration token" error from the send response? The issue you described might be a separate one. It's recommended to file a support ticket https://firebase.google.com/support and provide your: project id, FCM token (if any), sample request/response so our support team can investigate. Thanks!

ashrafsabrym commented 3 years ago

I'm still getting this error on my Xamarin iOS app. I've upgraded the FirebaseAdmin Nuget package to the latest version 2.1.0 on my ASP.Net backend but still get the issue Does this have to do with the Xamarin.Firebase.iOS.CloudMessaging Nuget package on the app?

lud4ik commented 5 months ago

Getting same error for silent ios push notification on new firebase API version

DooMMasteR commented 5 months ago

we have the same issue, and now the legacy API is being discontinued.

Doris-Ge commented 4 months ago

Please make sure that the key in the payload is "content-available" instead of "content_available".

ehtodd commented 3 months ago

@ramyassaf did you ever find a fix for this? We're experiencing this issue as well and it's really frustrating.

ramyassaf commented 3 months ago

@ramyassaf did you ever find a fix for this? We're experiencing this issue as well and it's really frustrating.

There is no fix since there is no problem, i deleted my comment since it was my fault. I was sending APNS tokens to firebase FCM V1, which was not the correct token. To make things clearer, delete the app and restart it to get a new FCM token then copy it and try to send using it.

Jonny1987 commented 2 months ago

I am also getting this error and I'm sending the correct token (not APNS token) and using FCM V1

UPDATE: The issue was that I needed to have this in the message for data only messages:

    apns: {
      payload: {
        aps: {
          { "content-available": 1 },
        },
      },
    },

So the "Invalid registration token" error I was getting from firebase seems to be wrong

lehha commented 2 months ago

Same problem.

Docs says that is must be "contentAvailable": true https://firebase.google.com/docs/reference/admin/node/firebase-admin.messaging.messagingoptions.md#messagingoptionscontentavailable

But it broke push like at topic author.

Works if delete this key or change to: "content-available": 1

Jonny1987 commented 2 months ago

Same problem.

Docs says that is must be "contentAvailable": true https://firebase.google.com/docs/reference/admin/node/firebase-admin.messaging.messagingoptions.md#messagingoptionscontentavailable

But it broke push like at topic author.

Works if delete this key or change to: "content-available": 1

Because that the docs for the node sdk, not the rest api. Rest api docs are here: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send

And if you keep following the links you get to the apple specific payload doc: https://developer.apple.com/documentation/usernotifications/generating-a-remote-notification