Problems using the Push notifications API for registering a Push-Device

Hi,
I have a problem with the NC Talk Push API. If this place is the wrong place to ask questions let me know!

I’m trying to subscribe a custom written client with Firebase Messaging to the nextcloud push “service” (https://github.com/nextcloud/notifications/blob/master/docs/push-v2.md#subscribing-at-the-nextcloud-server)

after generating an new SHA key and generating the token Hash from the Firebase Cloud Messaging I’m getting an 400 Response with an “INVALID_DEVICE_KEY”:

Request:

{"format": "json", "pushTokenHash": "3669169ec4dcf07fa65e89e3b169c29cb143b3babc57bbaf7287d577abe250f80ab7ed3208de9b6fe5a41c3e2d38732f82d3639794a2cb83812c3efc989ca5b3", "devicePublicKey": "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEA5SwFt6lUDO1oxRUBE0MYkKnFfCfEv5wfxgblW50yCMcVoLk8gc+z\nUQTZjoKu9OWrk+X2uQkT1nEvOprJml4Hg6RtkNbC32W6xHJ6f7U9QkDq3BY9A7ii\n111GPw0zmcOzOsuiETqFx3qlRxOWnkBPfermx3Khhhk8BOmo1YrN8w37M+dCFk8z\nto5v3SEH5Hd0hw1LlOyMCe5AogvYrEnrTyecj2lgyiyj6mNwdR3ynS0bWDUnMYhG\njhqniaeI5B1xneThZC+JvwwwRnv41YO6kT0H7EcBQEkVoKWsj0ItSmqY5qXmJ2QT\nE+n2XVhz0Rlysho1EHH3WI43xIkS/dIqpQIDAQAB\n-----END RSA PUBLIC KEY-----\n", "proxyServer": "https://push-notifications.nextcloud.com/devices"}

Response:

{
    "ocs": {
        "meta": {
            "status": "failure",
            "statuscode": 400,
            "message": null
        },
        "data": {
            "message": "INVALID_DEVICE_KEY"
        }
    }
}

The Documentation says to the message the following: “The device key does not match the one registered to the provided session token.”

Honestly I do not know what this means :sweat_smile:
Is the device Key the RSA “devicePublicKey” or something else? And why does it have to match something else?
What Session token?
I’ve tried Basic and Barer authentication, but I cannot register any device key beforehand while opaining the session token…

I’m clearly missing something here, already searched the source of the NC-Talk Android app, but this did not help either (https://github.com/nextcloud/talk-android/blob/e187e8c99969d26556baa0464d791e74d2d87a6a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java#L220)

I do not have administrative access to the Nextcloud instance, but Push Notifications work with the official Nextcloud Talk app, so the Problem is definitely on my side.

Thank you for any Help!

Hello. I have not digged into all the details here. Before doing so, I wanted to als if I understood your question correctly or if my gut gives me a better impression.

what I get from the question
You want to create a new client for Android (or mobile to be more generic) to the Nextcloud talk app. You want to send notifications to the user to notify him about newly incoming messages.

What I guessed
You want to write a client for the talk app and want to receive messages by other users from the Nextcloud instance and send ones out during the normal chat operation.

I am asking as there are quite some unclear questions at the end and I would like to help if possible with the real problem. :wink:

Hello,

yes, I built an App which utilizes the Nextcloud Talk API to display, and send messages, and that is working fine already.
What I want to archive are Push-Notifications. I want to get Notified even when my app is in Background or is closed. The Nextcloud Server provides a way to archive this via Google Firebase Cloud Messaging. I want to register a device from my app to the Nextcloud push service.

Recieving and sending messages is not an Problem, just the Notification which I want to display.

I’m following this documentation (https://github.com/nextcloud/notifications/blob/master/docs/push-v2.md#subscribing-at-the-nextcloud-server) and I want to archive that the devices with my app will be notified via push.

Thank you!

1 Like

Is your app a Nextcloud app or some third party, standalone app?

It is an standalone app, written in flutter with the target on Android and iOS

I’m using the REST API to get the data from and to the device.

I reread the last answer and have to correct a bit.

The notification app is a way for other apps and the core to notify the user of events. These notifications will be shown in the web frontend and trigger also notifications by the Nextcloud native mobile app.

The registration with the server is intended to be done by the official app as far as I understand to deploy the messages to all Android devices with the app installed and the Nextcloud server registered. You would register with all notifications of the server not just you’re intended events of the talk. I am also unsure if talk will send events for all messages or only if you have no unread messages in the corresponding chat.

Is this what you are after?

I think it is not possible what you want to do:

Yeah, I also utilize the webdav api from nextcloud, so getting all Notifications would be not an Problem, everything else I would filter out.

As already said, I’m trying to register a new device to the Nextcloud Server and after that to the Push-Proxy, so push notifications can be delivered.

From your screenshot the next paragraph contains information on the Push-Proxy. The Push Proxy is afaik built exactly for this purpose. I want to utilize the Push Proxy, but to register to the Push Proxy I need first to register on the Nextcloud server itself. And there lies my Problem.

Leaving aside the registration API for a second, to push to your application the push proxy need to be aware of multiple things (like push certificate, topic, etc.). This is not done via registration process, but on the proxy side. So this will not work „out of the box“ the way you might imagine.

I think it will not work because you are not using the same developer key like the official android and talk apps

Yeah sure, but therefore is the Push-Proxy.

So we created the push proxy push-notifications.nextcloud.com to protect our users and their data. We took some extra efforts and reduced the available information to a bare minimum for each of the sections.

You can register new devices to this push Proxy, which will proxy the notifications for you.

But before you can use the Push Proxy you’ll need to obtain data from the nextcloud server, and this is the point which is failing.

Again, the documentation (notifications/docs/push-v2.md at master · nextcloud/notifications · GitHub) never states that I need an predefined, private key, since that is the Push-Proxy for.

I know that I have to seperatly register everything at the Push-Proxy (https://github.com/nextcloud/notifications/blob/master/docs/push-v2.md#subscribing-at-the-push-proxy)
but anything I need from this I can obtain with the previous registration on the Nextcloud instance or am I missing something?

For the Proxy-Registration I need

POST /devices

{
  "pushToken": "{{PushToken}}",
  "deviceIdentifier": "{{deviceIdentifier}}",
  "deviceIdentifierSignature": "{{signature}}",
  "userPublicKey": "{{userPublicKey}}"
}

and the response from the Nextcloud registration is

publicKey string (512) rsa2048 public key of the user account on the instance
deviceIdentifier string (128) unique identifier encrypted with the users private key
signature string (512) base64 encoded signature of the deviceIdentifier

So everything is there isnt it? (Pushtoken is the Firebase token, I already have this on the device)