Access Manager v3 API for PubNub Unity SDK
Access Manager allows you to enforce security controls for client access to resources within the PubNub Platform. With Access Manager v3, your servers 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
tochannel1
andwrite
tochannel2
).
You can add the AuthorizedUUID
parameter to the grant request to restrict the token usage to only one client with a given UUID. Once specified, only this authorized UUID will be able to use the token to make API requests for the specified resources, according to permissions given in the grant request.
For more information about Access Manager v3, refer to Manage Permissions with Access Manager v3.
Client device support only
The Unity SDK supports only client implementation of Access Manager functionality. This means that you cannot use it to grant permissions, but rather to parse and set tokens received from a server SDK.
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
(time to live) details.
Method(s)
ParseToken(string token)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
token | String | Yes | n/a | Current token with embedded permissions. |
Basic Usage
pubnub.ParseToken("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI")
Returns
TokenContents p = pubnub.ParseToken("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI")
To better understand the structure of the TokenContents
object, see the details of all related custom types:
TokenContents
Parameter Type Description Resources
TokenResources
Resource permissions specified in a sequence. Patterns
TokenPatterns
Resource permissions expressed as RegEx patterns. Meta
Dictionary<string, object>
Extra metadata to be published with the request. Values must be scalar only; arrays or objects aren't supported. Signature
string
HMAC+SHA256 signed with a PubNub confidential signing key. Version
int
Version of the token structure. Timestamp
long
Parameter generated on the server side to record the time when the token was created. TTL
int
Total number of minutes for which the token is valid. - The minimum allowed value is
1
. - The maximum is
43,200
minutes (30 days).
AuthorizedUUID
string
Single UUID which is solely authorized to use the token to make API requests to PubNub. - The minimum allowed value is
TokenResources
Parameter Type Description Channels
Dictionary<string, TokenAuthValues>
Individual or sequential channel permissions. Groups
Dictionary<string, TokenAuthValues>
Individual or sequential group permissions. UUIDs
Dictionary<string, TokenAuthValues>
Individual or sequential UUID permissions. This resource is only used in Objects v2 operations. TokenPatterns
Parameter Type Description Channels
Dictionary<string, TokenAuthValues>
Channel permissions expressed as RegEx patterns. Groups
Dictionary<string, TokenAuthValues>
Group permissions expressed as RegEx patterns. UUIDs
Dictionary<string, TokenAuthValues>
UUID permissions expressed as RegEx patterns. This resource is only used in Objects v2 operations. TokenAuthValues
Parameter Type Read
bool
Write
bool
Manage
bool
Delete
bool
Create
bool
Get
bool
Update
bool
Join
bool
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 SetToken()
method is used by the client devices to update the authentication token granted by the server.
Method(s)
SetToken(string token)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
token | String | Yes | n/a | Current token with embedded permissions. |
Basic Usage
pubnub.SetToken("p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI")
Returns
This method doesn't return any response value.