Permissions

Control who can access channels and user metadata in your chat app. Define permission schemas to protect against unauthorized access.

Examples:

  • Restrict channel/profile modifications to specific users
  • Allow only admins to remove users from channels

Chat SDK limitations (client-side only):

  • Channel membership restrictions (direct, group, public)
  • Feature availability errors in public chats (typing indicator, invites, read receipts)

Use Access Manager for strict server-enforced access rules. Chat SDK exposes all JavaScript SDK methods including Access Manager.

Required configuration​

  1. Enable Access Manager in the Admin Portal.
  2. Initialize Chat SDK:
    • Server: with secretKey to administer permissions
    • Client: with authKey to authenticate users

See Moderation for examples.

Secret key security

Never expose secretKey to clients. If compromised, generate a new one in the Admin Portal.

Use Access Manager​

Available methods:

Channel group limitation

Chat SDK doesn't support channel groups. Use a core SDK for channel groups.

Resource permissions​

Define operations users can perform on PubNub resources:

Resource typePermissions
channelsread, write, get, manage, update, join, delete
uuidsget, update, delete

See Moderation for muting/banning with Access Manager.

Example​

Grant support-agent the read type of access to a group channel called priority-tickets and write type of access to all public channels. Granted access must expire after 15 minutes.

1try {
2 const token = await chat.sdk.grantToken({
3 ttl: 15,
4 authorized_uuid: "support-agent",
5 resources: {
6 channels: {
7 "priority-tickets": {
8 read: true
9 },
10 },
11 },
12 patterns: {
13 channels: {
14 // wildcard pattern that refers to all channels whose IDs start with the "public" prefix
15 "public.*": {
show all 23 lines

Operations-to-permissions mapping​

Access levels determine user operations. Example: write on channels allows sending messages via sendText().

The tables below map permissions to Chat SDK operations.

Pub/Sub​

PubNub operationResource type(s)PermissionChat SDK method(s)
Publish on channelschannelswriteSend text messages (sendText())

Send messages with referenced channels and user mentions (send())

Forward messages (forward(), forwardMessage())

Create and send events (emitEvent())

Report messages (report())
Send signals to channelschannelswriteTyping indicator methods

Create and send events (emitEvent())
Subscribe to channelschannelsreadTyping indicator methods

Receive events (channel.onCustomEvent())

Receive messages (onMessageReceived())

Membership updates (onUpdated(), onDeleted())

Channel updates (onUpdated(), onDeleted())

Messages updates (onUpdated())

User updates (onUpdated(), onDeleted())
Subscribe to presence channelsPresence channels (<channel-name>-pnpres)readn/a
Unsubscribe from channelschannelsNone requiredStop receiving typing signals, events, messages, updates on membership, channels, messages, and users

Presence​

PubNub operationResource type(s)PermissionChat SDK method(s)
Here NowchannelsreadChannel presence (whoIsPresent())
Where NowchannelsNone requiredChannel presence (wherePresent(), isPresentOn(), isPresent())

Message Persistence​

PubNub operationResource type(s)PermissionChat SDK method(s)
Fetch historical messageschannelsreadgetHistory()
Message countschannelsreadUnread messages (getUnreadMessagesCount(), fetchUnreadMessagesCounts())
Delete messageschannelsdeletedelete()

File sharing​

PubNub operationResource type(s)PermissionChat SDK method(s)
Send files on channelschannelswritesendText()
List fileschannelsreadgetFiles()
Delete fileschannelsdeletedeleteFile()

App Context​

PubNub operationResource type(s)PermissionChat SDK method(s)
Set user metadatauuidsupdateCreate users (createUser())

Update user metadata (update(), updateUser())
Delete user metadatauuidsdeletedeleteUser(), delete()
Get user metadatauuidsgetGet user data (getUser())

Track mentions (onChange())
Get all user metadatauuidsYou don't need to specify permissions to enable it if you uncheck the Disallow Get All User Metadata option in the App Context configuration in the Admin Portal.chat.getUsers()
Set channel metadatachannels

When working with threads, also grant permissions to PUBNUB_INTERNAL_THREAD channels.
update, getCreate channels (createDirectConversation(), createGroupConversation(), createPublicConversation())

Update channels (update(), updateChannel())

Pin messages (pin(), pinMessage())

Threads (createThread(), pinMessage(), pinMessageToParentChannel(), pinToParentChannel(), unpinMessage(), unpinMessageFromParentChannel(), unpinFromParentChannel())
Delete channel metadatachannelsdeletedelete(), deleteChannel()
Get channel metadatachannelsgetGet channel details (getChannel())

Get pinned messages (getPinnedMessage())

Get thread (getThread())
Get all channel metadatachannelsYou don't need to specify permissions to enable it if you uncheck the Disallow Get All Channel Metadata option in the App Context configuration in the Admin Portal.chat.getChannels()
Set channel memberschannelsmanageInvite multiple users to channels (inviteMultiple())

Mute/Ban users (setRestrictions())
Remove channel memberschannelsmanageUnmute/Unban users (setRestrictions())
Get channel memberschannelsgetGet members (getMembers())

Check restrictions (getUserRestrictions(), getUsersRestrictions(), getChannelsRestrictions(), getChannelRestrictions())
Set channel membershipschannels, uuidsjoin on channels
update on uuids
Create channels (createDirectConversation(), createGroupConversation())

Invite a user to a channel (invite())

Join channels (join())

Update membership (update())

Unread messages (setLastReadMessage(), markAllMessagesAsRead())
Remove channel membershipschannels, uuidsjoin on channels
update on uuids
Leave channels (leave())
Get channel membershipsuuidsgetList channels (getChannels()), getMemberships()

Mobile Push Notifications​

PubNub operationResource type(s)PermissionChat SDK method(s)
Register channel for pushchannelsreadregisterForPush(), registerPushChannels()
Remove channel's push registrationchannelsreadunregisterFromPush(), unregisterPushChannels()

Message Reactions​

PubNub operationResource type(s)PermissionChat SDK method(s)
Add message reactionchannelswritetoggleReaction()
Remove message reactionchannelsdeletetoggleReaction()
Get history with reactionschannelsreadgetHistory()

Was this page useful?

Last updated on