Secure Token. Protect live streams and VOD with temporary links

To protect your content from unwanted downloads use the Secure Token option in the CDN Resource settings.

How it works

We receive a stream with no token protection, transcode it, and then deliver via our CDN network. Token gets added to VOD or stream URL after transcoding. Links with token looks like these:

https://cdn.example.com/streams/10_14/WG99BSGMdZIwKy/1552551429/playlist.m3u8 (live stream)
https://cdn.example.com/videos/44_aJ0o71wfUwJvFDklkjlcu/master.m3u8 (VOD)

Control Panel Settings

Go to the CDN Resources section, choose the Resource and click on the Settings button. Navigate to Advanced Settings -> Access (Security) -> Secure Token.

Activate the option, type in a signature key and click on the Save button. The signature key should contain 6-32 characters.

1565585768090.png

Three parameters are used for token generation:

  • Expiration time,
  • Path to the file,
  • Key.

Leave the Add a client's IP to the token box unchecked.

Token Generation

Use the following php-script to generate URLs with token if needed.

PHP-script for live streams

<?php 
$secret = 'W39Hd509SeReT41p'; 
$vhost = 'cdn.example.com'; 
$client_id = '10'; 
$stream_id = '14'; 
$expires = time() + 10000; 
$link = "{$client_id}_{$stream_id}_${secret}_${expires}_"; 
$md5 = md5($linktrue); 
$md5 = base64_encode($md5); 
$md5 = strtr($md5, '+/', '-_'); 
$md5 = str_replace('=', '', $md5); 
$url = "https://{$vhost}/streams/{$client_id}_${stream_id}/${md5}/${expires}/playlist.m3u8"; 
echo $url; 
echo "n"; 

PHP-script for VOD


<?php
$secret = 'W39Hd509SeReT41p';
$vhost = 'cdn.example.com';
$client_id = '44';
$video_id = 'aJ0o71wfUwJvFcu';
$expires = time() + 10000;
$link = "{$client_id}_{$video_id}_${secret}_${expires}_";
$md5 = md5($link, true);
$md5 = base64_encode($md5);
$md5 = strtr($md5, '+/', '-_');
$md5 = str_replace('=', '', $md5);
$url = "https://{$vhost}/videos/{$client_id}_${video_id}/${md5}/${expires}/master.m3u8";
echo $url;
echo "n";

Parameters:

  • $secret — a signature key,
  • $vhost — CDN Resource domain name,
  • $video_id —  slug, an individual parameter in VOD's URL. You may find it in the VOD Page URL (VOD Settings -> Export -> Page URL) just after your account's ID. For example, in this URL https://cdn.example.com/videos/123_gnhWeEAA6LT, gnhWeEAA6LT - is a slug
  • $expires  — URL expiration time (in seconds),
  • $link — token generation schema,
  • $url — URL.
Was this article helpful?
Recently viewed articles