getting device fcm token without authentication (laravel) - android

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.

Related

Sending push notification to a specific user in cloud function FCM

Please note that this question is not about getting device token on client side.
I am very new to react-native and firebase and I want to implement push notication service of FCM. What I am planning to do is to send a notification to particular device using its device token on my nodejs app server or cloud function( not through console). But as I have found, FCM doesn't provides any API to accrss token by username. Suppose I want to send notification to user X( for the time being, suppose that one user signs only on single device). Now using the function sendToDevice(), I can send the message to a specific device. But how would I know the device token of user X. Do I need to store tokens in the firebase database by myself? Or can I get along without storing FCM tokens?
Please guide me because firebase docs aren't clear about this.
Save the device token for a particular user in DB and then you can use fcm-node npm in which there is a simple function to send a push to a particular device token.
You also need to use the FCM server key which you will get easily on the firebase console.
FCM doesn't offer a way to associate device tokens to individual users who might be using your app from multiple devices. You will need to write code to associate a device token to a user account by sending that token to your backend, along with the user's ID. Only then can you collect FCM tokens for that user, and message them on any of their devices.

Can Cordova's device.uuid value be used to send Firebase push notification?

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.

How does Firebase generates Device Registration Token?

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.

Firebase web application - authentication and cloud messaging

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?

How to send notifications through android app to all users installed and registered that android app?

Can anyone help me with a way to send requests as a notification through my android app to all the users who have installed my application and then their responses are sent back to the user who sent the request.
I have read about GCM but I dont understand how can I register all the users to get their GCM registration ID and how can i simulataneously send a notification to all users..I may sound naive but I am completely new to this GCM concept and I dont think that it is the exact thing what I am looking for..
So,somebody please tell me how to send notifications(simultaneously on click of a button or something..) to all the users who have registered in my android app .
You will need to build a server component that keeps track of all registered users. This component will be an app that you write and expose in the cloud. There are many app-hosting services to choose from. Amazon EC2 is one example.
So the app flow would be something like this:
User launches your Android app.
Android app registers itself with GMC. GCM will respond with a token that represents that device.
Android app POSTs that device token to your cloud application.
Cloud application saves that token. The app should now have a list of tokens that represents all active devices running your app. (of course you may want to have an expiration policy - i.e. remove all tokens corresponding to devices you have not heard from in say 30 days).
One of your app users posts a message that s/he wants to broadcast.
Your Android app responds by sending a request to your cloud application.
Your cloud application responds to this request, by making a request to GCM. In this request (or series of requests), the app will include all device tokens and the user-entered message.
GCM responds by pushing the message to all devices with your app (i.e. all of those that have register with GCM and received a token - see step 2).
If using GCM alone you would need to write a server component. I get the impression you don't want to do this. You could use Urban Airship push messaging, which will allow you to send out a message to all registered apps from the Urban Airship web portal. Urban Airship integrates with GCM (which is easy to setup). You would still need to add code to your app to handle the push notification the app receives.
http://docs.urbanairship.com/build/android.html

Categories

Resources