Signed tokens. How to make them working?

Hi. Can someone help me with signed tokens?
I did the following.

1)in janus.jcfg

general: {

token_auth = true
token_auth_secret = “a1”

}

2)created 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);

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

node token.js

3)created videoroom in videoroom.jcfg

room-445946 :
{

signed_tokens = “yes”;

};

4)in client Room.js
copied

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 want users to join the room with a token.

Hi can I ask why token must be in this format: 1691954689,janus,janus.plugin.videoroom:uBk4SS2yoIU4uBEm1mDTjOrAQl4=

They don’t HAVE to be. That’s only needed when you want to use signed tokens, instead of regular tokens, when you want to limit access to specific plugins (and in the case of the VideoRoom, specific rooms). Please do read the documentation.

1 Like