Signed tokens for Janus webRTC

67 Views Asked by At

Could someone help me with signed tokens for Janus webRTC? I cannot find a working example. I used next link https://janus.conf.meetecho.com/docs/auth.html I did the following.

1)In /opt/janus/etc/janus/janus.jcfg.

general: {
....
token_auth = true
token_auth_secret = “a1”
....
}

2)I created a file token.js.

const crypto = require(‘crypto’);
function getJanusToken(realm, data = , timeout = 24 * 60 * 60) {
const expiry = Math.floor(Date.now() / 1000) + timeout;
const strdata = [expiry.toString(), realm, …data].join(‘,’);
const hmac = crypto.createHmac(‘sha1’, ‘a1’);
hmac.setEncoding(‘base64’);
hmac.write(strdata);
hmac.end();
return [strdata, hmac.read()].join(‘:’);
};
const token = getJanusToken(‘janus’, [‘janus.plugin.videoroom’]);
consol.log(token);

3)node token.js.

Output:
1691954689,janus,janus.plugin.videoroom:uBk4SS2yoIU4uBEm1mDTjOrAQl4=

4)I created a videoroom in /opt/janus/etc/janus/janus.plugin.videoroom.jcfg.

room-445946 :
{
....
signed_tokens = “yes”;
....
};

5)I added next code to client's JavaScript /var/www/html/conference/Room.js.

........................
var registerRequest = {
“request”: “join”,
room: myRoom,
ptype: “publisher”,
display: “Anonymous”,
token: “1691954689,janus,janus.plugin.videoroom:uBk4SS2yoIU4uBEm1mDTjOrAQl4=”
};

    publisherPluginHandle.send(
    { 
        message: registerRequest
    });

Now I get the message “Unauthorized request (wrong or missing secret/token)” all the time. How to make it working?

I tried to read a manual and google groups and I couldn't find a working example of signed tokens.

0

There are 0 best solutions below