Skip to main content
Version: 1.1.4

Firebase Push Connector

Push notifications via Firebase Cloud Messaging (FCM) HTTP v1 API.

Package

dotnet add package Ratatosk.Firebase

Configuration Settings

ParameterTypeRequiredIs SecretDefaultDescription
ProjectIdstringYesNoFirebase project ID
ServiceAccountKeystringYesYesService account JSON key content
DryRunboolNoNofalseValidate without sending

Notes:

  • ServiceAccountKey is marked as sensitive and will be redacted in logs
  • ServiceAccountKey must be the complete JSON content, not a file path
  • DryRun=true is recommended for testing message validation

Configuration Examples

Connection String

Basic:

ProjectId=my-project-id;ServiceAccountKey={"type":"service_account",...}

With Dry Run:

ProjectId=my-project-id;ServiceAccountKey={"type":"service_account",...};DryRun=true

With Timeout:

ProjectId=my-project-id;ServiceAccountKey=...;Timeout.Send=00:00:30;Timeout.RetryOnTimeout=true

Note: For connection strings with JSON values, use quoted values:

ProjectId=my-project;ServiceAccountKey='{"type":"service_account","project_id":"my-project"}'

From appsettings.json

{
"Firebase": {
"ProjectId": "my-project-id",
"ServiceAccountKey": "{\"type\":\"service_account\",\"project_id\":\"my-project\",...}",
"DryRun": false,
"Timeout": {
"Send": "00:00:30"
},
"Retry": {
"MaxAttempts": 3
}
}
}
builder.Services
.AddMessaging()
.AddConnector<FirebasePushConnector>(cfg => cfg
.WithSettings("Firebase"));

Schema

PropertyValue
ProviderFirebase
TypePush
Version1.0.0
CapabilitiesSendMessages, BulkMessaging
Content typesPlainText, Json
EndpointsDevice (FCM token), Id (topic)
AuthenticationFirebase service account JWT

Send examples

Notification to a device token

var settings = new ConnectionSettings()
.SetParameter("ProjectId", "my-project")
.SetParameter("ServiceAccountKey", serviceAccountJson);

var connector = new FirebasePushConnector(FirebaseChannelSchemas.FirebasePush, settings);
await connector.InitializeAsync(ct);

var message = new MessageBuilder()
.WithId("push-1")
.To(Endpoint.Device("fcm-device-token-here"))
.WithText("You have a new notification")
.WithTitle("New message")
.Build();

var result = await connector.SendMessageAsync(message, ct);

Notification to a topic

new MessageBuilder()
.WithId("push-topic-1")
.To(Endpoint.Id("/topics/news"))
.WithText("Breaking news: ...")
.WithTitle("News alert")
.Build();

Push with custom data payload

new MessageBuilder()
.To(Endpoint.Device("fcm-token"))
.WithContent(new JsonContent("{\"order_id\": \"ORD-123\", \"status\": \"shipped\"}"))
.WithTitle("Order shipped")
.WithSound("default")
.WithBadge(1)
.Build();

Batch push to multiple devices

var batch = new MessageBatch();
foreach (var token in deviceTokens)
{
batch.Messages.Add(new MessageBuilder()
.WithId(Guid.NewGuid().ToString("n"))
.To(Endpoint.Device(token))
.WithText("You have a new message")
.WithTitle("New message")
.Build());
}

var result = await connector.SendBatchAsync(batch, ct);

Dry run (validation without sending)

settings.SetParameter("DryRun", true);
// All sends will be validated by Firebase but not delivered

Message properties

PropertyTypeDescription
TitlestringNotification title
soundstringSound file to play (e.g., "default")
badgeintBadge count for the app icon
imagestringImage URL for rich notifications
click_actionstringAction to perform on notification tap
prioritystring"normal" or "high"
ttlintTime-to-live in seconds

Authentication

Firebase uses OAuth 2.0 with a JWT signed by the service account's private key. The FirebaseServiceAccountAuthenticationProvider handles this automatically:

  1. Reads ProjectId and ServiceAccountKey from settings
  2. Creates a signed JWT with the service account's private key
  3. Exchanges the JWT for a Firebase OAuth 2.0 access token
  4. Caches the token and refreshes it before expiry

Error codes

Firebase-specific error codes are defined in FirebaseErrorCodes with domain "Firebase".

CodeDescription
MISSING_SERVICE_ACCOUNT_KEYService account key is missing or invalid
MISSING_PROJECT_IDFirebase project ID is missing
INITIALIZATION_FAILEDFirebase app initialization failed
UNREGISTERED_TOKENDevice registration token is no longer valid
INVALID_ARGUMENTRequest contains an invalid argument
SENDER_ID_MISMATCHSender ID does not match the registered token
THIRD_PARTY_AUTH_ERRORThird-party authentication error occurred
SERVICE_UNAVAILABLEFCM service is temporarily unavailable
INTERNAL_ERRORInternal error in the Firebase service

Standard MessagingErrorCodes are also used — see the error codes reference.

Original provider codes

Firebase Admin SDK errors (FirebaseMessagingException) are mapped to framework error codes in FirebaseService.MapFirebaseErrorCode():

FCM MessagingErrorCodeMapped framework code
InvalidArgumentINVALID_ARGUMENT
UnregisteredUNREGISTERED_TOKEN
SenderIdMismatchSENDER_ID_MISMATCH
QuotaExceededRATE_LIMIT_EXCEEDED
ThirdPartyAuthErrorTHIRD_PARTY_AUTH_ERROR
UnavailableSERVICE_UNAVAILABLE
InternalINTERNAL_ERROR
OtherSEND_MESSAGE_FAILED

Troubleshooting

SymptomLikely causeFix
INVALID_CREDENTIALSWrong ProjectId or ServiceAccountKeyVerify in Firebase Console → Project Settings → Service Accounts
INVALID_RECIPIENTInvalid FCM tokenToken may be stale; request a new token from the client
PROVIDER_VALIDATION_FAILEDPayload too largeFCM limit is 4096 bytes for most payloads
Device not receivingToken was unregisteredRemove token from your store; Firebase returns UNREGISTERED
Topic send failingTopic doesn't existTopics are auto-created; verify the format starts with /topics/
Token expiredToken refreshedListen for token refresh on the client and update your store

FirebaseChannelSchemas

// Push notification schema
FirebaseChannelSchemas.FirebasePush