Update UserID and PhoneNumber in PUSH_DEVICES table - push-notification

Using MFP 8, Related to PUSH NOTIFICATION and USERLOGIN Security check, If i register a device, I can see in MFP CONSOLE (DEVICE SECTION) and PUSH_DEVICES Table as well.
In PUSH_DEVICES table (UserId is anonymous) and phonenumber is empty.
How to update these 2 from app (NOT BY REST SERVICE) ?
if the userid is anonymous, i cannot see the USERID and DISPLAY NAME in DEVICES Section of MFP CONSOLE as well

Push device registration and subscription takes an independent path. These steps have to be done separately.
However, the user identity assigned against Push device registration and subscription flows from identity created using the securitycheck that maps to "push.mobileclient".
If you see "anonymous" user against your push registration, this normally happens when you make the push registration when an identity has not already been established with the secuirtycheck.
Verify your application code flow and ensure you do MFPPush.registerDevice() only after authentication is complete. You can use network traffic analysis to understand your current sequence.

Related

MFP 8 Push Notification to Particular USER ID

Trying to send Push Notification based on DEVICE_ID, In MFP 8 Console, My device ID is showing under DEVICES section but if i try to send notification, Console throws error as "An error occurred while the notification was sent. Internal server error. No devices found."
Scope - push.mobileclient
Initialize, isPushSupported and then RegisterDevice is triggered and in logs, it shown the token as well. how to resolve ?
Device registration showing up in the Devices console does not mean that push registration is successful. Even if push registration is complete, it will depend entirely on the application logic that there is a user identity associated with the subscription.
When you attempt to send notification by userid and it says "No devices found", this means that there are no subscriptions against this userid. It is possible there is no subscription at all , or the subscriptions have been made against a different user - or even anonymous user.
Use get push registrations and get push subscriptions REST calls to verify your current registration and subscription. If these are with anonymous user identity verify your scope -> security check mapping and your application logic.

Push notifications by username

I have been looking for ways to send notifications to specific users and what I found was that I need the device token to do that.
I have tried Firebase and Ionic Cloud Service to do some pushs and it worked fine, but I'm wondering if it's possible to register a service with a key -> value, for exemple, register with the username and the token. If so, how can I do it?
And what is the best service to do it?
Thank you in advance for the help.
P.S.: I'm not asking for code, just the theory.
From you question [for example, register with the username and the token. If so, how can I do it?] I understand following.
You mean to say, there is a mobile app, which user will sign up to use and you want to send the notification to registered user i.e. get send push notification by username.
To solve this, you can follow the steps mentioned below.
On app launch when you get FCM registration token, save it to some intermediate location such as local storages along with device-id, mobile details etc..
Create a backend API which can save username and registration token in DB.
When a user signs up or signs in, then fetch the registration token from local storages, post username, token to backend API to save it. You can make backend API bit intelligent to handle multiple devices of the single user, distinguishable by device-id, mobile details.
Then while sending API from the backend, you can fetch all registration ids of a single user and send the notification to that users using all tokens of that user in FCM API. Use registration ids as JSON array in "registration_id" field. FCM Document - link.

Adding registration tokens in an empty device group throws bad request in Firebase

We have one device group per user for our mobile app. When a new user sign up, a new device group with registration token is created via create operation from app server and its notification key is stored with user data.
When a user sign out of the app, its registration token is removed from the notification key via remove operation as we don't want to send personal notification for that user to that device anymore. This step returns same notification key.
When a user sign in again, we try to add the registration token via add operation using the stored notification key. This action returns 400 (Bad Request) status from Firebase server.
Is this expected behavior? If so, how to handle the above use-case?
Notification key for a device group is removed as soon as the token count reaches zero.
I ended up using topics instead of device groups for this use case.

IBM MobileFirst V7.1 Push Notification Issue

We are developing hybrid mobile application in IBM MobileFirst V7.1,Java 1.7v.
In this application we are developed push notification using Adapter Based Authentication.
In our application we are sending push notification using Adapter based Authentication.
The notification is delivered based on userId.
Here for first time to a particular userId,I'm able to send notification.
After that when user trying with another userId I'm unable to send notification,getting an error "user already exist please logout".
Error in Log:
Cannot change identity of an already logged in user in realm 'pushAppRealm'. The application must logout first.
for this in client side I'm checking whether user is authenticated or not by using "WL.Client.isUserAuthenticated(realm)" ,it is always retuning false.
I also tried with logout option when user clicks on login button I'm logging out the user and again authenticating the user -
here also I'm facing same issue "user already exist please logout".
Push notifications should be dispatched from the server , not from the client.
In your flow, the very first time you authenticate , you will assign a user identity into your user realm. Now from the client , you invoke the adapter procedure that sends out the notification.
The second time around , you pass another userid. This time you try to authenticate again with the another user (all within the same session). It amounts to forcing a new identity when the realm already has one.
This is why you see message in the server that says - "Cannot change identity of an already logged in user in realm 'pushAppRealm'. The application must logout first."
The right approach to be adopted is :
Authenticate into the realm.
Subscribe for Push. This assigns the user identity from 1) to your subscription.
Either use poll mechanism or REST API calls to dispatch notification. Pass the userids as arguments in the REST calls.

Best practices for push notifications in multi user applications?

I'm working on a push architecture that needs to support applications which allow for multiple users. This means more than one user can log into the application with their credentials. The problem I'm running into is what if user A allows push notifications, then logs out, then user B logs in and starts getting user A's push notifications?
What are some best practices for handling this type of thing? One thought I had was you could remember the last user who logged in and only display push notifications to the "logged in" user. You would have to send some sort of user context in the message payload so it could be checked against the logged in user. However this feels a little funky.
Anyone else ran into this? It's seems like a really relevant problem, especially for tablets where families tend to share the device.
We're implementing this by Registering the device with APSN, getting the device token and sending this to our server through a ws.
On the server side the device token is only associated with the last logged in user.
New app
User A (first ever user) uses IPAD A
Register with APSN, get token
Send token to our servers through ws
Search for token in db, token is new, store it
assign token to USER A
Next user logs into app
Register with APSN, get token
Send token to our servers through ws
Search for token in db, token exists already
Remove connection to USER A
assign token to USER B
SEND Notification to device WITH USERNAME
if username is logged in show it - else dont
Still not perfect as its sent to home screen first so to ALL users
I think your suggestion is acceptable in a multi-user app. It is much simpler to implement this in the client side, than on the server side. The downside is extra bandwidth wasted to send an unneeded notification. But vast majority of the usage is probably single-user so this may not matter much.
The alternative is to track the logged on users on your server and their current reg_ids. This could be more complicated because A could be logged on on multiple devices, then logs out from device 1, and B logs onto device 1, etc. and your server has to track all of these. So probably another table to track the relationships between 'Logged On Users' to 'Reg Ids'.
If you hate the idea of sending unneeded notifications, go with the server route. If you value Keep-It-Simple principle, go with the client route.
Let's suppose users of your app can logging on multi devices.
We have to make two API on server side:
func setUserDeviceNotifyToken(userId: Int, deviceToken: String) {}
func removeUserDeviceNotifyToken(userId: Int, deviceToken: String {}
On your app side, you have to call setUserDeviceNotifyToken API on every Login In and call removeUserDeviceNotifyToken on every logout.
On server side, you can track every user with its deviceNotificationToken and send notification for correct device.
Notice: If your service doesn't suppose to support multi device login with one user, you can handle it just by one updateUserDeviceNotifyToken and pass null for remove user's device token.
Notice 2: Do not let user logout before calling removeUserDeviceNotifyToken API.

Resources