Manage access

PubNub's Access Manager controls access to resources. These include channels and user metadata in real‑time apps. For example, you can set up a one‑to‑one chat room or allow only two authenticated clients (individual users or application instances) to send and receive messages in a specific channel.

Define roles and permissions first. For example, a chat app may have moderators who delete messages and regular users who send messages.

Access Manager controls access to resources. It works by:

You can bind a token to one User ID. Only that User ID is authorized.

Your server requests tokens using an SDK. Not every SDK instance can request tokens. To use Access Manager, first enable it in the Admin Portal. Then set up one of PubNub's SDKs with a secretKey. That server SDK sits between client SDKs and PubNub.

Access Manager integrates with Functions. Use it for server‑side validation and custom logic.

To implement Access Manager, set up a server SDK with a secretKey. The examples below show how.

User ID / UUID

User ID is also referred to as UUID/uuid in some APIs and server responses but holds the value of the userId parameter you set during initialization.

const pubnub = new PubNub({
subscribeKey: 'mySubscribeKey',
publishKey: 'myPublishKey',
uuid: 'myUniqueUUID',
secretKey: 'mySecretKey'
});

To issue a grant request, the client SDK calls your server SDK. The server SDK is the intermediary between clients and PubNub.

Once your server SDK is initialized, you can grant specific permissions to a User ID. The examples below grant the thomas_anderson User ID read access to channel-a and read/write access to channel-b, channel-c, and uuid-d for 15 minutes.

pubnub.grantToken(
{
ttl: 15,
authorized_uuid: "thomas_anderson",
resources: {
channels: {
"channel-a": {
read: true
},
"channel-b": {
read: true,
write: true
},
"channel-c": {
read: true,
show all 29 lines

When you grant permissions, you don’t need to list every resource. With one call, you can grant access to multiple channels, channel groups, and user metadata using RegEx.

Some operations create network events. Examples include joining or leaving a channel and sending a message. Learn how to intercept these events and trigger your business logic.

Last updated on
On this page