Created
December 26, 2016 10:40
-
-
Save fikrifirat/9345416fbc05ce4c0a5de42889d4ebce to your computer and use it in GitHub Desktop.
Voxbone WebRTC SDK ephemeral authentication script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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