Creating protected videos is a request that comes up once in a while in talks and on the forums.
Whether you’d like to sell the videos or allow restricted access for members only, this short tutorial is going to set the ground for it.
The KS Protected Access Control is a way to protect the access to your videos by enforcing the need to pass a KS (Kaltura Session) for the request that serves the video.
It is an advanced method meant to provide the developer of the integrated system means to decide on his side who should have access (valid KS specified) to the videos and who will be denied (no KS provided).
Step 1 – Create an Access Control Profile
Follow these steps:
a. Go to Settings > Access Control > Add Profile.
b. Scroll the window down to “Advanced Security & Pay-per-view”.
c. Check the two boxs (“Secure viewing of this video using server side session” and “Free Preview”).
d. Set the time for the preview period.
Or.. since video is much better than words, watch this short video:
Step 2 – Write the PHP code
We’ll use the PHP API Client library, this of course for the sake of example, you can use any other language for that.
The important part is the definition of the client object, configuring it and creation of the Kaltura Session (KS):
The KS (Kaltura Session) is constructed of a number of elements and must be generated on the system side:
// Your Kaltura credentials
define("PARTNER_ID", "--Set your partner id here--");
define("USER_SECRET", "--Set your API user secret here (KMC>Settings>Integration Settings>User Secret)--");
define("ENTRY_ID", "--Set the entry id of a video with relevant KS access control applied that belong to the above partner id--");
define("UICONF_ID", "--Set the uiconf id of the player you'd like to use. You can find this id in the players list on the Studio tab in KMC--");
// Whatever user id you want to set (This is according to your system deployment):
$user = "SomeoneWeKnow";
//This is the session start function signature: start($secret, $userId = "", $type = 0, $partnerId = -1, $expiry = 86400, $privileges = "")
$session = $client->session->start(USER_SECRET, $user, KalturaSessionType::USER, PARTNER_ID, 86400, 'sview:'.ENTRY_ID);
Note “sview:ENTRY_ID”
To create a KS (Kaltura Session) that will provide access to the video, pass “sview:ENTRY_ID” in the permissions variable when creating a new KS (using the session create function), replacing ENTRY_ID with the id of the video entry to allow access to.
This generated KS should then be rendered to the page if the user has permissions to access the full video.
If the user doesn’t have permissions to access the full video, flashvars shouldn’t render a KS and Kaltura will only stream the preview part of the video as defined in the access control profile.
Then, on the flashvars of the embedded KDP, we’ll provide the created ks as follow:
kWidget.embed( 'playerTarget', {
'wid' : '_243342',
'uiconf_id' : '8145862',
'entry_id' : '1_20x0ca3l',
'flashvars':{
'ks': < ?php echo $session; ?>
}
});
All done. 🙂
Download the sample PHP app here.
If that helped you, or you find a good way to improve it – let us know in the comments / twitter..