Search code examples
phpsecurityiframestreamingdailymotion-api

DailyMotion Cloud API how to get an URL with referer strict security?


I'm stuck with the DailyMotionCloud API I need to sign a URL with security levels on it

  1. geo-blocking allowing only: France
  2. referer strict allowing only: 1 Domain (oxygenstream.fr)

My code works but I don't know where to put the security levels when signing my URL I'm supposed to put it in the component [-<pub-sec-data>] here: https://www.dmcloud.net/doc/api/api-streaming.html#signing-a-url

How am I supposed to store de referer strict URL and the Country in the [-<pub-sec-data>]?

Here is the code of the CloudKey.php: https://github.com/dailymotion/cloudkey-php/blob/master/CloudKey.php

Here is my code:

<iframe src="<?php 
require_once 'CloudKey.php';

$user_id = 'aaaaaaaaaaaaaaaaaaaaaa'; 
$api_key = 'bbbbbbbbbbbbbbbbbbbbbb'; 
$media_id = '5466232b947399290102cdb6';
$preset_id = '54662c7c06361d307810e3b5'; // player preset 
$preset_name = 'OxygenStream'; // preset name

$seclevel = 32800 ; // I need 2 security levels (country & referer strict)
//          32800 = 1 << 5 . 1 << 15 or CLOUDKEY_SECLEVEL_COUNTRY . CLOUDKEY_SECLEVEL_REFERER_STRICT
$countries = 'cc=fr'; // I'm supposed to put it in the [-<pub-sec-data>] 
$referers = 'rf=http://www.oxygenstream.fr/vod/dmcloud';; // I'm supposed to put it in the [-<pub-sec-data>]

// We create the url 
$url = sprintf('https://api.dmcloud.net/player/embed/%s/%s/';, $user_id, $media_id);

// We sign the url 
$url = CloudKey_Helpers::sign_url($url, $api_key, $seclevel, null, null, null, $countries, $referers, null);

// We write the URL in the Iframe 
print($url . '&autoplay=1&preset=54662c7c06361d307810e3b5');?>" width="640" height="360" frameborder="0" allowfullscreen></iframe>

Thanks in advance for helping me with this.
Hope you know how to fix my code.

I wish you a great day,

Antoine


Solution

  • Since you are using the CloudKey PHP SDK you should really not have to build the URL yourself.

    When using the SDK, this works for me:

    $user_id = 'aaaaaaaaaaaaaaaaaaaaaa'; 
    $api_key = 'bbbbbbbbbbbbbbbbbbbbbb'; 
    $media_id = '5466232b947399290102cdb6';
    $preset_id = '54662c7c06361d307810e3b5';
    $preset_name = 'OxygenStream';
    
    $seclevel = CLOUDKEY_SECLEVEL_COUNTRY | CLOUDKEY_SECLEVEL_REFERER_STRICT ;
    $countries = array('fr');
    $referers = array('http://oxygenstream.fr/vod/dmcloud');
    
    $cloudkey = new CloudKey($user_id, $api_key);
    $url = $cloudkey->media->get_embed_url(array('id' => $media_id, 'seclevel' => $seclevel, 'expires' => time() + 3600, 'countries' => $countries, 'referers' => $referers));