6

It has been a while since we touch this google-services.json file. We download the file again from Firebase console and do a diff for it with whatever we have on file and saw that the api key is different .

However, we could not find any good documentation about why it is changed and what is supposed to do on our side.

      "api_key": [
        {
-         "current_key": "AI***********************************BC"
+         "current_key": "AI***********************************K0"
        }
      ],

We saw this question that this api key is supposed to be used to send push notifications. We tested notification with both versions of the key and both of them are working fine.

https://stackoverflow.com/a/38227768/1035008

What might be causing the change in the current_key field in the JSON file? Is it safe to just swap in the new file?


Edit:

We saw the old key is still there under https://console.firebase.google.com > Project Overview > Project Settings > Web API Key:

enter image description here

I guess Google just decided to move the web API key outside of file and created a new one for each project?

Yuchen
  • 30,852
  • 26
  • 164
  • 234
  • 1
    It is safe to just swap in the new file. I don't know what the change means, but your app should work fine regardless. – Doug Stevenson Mar 20 '19 at 20:35
  • 1
    From my experience it is not only safe to swap in the new file, but you are forced to swap it if you happened to download a new `google-services.json`. Your old API key is disabled immediately (without any warning) and your users (using the old API key still) cannot sign in to your app anymore. So the button for downloading a new `google-services.json` is like a bomb, it will "kill" your app until you publish an update with the new API key. I think this is a Firebase bug and I have already contacted support. Luckily I tried this only with my dev project. – kine Jan 23 '20 at 08:32
  • Not sure if there is some precondition for that to happen, but it happened to me. Anyway, now I don't dare to hit the `google-services.json` button anymore until I get some information why this happened. – kine Jan 23 '20 at 08:39
  • For me, the current_key in my google-services.json has updated to the new key which I created in my GCP project (restricted to app's package name). So i'm guessing Firebase picks up the most recent app-scoped API key from GCP? Beware! – Vibin Jul 06 '20 at 19:19

1 Answers1

2

A Firebase project can have many API keys, but each API key can only be associated with a single Firebase project. See The docs

You can view your API keys in Firebase console at APIs & Services > Credentials

From what I can gather, when you download the google-services.json it 'auto matches' what it thinks is the most appropriate key. In my case it changed the key to a different (existing) key, but both keys still work - tested with FCM Push Notifications and Firebase Analytics on Android device.

jpmc
  • 1,147
  • 7
  • 18