How te send push notifications from FCM using Postman - firebase

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

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 to send Firebase Auth Token ID from Mobile Clients (iOS & Android) for HTTPS triggers on Cloud Functions?

Ok not an expert on server side coding and stuff but have a basic understanding. Here is my question;
I have firebase triggers setup on cloud functions
Now there is a requirement that I need to communicate with external servers to retrieve some other data
So I use HTTPS triggers and I followed tutorials and managed to use express and other middlewares to get the job done
The problem is, I don't think I understand how these HTTP triggers are authenticated. I obviously want only the authenticated users to make a call to these end points and my users are either iOS or Android users.
What i have already found out:
I followed the code sample in this link: https://github.com/firebase/functions-samples/blob/master/authorized-https-endpoint/functions/index.js but I have one question
It says The Firebase ID token needs to be passed as a Bearer token in the Authorization HTTP header like this: Authorization: Bearer <Firebase ID Token>
Is this token passed automatically from iOS and android clients or do I need to manually call some FirebaseAuth get token function in the mobile SDKs and manually created this authorization bearer as a part of my request url?
You need to manually call a Firebase API to get a token to pass to your backend.
This process is documented fairly thoroughly in the documentation for the Firebase Admin SDK, which you would use to verify ID tokens. That link will give you examples for Android and iOS.
The code sample you linked to also has client code for web that does the same.

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.

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

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

How to get Firebase ID Token in Firebase Cloud Functions on auth.user().onCreate event?

Background
I have some Endpoint APIs on App Engine. I am able to authenticate the Firebase User in my Endpoint API when making a call from my client. (I append the Bearer token to HTTP request header when making the call).
I want to create a Cloud Function that is triggered on User Creation in Firebase (referred this video tutorial). From this Cloud Function, I want to call an Endpoint API using HTTP Request. For the HTTP API call to work, I need to send a Firebase Token in the request header.
Question
How do I get current user's ID Token inside Cloud Function?
A related post here recommends that I should call the API from my Ionic/Angularjs client. However, that will be a roundtrip back to the client and then to Endpoints. I am trying to avoid that.
I found that in /node_modules/firebase-admin/lib/firebase-app.js, there is a call to "FirebaseAppInternals.prototype.getToken". But I am not sure how to call it from my Cloud Function.
Sorry if its a noob question. I am new to Javascript and NodeJs. Any pointers will be of great help!
Also, I am not using Custom Tokens.
Thanks!

Resources