Firebase Cloud Messaging (FCM) is a great platform for sending push notifications.
This is the default service for sending push notifications to Android devices, but it also enables sending them to iOS devices and web browsers.
Using the Firebase console you can send notifications to specific devices, but if you want to incorporate push notifications into your business logic, you need to authorize a proprietary backend (or an external service) to send notifications on your behalf.
1. Setting up a project in Firebase
- Head to the Firebase console and log in with your Google/GSuite account (and ensure you are on the correct user, because firebase automatically selects your “primary” user).
- If you want to add notifications to an existing project, you can select it and move on to the next part.
- If you want to create a new project, click “Add project” and follow the steps there to name your project and attach it to your organization (you will also see the option to set Google Analytics).
Eventually, you will be redirected to the dashboard.
2. Setting up authorization
In order to send a notification from your backend, you will need to authenticate and authorize with Firebase and have a list of device tokens (a way to identify your notification’s target audience) to send messages to.
In this post, we will be focusing on the former step, as there are many online resources about retrieving and using tokens (also, this is one of many aspects SendMan takes care of for you, if you use our service).
There are two components to authorizing an external service to perform actions using the Firebase API: a database URL and a JSON file containing, amongst other things, a private key. In order to get these:
- Look at the upper-left corner of the dashboard.
- Click on the Settings icon next to “Project Overview”.
- Click “Project settings” in the opened menu.
- In the settings screen, under the “General” tab, there should be a section called “Your apps”. If you have not yet created an app for this project, you should create one on the platform of your choice, following the on-screen guide.
- Go to the “Service accounts” tab in your Settings page, making sure you are in the “Firebase Admin SDK” section (on the left-hand side).
- Click “Create service account” to generate an authenticated identity (managed via GCP’s IAM). A JSON file containing the private key will be downloaded (notice that it contains sensitive data, so keep it safe).
You are done! You now have a JSON configuration file and the database URL that you need for authorization.
Now that you have the configuration for properly authenticating with Firebase, you can read more about sending push notifications to your apps: