Getting invalid token in Firebase Cloud Messaging in cURL command and postman - firebase

guys, I'm trying to get information about app instance and I'm also trying to subscribe an app instance to a Google Cloud Messaging topic but the problem is whenever I try to use the server key it throws me the error of invalid token and when I try to use the web api key it gives me unauthorized
I've tried it using postman but the results are the same. Can somebody tell me what is it that I'm doing wrong
Here is the screenshot of the request that I'm sending using postman
and here is the screenshot of the request that I'm sending using curl

Related

Getting Firebase Bearer token by simple HttpCall (REST API)

I am currently facing the following situation.
Sending Firebase Messages via HttpCall via the google API endpoint:
https://fcm.googleapis.com/v1/projects/projectName/messages:send
Here we have to use OAuth2.0 with a valid Bearer Token like discussed in this question:
What Bearer token should I be using for Firebase Cloud Messaging testing?
After following these steps I was able to send Firebase Messages via the google API.
Now I would like to get the Bearer Token via a HttpCall without doing the manual step with the Playground https://developers.google.com/oauthplayground.
I cannot find any documentation on how to "Exchange authorization code for tokens" via simple HttpCall. I have no possibility to implement any code because I would like to send Firebase messages inside a "Dataverse Cloud Flow/PowerAutomate", therefore no possibility to load any external DLL (like the Firebase Admin Dll, which would implement this functionality).
I am not,looking for a solution which depends on external Dll like https://firebase.google.com/docs/database/rest/auth#authenticate_with_an_access_token or Pre-RequestScript
Any help is appreciated
What you are after is fundamentally not possible, since you can't hook the result of the bearer token into the same URL process to send messages. By the sounds of it you are unable to fetch one URL, process the results from that URL to pass onto the other which is what the REST API would do.
As such, you will need a secondary service that you can simply send messages to and it will invoke the Message and authentication for you, a bridge as you will. You can use Firebase Cloud Functions with an onRequest call or a simple express server on a Google Compute Engine instance (f1 free tier).
Then you can send your message request from your service to this bridge which will authenticate for you and send the message, it would be a fairly simple script to implement, specially with the admin-sdk.

How te send push notifications from FCM using Postman

I'm using the documentation from firebase to try send a message to an device using the Post method. firebase documentation and
here is my example:authentication where has the My_key i put the server key from firebase cloud and here is the body body And I'm reciving an 401 status error
I think the issue you are facing is because of your Authorization value in the header.
Based on your screenshot, you seem to be trying to use a key for authentication. Hence I assume you are using legacy protocol.
In this case for your authorization header value, try giving key=My_key instead of bearer My_key
Hopefully, this should solve your issue.
Refer firebase documentation to authorize send requests - https://firebase.google.com/docs/cloud-messaging/auth-server

Get Internal Server Error for Get Information About App Instance

When I try to send Get Request in Postman in the Url
'https://iid.googleapis.com/iid/info/IID_TOKEN', it gives me Internal Server Error.
The IID_TOKEN I get is from FCM (Firebase Cloud Messaging) Server Key.
The YOUR_API_KEY I get is from FCM (Firebase Cloud Messaging) Legacy Server Key.
Am I sending the correct IID_TOKEN and YOUR_API_KEY? Or is it any authorization that I have not done?
Please help me on this.
Thank you.
How you obtain the IID_TOKEN depends on the client SDK you are using. In the Cloud Messaging Guide, the section for each client SDK (e.g. iOS, Android, Web, etc) has a topic titled Send Your First Message with a step describing how to obtain the registration token. For example, the Android description says to use FirebaseInstanceId.getInstance().getToken().
From your post, it sounds like you are using a server key, which is not correct.
There is an example GET request in the documentation.

Using postman to test firebase returns 401 unauthorised with right api key

I am using postman to test my application that i added to firebase add project. I am trying to trigger a cloud notification from a postman to test purposes but its returning 401 unauthorised always. I double checked the api key and instance key even from google settings> project settings nad its correctly entered. Please help me find the problem. Sharing the screenshot of postman below

Firebase: INVALID_TOKEN: Failed to validate MAC

I get this error when trying to authenticate via Google using custom JWT tokens generated with Flask-restful and firebase-token-generator-python library. In short:
ref.authWithCustomToken(authData)
Error message:
INVALID_TOKEN: Failed to validate MAC.
I am using Angular 2.0.0-beta.2 / Ionic 2. The app is being tested on an android device using cordova-plugin-googleplus (with necessary credentials in Google Developer Console). I have recently enabled Cross-domain requests on nginx server. I can't find any documentation related to this error on Firebase or SO.
Any ideas?
The problem was sending an Authentication Token to Firebase formatted as a JSON string via authData.toString() including delimiters and quotes. This must have thrown the Failed to validate MAC error, whatever that means.
I got the same error when using the incorrect key. I was using the apiKey provided right on the homepage in the Firebase Console while I should have been using the database secret key given at https://console.firebase.google.com/project/YOUR_PROJECT/settings/database.

Resources