Firebase messaging/mismatched-credential

10,707

Solution 1

The issue was with my google-services.json. My app uses two projects and was defaulting to the first project. Adding the second project json file ended up fixing this since it can now send the tokens to the proper project.

Solution 2

This error message can be found in the documentation for FCM.

It means that you've initialized the Admin SDK with a credential for a project that is not the same as the device registration token.

To put it another way: for security reasons, you can't simply send messages to any device token that you come up with. You can only send messages to device tokens via apps in the same project.

Solution 3

I faced the same problem. It took me two days to figure out that I need to enable the Firebase Cloud Messaging API through google cloud platform. Without enabling it, it also yields the error "mismatched-credential". I really wish that the error message could be more specific.

Share:
10,707
Joe Scotto
Author by

Joe Scotto

Writer of code, creator of videos, and taker of photos.

Updated on June 03, 2022

Comments

  • Joe Scotto
    Joe Scotto almost 2 years

    I'm trying to send notifications to a specific device with Firebase but am getting the following error:

    {"r": {"results":[{"error":{"code":"messaging/mismatched-credential","message":"The credential used to authenticate this SDK does not have permission to send messages to the device corresponding to the provided registration token. Make sure the credential and registration token both belong to the same Firebase project."}}],"canonicalRegistrationTokenCount":0,"failureCount":1,"successCount":0,"multicastId":5165415028752234000}}

    I'm not sure what is causing this, I'm using the service account associated with the project and the proper device id.

    Any help would be great, thanks!

  • Joe Scotto
    Joe Scotto over 6 years
    But the app I'm sending to is in the same project?
  • Doug Stevenson
    Doug Stevenson over 6 years
    I have no way of telling. You have to initialize with a credential that comes from the same project. That's something only you have access to.
  • Joe Scotto
    Joe Scotto over 6 years
    I'm using the service account from the exact same project. Make no sense to me why it wouldn't be working.
  • Doug Stevenson
    Doug Stevenson over 6 years
    All I can say is that you should double check all your data and make sure your service account is still valid. After you have double checked, if there is still a problem, contact Firebase support. firebase.google.com/support/contact/troubleshooting
  • BSQ
    BSQ about 6 years
    Thank you ! Very annoy for enable !
  • Gillis Haasnoot
    Gillis Haasnoot about 6 years
    Did you find a solution? i have the same issue
  • ehacinom
    ehacinom over 5 years
    like the answer says, I was trying to send push notifications to the wrong FCMToken (the 152 char token that my client app gets from Firebase after sending a deviceId to firebase)
  • Mark Adel
    Mark Adel over 5 years
    @Martin Z How do I achieve this?
  • Jay Sojitra
    Jay Sojitra about 5 years
    Hi Joe, I am facing the same problem. But I didn't get your point. Can you please elaborate in detail?
  • Chris.D
    Chris.D almost 5 years
    1) From the Firebase Console for your project go to settings service accounts. 2) Click the Service accounts for Google cloud platform link to go to the related google cloud project 3) From the left hamburger menu got to APIs and Services 4) Find "Firebase Cloud Messaging" (don't confuse it with "Cloud Messaging") 5) Enable API
  • Suraj Malviya
    Suraj Malviya over 4 years
    I faced the same problem, it is with Android studio, it is caching the JSON file across builds if not clean build the project at first place
  • Suraj Malviya
    Suraj Malviya over 4 years
    Enabling is not the requirement here. My project is working without enablilng the api from GCP as well.
  • MadMac
    MadMac about 3 years
    The amount of times I have used the development google-services.json file by mistake!
  • Elemental
    Elemental almost 3 years
    If you change your json credential files you need to do a clean on the project or android studio will not build the new credentials.