Access control & data security
Control who can access resources in your chat app through authentication (identity verification) and authorization (permission management).
Required keyset configuration
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
| Parameter | Description |
|---|---|
Origin *Type: FString | The custom origin to be set for PubNub requests. |
Output
| Type | Description |
|---|---|
int | 0 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
| Type | Description |
|---|---|
FString | The 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);
| Parameter | Description |
|---|---|
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 Value | Description |
|---|---|
PCAMP_Read | Read permission for a resource. |
PCAMP_Write | Write permission for a resource. |
PCAMP_Manage | Manage permission for a resource. |
PCAMP_Delete | Delete permission for a resource. |
PCAMP_Get | Permission to get details of a resource. |
PCAMP_Join | Permission to join a channel. |
PCAMP_Update | Permission to update a resource's details. |
EPubnubChatAccessManagerResourceType
| Enum Value | Description |
|---|---|
PCAMRT_Users | Resource type for Users. |
PCAMRT_Channels | Resource type for Channels. |
Output
| Type | Description |
|---|---|
bool | Whether 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
| Parameter | Description |
|---|---|
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).