Worklight: Push notification without User ID

2019-01-15 16:27发布

问题:

Kindly suggest, is it possible to send push notification without having user ID ? Lets say we want to send push messages to all users who have downloaded our App. OR due to security reasons, user IDs can not be stored in the DB (or used within the App).

回答1:

One way or another, you need a way to identify the user. It will come down to what you consider to be a 'userID'. There is a way to distinguish between users without using a permanent userID. You can use the persistent cookie realm. If you add this to your authenticationConfig.xml file:

       <realm name="PersistentCookie" loginModule="WeakDummy">
            <className>com.worklight.core.auth.ext.PersistentCookieAuthenticator</className>
        </realm>

Then a unique ID based on a persistent cookie will be created for the user when they connect to the worklight server:

"PersistentCookie":{"userId":"6410a0f9-98fb-4940-a127-da940c5d7e16","attributes":{},"isUserAuthenticated":1,"displayName":"6410a0f9-98fb-4940-a127-da940c5d7e16"}

No further interaction is required by the user or the developer. Simply adding the class to authenticationConfig.xml is enough to generate the userID.

You can use this cookie to subscribe a user for push notifications. If for security reasons you wish to no longer have this user identified by this persistentCookieID, then you can simply clear the cookies on the application and a new ID will be generated for the user. They will then need to resubscribe for push notifications if a new persistentCookieID is generated.



回答2:

You need a list of subscriptions to send push notification in Worklight and the adapter (server) side API to get all the subscriptions is

WL.Server.getUserNotificationSubscription(eventSource, userId);

So without userId, it is not possible to send push notifications.

I am not sure about security concerns since userID is nothing but username used to login to the app. If both your app and event source have securityTests, then storing subscriptions along with userId is automatically taken care by Worklight.



回答3:

Starting in Worklight 6.2, you can send notification to all users (subscribed or not) using the 'broadcast notification' feature.

For more info, refer to http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.dev.doc/devref/c_push_notif_broadcast.html

To send the broadcast notification, you can use WL.Server.sendMessage( applicationId, notificationOptions ). More info can be found at http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.dev.doc/devref/c_send_push_notifications.html