I have a Progressive Web Apps project which is using firebase cloud messaging service for push notifications. It was working fine but since last month, I am not able to receive push notifications anymore.
I checked and found out that the firebase access token was not getting generated on the client side.
Method call - firebase.messaging().getToken()
which in turn hits the following api :
POST https://fcm.googleapis.com/fcm/connect/subscribe
But surprisingly, for one firebase account, I am able to generate an access token, but for another app, I am not able to generate the access token.
Click here for the error log in the chrome network tab
I should have got the access token by using firebase.messaging().getToken() just like I am getting in my other projects.
Related
I've added my project to firestore and I'm doing firestore google auth just fine.
My problem is firebase firestore.
It just doesn't work and I have no idea why.
I'm trying to do a simple add before doing the actual process for my app and it doesn't work.
here I implemented a simple function to add a user and then called it, doing it all in build function.
I get this in my console:
p.s.
"adding user" is printed on console.
p.s.
I do have the firebase_options.dart file.
These thing are you sure that the correct:
1.Using correct google_services.json file
2.Edit Fire store rules if you are not using authorization
You have to manually whitelist your existing Google OAuth 2.0 client IDs in the Firebase console before using it with the new Auth APIs.
In order to do so, follow these steps:
Go to the Credentials section in the Google API Console.
Select from the top right corner the project where you had previously configured Google Sign-In.
Go to the OAuth 2.0 client IDs section
If you are using Google Sign-In on Android or iOS applications:
Take note of the Client ID string corresponding to all the entries registered for your applications.
Input these Client IDs into your Firebase project’s configuration:
Go to the Firebase console at https://console.firebase.google.com
Open the Auth section
Under Sign-In methods, open the Google configuration, and add there all you client IDs, to the whitelist of client IDs from external projects.
If you are using Google Sign-In on a web application:
Click to open your web client ID and take note of both the client ID and secret.
Input this Client ID into your Firebase project’s configuration:
Go to the Firebase console at https://console.firebase.google.com
Open the Auth section
Under Sign-In methods, open the Google configuration, and add the values under the Web SDK configuration section.
Start Notes :
When a mobile application starts with Firebase enabled, the first thing that happens is Firebase creates a Token ID for the device on that app.
This requires the device to connect to the Firebase server, and register the device with all the required data about the device.
Unfortunately this cannot happen if the device has blocked access to the Firebase server.
Searches :
As I know, there is a Firebase Admin API on the server side, that can be used to create functions and probably one of them is to create a custom Token ID and register the device using that ID.
However, searching Firebase Docs, only creating a Custom Auth ID appeared
Create Custom Tokens
But this Token ID is not for the device, it is for the user on the device (i.e, Firebase Authentication API).
Goal :
What I want to do, is handle the entire Token ID process from the server side, so that even a Firebase blocked device can be registered on Firebase.
Question :
What is the method of creating a Firebase Token ID on the server that also registers the device as a user with its data (Device Name, OS, etc)?
Is there such a process? Or does Firebase exclusively register the device from the client side?
Side Notes :
I believe it is possible, as some applications that obviously use Firebase Messaging are available for use even when Firebase's access is blocked.
Examples : Discord, Telegram.
The token ID is managed by the client device. The backend and admin SDK are not involved in this process. It's the responsibility of the client app to send this token to you backend, if you need to target the app for use with Cloud Messaging. If the app is temporarily unable to reach your backend, you will have to retry sending the token until it's able to reach the backend.
I need to handle social activity events in my web app application developed using Vue JS framework and Firebase.
I want to show to the user “Facebook like” notifications when some activity happen in the application, for example:
“John liked your post”.
Is Firebase Cloud Messaging useful for this scenario? Or do I have to develop some custom solution from scratch?
If Firebase Cloud Messaging do the job, is it possible to send messages directly from user web client?
You should not try to send messages directly from the web client. FCM is intended to be used via a secure backend where your code runs to send messages. The reason a backend is needed is to prevent your private server key from being exposed to the world, which can cause security issues in your app.
You will have to arrange on your backend to determine when events occur that should generate messages, and use the Firebase Admin SDK to send those message, or work with the REST API directly.
I have my client app with Android installed in several devices.
I also have my Server app that send messages to those apps.
The problem is that some devices receive the messages and other don't.
I get the error "MismatchSenderId" when sending the message to those devices.
I divided the problem, so I open the firebase console and send notifications to my apps (I have the Token for each of them). So, using the console app, I get errors on the same devices that using my server. But as I said, every device is using the same app.
Any help of the reason?
So to start of, I'd point out the description for MismatchSenderId error:
A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.
As per our discussion, it was pointed out that you created a new Firebase Project instead of importing your Google Project that you were using for GCM. From the new project, the google-services.json was generated and used for the app, which resulted for new tokens to be associated with the new Project's Sender ID. To visualize it properly:
GCM Registration Tokens > only receive messages from > Google Project (1st)
New Tokens > only receive messages from > Firebase Project (2nd)
As a solution, I advised for you to import the Google Project to the Firebase Console, generate a google-services.json from that Project and replace the one in your app with that, which associates the app to that (correct) project. This in turn created tokens that are now associated with your 1st Project.
GCM Registration Tokens > only receive messages > Google Project (1st)
New Tokens > now receive messages > Firebase Project (2nd) Imported Google Project (1st)
Hope that makes sense.
Good to mention from the discussion:
After applying the changes, you mentioned that the error persisted, but it was a different issue that was fixed by simply using the Server Key.
Linked a post during discussion.
Supporting #AL's answer, basically you need to uninstall the app on all the devices and install the app again so that all devices receive new tokens that correspond with the newly connected firebase project database.
Need to enable the following api in the Google Console (https://console.cloud.google.com/)
Firebase Cloud Messaging API
Cloud Messaging
Then your senderId will be identified
We have implemented Firebase Google Authentication With Google Cloud Endpoints in our APIs . The code is going fine with all the APIs of our project.
But we are also using the Picker API JavaScript Library: https://developers.google.com/picker/docs/ .
So when we attach any document from our drive, the Picker API prompts the Google sign-in once again, which is not done via Firebase but is the default one provided by the Picker API. The token returned for the same user via this Picker API is not the same as the ID token returned by the Firebase login. This makes the login not able to verify this user.
We are using this token to verify the Firebase one:
user = google.oauth2.id_token.verify_firebase_token(id_token, HTTP_REQUEST)
This gives us a 401 Unauthorized Error and our logs read the following :