Skip to content

Instantly share code, notes, and snippets.

@fikrifirat
Created December 26, 2016 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fikrifirat/9345416fbc05ce4c0a5de42889d4ebce to your computer and use it in GitHub Desktop.
Save fikrifirat/9345416fbc05ce4c0a5de42889d4ebce to your computer and use it in GitHub Desktop.
Voxbone WebRTC SDK ephemeral authentication script
<?php
/*
To use, $.get to obtain the json data.
Pass that response to voxbone.WebRTC.init(data);
This code is a 1-1 map of the NodeJS functions
*/
$username = 'changethis'; // Voxbone account name
$secret = 'changethis'; // Voxbone webrtc password
// Function mapped from NodeJS version
function cleanHmacDigest($hmac) {
while ((strlen($hmac) % 4 != 0)) {
$hmac .= '=';
}
$hmac = str_replace(' ', '+', $hmac);
return $hmac;
};
$expires = time() + 900;
$text = $expires . ':' . $username;
$key = cleanHmacDigest(base64_encode(hash_hmac('sha1', $text, $secret, true)));
// Structure output array
$output = array('key'=>$key,'expires'=>$expires,'username'=>$username);
// Output as JSON
header('Content-Type: application/json');
echo 'var voxrtc_config = ' . json_encode($output).';';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment