
Firebase Admin SDK for service-account credentials, OAuth2 token caching, JWT auth, and FCM messaging with rich notifications, topics/conditions, plus custom HTTP and crypto support.
A Firebase Admin SDK for Kotlin Multiplatform.
Add the dependency to your build.gradle.kts:
dependencies {
// Core module (required for credentials and authentication)
implementation("digital.guimauve.flareon:core:0.1.1")
// Messaging module (for Firebase Cloud Messaging)
implementation("digital.guimauve.flareon:messaging:0.1.1")
}Flareon supports all Kotlin Multiplatform targets:
First, obtain a service account JSON file from your Firebase Console:
import digital.guimauve.flareon.core.credentials.GoogleCredentials
// Load from JSON string (in production, load the string from a secure location like file or environment variable)
val serviceAccountJson = """
{
"type": "service_account",
"project_id": "your-project-id",
"private_key": "-----BEGIN PRIVATE KEY-----\n...",
"client_email": "firebase-adminsdk@your-project.iam.gserviceaccount.com",
"token_uri": "https://oauth2.googleapis.com/token"
}
""".trimIndent()
val credentials = GoogleCredentials.fromJson(serviceAccountJson)import digital.guimauve.flareon.messaging.FcmService
import digital.guimauve.flareon.messaging.models.*
// Initialize the service
val messaging = FcmService(credentials)
// Send a simple notification
val response = messaging.sendNotification(
token = "device-registration-token",
title = "Hello from Flareon!",
body = "This is a test notification"
)
println("Message sent: ${response.name}")messaging.sendNotification(
token = "device-token",
title = "New Message",
body = "You have a new message",
data = mapOf(
"userId" to "12345",
"messageId" to "msg_001",
"type" to "chat"
)
)val message = FcmMessage(
topic = "news",
notification = FcmNotification(
title = "Breaking News",
body = "Check out the latest updates",
image = "https://example.com/image.png"
)
)
messaging.sendMessage(message)val message = FcmMessage(
token = "device-token",
notification = FcmNotification(
title = "Platform-Specific Notification",
body = "This notification has custom settings per platform"
),
// Android-specific options
android = AndroidConfig(
priority = AndroidPriority.HIGH,
ttl = "3600s",
notification = AndroidNotification(
channelId = "important_updates",
color = "#FF5722",
sound = "default",
notificationPriority = AndroidNotificationPriority.HIGH,
sticky = true
)
),
// iOS-specific options
apns = ApnsConfig(
payload = ApnsPayload(
aps = Aps(
alert = ApsAlert(
title = "iOS Notification",
body = "Custom alert for iOS",
sound = "default"
),
badge = 1
)
)
),
// Web Push options
webpush = WebpushConfig(
notification = WebpushNotification(
title = "Web Notification",
body = "Custom notification for web",
icon = "https://example.com/icon.png",
badge = "https://example.com/badge.png"
)
)
)
messaging.sendMessage(message)val tokens = listOf(
"token1",
"token2",
"token3"
)
val results = messaging.sendNotificationToMultiple(
tokens = tokens,
title = "Bulk Notification",
body = "Sent to multiple devices"
)
// Handle results
results.forEachIndexed { index, result ->
result.onSuccess { response ->
println("Message ${index + 1} sent: ${response.name}")
}.onFailure { error ->
println("Message ${index + 1} failed: ${error.message}")
}
}val message = FcmMessage(
// Target users subscribed to both 'sports' and 'cricket' topics
condition = "'sports' in topics && 'cricket' in topics",
notification = FcmNotification(
title = "Cricket Match Update",
body = "Your team is winning!"
)
)
messaging.sendMessage(message)The core module provides authentication and credential management:
Example:
import digital.guimauve.flareon.core.credentials.GoogleCredentials
val credentials = GoogleCredentials.fromJson(serviceAccountJson)
val accessToken = credentials.getAccessToken() // Automatically cached and refreshedThe messaging module provides Firebase Cloud Messaging (FCM) functionality:
Example:
import digital.guimauve.flareon.messaging.FcmService
val messaging = FcmService(credentials)
messaging.sendNotification(
token = "device-token",
title = "Hello",
body = "World"
)You can provide your own Ktor HTTP client for advanced configuration:
import io.ktor.client.*
import io.ktor.client.plugins.logging.*
val customClient = HttpClient {
install(Logging) {
level = LogLevel.ALL
}
}
val credentials = GoogleCredentials.fromJson(
serviceAccountJson,
httpClient = customClient
)
val messaging = FcmService(
credentials = credentials,
httpClient = customClient
)For advanced use cases, you can provide a custom cryptography provider:
import dev.whyoleg.cryptography.CryptographyProvider
val customProvider = CryptographyProvider.Default
val credentials = GoogleCredentials.fromJson(
serviceAccountJson,
cryptographyProvider = customProvider
)A Firebase Admin SDK for Kotlin Multiplatform.
Add the dependency to your build.gradle.kts:
dependencies {
// Core module (required for credentials and authentication)
implementation("digital.guimauve.flareon:core:0.1.1")
// Messaging module (for Firebase Cloud Messaging)
implementation("digital.guimauve.flareon:messaging:0.1.1")
}Flareon supports all Kotlin Multiplatform targets:
First, obtain a service account JSON file from your Firebase Console:
import digital.guimauve.flareon.core.credentials.GoogleCredentials
// Load from JSON string (in production, load the string from a secure location like file or environment variable)
val serviceAccountJson = """
{
"type": "service_account",
"project_id": "your-project-id",
"private_key": "-----BEGIN PRIVATE KEY-----\n...",
"client_email": "firebase-adminsdk@your-project.iam.gserviceaccount.com",
"token_uri": "https://oauth2.googleapis.com/token"
}
""".trimIndent()
val credentials = GoogleCredentials.fromJson(serviceAccountJson)import digital.guimauve.flareon.messaging.FcmService
import digital.guimauve.flareon.messaging.models.*
// Initialize the service
val messaging = FcmService(credentials)
// Send a simple notification
val response = messaging.sendNotification(
token = "device-registration-token",
title = "Hello from Flareon!",
body = "This is a test notification"
)
println("Message sent: ${response.name}")messaging.sendNotification(
token = "device-token",
title = "New Message",
body = "You have a new message",
data = mapOf(
"userId" to "12345",
"messageId" to "msg_001",
"type" to "chat"
)
)val message = FcmMessage(
topic = "news",
notification = FcmNotification(
title = "Breaking News",
body = "Check out the latest updates",
image = "https://example.com/image.png"
)
)
messaging.sendMessage(message)val message = FcmMessage(
token = "device-token",
notification = FcmNotification(
title = "Platform-Specific Notification",
body = "This notification has custom settings per platform"
),
// Android-specific options
android = AndroidConfig(
priority = AndroidPriority.HIGH,
ttl = "3600s",
notification = AndroidNotification(
channelId = "important_updates",
color = "#FF5722",
sound = "default",
notificationPriority = AndroidNotificationPriority.HIGH,
sticky = true
)
),
// iOS-specific options
apns = ApnsConfig(
payload = ApnsPayload(
aps = Aps(
alert = ApsAlert(
title = "iOS Notification",
body = "Custom alert for iOS",
sound = "default"
),
badge = 1
)
)
),
// Web Push options
webpush = WebpushConfig(
notification = WebpushNotification(
title = "Web Notification",
body = "Custom notification for web",
icon = "https://example.com/icon.png",
badge = "https://example.com/badge.png"
)
)
)
messaging.sendMessage(message)val tokens = listOf(
"token1",
"token2",
"token3"
)
val results = messaging.sendNotificationToMultiple(
tokens = tokens,
title = "Bulk Notification",
body = "Sent to multiple devices"
)
// Handle results
results.forEachIndexed { index, result ->
result.onSuccess { response ->
println("Message ${index + 1} sent: ${response.name}")
}.onFailure { error ->
println("Message ${index + 1} failed: ${error.message}")
}
}val message = FcmMessage(
// Target users subscribed to both 'sports' and 'cricket' topics
condition = "'sports' in topics && 'cricket' in topics",
notification = FcmNotification(
title = "Cricket Match Update",
body = "Your team is winning!"
)
)
messaging.sendMessage(message)The core module provides authentication and credential management:
Example:
import digital.guimauve.flareon.core.credentials.GoogleCredentials
val credentials = GoogleCredentials.fromJson(serviceAccountJson)
val accessToken = credentials.getAccessToken() // Automatically cached and refreshedThe messaging module provides Firebase Cloud Messaging (FCM) functionality:
Example:
import digital.guimauve.flareon.messaging.FcmService
val messaging = FcmService(credentials)
messaging.sendNotification(
token = "device-token",
title = "Hello",
body = "World"
)You can provide your own Ktor HTTP client for advanced configuration:
import io.ktor.client.*
import io.ktor.client.plugins.logging.*
val customClient = HttpClient {
install(Logging) {
level = LogLevel.ALL
}
}
val credentials = GoogleCredentials.fromJson(
serviceAccountJson,
httpClient = customClient
)
val messaging = FcmService(
credentials = credentials,
httpClient = customClient
)For advanced use cases, you can provide a custom cryptography provider:
import dev.whyoleg.cryptography.CryptographyProvider
val customProvider = CryptographyProvider.Default
val credentials = GoogleCredentials.fromJson(
serviceAccountJson,
cryptographyProvider = customProvider
)