firebase-adminsdk Go: Mismatched-Credential Sending Notifications to GCM Registration Tokens

1,795 views
Skip to first unread message

wil...@nextdoor.com

unread,
Mar 12, 2018, 9:19:48 PM3/12/18
to Firebase Google Group
Hello all, 

I'm currently managing a service that has sent notifications to devices in our Android project using a POST request to the legacy HTTP endpoint: https://fcm.googleapis.com/fcm/send
We only need our API Key in the header, and DeviceToken in the Token field of the message, in order for the notification to reach a device which has our app installed. 

However, now we are trying to migrate to the firebase-admin-go SDK. We have been successful with setting up an instance of the Firebase App and Messaging Client in our code. But when we try to call the Client's Send() method to send the notification payload to a device, we get a HTTP 403 error with the following description: "Reason: Sender ID does not match Registration Token; code: mismatched-credential

The ProjectID that we give our FirebaseConfig in order to initialize the app matches the Firebase documentation; it is the ProjectID of our firebase-adminsdk Service Account. The number in the ProjectID matches the SenderID for our Firebase App. And that SenderID matches the google-app-id of our Android project. Our Android project does not have a google-services.json file, which I've seen to check in some troubleshooting answers. 
It is important to note that our Android app still uses GCM, instead of FCM, to generate Registration Tokens for our client devices. Furthermore, our Android app does not even have Firebase as a dependency. We are hoping that since we didn't need to have Firebase on our Android app before when we were sending POST requests straight to FCM, that we won't need it now. If this is not true, please let us know!

Since there is no mismatch between the Project, Sender, or App IDs, the Firebase documentation has not been sufficient for us to solve this issue. We are wondering if anyone knows if there are certain steps that we have to take, such as extra details that we need to include in our message payload, or additional modifications or upgrades that we have to make to our Android App, in order to solve this error.


Ian Barber

unread,
Mar 13, 2018, 2:12:52 PM3/13/18
to Firebase Google Group
Have you got an instance ID token from the app? There is a server API you can use to verify: https://developers.google.com/instance-id/reference/server

You can call https://iid.googleapis.com/iid/info/IID_TOKEN to check the authorizedEntity matches the project ID you're using on on the server side

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/98f9e80e-9f50-4b68-ac2a-484b0bdc03b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hiranya Jayathilaka

unread,
Mar 13, 2018, 5:10:37 PM3/13/18
to fireba...@googlegroups.com
On Mon, Mar 12, 2018 at 6:19 PM <wil...@nextdoor.com> wrote:
Hello all, 

I'm currently managing a service that has sent notifications to devices in our Android project using a POST request to the legacy HTTP endpoint: https://fcm.googleapis.com/fcm/send
We only need our API Key in the header, and DeviceToken in the Token field of the message, in order for the notification to reach a device which has our app installed. 

However, now we are trying to migrate to the firebase-admin-go SDK. We have been successful with setting up an instance of the Firebase App and Messaging Client in our code. But when we try to call the Client's Send() method to send the notification payload to a device, we get a HTTP 403 error with the following description: "Reason: Sender ID does not match Registration Token; code: mismatched-credential

The ProjectID that we give our FirebaseConfig in order to initialize the app matches the Firebase documentation; it is the ProjectID of our firebase-adminsdk Service Account. The number in the ProjectID matches the SenderID for our Firebase App.

Number in the project ID? That sounds a little suspicious. Can you confirm that your ProjectID string is same as the project_id field in the service account JSON?
 
And that SenderID matches the google-app-id of our Android project. Our Android project does not have a google-services.json file, which I've seen to check in some troubleshooting answers. 
It is important to note that our Android app still uses GCM, instead of FCM, to generate Registration Tokens for our client devices. Furthermore, our Android app does not even have Firebase as a dependency. We are hoping that since we didn't need to have Firebase on our Android app before when we were sending POST requests straight to FCM, that we won't need it now. If this is not true, please let us know!

Since there is no mismatch between the Project, Sender, or App IDs, the Firebase documentation has not been sufficient for us to solve this issue. We are wondering if anyone knows if there are certain steps that we have to take, such as extra details that we need to include in our message payload, or additional modifications or upgrades that we have to make to our Android App, in order to solve this error.


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/98f9e80e-9f50-4b68-ac2a-484b0bdc03b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Hiranya Jayathilaka | Software Engineer | h...@google.com | 650-203-0128

wil...@nextdoor.com

unread,
Mar 14, 2018, 5:28:50 PM3/14/18
to Firebase Google Group
@Ian, our Android app doesn't have an InstanceID, so we are unable to make the call you suggested to the Firebase API.

To be frank, our Android app's messaging system was set up in 2013 with GCM, and essentially hasn't been touched since then. We are hoping that there is some way to use the new FCM SDK to send our messages, without changing our Android app, at least for now.

wil...@nextdoor.com

unread,
Mar 14, 2018, 5:28:50 PM3/14/18
to Firebase Google Group
Hello Hiranya, I just checked that our project_id string matches the project_id field in the JSON exactly. 


On Monday, March 12, 2018 at 6:19:48 PM UTC-7, wil...@nextdoor.com wrote:

Hiranya Jayathilaka

unread,
Mar 14, 2018, 5:36:46 PM3/14/18
to fireba...@googlegroups.com
You might be running into https://github.com/firebase/firebase-admin-go/issues/116

Have you enabled the FCM API in your project?


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

wil...@nextdoor.com

unread,
Mar 15, 2018, 10:32:48 AM3/15/18
to Firebase Google Group
Our most recent update is that we do indeed get a response from the FCM SDK and it is formatted as expected. We also get no error from sending with the SDK's Messaging Client.

However, the notification still does not appear on our device. We are sending to the device's GCM registration token, which we could send a notification to with a POST request to https://fcm.googleapis.com/fcm/send, and our GCM API Key. Do we need to convert or update our devices' GCM registration tokens in order to send our notifications?


On Monday, March 12, 2018 at 6:19:48 PM UTC-7, wil...@nextdoor.com wrote:

wil...@nextdoor.com

unread,
Mar 15, 2018, 10:32:48 AM3/15/18
to Firebase Google Group
I just enabled the FCM API in my project by following the link to the issue that you posted, and I no longer get a mismatch-credentials error!
However, I now get a nil response from the SDK, and the notification does not send to my phone, despite the deviceToken being correct. The error returned is also nil, which is confusing.

What does a nil response, AND no error, mean from the FCM SDK client?

wil...@nextdoor.com

unread,
Mar 15, 2018, 10:32:48 AM3/15/18
to Firebase Google Group
One more piece of information about trying to make a GET request with the InstanceID as detailed here: https://developers.google.com/instance-id/reference/server
Using an InstanceId from our Android app, which still uses GCM and does not have Firebase at all, and our Firebase Web API Key, we get a 401: Unauthorized error back.


On Monday, March 12, 2018 at 6:19:48 PM UTC-7, wil...@nextdoor.com wrote:
Reply all
Reply to author
Forward
0 new messages