Grant token
Returns a signed token that can be used to access the requested resources for a specific duration.
Path Parameters |
---|
sub_key string — REQUIREDYour app's subscribe key from Admin Portal. |
Query Parameters |
---|
timestamp integer — REQUIREDUnix epoch timestamp used as a nonce for signature computation. Must have no more than ± 60 second offset from NTP. This is not associated with the TTL at all. Example:
|
signature string — REQUIREDUsed to verify the request was signed with the secret key associated with the subscribe key. For information on how to compute the signature, refer to Signature generation. Example:
|
uuid stringA UTF-8 encoded string of up to 92 characters used to identify the client. Example:
|
Request Body — REQUIRED The request body takes the form of a JSON object containing
| |||
---|---|---|---|
ttl | Int | The total number of minutes for which the token will remain valid. The minimum allowed ttl is 1 minute. The maximum allowed ttl is 43200 (30 days). This parameter is required and there is no default for it. Once the ttl expires, the read and write attributes are immediately set to false . | |
permissions.resources.channels | Object | A mapping of channel names to permissions. Read more in Permission Bits. | |
permissions.resources.groups | Object | A mapping of channel group names to permissions. Read more in Permission Bits. | |
permissions.resources.users | Object | A mapping of users to permissions. This resource is used only for Objects v1 operations. Read more in Permission Bits. | |
permissions.resources.spaces | Object | A mapping of spaces to permissions. This resource is used only for Objects v1 operations. Read more in Permission Bits. | |
permissions.resources.uuids | Object | A mapping of uuids to permissions. This resource is used only for App Context operations. Read more in Permission Bits. | |
permissions.patterns.channels | Object | A mapping of regular expressions to permissions for channel names that match the pattern. Read more in Patterns. | |
permissions.patterns.groups | Object | A mapping of regular expressions to permissions for channel group names that match the pattern. Read more in Patterns. | |
permissions.patterns.users | Object | A mapping of regular expressions to permissions for Objects v1 users that match the pattern. Read more in Patterns. | |
permissions.patterns.spaces | Object | A mapping of regular expressions to permissions for Objects v1 spaces that match the pattern. Read more in Patterns. | |
permissions.patterns.uuids | Object | A mapping of regular expressions to permissions for App Context uuids that match the pattern. Read more in Patterns. | |
permissions.meta | Object | The meta mapping is available for arbitrary key-value pairs, to use as your application sees fit. This mapping may be used for identity/authentication purposes, restricting the token use (in the "public key use" sense as defined by JWK), or exclusions/exceptions. | |
permissions.uuid | String | The uuid that will be exclusively authorized to use the granted token. This uuid must be supplied in the query string with every PubNub API request where the granted token is used. |
Permission bits
Name | Value (Binary) | Value (Hex) | Value (Dec) | Description |
---|---|---|---|---|
READ | 0b0000_0001 | 0x01 | 1 | Applies to Subscribe, Message Persistence, Presence |
WRITE | 0b0000_0010 | 0x02 | 2 | Applies to Publish |
MANAGE | 0b0000_0100 | 0x04 | 4 | Applies to Channel-Groups, App Context |
DELETE | 0b0000_1000 | 0x08 | 8 | Applies to Message Persistence, App Context |
CREATE | 0b0001_0000 | 0x10 | 16 | Applies to Objects v1 |
GET | 0b0010_0000 | 0x20 | 32 | Applies to App Context |
UPDATE | 0b0100_0000 | 0x40 | 64 | Applies to App Context |
JOIN | 0b1000_0000 | 0x80 | 128 | Applies to App Context |
Patterns
Patterns refer to regular expressions that you can use in the grant request to assign permissions to multiple resources at a time, instead of listing them one by one.
For an exact match, a pattern must start with the caret (^) and end with the dollar ($) sign. Otherwise, the permissions will apply to any resource with a full name containing a substring that meets the given pattern.
ttl
integerpermissions
objectresources objectA mapping of resource types to resource IDs.
| |||||
patterns objectA mapping of resource types to regular expressions.
| |||||
meta objectThe meta mapping is available for arbitrary key-value pairs to use as your application sees fit. Beware that the | |||||
uuid stringPossible values: 1 ≤ length The uuid that is exclusively authorized to use this token to make API requests. When this feature is enabled on the subkey, all PubNub API requests must supply the same uuid query string parameter along with the auth token issued from this Grant request. |
Responses | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
200 Grant request was successful. The response body contains a token that can be provided to the end-user application for access to the resources contained within the token. The token can also be unwrapped by Base 64 decoding (add padding characters as necessary) and then CBOR decoding the binary. This is an example of the authentication token returned by the Grant v3 API. It can be decoded, then parsed with any CBOR parser.
| ||||||||||
400 Error validating inputs, like missing required params or invalid input types.
| ||||||||||
403 Invalid signature, like a wrong secret key or character set encoding for signature computation.
|