[GH-ISSUE #682] Dynamic FCM credentials #500

Open
opened 2026-05-07 00:24:48 +02:00 by BreizhHardware · 22 comments

Originally created by @AndreKR on GitHub (Mar 25, 2023).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/682

💡 Idea
Currently the service URL is configurable but the FCM credentials are hardcoded, so changing them requires building and deploying a new build. I guess the reason is that it's done this way in the tutorial.

But technically there's no reason to do it like that. The credentials could just as well be made dynamic, in particular they could be fetched from the server.

When project_id, mobilesdk_app_id, current_key and storage_bucket have arrived from the server, they can be used to initialize FCM like this:

if (FirebaseApp.getApps(this).size == 0) {
  val builder = FirebaseOptions.Builder()
    .setProjectId(googleServiceJson.getJSONObject("project_info").getString("project_id"))
    .setApplicationId(mobilesdk_app_id)
    .setApiKey(current_key)
    .setStorageBucket(storage_bucket)
  
  FirebaseApp.initializeApp(this, builder.build())
}

💻 Target components
ntfy server + Android app

Originally created by @AndreKR on GitHub (Mar 25, 2023). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/682 :bulb: **Idea** Currently the service URL is configurable but the FCM credentials are hardcoded, so changing them requires building and deploying a new build. I guess the reason is that [it's done this way in the tutorial](https://firebase.google.com/docs/android/setup#add-config-file). But technically there's no reason to do it like that. The credentials could just as well be made dynamic, in particular they could be fetched from the server. When `project_id`, `mobilesdk_app_id`, `current_key` and `storage_bucket` have arrived from the server, they can be used to initialize FCM like this: ``` if (FirebaseApp.getApps(this).size == 0) { val builder = FirebaseOptions.Builder() .setProjectId(googleServiceJson.getJSONObject("project_info").getString("project_id")) .setApplicationId(mobilesdk_app_id) .setApiKey(current_key) .setStorageBucket(storage_bucket) FirebaseApp.initializeApp(this, builder.build()) } ``` :computer: **Target components** ntfy server + Android app
Author
Owner

@binwiederhier commented on GitHub (Mar 25, 2023):

This is mindblowing to me. I did not know this is possible. I'd be happy to support this.

<!-- gh-comment-id:1483812268 --> @binwiederhier commented on GitHub (Mar 25, 2023): This is mindblowing to me. I did not know this is possible. I'd be happy to support this.
Author
Owner

@FingerlessGlov3s commented on GitHub (Apr 14, 2023):

This would be really good news. Is there any ETA on this support?

Also probably not the place to ask but does the FCM, get told the content of the message or does it work like the iOS one with the SHA256?

<!-- gh-comment-id:1508617815 --> @FingerlessGlov3s commented on GitHub (Apr 14, 2023): This would be really good news. Is there any ETA on this support? Also probably not the place to ask but does the FCM, get told the content of the message or does it work like the iOS one with the SHA256?
Author
Owner

@binwiederhier commented on GitHub (Apr 18, 2023):

No ETA, no.

FCM does receive the message contents. The proper place to ask this stuff is Discord/Matrix. Happy to answer questions there.

<!-- gh-comment-id:1513303808 --> @binwiederhier commented on GitHub (Apr 18, 2023): No ETA, no. FCM does receive the message contents. The proper place to ask this stuff is Discord/Matrix. Happy to answer questions there.
Author
Owner

@AndreKR commented on GitHub (Apr 18, 2023):

I'm not currently using ntfy but I probably will again in the future, so at some point I'll most likely contribute this, so far there just wasn't an urgent need.

<!-- gh-comment-id:1513318078 --> @AndreKR commented on GitHub (Apr 18, 2023): I'm not *currently* using ntfy but I probably will again in the future, so at some point I'll most likely contribute this, so far there just wasn't an urgent need.
Author
Owner

@FingerlessGlov3s commented on GitHub (Apr 18, 2023):

Shame about the ETA, one of the main reasons I've not fully moved to ntfy. Once the support is there, I'd be quite happy knowing I'll get the noticaitons.

<!-- gh-comment-id:1513346551 --> @FingerlessGlov3s commented on GitHub (Apr 18, 2023): Shame about the ETA, one of the main reasons I've not fully moved to ntfy. Once the support is there, I'd be quite happy knowing I'll get the noticaitons.
Author
Owner

@binwiederhier commented on GitHub (Apr 18, 2023):

@FingerlessGlov3s You more more than welcome to donate and/or buy a Pro subscription. Maybe that'll change my mind, haha 😄 Other than that, you can of course compile your own or add support yourself. ntfy is after all 100% open source.

<!-- gh-comment-id:1513354258 --> @binwiederhier commented on GitHub (Apr 18, 2023): @FingerlessGlov3s You more more than welcome to donate and/or buy a Pro subscription. Maybe that'll change my mind, haha :smile: Other than that, you can of course compile your own or add support yourself. ntfy is after all 100% open source.
Author
Owner

@FingerlessGlov3s commented on GitHub (Apr 18, 2023):

💸

<!-- gh-comment-id:1513368778 --> @FingerlessGlov3s commented on GitHub (Apr 18, 2023): 💸
Author
Owner

@binwiederhier commented on GitHub (Apr 18, 2023):

image

Who knew?! All you have to do is ask for donations, and you'll get them. Haha. Much appreciated. I promise nothing, but I'll be sure to check it out when I work on Android next.

<!-- gh-comment-id:1513372017 --> @binwiederhier commented on GitHub (Apr 18, 2023): ![image](https://user-images.githubusercontent.com/664597/232827770-8a4ef5da-8244-458d-b076-3ca518f5e321.png) Who knew?! All you have to do is ask for donations, and you'll get them. Haha. Much appreciated. I promise nothing, but I'll be sure to check it out when I work on Android next.
Author
Owner

@FingerlessGlov3s commented on GitHub (Apr 18, 2023):

It's great project, so I wanted to support. Hopefully you'll find some time at somepoint 😊

<!-- gh-comment-id:1513376507 --> @FingerlessGlov3s commented on GitHub (Apr 18, 2023): It's great project, so I wanted to support. Hopefully you'll find some time at somepoint 😊
Author
Owner

@AndreKR commented on GitHub (Apr 18, 2023):

@binwiederhier Maybe you could do the server side (add form fields to paste the four credential values or to paste/upload the google-services.json + API endpoints for the client), then I don't need to look into building the GUI and I can do the Android side then you don't need to look into initializing FCM. 🤷

<!-- gh-comment-id:1513413277 --> @AndreKR commented on GitHub (Apr 18, 2023): @binwiederhier Maybe you could do the server side (add form fields to paste the four credential values or to paste/upload the `google-services.json` + API endpoints for the client), then I don't need to look into building the GUI and I can do the Android side then you don't need to look into initializing FCM. 🤷
Author
Owner

@binwiederhier commented on GitHub (Apr 21, 2023):

@AndreKR You are assuming an implementation in your comment. I was just going to allow people to add their own credentials in the Android app. The ntfy server already has the firebase-file option, which allows you to drop your firebase creds file.

<!-- gh-comment-id:1517882910 --> @binwiederhier commented on GitHub (Apr 21, 2023): @AndreKR You are assuming an implementation in your comment. I was just going to allow people to add their own credentials in the Android app. The ntfy server already has the `firebase-file` option, which allows you to drop your firebase creds file.
Author
Owner

@AndreKR commented on GitHub (Apr 23, 2023):

@binwiederhier I would strongly recommend providing the FCM credentials from the server. Otherwise you would have to fiddle around with 4 values that are not easy to find nor easy to type, every time you want to subscribe to something. That would be terrible UX that can easily be avoided.

I now took a look at both server and client. Some ideas:

  • The server side should be relatively easy. We can't use the firebase-key-file though because that's the wrong file: The my-app-1a2b3c4d5e.json file does not contain the necessary values for the client, we also need the google-services.json file on the server, which we can then provide to the clients.
  • On the client side we currently have this notion of "FCM messages are only available for subscriptions from app_base_url". Since the main goal is that we don't need a custom build anymore to use FCM we have to get rid of that constant.
  • This constant is used in quite a few places, for example when processing poll messages, where we would now have to check which FCM account a message comes from and map it to the corresponding server URL. To keep things a bit simpler (maybe as a first step), we could of course only allow subscription to one FCM account, maybe the configured default server (DefaultBaseURL).
  • On a side note, we also have the keepalive messages, which we technically only need from one server, but I guess processing them from multiple servers wouldn't hurt either.

WDYT?

<!-- gh-comment-id:1518916374 --> @AndreKR commented on GitHub (Apr 23, 2023): @binwiederhier I would *strongly* recommend providing the FCM credentials from the server. Otherwise you would have to fiddle around with 4 values that are not easy to find nor easy to type, every time you want to subscribe to something. That would be terrible UX that can *easily* be avoided. I now took a look at both server and client. Some ideas: * The server side should be relatively easy. We can't use the `firebase-key-file` though because that's the wrong file: The `my-app-1a2b3c4d5e.json` file does not contain the necessary values for the client, we also need the `google-services.json` file on the server, which we can then provide to the clients. * On the client side we currently have this notion of "FCM messages are only available for subscriptions from `app_base_url`". Since the main goal is that we don't need a custom build anymore to use FCM we have to get rid of that constant. * This constant is used in quite a few places, for example when processing poll messages, where we would now have to check which FCM account a message comes from and map it to the corresponding server URL. To keep things a bit simpler (maybe as a first step), we *could* of course only allow subscription to *one* FCM account, maybe the configured default server (`DefaultBaseURL`). * On a side note, we also have the keepalive messages, which we technically only need from *one* server, but I guess processing them from multiple servers wouldn't hurt either. WDYT?
Author
Owner

@rsporsche commented on GitHub (May 4, 2023):

I would also appreciate this feature. Just tried and failed to build the android app myself.

Edit: Managed to get it to work, just needed to sign the apk, but this would still be a nice feature.

<!-- gh-comment-id:1534662187 --> @rsporsche commented on GitHub (May 4, 2023): I would also appreciate this feature. Just tried and failed to build the android app myself. Edit: Managed to get it to work, just needed to sign the apk, but this would still be a nice feature.
Author
Owner

@emigrating commented on GitHub (Sep 1, 2023):

Anyone taken on this for the official app? I'd rather not publish my own app, so being able to use official based on server.yaml config would be dope.

<!-- gh-comment-id:1702577964 --> @emigrating commented on GitHub (Sep 1, 2023): Anyone taken on this for the official app? I'd rather not publish my own app, so being able to use official based on server.yaml config would be dope.
Author
Owner

@AndreKR commented on GitHub (Sep 1, 2023):

Not yet. It would make sense to remove the special role of the DefaultBaseURL but that's quite a bit of work, so I'm a bit reluctant to just start with an implementation as long as we haven't agreed on what the desired implementation will look like. I might also need some guidance from @binwiederhier about some details regarding poll messages here and there.

<!-- gh-comment-id:1702656322 --> @AndreKR commented on GitHub (Sep 1, 2023): Not yet. It would make sense to remove the special role of the `DefaultBaseURL` but that's quite a bit of work, so I'm a bit reluctant to just start with an implementation as long as we haven't agreed on what the desired implementation will look like. I might also need some guidance from @binwiederhier about some details regarding poll messages here and there.
Author
Owner

@jangrewe commented on GitHub (Dec 16, 2023):

I recently came across Ntfy (via Gatus) and set it up on my server, but was a bit disappointed that FCM doesn't work with the published Android app. As mentioned above, it shouldn't be too complicated to enable FCM for self-hosted instances, as i recently set up openHAB Cloud which also does notifications via FCM with their official app.

Maybe their app source is of any help when implementing this for the Ntfy app? 😃
https://github.com/openhab/openhab-android

<!-- gh-comment-id:1858733374 --> @jangrewe commented on GitHub (Dec 16, 2023): I recently came across Ntfy (via Gatus) and set it up on my server, but was a bit disappointed that FCM doesn't work with the published Android app. As mentioned above, it shouldn't be too complicated to enable FCM for self-hosted instances, as i recently set up openHAB Cloud which also does notifications via FCM with their official app. Maybe their app source is of any help when implementing this for the Ntfy app? 😃 https://github.com/openhab/openhab-android
Author
Owner

@FingerlessGlov3s commented on GitHub (Jan 19, 2024):

I would also appreciate this feature. Just tried and failed to build the android app myself.

Edit: Managed to get it to work, just needed to sign the apk, but this would still be a nice feature.

Did you document your process for building the app?

<!-- gh-comment-id:1900488115 --> @FingerlessGlov3s commented on GitHub (Jan 19, 2024): > I would also appreciate this feature. Just tried and failed to build the android app myself. > > Edit: Managed to get it to work, just needed to sign the apk, but this would still be a nice feature. Did you document your process for building the app?
Author
Owner

@user8446 commented on GitHub (Jul 24, 2024):

I found this issue looking for the same request.

Like another post above, my home automation app has this as well if the source is any help:

https://github.com/domoticz/domoticz-android

<!-- gh-comment-id:2248304473 --> @user8446 commented on GitHub (Jul 24, 2024): I found this issue looking for the same request. Like another post above, my home automation app has this as well if the source is any help: https://github.com/domoticz/domoticz-android
Author
Owner

@AndreKR commented on GitHub (Jul 24, 2024):

I'm a bit familiar with the various home automation apps (although I use Home Asssistant myself) and as far as I remember neither of the two allow you to set FCM credentials. To my knowledge someone runs the server for OpenHAB (like Nabu Casa does for Home Assistant) while Domoticz I think has no direct FCM notifications at all.

<!-- gh-comment-id:2248484219 --> @AndreKR commented on GitHub (Jul 24, 2024): I'm a bit familiar with the various home automation apps (although I use Home Asssistant myself) and as far as I remember neither of the two allow you to set FCM credentials. To my knowledge someone runs the server for OpenHAB (like Nabu Casa does for Home Assistant) while Domoticz I think has no direct FCM notifications at all.
Author
Owner

@user8446 commented on GitHub (Jul 24, 2024):

Domoticz does have FCM fully self-hosted. Normally when you log-in the first time on a mobile device it syncs the UUID. If for some reason it doesn't there is even a button in the app to sync it. I can see the UUID from the mobile devices in Domoticz.

Screenshot_20240724-151628


Screenshot 2024-07-24 152513

<!-- gh-comment-id:2248747753 --> @user8446 commented on GitHub (Jul 24, 2024): Domoticz does have FCM fully self-hosted. Normally when you log-in the first time on a mobile device it syncs the UUID. If for some reason it doesn't there is even a button in the app to sync it. I can see the UUID from the mobile devices in Domoticz. ![Screenshot_20240724-151628](https://github.com/user-attachments/assets/96a7610b-7e45-41be-b7a9-f244404c2bd6) --- ![Screenshot 2024-07-24 152513](https://github.com/user-attachments/assets/40263486-dc5f-4006-b3b3-ff26884f411f)
Author
Owner

@kuolemaaa commented on GitHub (Dec 24, 2024):

Is this issue abandoned ? I really would like to have a mechanism to provide FCM creds without rebuild the apk every time

<!-- gh-comment-id:2560891956 --> @kuolemaaa commented on GitHub (Dec 24, 2024): Is this issue abandoned ? I really would like to have a mechanism to provide FCM creds without rebuild the apk every time
Author
Owner

@MatthiasGrandl commented on GitHub (Apr 20, 2026):

@binwiederhier would you be open to contributions here? if yes, would it be acceptable to move the firebase credential config fully to the server and have the android client use whatever the server provides?

<!-- gh-comment-id:4281307992 --> @MatthiasGrandl commented on GitHub (Apr 20, 2026): @binwiederhier would you be open to contributions here? if yes, would it be acceptable to move the firebase credential config fully to the server and have the android client use whatever the server provides?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#500
No description provided.