Request an access token
This is the means by which clients obtain access tokens to use the service. You can see how to construct an Ably TokenRequest in the Ably TokenRequest spec documentation, although we recommend you use an Ably SDK rather to create a TokenRequest, as the construction of a TokenRequest is complex. The resulting token response object contains the token properties as defined in Ably TokenRequest spec. Authentication is not required if using a Signed TokenRequest.
Body
object
-
keyName
string Required Name of the key used for the TokenRequest. The keyName comprises of the app ID and key ID on an API Key.
-
capability
object Required The capabilities (i.e. a set of channel names/namespaces and, for each, a set of operations) which should be a subset of the set of capabilities associated with the key specified in keyName.
-
clientId
string The client ID to be assosciated with the token. Can be set to * to allow for any client ID to be used.
-
timestamp
integer Required Time of creation of the Ably TokenRequest.
-
nonce
string Required An unquoted, un-escaped random string of at least 16 characters. Used to ensure the Ably TokenRequest cannot be reused.
curl \
-X POST https://rest.ably.io/keys/{keyName}/requestToken \
-H "Content-Type: application/json" \
-d '{"keyName":"YourKey.Name","timestamp":"1559124196551","capability":{"channel1":["publish","subscribe"],"wildcard:channels:*":["publish"]}}'
{
"keyName": "YourKey.Name",
"timestamp": "1559124196551",
"capability": {
"channel1": [
"publish",
"subscribe"
],
"wildcard:channels:*": [
"publish"
]
}
}
{
"keyName": "xVLyHw.LMJZxw",
"capability": {
"channel1": [
"publish",
"subscribe"
]
},
"clientId": "string",
"timestamp": 42,
"nonce": "string"
}
{
"keyName": "xVLyHw.LMJZxw",
"capability": {
"channel1": [
"publish",
"subscribe"
]
},
"clientId": "string",
"timestamp": 42,
"nonce": "string",
"mac": "string"
}
{
"token": "string",
"keyName": "string",
"issued": 42,
"expires": 42,
"capability": "string"
}
{
"token": "string",
"keyName": "string",
"issued": 42,
"expires": 42,
"capability": "string"
}
# Headers
x-ably-errorcode: 42
x-ably-errormessage: string
x-ably-serverid: string
# Payload
{
"message": "string",
"code": 42,
"statusCode": 42,
"href": "string",
"serverId": "string"
}
# Headers
x-ably-errorcode: 42
x-ably-errormessage: string
x-ably-serverid: string
# Payload
{
"message": "string",
"code": 42,
"statusCode": 42,
"href": "string",
"serverId": "string"
}