Dear all,
I’m writing the function to generate Janus Token in PHP language based the code written for NodeJS that posted in this document
https://janus.conf.meetecho.com/docs/auth
Below is my code:
function getJanusToken($secret, $data = [], $timeout = 24 * 60 * 60) {
$realm = 'janus';
//$expiry = Math.floor(Date.now() / 1000) + timeout;
$expiry = time() + $timeout;
//$strdata = [expiry.toString(), realm, ...data].join(',');
$data = array_merge([$expiry, $realm], $data);
$strdata = implode(',', $data);
//const hmac = crypto.createHmac('sha1', secret);
// hmac.setEncoding('base64');
// hmac.write(strdata);
// hmac.end();
$hmac = base64_encode(hash_hmac('sha1', $strdata, $secret));
//return [strdata, hmac.read()].join(':');
//<timestamp>,janus,<plugin1>[,plugin2...]:<signature>
return implode(':', [$strdata, $hmac]);
};
//const token = getJanusToken('janus', ['janus.plugin.videoroom']);
$tokenSecret = 'janus-token';
$token = getJanusToken($tokenSecret, ['janus.plugin.videoroom']);
var_dump($token);
But the token generated by this function was invalid.
Does anyone know what is the incorrect code line, and please help me to correct it.
Thanks,
Thanh Nguyen