Streaming platform
Streaming platform
Home/Streaming platform/Extra features/Secure Token

Protect your content with temporary links

What is a Secure token, and how it works

The Secure token is a Gcore CDN feature that helps to protect files from unwanted downloading. You will find more information about the feature in the "About Secure Token" article.

As far as streaming is concerned, protection using a Secure token is as follows:

1. A live stream or video is received into the Streaming Platform with no Secure token protection.

2. Streaming Platform transcodes the content and forwards it to CDN for delivery.

3. The Secure token will be added to the following URLs:

  • https://123456.gvideo.io/streams/123456_WG99BSGMdZIwKy/1552551429/playlist.m3u8 (live stream);
  • https://123456.gvideo.io/videos/123456_aJ0o71wfUwJvFDklkjlcu/master.m3u8 (VoD)

Enable the "Secure token" feature

1. Go to the CDN resources section and open the settings of the CDN resource used for the streaming.  

2. Go to the "Access" section, select Secure token, and enable the feature.

3. Enter a signature key between 6 and 32 characters and click Save changes

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

Use the PHP script for the generation of URLs

Once the feature is enabled, a PHP script can generate temporary links for live streams and videos on demand (VoDs).

PHP script for live streams

<?php $secret = 'iFCjcOAhQ'; $vhost = '123456.gvideo.io'; $client_id = '1'; $stream_id = '123'; $expires = time() + 10000; $link = "{$client_id}{$stream_id}${secret}${expires}"; $md5 = md5($link, true); $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

$secret = 'iFCjcOAhQ'; $vhost = '123456.gvideo.io'; $client_id = '2'; $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";

Where you need to substitute your values after the equals in the following lines:

  • $secret — a signature key specified in step 3 of this guide.
  • $vhost — a subdomain that is used for the streaming,
  • $video_id —  slug, an individual parameter in VOD's URL. You will find it in the Video Hosting section when you open the video and go to the export tab. For example, in this URL https://123456.gvideo.io/videos/123456_AHgywxonRd8F9ctX, AHgywxonRd8F9ctX is a slug.
  • $expires  — URL expiration time (in seconds),
  • $link — token generation schema,
  • $url — URL.

Was this article helpful?

Not a Gcore user yet?

Explore the Streaming Platform by Gcore

Go to the product page