binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
17.6k stars 681 forks source link

Dynamic FCM credentials #682

Open AndreKR opened 1 year ago

AndreKR commented 1 year ago

: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.

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

binwiederhier commented 1 year ago

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

FingerlessGlov3s commented 1 year ago

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?

binwiederhier commented 1 year ago

No ETA, no.

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

AndreKR commented 1 year ago

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.

FingerlessGlov3s commented 1 year ago

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.

binwiederhier commented 1 year ago

@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.

FingerlessGlov3s commented 1 year ago

💸

binwiederhier commented 1 year ago

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.

FingerlessGlov3s commented 1 year ago

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

AndreKR commented 1 year ago

@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. 🤷

binwiederhier commented 1 year ago

@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.

AndreKR commented 1 year ago

@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:

WDYT?

rsporsche commented 1 year ago

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.

emigrating commented 11 months ago

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.

AndreKR commented 11 months ago

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.

jangrewe commented 8 months ago

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

FingerlessGlov3s commented 7 months ago

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?

user8446 commented 4 weeks ago

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

AndreKR commented 4 weeks ago

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.

user8446 commented 4 weeks ago

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