Skip to main content
Skip table of contents

Create an OAuth tоken for a stream: Auth.CreateAccessToken

The method and parameters

This method generates an authorization token for a stream, if, when configuring a stream via Stream.Add, the private authorization method was specified.

string Auth.CreateApiToken (uid stream, unsigned ttl)

Parameters

uid stream REQUIRED – a unique identifier of a stream that requires an access token.


unsigned ttl = 3600 – the duration of the generated token, in seconds. If 0 is specified, the duration is unlimited.

Avoid using tokens with unlimited validity unless absolutely necessary.


bool live = false – the permission to watch Live. false – no access to Live, true – access to Live is allowed.


bool dvr = false – the permission to watch DVR. false – no permissions to watch DVR, true – it’s allowed to watch DVR.


bool copy = false – the permission to download DVR. false – it’s not allowed to download DVR, true – it’s allowed to download DVR.


unsigned from – a lower time bound for DVR, in seconds. If 0 is specified, the lower bound is unlimited. This parameter is only relevant if the DVR recording or the copy function is enabled.


unsigned to – the upper time bound for DVR, in seconds. If 0 is specified, the upper bound is unlimited. This parameter is only relevant if the DVR recording or copy function is enabled.

to must be greater than or equal to from.

POST /api/

JSON-RPC
JSON
{
    "jsonrpc": "2.0",
    "method": "Auth.CreateApiToken",
    "params": {
        "stream": "uid",
        "ttl": 3600
    },
    "id": 1
}
cURL
BASH
curl -k --request POST \
	--url 'https://your-domain/api/' \
	--header 'Content-Length: 142' \
	--header 'Content-Type: application/json' \
	--header 'Accept: application/json' \
	--header 'Authorization: Bearer <api-authorization-token>' \
	--header 'Content-Length: <Data length>' \
	--data '{
    "jsonrpc": "2.0",
    "method": "Auth.CreateApiToken",
    "params": {
        "stream": "uid",
        "ttl": 3600
    },
    "id": 1
}'
PHP
PHP
$data = array (
  'jsonrpc' => '2.0',
  'method' => 'Auth.CreateApiToken',
  'params' => 
  array (
    'stream' => 'uid',
    'ttl' => 3600,
  ),
  'id' => 1,
);
$context = stream_context_create([
	'ssl'=>['verify_peer' => false],
	'http' => [
		'method' => 'POST',
		'header' => "Content-Type: application/json\r
Accept: application/json\r
Authorization: Bearer <api-authorization-token>\r
Content-Length: <Content length>",
		'content'=>json_encode($data)
	]
]);
$result = file_get_contents('https://your-domain/api/', false, $context);

200 OK

An OAuth token

JSON
"<api-auth-token>"

400 Bad Request

JSON-RPC error

JSON
{
    "error": {
        "code": -32601,
        "message": "Method not found"
    }
}

500 Internal Server Error

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.