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

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.

Related

Getting an error while adding FCM API Key to Azure Notification Hub

I have created a Azure Notification hub namespace, I'm trying to configure the Google FCM section of it by entering the API Key, but when I do that it is giving me this error
Error updating notification hub
{"error":{"code":"BadRequest","message":"Invalid Firebase credentials."}}
The Key I added it from the google-services.json file
But when I send a notification from FCM console, I'm able to send it and receive the notification.
Any inputs would be appreciated
Azure Notification Hub doesn't support FCM (yet) but GCM as I'm writing those lines.
You need to mention the server key available under your Firebase project settings in the Cloud Messaging tab. You should see something like this:
The key that you want to mention in Azure Notifications Hub is the purple one.
If Cloud Messaging API (Legacy) is disabled (which should be the case by default since it's deprecated), just hit the 3 vertical dots on the right and navigate to the only available menu "Manage API in Google Cloud Console". And just enable it :)

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.

Firebase API Key Application Restriction Problem

I received an alarming email from Google a couple of days ago stating that:
[Action Required] Firebase services for your application are malfunctioning due to Application restrictions
I have a Vue based website that uses Firebase for Authorization of users and storing files they are uploading. When I configured the API key that I set up, I restricted this key on the application level, to only work from the address of my website.
I did not impose any API restrictions - Under API Restrictions the radio button with Don't Restrict Key is marked
Having said that, when I try to use my website, I get the following error:
[403] Requests from referer [WEBSITE] are blocked.
The email I got from Google stated that:
Firebase SDK updates on February 27, 2020 (Android) and January 14, 2020 (iOS) replaced the Firebase Instance ID service with a dependency on the Firebase Installations API.
As a result, Firebase services like Firebase Cloud Messaging will malfunction for users who installed your app after it was released with updated Firebase SDKs. Additionally, repeated failing requests to Firebase may slow down the end-user experience of your app.
Application restrictions you have applied to the API key used by your Firebase application need to be updated to allow your application to use the API key.
Inside this mail, there were the following instructions:
Open the Google Cloud Platform Console.
Choose the project you use for your application(s). Open APIs &
Services and select Credentials.
Click Edit API key for the API key in question.
Scroll down to the Application restrictions section.
Change the radio button to None, and click Save, or add your
application to the list of allowed Android apps, iOS apps, or HTTP
referrers, respectively.
If the radio button already shows None you may be looking at the
wrong API key.
You can check which API key is used for the Firebase Installations
API by looking at the service usage page for your project.
Since I do not have any API restrictions and there is also no other API key that I have, I don't understand how to solve this situation.
One option that works is having no application restrictions, but I don't think that is the correct solution.
I also tried changing the API Restrictions to allow only the services from Firebase that I am using, but that did not fix the problem.
Any help or direction to a solution, will be appreciated.

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

Firebase messaging, where to get Server Key?

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

Resources