On this page

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. Set this in the PNConfiguration object during initialization.

Contact support

To request a custom origin, contact PubNub Support.

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.

Enable Access Manager

Enable Access Manager on your keyset in the Admin Portal and initialize the Chat SDK with SecretKey. Access Manager is available in Unity SDK, not Unity Chat SDK.

Token permissions

When you use Access Manager, your client application will receive a token that governs the access levels and types of operations you can perform. The CanI() method checks if a client has permissions to perform a specific action on a given resource.

Method signature

1Chat.ChatAccessManager.CanI(
2 PubnubAccessPermission permission,
3 PubnubAccessResourceType resourceType,
4 string resourceName
5)

Input

* required
ParameterDescription
permission *
Type: PubnubAccessPermission
The operation type to check if the current user has permissions for.
resourceType *
Type: PubnubAccessResourceType
The resource type to check if the current user has permissions for.
resourceName *
Type: string
The name of the resource, for example, a channel name or a user ID.
  • PubnubAccessPermission

    1public enum PubnubAccessPermission
    2{
    3 Read,
    4 Write,
    5 Manage,
    6 Delete,
    7 Get,
    8 Join,
    9 Update
    10}
  • PubnubAccessResourceType

    1    public enum PubnubAccessResourceType
    2 {
    3 Uuids,
    4 Channels
    5 }

Output

ParameterDescription
Task<bool>
An awaitable Task with a bool signifying whether or not the client has permissions to perform the requested operation on the requested resource.

Sample code

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

1

Token management

The Chat object's PubnubInstance contains methods for managing the auth token of an initialized Chat instance.

Set token

The SetAuthToken() method allows client devices to update their authentication token. This token, granted by the server, contains embedded permissions that define the client's access to PubNub resources. By setting a new token, the client ensures that its requests to PubNub are authorized according to the permissions specified in the updated token.

Method signature

1chat.PubnubInstance.SetAuthToken(string token)

Input

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

Sample code

1

Returns

This method does not return any response value. If the operation fails, an exception will be thrown.

Parse token

The ParseToken() method decodes an existing token and returns a JSON string containing the permissions embedded in that token. This method is useful for debugging purposes, allowing you to inspect the token's permissions and other metadata, such as its time-to-live (TTL) and authorized user ID.

Method signature

1chat.PubnubInstance.ParseToken(string token)

Input

* required
ParameterDescription
token *
Type: string
The authentication token to decode.

Output

ParameterDescription
result
Type: string
A JSON string containing the token's permissions and metadata.

Sample code

1

Example output

1{
2 "Version":2,
3 "Timestamp":1619718521,
4 "TTL":15,
5 "AuthorizedUuid":"my_uuid",
6 "Resources":{
7 "Uuids":{
8 "uuid-id":{
9 "Read":true,
10 "Write":true,
11 "Manage":true,
12 "Delete":true,
13 "Get":true,
14 "Update":true,
15 "Join":true
show all 43 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.

Last updated on