I'm trying to create a python app that pretends to be an android mobile app.
The app I'm trying to mimic is using firebase cloud messaging client. and it's using the FirebaseMessaging.getInstance().getInstanceId() method to get a token.
Google documentation mentions:
On initial startup of your app, the FCM SDK generates a registration
token for the client app instance. If you want to target single
devices or create device groups, you'll need to access this token by
extending FirebaseMessagingService and overriding onNewToken.
All the communications between the server is encrypted with this token. and in order to communicate the to app server I need to be able to generate this token.
My question is how can I generate a new token? is there a particular endpoint for this?
I've seen this and this but none of them mention how its getting done.
Related
I am trying to use Delphi (10.3.2) code to send push notifications to specific Android devices, but can't figure out how to do it properly.
The tutorials and guides I have looked at only provide help for receiving notifications (which works very nicely), but in all of them the notifications are sent directly via the Firebase console.
Is it possible to accomplish this directly in Delphi?
Sending messages to devices through Firebase Cloud Messaging requires that you call the FCM versioned API and specify the so-called FCM Server Key. As its name implies, this key should only be used on trusted environments, such as your development machine, a server you control, or Cloud Functions. The reasons for this is that anyone who has the FCM Server Key for your project can send notifications to all users of your app. So you'll not want to include this key and functionality directly in your application code.
The common approach is to set up a server-side endpoint (e.g. a self-defined API that you create on something like Cloud Functions or your existing server), and call that from your application code. The server-side code can then ensure that the user is authorized to send notifications to the folks that are targeted, and call the relevant FCM API to send the messages to the devices.
This FCM API for sending messages comes in a few flavors. I'd first consider if there's an Admin SDK for your platform, as that's the easiest way to make this work. If there is no Admin SDK, you can make HTTP calls to the v1 API directly.
I am trying to build a wrapper app with cordova and using PHP as server backend.
I am using cordova-plugin-fcm to handle push notification.
Correct me if I am wrong, each device (android and ios) has own id which is used to send notification.
How can I get that id and send it to PHP route so that I can bind it with the logged in user and send notification?
//FCMPlugin.onTokenRefresh( onTokenRefreshCallback(token) );
//Note that this callback will be fired everytime a new token is generated, including the first time.
FCMPlugin.onTokenRefresh(function(token){
alert( token );
});
In above example token is the id to be send to PHP to send notification?
Can the device.uuid used for sending notification?
I have already setup my Firebase configuration and the project has google-services.json and GoogleService-Info.plist in place.
Thank you
Firebase Cloud Messaging targets its messages at a specific app on a specific device. Each specific app install is identified by Firebase's Instance ID, also referred to as a device registration token, or an FCM token.
The Firebase documentation on accessing the registration token says this about it:
On initial startup of your app, the FCM SDK generates a registration token for the client app instance. If you want to target single devices or create device groups, you'll need to access this token by extending FirebaseMessagingService and overriding onNewToken.
From a quick read through the Cordova documentation on device.uuid, this seems to merely identify the device, and not the app on the device. Since FCM messages are delivered to a specific app on each device, it seems unlikely you can use the UUID of the device as a replacement.
Even if the UUID is unique for each app on each device, it won't be a drop-in replacement, as FCM only works with its own registration tokens. At the very least you'll need to keep a mapping of the device.uuid values to their corresponding FCM token.
I have a web app made by laravel framework and I want to send notifications from my web app to the android and ios versions of my platform, I'm considering using firebase for notifications.
But here is the problem the authentication (registration) is not done using firebase It's done using the web application because users are not allowed to make their own accounts(it must be given to them), now I find my self in a dilemma because if the authentication is not done using firebase I can't get the fcm token, and therefor I can't send notifications.
My question is there a way to get a device's fcm token without having it authenticating using firebase?
And if that is not possible is there any other way to send notifications in the manner i described?
I think you are mixing two different things.
1) The user registration with the web site (This happens in you web site/application and has nothing to do with FCM).
2) The registration of the device to FCM done through the google account set on the Android Device.
The way this works is that the device register's to FCM, at that point your app receives a "callback" (onTokenRefresh()) from FCM informing you about the new token that was created for the device.
In that callback you call the web site's server and associate the FCM token you received with the account of the user that registered to the website (1). The association would be kept in a table in a database so you can lookup the token by the user id assigned by the web application.
I am following the guide at https://github.com/firebase/quickstart-js/tree/master/messaging which explains how to set up a web app for Firebase Cloud Messaging.
What I'm wondering is how I would incorporate authentication into this process. What I aim to do is to have a user sign in with their Google account to both an Android device and this web application. Afterwards, the Android device would send upstream messages which would be processed by my app server and sent to the web application.
How would the application server connect the user's Google account to each instance id token - created on the webapp and the Android app?
What I'm thinking is that while I send the instance id to the application server, I also send the authenticated user id with it. The app server would be able to match the two instance id tokens together and pass a message along.
Is this process correct?
I'm developing a new chat application that currently works with firebase realtime database and cordova.
I was looking for a backend-less solution since my currently working app doesn't need any server at all apart from a tiny server that its only function is to provide with temporal authorization tokens for the clients.
This tokens allow the client to work directly with firebase without the need for a more expensive and loaded server, and still have a central control for the usage of the app.
By reading the new firebase documentation I believe that the notifications and the firebase cloud messages app can't be used by the client side to post messages, only to listen notifications since all the send message examples expose the server API key, which obviously can't be on the client side.
Is there a way to issue temporal tokens from a central server that can be used by the clients to send messages instead of having to send all the messages to the server and then back to the other devices?
Thanks
Sending downstream messages to devices with Firebase Cloud Messaging requires access to the authorization key. For that reason it should run in a trusted process, such as on hardware you control.
Cloud Functions for Firebase was launched today, which would solve your problem! You can initialize the firebase-admin SDK within your functions code (which runs on Google's servers, not client side), and use it to access FCM. That way you can send messages in response to new database items, or in response to HTTPS requests.
Here's an intro to Cloud Functions for Firebase: https://firebase.google.com/docs/functions/
Here's how you can use firebase-admin to send FCM messages:
https://firebase.google.com/docs/cloud-messaging/admin/send-messages