The REST API provides secure administrative tasks for managing and auditing permissions (aka Access Control List, or ACL). All of the REST APIs require a cryptographic signature and a timestamp that is reasonably close to NTP time.
The timestamp is an HTTP query parameter following the Unix Time convention
(number of seconds elapsed since 00:00:00 January 1, 1970 UTC). The service will
reject any request containing a timestamp that is +/- 60 seconds from the
current time according to NTP. This strict requirement prevents certain kinds of
replay attacks.
The signature is an HTTP query parameter computed with the HMAC+SHA256
algorithm and encoded with URL-safe Base64. The message to be signed is composed
of all query parameters (with obvious exception of the signature itself) plus
the PubNub account subscribe and publish keys, and the REST resource. The
signing key is the PubNub account secret key. Full details for signature
computation are provided later.
<sign> is computed using HMAC+SHA256 with the user's secret key as the signing
key, and the request string as the message. The request string is composed of
the request query parameters concatenated to the subscribe key, publish key, and
action (grant or audit) in the following format string:
"{sub_key}\n{pub_key}\n{action}\n{query_string}"Query string parameters must be sorted lexicographically (case-sensitive) by
key. Secondly, all characters in the query string parameters must be
percent-encoded except alphanumeric, hyphen, underscore, and period; E.g. all
characters matching the RegExp /[^0-9a-zA-Z\-_\.]/. Space characters must be
replaced by %20 (NOT + character). Each key-value pair must be separated by
ampersand characters. Unicode characters must be broken up into UTF-8 encoded
bytes before percent-encoding.
Here is an example of a query string containing unicode characters:
auth=joker&r=1&w=1&ttl=60×tamp=123456789&PoundsSterling=£13.37And here is the same query string after sorting and percent-encoding:
PoundsSterling=%C2%A313.37&auth=joker&r=1×tamp=123456789&ttl=60&w=1Here is a full example message:
demo
demo
grant
auth=jay&channel=jays_channel&r=1×tamp=123456789&ttl=1440&w=1Let's imagine the demo account's secret key is:
wMfbo9G0xVUG8yfTfYw5qIdfJkTd7A
The signature generated for this request is Base64 encoded using the "URL safe"
characters - and _ replacing + and / respectively:
v2rgQQ1eFzk8omugFV9V1_eKRUvvMv9jyC9Z-L1ogdw=
This signature is then percent-encoded according to standard query parameter
percent-encoding practices. E.g. the = character is transformed into %3D.
PubNub Access Manager
Use the Python module like this:
Setup Your Keys:
Grant read & write:
Revoke write (Grant read):
Revoke all:
Lookup all grants on subkey:
Lookup grants on channels:
Lookup grants on
auth:TTL
Permissions can expire automatically, like sessions! Use the
ttlparameter to change the expiration time. Its value is represented in minutes:Expire in one hour
Expire in 30 days