Access Manager v3 API for Unreal SDK

Access Manager isn't enabled by default
Until you enable it, any client that connects to this keyset can publish, subscribe, and reach channels and metadata. PubNub runs no permission checks. Enable Access Manager in the Admin Portal before you deploy to production.

Access Manager allows you to enforce security controls for client access to resources within the PubNub Platform. With Access Manager v3, your servers (that use a PubNub instance configured with a secret key) can grant their clients tokens with embedded permissions that provide access to individual PubNub resources:

  • For a limited period of time.
  • Through resource lists or patterns (regular expressions).
  • In a single API request, even if permission levels differ (read to channel1 and write to channel2).

You can add the authorizedUuid parameter to the grant request to restrict the token usage to one client with a given userId. Once specified, only this authorizedUuid will be able to use the token to make API requests for the specified resources, according to permissions given in the grant request.

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.

icon

Usage in Blueprints and C++


Asynchronous and synchronous method execution

Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.

  • Asynchronous methods (Async suffix) return void and take an optional delegate parameter that fires when the operation completes.

    1PubnubClient->GrantTokenAsync(30, "my-user", Permissions, OnGrantTokenResponseDelegate);

    You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubGrantTokenResponseNative).

  • Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.

    1FPubnubGrantTokenResult Result = PubnubClient->GrantToken(30, "my-user", Permissions);

Grant token​

Requires Access Manager add-on

This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.

Requires Secret Key authentication

Granting permissions to resources should be done by administrators whose SDK instance has been initialized with a Secret Key (available on the Admin Portal on your app's keyset).

In the Unreal SDK, you set SecretKey on FPubnubConfig before you call CreatePubnubClient. The client applies SecretKey only at creation, and no setter exists to change it later. If SecretKey isn't empty, the client uses it from creation. There's no separate step to turn it on. Never ship the secret key in client builds.

The GrantToken() method generates a time-limited authorization token with an embedded access control list. The token defines time to live (TTL), AuthorizedUser, and a set of permissions giving access to one or more resources:

  • Channels
  • ChannelGroups
  • Uuids (other users' object metadata, such as their names or avatars)
  • Categories (list all channel or user metadata on the subscribe key, not one named resource)

Only this AuthorizedUser will be able to use the token with the defined permissions. The authorized client will send the token to PubNub with each request until the token's TTL expires. Any unauthorized request or a request made with an invalid token will return a 403 with a respective error message.

The grant request allows your server to securely grant your clients access to the resources within the PubNub Platform. There is a limited set of operations the clients can perform on every resource:

ResourcePermissions
Channelsread, write, get, manage, update, join, delete
ChannelGroupsread, manage
Uuidsget, update, delete
Categories (Channels, Users)get only

In GrantToken, Channels sets the channels category and Users sets the uuids category.

  • A category permission lets a token list all metadata of one resource type on your subscribe key. Valid categories are channels and uuids. The only permission is get (32).
  • A get permission on one named channel or user, or on a pattern, does not grant a category.
  • A token can contain only categories. It needs no resource or pattern.
  • When enumeration enforcement is enabled for a keyset, App Context list requests from a token or auth key without the matching category permission return a 403 error.

AuthorizedUser is required even when the token holds only categories.

For permissions and API operations mapping, refer to Manage Permissions with Access Manager v3.

Method(s)​

1PubnubClient->GrantTokenAsync(
2 int Ttl,
3 FString AuthorizedUser,
4 const FPubnubGrantTokenPermissions& Permissions,
5 FOnPubnubGrantTokenResponse OnGrantTokenResponse,
6 FString Meta = ""
7);
required
Ttl required#
Type: int
Time-To-Live (TTL) in minutes for the granted token.
AuthorizedUser required#
Type: FString
The User ID that is authorized by this grant.
Permissions required#
Type: const FPubnubGrantTokenPermissions&
Permissions applied to the listed resources.
OnGrantTokenResponse required#
The delegate for the operation's result.

You can also use a native callback of the type FOnPubnubGrantTokenResponseNative to handle the result using a lambda.
Meta#
Type: FString
Additional metadata to be included in the token.

FPubnubGrantTokenPermissions​

Channels#
A list of exact channel names and their associated permissions. Applied to the resources.channels section of the grant token.
ChannelGroups#
A list of exact channel group names and their associated permissions. Applied to the resources.groups section of the grant token.
Users#
Type: TArray<FUserGrant>
A list of exact user IDs and their associated permissions. Applied to the resources.uuids section of the grant token.
ChannelPatterns#
A list of channel name patterns (regular expressions) and their associated permissions. Applied to the patterns.channels section of the grant token.
ChannelGroupPatterns#
A list of channel group name patterns (regular expressions) and their associated permissions. Applied to the patterns.groups section of the grant token.
UserPatterns#
Type: TArray<FUserGrant>
A list of user ID patterns (regular expressions) and their associated permissions. Applied to the patterns.uuids section of the grant token.
Categories#
Lists all channel metadata (Channels) or all user metadata (Users) on the subscribe key. Applied to the categories section of the grant token. Named resource and pattern permissions do not grant this.

FChannelGrant​

FieldTypeDescription
ChannelFStringThe ID of a single Channel if used in the "Channels" field of [FPubnubGrantTokenPermissions](#fpubnubgranttokenpermissions) or a regular expression pattern if used in the "ChannelPatterns" field.
PermissionsFPubnubChannelPermissionsPermissions to grant for the specified Channel name or pattern.

FChannelGroupGrant​

FieldTypeDescription
ChannelGroupFStringThe name of a single Channel Group if used in the "ChannelGroups" field of [FPubnubGrantTokenPermissions](#fpubnubgranttokenpermissions) or a regular expression pattern if used in the "ChannelGroupPatterns" field.
PermissionsFPubnubChannelGroupPermissionsPermissions to grant for the specified Channel Group name or pattern.

FUserGrant​

FieldTypeDescription
UserFStringThe ID of a single User if used in the "Users" field of [FPubnubGrantTokenPermissions](#fpubnubgranttokenpermissions) or a regular expression pattern if used in the "UserPatterns" field.
PermissionsFPubnubUserPermissionsPermissions to grant for the specified User ID or pattern.

FPubnubCategoryPermissions​

FieldTypeDescription
ChannelsboolWhen true, the token can list all channel metadata. Applied to categories.channels in the grant token. Default false.
UsersboolWhen true, the token can list all user metadata. Applied to categories.uuids in the grant token. Default false.

FPubnubChannelPermissions​

FieldTypeDescription
ReadboolRead permission. Applies to Subscribe, History, and Presence.
WriteboolWrite permission. Applies to Publish.
DeleteboolDelete permission. Applies to History and App Context.
GetboolGet permission. Applies to App Context.
UpdateboolUpdate permission. Applies to App Context.
ManageboolManage permission. Applies to Channel Groups and App Context.
JoinboolJoin permission. Applies to App Context.

FPubnubChannelGroupPermissions​

FieldTypeDescription
ReadboolRead permission. Applies to presence and history access for the group.
ManageboolManage permission. Applies to modifying members of the group.

FPubnubUserPermissions​

FieldTypeDescription
DeleteboolDelete permission. Allows deletion of user metadata.
GetboolGet permission. Allows retrieval of user metadata.
UpdateboolUpdate permission. Allows updating of user metadata.

For a successful grant request, you must specify permissions for at least one User, channel, or group, either as a resource list or as a pattern (RegEx), or set Categories. You can specify the permissions in the following ways:

  • apply the same permission to multiple objects

    1// permission1 as applied to all channels
    2Channels = {channel1, channel2, channel3}
    3Permisions = {permission1}
  • apply different permissions to multiple objects

    1// the indexes in the Channels array correspond to the indexes in the Permissions array
    2// so channel1 gets permission1, channel2 permission2, etc
    3Channels = {channel1, channel2, channel3}
    4Permisions = {permission1, permission2, permission3}

If you provide more than one permission to multiple objects, an error will be thrown.

1// this throws an error as the permissions don't match the objects
2Channels = {channe1, channel2, channel3}
3Permisions = {permission1, permission2}

Sample code​

Actor.h​


1

Actor.cpp​


1

Returns​

This method is void. The delegate returns the following struct:

FOnPubnubGrantTokenResponse​

Delegate type: DECLARE_DYNAMIC_DELEGATE_TwoParams

Result#
The result of the operation.
Token#
Type: FString
The token that was granted.

FOnPubnubGrantTokenResponseNative​

Native callback variant that accepts a lambda.

Result#
The result of the operation.
Token#
Type: FString
The token that was granted.

Other examples​

Grant an authorized client access to list all channel and user metadata​

The code below grants my-authorized-user the get category permission for both Channels and Users, so the client can list all channel and user metadata on the subscribe key.

Actor.h​


1

Actor.cpp​


1

Grant an authorized client different levels of access to various resources in a single call​

The code below grants my-authorized-user:

  • Read access to channel-a, channel-group-b, and get to user-c.
  • Read/write access to channel-b, channel-c, channel-d, and get/update to user-d.

Actor.h​


1

Actor.cpp​


1

Grant an authorized client read access to multiple channels using RegEx​

The code below grants my-authorized-user read access to all channels that match the channel-[A-Za-z0-9] RegEx pattern.

Actor.h​


1

Actor.cpp​


1

Grant an authorized client different levels of access to various resources and read access to channels using RegEx in a single call​

The code below grants the my-authorized-user:

  • Read access to channel-a, channel-group-b, and get to user-c.
  • Read/write access to channel-b, channel-c, channel-d, and get/update to user-d.
  • Read access to all channels that match the channel-[A-Za-z0-9] RegEx pattern.
Actor.h​

1

Actor.cpp​

1

Error responses​

If you submit an invalid request, the server returns HTTP 400 with a message that identifies the missing or incorrect argument. Causes can include a RegEx issue, an invalid timestamp, or incorrect permissions.

Revoke token​

Requires Access Manager add-on

This method requires that the Access Manager add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.

Enable token revoke

To revoke tokens, you must first enable this feature on the Admin Portal. To do that, navigate to your app's keyset and mark the Revoke v3 Token checkbox in the ACCESS MANAGER section.

The RevokeToken() method allows you to disable an existing token and revoke all permissions embedded within. You can only revoke a valid token previously obtained using the GrantToken() method.

Use this method for tokens with TTL less than or equal to 30 days. If you need to revoke a token with a longer TTL, contact support.

For more information, refer to Revoke permissions.

Method(s)​

1PubnubClient->RevokeTokenAsync(
2 FString Token,
3 FOnPubnubRevokeTokenResponse OnRevokeTokenResponse
4);
required
Token required#
Type: FString
Default: no default
Existing token with embedded permissions.
OnRevokeTokenResponse required#
Default: no default
The delegate for the operation's result.

You can also use a native callback of the type FOnPubnubRevokeTokenResponseNative to handle the result using a lambda.

Sample code​

Actor.h​


1

Actor.cpp​


1

Returns​

This method is void. The delegate returns the following struct:

FOnPubnubRevokeTokenResponse​

Delegate type: DECLARE_DYNAMIC_DELEGATE_OneParam

Result#
The result of the operation.

FOnPubnubRevokeTokenResponseNative​

Native callback variant that accepts a lambda.

Result#
The result of the operation.

Other Examples​

Revoke a token with lambda​

You can use a lambda function to handle the response:

Actor.h​

1

Actor.cpp​

1

Revoke a token with result struct​

You can use the result struct to handle the response:

Actor.h​

1

Actor.cpp​

1

Error responses​

If you submit an invalid request, the server returns an error status code with a descriptive message informing which of the provided arguments is missing or incorrect. Depending on the root cause, this operation may return the following errors:

  • 400 Bad Request
  • 403 Forbidden
  • 503 Service Unavailable

Parse token​

The ParseToken() method decodes an existing token and returns the object containing permissions embedded in that token. The client can use this method for debugging to check the permissions to the resources or find out the token's TTL details.

Method(s)​

1FString ParsedToken = PubnubClient->ParseToken(FString Token);
required
Token required#
Type: FString
Existing token with embedded permissions.

Sample code​

Actor.h​


1

Actor.cpp​


1

Read category permissions from a parsed token​

The code below parses a token and reads its category permissions.

Actor.h​


1

Actor.cpp​


1

Returns​

ParseToken returns an FString that contains the JSON-encoded token contents:

1{
2 "Version": 2,
3 "Timestamp": 1752200000,
4 "TTL": 30,
5 "Resources": {
6 "Channels": {
7 "my_first_channel": {
8 "Read": true,
9 "Write": false,
10 "Manage": true,
11 "Delete": true,
12 "Get": false,
13 "Update": true,
14 "Join": true
15 }
show all 33 lines

The result includes a Categories object only when the token carries category grants. Its Channels and Users booleans are true only when the token can list all channel metadata or all user metadata. Both are false when that category is not granted. The Categories object doesn't depend on named resource permissions. When the token has no category grants, the Categories key is absent.

Error responses​

If you receive an error while parsing the token, it may suggest that the token is damaged. In that case, request the server to issue a new one.

Set token​

The SetAuthToken() method is used by the client devices to update the authentication token granted by the server.

Method(s)​

1// Synchronous
2PubnubClient->SetAuthToken(FString Token);
3
4// Asynchronous
5PubnubClient->SetAuthTokenAsync(FString Token);
required
Token required#
Type: FString
Default: no default
Existing token with embedded permissions. Pass an empty string to clear the token.

Sample code​

Actor.h​


1

Actor.cpp​


1

Returns​

This method doesn't return any response value.

Was this page useful?

Last updated on