Firebase web application - authentication and cloud messaging - android

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?

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.

How to send push notification to specific devices

I got two mobile apps for service provider and customer, i need to send push notifications for service provider user once the customer requests a specific service type. So it needs to be filtered and send only for those who can provide such a service. Therefore web api needs to send the notification only for specific users, how can i do that with firebase should i use, device mac or registration id generated by firebase.
Any help
register a new project in FCM console.
Make android/ios and web(for configuration) application.
The first-time app will be loaded it gives device token and store to the database.
by using device token you can send a notification to a particular device.
Reference link:- https://www.djamware.com/post/5c6ccd1f80aca754f7a9d1ec/push-notification-using-ionic-4-and-firebase-cloud-messaging
First you have to get the fire base token from android app.
Register your mobile app in Firebase console.
If you have any user login api and database, send the fire base token while user
login your app and save the token against the user.
Whenever the user request for service you can get the token of the particular user
and send a message to fire base api with that token from server side.
It will automatically send the message to that particular device whoever login your
app.
Make sure you update the token while if other user login your app in same device.

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.

getting device fcm token without authentication (laravel)

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.

Android Google Cloud Messaging between users

I'm trying to use GCM to establish communication between some users. They should send to each other their GPS location. Is it even possible? There is a subscribeToCloudMessage method but I don't know whether it will be useful or not.
Info: Server works fine (Google app-engine) with all the required keys.
It's possible for one app to send a message to another app via Google Cloud Messaging if the sending app knows the registration ID of the recipient app. Usually when a app register to Google Cloud Messaging, it sends it's Registration ID to a server, and that server sends GCM notifications. If you want the app to send the notifications directly, you must send each device (where the app is installed) the Registration IDs of other devices that it needs to send messages to.

Categories

Resources