Skip to content

Commit

Permalink
DRM token
Browse files Browse the repository at this point in the history
  • Loading branch information
sebest committed Sep 13, 2012
1 parent 00f4c0a commit 339e72e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions CloudKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,43 @@ public function __call($method, $args)
}
}


define('DRM_TOKEN_TIMEOUT', 600);

class CloudKey_Helpers
{
static public function gen_drm_token($user_id, $media_id, $api_key, $rights=null, $meta=null, $callback_url=null, $expires=null, $encode=true)
{
$info = array(
'user_id' => $user_id,
'media_id' => $media_id,
'expires' => intval($expires == null ? time() + DRM_TOKEN_TIMEOUT : $expires),
'nonce' => md5(uniqid(rand(), true)),
);

if ($rights != null)
{
$info['rights'] = $rights;
}
if ($data != null)
{
$info['meta'] = $meta;
}
if ($callback_url != null)
{
$info['callback_url'] = $callback_url;
}

$info['auth'] = md5(self::normalize($info) . $api_key);

$payload = json_encode($info);
if ($encode)
{
$payload = strtr(base64_encode($payload), '+/=', '-_,');
}
return $payload;
}

static public function normalize($data)
{
$normalized = '';
Expand Down

0 comments on commit 339e72e

Please sign in to comment.