Firebase messaging, where to get Server Key? - firebase

Firebase allows us to send notification messages via our own application by making POST request.
This tutorial, gives to us instructions how to make this request. However, there is Authorization field in header where I must to place my own Server key.
Where I can get this Server key? There are no instructions for this.

Solution:
Click the Settings (Cog wheel) icon next to your project name at the top of the new Firebase Console, as per screenshot below:
Click Project settings.
Click on the Cloud Messaging tab.
The key is right under Server Key.

Updated UI June 2022
I was able to get the Server key by doing the following steps:
Click on the "..." next to "Cloud Messaging API (Legacy)"
Click "Enable Cloud Messaging Api (Legacy)"
Go back to the previous page and refresh and you should now see the Server Key
Not sure if we need to do something different moving forward now that it's considered legacy....
Steps with images: https://documentation.onesignal.com/docs/generate-a-google-server-api-key

Take this one: (First answer is right - this one is just to show how the page looks like!)
https://support.clevertap.com/docs/android/find-your-fcm-sender-id-and-fcm-server-api-key.html#

July 2022
Click on the "..." (Positioned vertically) next to "Cloud Messaging API (Legacy) (DISABLED)" on your Firebase project settings.
Click on the pop-up menu listing. *It should say something like "Manage API in Google Cloud Console"
OnClick it will redirect to your google cloud console page, over there you should see an option to enable the Cloud Messaging API. Enable it and go back to your Firebase project settings and wallah, its there!

UPDATE: As of April 2017 this method does not work. The api_key in google-services.json is only the legacy key. The selected answer is correct.
Deprecated way:
In your project there is a JSON file called google-services.json
Open that file and search for
"api_key": [
{
"current_key": "********"
}
those *** are your server api key
If you dont have that file then you can download it from your app details in firebase account

There are two keys on firebase, the first one is in Settings (Tab General)
and its call Web API Key.
The second one and in what you are interesting for is in Settings (Tab Cloud Messaging) its called Server key
Use the second one for push notifications from php.

Updated UI 2022
Here are Steps to get serverKey
GO to firebase console
You can get view like this. if you have Created Project select project else Create new Project by click on Add project.
Now you are in Project overview panel.
In Project overview panel in left upper corner click on settings button and go to Project Settings --> Cloud Messaging
That's it. in Project credentials Key and token are mentioned. Copy code and paste it. You are good to go

In my case, I did an integration with a 3rd party system and they asked for the "server key" json file.
They what I get it from firebase was:
Project Overview -> Project Settings -> Service accounts screen and A press the Generate new private key button.
I used that file and everything worked as expected

Related

Firebase Cloud Messaging (FCM) Api Key for Azure Notification Hub

I'm creating a Xamarin project to test Azure Notification Hub, but I'm having trouble going through the steps in this article
Under the section "Create a Firebase project and enable Firebase Cloud Messaging"
Step 6 is obsolete as Google seems to have changed their model to obtain a Server Key, or the Server Key does not apply to FCM.
Can anyone shed a light on how to obtain an Api key for Azure Notification Hub?
expanding DrDave's comment
From https://console.firebase.google.com/project/--your_project_name--/settings/cloudmessaging
Click on the three-dots menu of the "Cloud Messaging API (Legacy) 🚫 Disabled" Heading
Follow the offered link to manage in google cloud console, and there press the button to enable the googlecloudmessaging API
Wait a few minutes
Go back to your Firebase console Cloud Messaging Tab, and refresh.
See that the Cloud Messaging API header has changed to "Cloud Messaging API (Legacy) ✅ Enabled" and that a Server Key is now shown.
If you go to the Build section, Authentication menu item, and then click the 'Get Started' button, then navigate back to the Project Settings/General tab, you should see the API key.
EDIT: This is not the proper key for the Azure Notification Hub. See my comment below for the correct key.
There currently does not seem to be a proper answer to this.
When using FCM, if you head to the Authentication page on the Firebase Console for your app and select 'Get Started', follow the steps and then head back to the 'General' tab in your project settings page, you will see that it now has a Web API key.
This isn't useful for Azure Notification Hubs as if you try insert this key into the API key entry for a hub, it will not accept it.
The only answer seems to be to use the legacy GCM API, which is not ideal as it has been deprecated and certain APIs are no longer available.

firebase firestore gives error for a project that's been added to firebase projects

I've added my project to firestore and I'm doing firestore google auth just fine.
My problem is firebase firestore.
It just doesn't work and I have no idea why.
I'm trying to do a simple add before doing the actual process for my app and it doesn't work.
here I implemented a simple function to add a user and then called it, doing it all in build function.
I get this in my console:
p.s.
"adding user" is printed on console.
p.s.
I do have the firebase_options.dart file.
These thing are you sure that the correct:
1.Using correct google_services.json file
2.Edit Fire store rules if you are not using authorization
You have to manually whitelist your existing Google OAuth 2.0 client IDs in the Firebase console before using it with the new Auth APIs.
In order to do so, follow these steps:
Go to the Credentials section in the Google API Console.
Select from the top right corner the project where you had previously configured Google Sign-In.
Go to the OAuth 2.0 client IDs section
If you are using Google Sign-In on Android or iOS applications:
Take note of the Client ID string corresponding to all the entries registered for your applications.
Input these Client IDs into your Firebase project’s configuration:
Go to the Firebase console at https://console.firebase.google.com
Open the Auth section
Under Sign-In methods, open the Google configuration, and add there all you client IDs, to the whitelist of client IDs from external projects.
If you are using Google Sign-In on a web application:
Click to open your web client ID and take note of both the client ID and secret.
Input this Client ID into your Firebase project’s configuration:
Go to the Firebase console at https://console.firebase.google.com
Open the Auth section
Under Sign-In methods, open the Google configuration, and add the values under the Web SDK configuration section.

Web API Key missing in firebase

I'm trying to get an API key for a live chat plugin, but I can't get the key from Firebase.
No Web API Key for this project:
Any solution? Thanks!
Go to the authentication tab and enable a sign-in method (for example email/password). This will generate the web api key.
EDIT: as fen1ksss said: It seems this has been changed just recently. You don't actually need to toggle any of the providers to make it work.
there's been another small change: the authentication tab is now inside the "Engage" tab because google likes hide and seek. once there, follow as above.
Visiting https://console.firebase.google.com/u/0/project/project-id/settings/general/ where project-id is your project's id, should show you your api key written directly under your gcp resource location as "Web Api Key"
Also if you have gotten the config object from your firebase project before, your web api key is listed under the key "apiKey"

How to disable reCaptcha in firebase phone-auth (OTP) android?

I've updated the firebase library recently and didn't change anything else.
implementation 'com.google.firebase:firebase-auth:20.0.1'
implementation 'com.google.firebase:firebase-messaging:21.0.0'
implementation 'com.google.firebase:firebase-storage:19.2.0'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
but whenever a user tries to signup, a Recaptcha is showing for a few seconds and then sometimes redirects to a web browser (CustomChromeTab) after that OTP is received from firebase auth. It takes about 15-30 seconds. How to prevent the Recaptcha? However, I added the SHA1 and SHA256 in the firebase console and have not changed the code. Thanks.
Here is the screenshot of the captcha verification process:
Most of the times while implementing dependencies like:
implementation 'androidx.browser:browser:1.2.0'
the above window pops-up in the browser.
Here, is a way to resolve it successfully.
Step 1-
In the Google Cloud Console, enable the Android DeviceCheck API for your project. The default Firebase API Key will be used, and needs to be allowed to access the DeviceCheck API.
Step 2-
If you haven't yet specified your app's SHA-256 fingerprint, do so from the Settings Page of the Firebase console. Refer to Authenticating Your Client for details on how to get your app's SHA-256 fingerprint.
Hope it works!!!
For more information, you can also check Google SafetyNet API for checking Google Play Services installation in device at the time of Phone Authentication.
Also, need to perform additional steps:
Firebase Project Settings > App check > and Register firebase project in SafetyNet and Play Integrity register with default time token 1 hour.
Don't forget to go in Firebase Project Settings > App check > and Register firebase project in SafetyNet and Play Integrity register with default time token 1 hour and u will remove reCaptcha from phone auth OTP!
Try this alternative method to disable reCaptcha
mAuth = FirebaseAuth.getInstance();
// set this to remove reCaptcha web
mAuth.getFirebaseAuthSettings().setAppVerificationDisabledForTesting(true);
because I've been following Mohd Asim answer, and it doesn't work.
In order to remove the captcha verification, you have to do this in Google cloud console.
IMPORTANT (you may have done that, but for the reminder):
Add the SHA1 and SHA256 of your project (see how to get) in the firebase project setting page (See how to set).
Go to the Library page in the Google APIs Console.
In the search bar type "Android Device Verification", and select the Android Device Verification box (API). The Android Device Verification API dashboard screen appears.
If the API isn't already enabled, click Enable. Hope here your problem solves and if not then proceed further.
If the Create credentials button appears, click on it to generate an API key. Otherwise, click the All API credentials drop-down list, then select the API key that's associated with your project that has enabled the Android Device Verification API.
In the sidebar on the left, click Credentials. Copy the API key that appears.
Use this API key when you call the attest() method of the SafetyNetClient class.
For more information read this official page - https://developer.android.com/training/safetynet/attestation
go to google cloud console
Select project it should be same project in which firebase is running and make sure you have added sha-1 and sha-256 of both debug and release version and put updated google-services.json file in your app.
search android device verification
click on enable
5.done

Disable Legacy Server Key

I found that Firebase Cloud Messaging has two ways to send Push Notifications.
I am aware of how the two ways are working and I have already implemented and tested my app and server using both ways.
However, I am required to disable the "Legacy server key" way of sending messages.
I cannot find how to disable this using Firebase Console.
Is it possible to disable the Legacy way of sending Push Notifications? How?
you have to enable the firebase messaging API from the google developer console
by clicking on the three dots and clicking on the "Manage API in Google Cloud Console"
after enabling the API go back to firebase and refresh then you will get the FCM key for messaging
There is currently no way to disable or even delete the Legacy Server Key from the Firebase Console. The Legacy Server Keys automatically get generated and tied to the project after creation.
There may still be a number of users (most coming from GCM) who still use the Legacy Server Key in their apps , which I believe is the reason why it hasn't been removed yet. Other than that, there is no other use for it as far as I know.
Update:
There is a way for you to delete the currently tied Legacy Server Key in your Firebase Project, however, I would like to point out that this might cause issues if not handled properly. Only do this if you are absolutely sure that you won't be using the Legacy Server Key ever again.
Here are the steps:
Go to your Google Developers Console Page.
After sign in, select the correct project on the upper right side. If you can't find it in Recent, go to the All tab.
After selecting the correct project, click on Credentials on the panel to the left. You should then see a list of keys, one of which is named Server key (auto created by Google Service). If you check, this is the same Legacy Server Key visible in your Firebase Project.
From here, you can click on the Pencil or Trash icon.
If you click on the pencil icon, it will direct you to a page where you can choose to Re-Generate or Delete the key. Choosing to generate a new key would give you a new server key, where the change would also reflect in your Firebase Project, while also still having the option to revert to it (only within the 24 hours limit).
Choosing to delete the key would automatically generate a new one for you, but you won't be able to have the option to revert to it.
Go to https://console.cloud.google.com/apis/library/googlecloudmessaging.googleapis.com?authuser=0&project=courseflutter-15e95&hl=en
Click enable
Refresh the page

Resources