7

I've just opened a Firebase Cloud Messaging project intended for Android push messages.

The gear icon shows one server key (obfuscated here for obvious reasons):

enter image description here

I would like to have more than one key, so I can distribute them to servers and developers and revoke compromised keys if necessary.

How do I manage (add and delete) server keys in Firebase?

Adam Matan
  • 128,757
  • 147
  • 397
  • 562

4 Answers4

2

Update:

As of the moment, the way it should be done in order to generate a new Server Key, as stated in the docs:

Starting from Sept. 2016 new server key can only be created in the Firebase Console using the Cloud Messaging tab of the Settings panel. Existing projects that need to create a new server key can be imported in the Firebase console without affecting their existing configuration.

For the project migration steps, see my answer here.


For generating Server Keys, there is no way to generate one in the Firebase Console. It can be done via the Google Developers Console:

  1. Go to your Google Developers Console
  2. On the left-pane, click on Credentials
  3. Under the Credentials Tab, Click on Create Credentials
  4. Select API Key

Steps retrieved from my answer here

After you select API Key, it will directly create an API key without asking what type of key (Server, Android, Browser, iOS) it is. It will only allow you to set some Restrictions that was visible depending on which API Key you intend to generate.

By default, the key generated has No Restrictions, this makes a key vulnerable, that's why it is highly encouraged for you to add a restriction for your API key. In this case, since you are using it for FCM (Server Key is needed), you must add an IP Address restriction and only allow specific server IP addresses.


With that said, I don't know how you plan to integrate multiple server keys to a single Firebase Project though. Why not just make use of the IP Addresses restriction and remove the server IP address that are deemed compromised?

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • 2
    It could be useful to have different server keys to production/development environments, but apparently adding new API Keys using the Developers Console does not work as a FCM server key. – Meriw Nov 01 '16 at 02:03
  • 1
    @Meriw Yup. You would need to create a separate project in your Firebase Console and use the auto-generated one from there. – AL. Nov 01 '16 at 02:25
  • hi, im trying to send notifcation to Both android and IOS from php, but the server is key is Different for both the apps, should i keep condition to take android's serverkey for android notifications and ios's key for ios messages? – ɹɐqʞɐ zoɹǝɟ Sep 23 '17 at 05:27
  • @ɹɐqʞɐzoɹǝɟ If the way it was registered was that Android and iOS were separate, then yes, you should keep the condition. – AL. Sep 23 '17 at 06:23
1

It's not possible to have multiple cloud messaging server keys per project. I'd suggest you to have multiple Firebase projects for your application development staging environments.

If needed, you can then re-generate the server key in the Google Developer Console.

  1. On the top-left corner of the screen, verify that the correct project is selected.

  2. On the left-side panel, click Credentials.

  3. Under Credentials tab, click Server key (auto created by Google Service).

  4. Click Regenerate key button

  5. A confirmation box will show up asking if you'd like to replace the current key, then click Replace key button.

    Note that the new key will be available immediately. The current key will be deactivated permanently in 24 hours.

After all of these steps, you can check that the cloud messaging server key of your Firebase project is now updated.

Community
  • 1
  • 1
looptheloop88
  • 3,026
  • 17
  • 20
1

In Firebase, the Server Key is auto-generated. If you check out the Firebase project in the Google Developer Console, it will be listed as such. You can then create more Keys from there (but will not be listed in the Firebase Console, from what I can tell).

Basically, you can better manage the keys thru the Google Developer Console.

Hope this helps!

adjuremods
  • 2,938
  • 2
  • 12
  • 17
0

You should avoid distributing API keys for the same project. If any one of those using the API keys are found to be abusing it then the entire project will be throttled, affecting all keys for the project.

If you do want to have multiple developers send notifications to your application then have each developer create a Firebase project then have the client register with each sender ID. You will still have the ability to rotate the API key for each developer, or have the client delete the token for a developer that you no longer want to receive messages from. This way any abuse from one developer does not negatively affect the project as a whole.

Arthur Thompson
  • 9,087
  • 4
  • 29
  • 33