Access control & data security

Control who can access resources in your chat app through authentication (identity verification) and authorization (permission management).

Required keyset configuration
To use the GetChannels(), GetChannelSuggestions(), GetUsers(), and GetUserSuggestions() methods in the Chat SDKs with Access Manager, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal.

Custom origin​

A custom origin is a subdomain configured specifically for your application, such as abc.pubnubapi.com. Using a custom origin allows PubNub to route traffic uniquely for your application.

Contact support

To request a custom origin, contact PubNub Support.

Set origin​

The SetPubnubOrigin() method in Unreal Chat SDK allows client devices to configure a custom origin for their PubNub requests.

Method signature​

1UPubnubChatAccessManager::SetPubnubOrigin(FString Origin)

Input​

* required
ParameterDescription
Origin *
Type: FString
The custom origin to be set for PubNub requests.

Output​

TypeDescription
int0 if the origin is set successfully, +1 if it will be applied on reconnect, -1 if setting the origin is not enabled.

Sample code​

Actor.h​
1

Actor.cpp​
1

Get origin​

The GetPubnubOrigin() method returns the current PubNub origin (host) used by the underlying client.

Method signature​

1UPubnubChatAccessManager::GetPubnubOrigin()

Output​

TypeDescription
FStringThe current origin string, or empty if not set.

User authentication​

Authentication verifies user identity. The Chat SDK does not include built-in authentication. Implement your own system using:

  • Username/password login
  • Token-based authentication
  • Single Sign-On (SSO)
  • Two-factor authentication (2FA)
  • OAuth or external identity providers

User authorization​

Authorization controls what authenticated users can do. Use Access Manager to:

  • Grant or deny access to channels and users
  • Define permissions for reading, writing, and managing data
  • Protect private channels and user metadata

For details on client-server-PubNub interactions, see the authorization workflow.

Access Manager

Access Manager is available in Unreal SDK, not Unreal Chat SDK.

As long as the tokens with correct permissions are granted and set in the client that uses Unreal Chat SDK, it doesn't matter which SDK grants them.

Token permissions​

When you use Access Manager, your client application receives a token that governs access levels and operations. Use the AccessManager->CanI() method to check if a client has permissions for a specific action on a given resource.

Method signature​

1AccessManager->CanI(
2 EPubnubChatAccessManagerPermission Permission, EPubnubChatAccessManagerResourceType ResourceType,
3 FString ResourceName
4);
* required
ParameterDescription
Permission *The operation type to check if the current user has permissions for.
ResourceType *The resource type to check if the current user has permissions for.
ResourceName *
Type: FString
The name of the resource, for example, a channel name or a user ID.

EPubnubChatAccessManagerPermission​


Enum ValueDescription
PCAMP_ReadRead permission for a resource.
PCAMP_WriteWrite permission for a resource.
PCAMP_ManageManage permission for a resource.
PCAMP_DeleteDelete permission for a resource.
PCAMP_GetPermission to get details of a resource.
PCAMP_JoinPermission to join a channel.
PCAMP_UpdatePermission to update a resource's details.

EPubnubChatAccessManagerResourceType​


Enum ValueDescription
PCAMRT_UsersResource type for Users.
PCAMRT_ChannelsResource type for Channels.

Output​

TypeDescription
boolWhether or not the client has permissions to perform the requested operation on the requested resource.

Sample code​

Reference code

This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.

Check if the current user can send messages to the customer_XYZ channel.

Actor.h​
1

Actor.cpp​
1

Token management​

The UPubnubChatAccessManager class provides methods for managing authentication tokens.

Set token​

Use SetAuthToken() to update the client's authentication token. The token contains embedded permissions that define access to PubNub resources.

Method signature​

1void UPubnubChatAccessManager::SetAuthToken(FString Token)

Input​

* required
ParameterDescription
Token *
Type: FString
The authentication token with embedded permissions.

Sample code​

Actor.h​
1

Actor.cpp​
1

This method does not return any response value. If the operation fails, ensure the token is valid and properly formatted.

Parse token​

Use ParseToken() to decode an existing token and inspect its permissions and metadata (TTL, authorized user ID).

Method signature​

1FString UPubnubChatAccessManager::ParseToken(FString Token)

Input​

* required
ParameterDescription
Token *
Type: FString
The authentication token to decode.

Output​

TypeDescription
FStringA string containing the token's permissions and metadata.

Sample code​

Actor.h​
1

Actor.cpp​
1

Example output​

The server returns the permissions in a CBOR format. You can Base 64 decode it, and parse with any a CBOR parser.

1{
2 "v":2,
3 "t":1619718521,
4 "ttl":15,
5 "res":{
6 "usr":{},
7 "spc":{},
8 "chan":{{"ch1":19}},
9 "grp":{}
10 },
11 "pat":{
12 "usr":{},
13 "spc":{},
14 "chan":{},
15 "grp":{}
show all 19 lines

Operations-to-permissions mapping​

The type of access level you grant on a given resource type defines which operations users can perform in your app. For example, write access given to a user for the channels resource type (either specific channels or channel patterns) lets them send messages to this channel/these channels (calling the PubNub Pub/Sub API underneath and the Unreal Chat SDK's SendText() method).

Chat SDK method to required Access Manager permission mapping

For information about which Chat SDK methods require what Access Manager permissions, refer to Security and permissions.

Was this page useful?

Last updated on