This project provides an API for sending Firebase Cloud Messaging (FCM) notifications dynamically by allowing you to configure the Firebase service account JSON and target multiple Firebase projects. The service is hosted on Vercel, making it accessible at https://fcm-service-provider.vercel.app/.
- Dynamically configure Firebase service accounts per request.
- Support for sending notifications to individual device tokens or to topics for broadcasting.
- Hosted on Vercel with request logs available for monitoring.
service_account(required): The Firebase service account JSON object for the project you wish to use.project_id(required): The Firebase project ID.token(optional): The device token to send a notification to.topic(optional): The topic name to send a notification to (for broadcasting).title(optional): Title of the notification. Default: "Default Title".body(optional): Body of the notification. Default: "Default Body".data(optional): Key-value pair object for custom data to include with the notification.
- Send to a Topic (Broadcast Notification):
{
"type": "service_account",
"project_id": "your-project-id",
"private_key_id": "your-private-key-id",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk@your-project-id.iam.gserviceaccount.com",
"client_id": "your-client-id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk%40your-project-id.iam.gserviceaccount.com"
"topic": "all-users",
"title": "Broadcast Title",
"body": "This is a broadcast notification.",
"data": {
"key1": "value1",
"key2": "value2"
}
}- Send to an Individual Token:
{
"type": "service_account",
"project_id": "your-project-id",
"private_key_id": "your-private-key-id",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk@your-project-id.iam.gserviceaccount.com",
"client_id": "your-client-id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk%40your-project-id.iam.gserviceaccount.com"
"project_id": "your-project-id",
"token": "device_token_here",
"title": "Direct Title",
"body": "This is a direct notification.",
"data": {
"key1": "value1",
"key2": "value2"
}
}200 OK: Notification was sent successfully.400 Bad Request: Missing required fields.500 Internal Server Error: Error occurred during processing.
- Request Logs: Vercel automatically logs all incoming requests and payloads. Logs include sensitive information such as the service account JSON, project ID, tokens, and notification data.
- Ensure that sensitive data is managed responsibly to avoid unintentional exposure.
- Use environment-specific restrictions on your Firebase service accounts.
- Clone this repository to your local machine.
- Install dependencies:
pip install -r requirements.txt
- Deploy to Vercel:
- Use the Vercel CLI to deploy:
vercel deploy
- Use the Vercel CLI to deploy:
Run the Flask app locally:
python app.pyUse tools like Postman or curl to send requests to the hosted endpoint or local server.
- Service Account Security:
- Avoid sharing your service account JSON publicly.
- Rotate keys periodically.
- API Access:
- Implement authentication or IP whitelisting to restrict access to the API.
- Log Management:
- Monitor Vercel logs regularly for unauthorized access attempts or anomalies.
- Configure log retention policies in Vercel if sensitive information is present.
Feel free to contribute to this project by submitting issues or pull requests. Please ensure your changes are well-documented and tested.
This project is licensed under the MIT License. See the LICENSE file for more details.
This example shows how to use Flask 3 on Vercel with Serverless Functions using the Python Runtime.
https://flask-python-template.vercel.app/
This example uses the Web Server Gateway Interface (WSGI) with Flask to enable handling requests on Vercel with Serverless Functions.
npm i -g vercel
vercel devYour Flask application is now available at http://localhost:3000.
Deploy the example using Vercel: