I have an application where each user must receive notifications relevant only to themselves.
To do this, I have created a unique channel name for each user. I subscribe to this channel when the user logs in from the browser using javascript.
pubnub = PUBNUB.init({
subscribe_key : '<subscriber-key>'
});
pubnub.subscribe({
channel: "<unique-channel-name>",
})
My question is, if someone gets the name of a user's unique channel, they can setup their own pubnub client and receive the notifications without any authorization? Basically, all that is protecting my user's data is a channel name and subscriber key that are publicly available in the source-code of the page. I looked the pubnub's access manager, but it suffers from the same problem, does it not? If someone opens the source code and copies the auth-key, they can setup their own client and receive messages?
Edit: Additional information
I generate and save a channel name for every user when they sign up. This name is a random UUID like "7304cd62-9ba2-4842-98d8-8a5c8e561275." When I want to notify a user that, let's say, they got a friend request, I pull the channel name from the database and publish a notification. Whenever they login, the rendered page uses Ruby to inject their channel name, and my subscriber key into a hidden field which javascript uses to initialize pubnub.
<%= my_pubnub_subscriber_key %>
<%= current_user.channel.name %>
In this case, using Access Manager would mean that I will have to store an auth key in addition to the channel name and authorize the key to read the channel.
John
- john-channel
- john-key-authorizing-read-on-john-channel
Jane
- jane-channel
- jane-key-authorizing-read-on-jane-channel
The rendered page will then have three fields to initialize pubnub:
<%= my_pubnub_subscriber_key %>
<%= john-channel %>
<%= john-key %>
The original problem remains. If Jane goes to John's house, opens the source-code of John's homepage, copies the 3 keys, goes back home and create her own client, she can subscribe to the John's notifications. I can't know if the receiver of my notifications is actually logged in or just copied the keys.
Is my thinking right that to secure against such a possibility, I should simply regenerate the channel name or auth key regularly, such as when a user logs out or daily?