Skip to content
Shiny.NET

FCM

The FCM transport sends to Android devices through Firebase Cloud Messaging’s HTTP v1 API, authenticated with a Google service account. It ships in the Shiny.Extensions.Push package (namespace Shiny.Extensions.Push.Fcm) and delivers to registrations with Platform = DevicePlatform.Android.

  1. Open your Firebase project in the Firebase console, or create one. The app and the server must use the same project.
  2. Create a service account key. Go to Project settings → Service accounts and click Generate new private key. The downloaded JSON contains project_id, client_email and private_key. It’s a server secret, so keep it out of source control and out of the app.
  3. Check the FCM API is enabled. Project settings → Cloud Messaging should show Firebase Cloud Messaging API (V1) as enabled. If it isn’t, enable the Firebase Cloud Messaging API in Google Cloud.

The app side (adding the Android app and google-services.json) is covered in the client Platform Setup → Android.

using Shiny.Extensions.Push.Fcm;
push.AddFcm(o => o.ServiceAccountJsonPath = "firebase-service-account.json");
// or from a secret store
push.AddFcm(o => o.ServiceAccountJson = builder.Configuration["Push:FcmServiceAccount"]);
Option Description
ServiceAccountJson The service account JSON contents
ServiceAccountJsonPath Path to the service account JSON file
ProjectId Overrides the project_id in the service account (rarely needed)

The provider exchanges the service account for an OAuth token and caches it. Sends are batched up to 500 devices per request (see Sending → Batching).

DeviceToken is the FCM registration token the app reports from IPushDelegate.OnNewToken:

await pushManager.RegisterDevice(new DeviceRegistration
{
DeviceToken = fcmToken,
Platform = DevicePlatform.Android,
DeviceId = installId
});

FCM tokens from an iOS app using Firebase aren’t delivered by this transport, because it only claims Android registrations. See Client Apps.

AndroidPushOptions sets the notification’s ChannelId, Icon, Color and ImageUrl. Data is sent as the FCM data section and CollapseId as collapse_key.

FCM error Status Manager action
UNREGISTERED TokenExpired token pruned
INVALID_ARGUMENT / SENDER_ID_MISMATCH InvalidToken token pruned
QUOTA_EXCEEDED / UNAVAILABLE, HTTP 429 / 503 RateLimited surfaced (no auto-retry)

SENDER_ID_MISMATCH usually means the app and the server use different Firebase projects.