Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Integrates token authentication.

paweldomasb1f617502e67
diff --git a/lang/main.json b/lang/main.json
index 6b5ff4960e..71036c950d 100644
--- a/lang/main.json
+++ b/lang/main.json
@@ -194,6 +194,7 @@
"password": "password",
"userPassword": "user password",
"token": "token",
+ "tokenAuthFailed": "Failed to authenticate with XMPP server: invalid token",
"displayNameRequired": "Please enter your display name:",
"extensionRequired": "Extension required:",
"firefoxExtensionPrompt": "You need to install a Firefox extension in order to use screen sharing. Please try again after you <a href='__url__'>get it from here</a>!"
diff --git a/modules/UI/UI.js b/modules/UI/UI.js
index 5f22514f45..5d0ab1ce7b 100644
--- a/modules/UI/UI.js
+++ b/modules/UI/UI.js
@@ -315,7 +315,11 @@ function registerListeners() {
});
APP.xmpp.addListener(XMPPEvents.PROMPT_FOR_LOGIN, function (callback) {
// FIXME: re-use LoginDialog which supports retries
- UI.showLoginPopup(callback);
+ if (config.token) {
+ messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
+ } else {
+ UI.showLoginPopup(callback);
+ }
});
APP.xmpp.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focusComponent, retrySec) {
diff --git a/modules/util/RandomUtil.js b/modules/util/RandomUtil.js
new file mode 100644
index 0000000000..ba888b0201
--- /dev/null
+++ b/modules/util/RandomUtil.js
@@ -0,0 +1,37 @@
+
+/**
+ * Generates random hex number within the range [min, max]
+ * @param max the maximum value for the generated number
+ * @param min the minimum value for the generated number
+ * @returns random hex number
+ */
+function rangeRandomHex(min, max)
+{
+ return Math.floor(Math.random() * (max - min) + min).toString(16);
+}
+
+/**
+ * Exported interface.
+ */
+var RandomUtil = {
+ /**
+ * Generates hex number with length 4
+ */
+ random4digitsHex: function() {
+ return rangeRandomHex(4096, 65535);
+ },
+ /**
+ * Generates hex number with length 8
+ */
+ random8digitsHex: function() {
+ return rangeRandomHex(268435456, 4294967295);
+ },
+ /**
+ * Generates hex number with length 12
+ */
+ random12digitsHex: function() {
+ return rangeRandomHex(17592186044416, 281474976710655);
+ }
+};
+
+module.exports = RandomUtil;
diff --git a/modules/xmpp/strophe.emuc.js b/modules/xmpp/strophe.emuc.js
index 2b83c049bf..ef6be3585a 100644
--- a/modules/xmpp/strophe.emuc.js
+++ b/modules/xmpp/strophe.emuc.js
@@ -562,6 +562,10 @@ module.exports = function(XMPP, eventEmitter) {
delete this.presMap["startMuted"];
}
+ if (config.token) {
+ pres.c('token', { xmlns: 'http://jitsi.org/jitmeet/auth-token'}).t(config.token).up();
+ }
+
pres.up();
this.connection.send(pres);
},
diff --git a/modules/xmpp/xmpp.js b/modules/xmpp/xmpp.js
index a95dcb39b5..410599a6f3 100644
--- a/modules/xmpp/xmpp.js
+++ b/modules/xmpp/xmpp.js
@@ -11,11 +11,22 @@ var StreamEventTypes = require("../../service/RTC/StreamEventTypes");
var RTCEvents = require("../../service/RTC/RTCEvents");
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
var retry = require('retry');
+var RandomUtil = require("../util/RandomUtil");
var eventEmitter = new EventEmitter();
var connection = null;
var authenticatedUser = false;
+/**
+ * Utility method that generates user name based on random hex values.
+ * Eg. 12345678-1234-1234-12345678
+ * @returns {string}
+ */
+function generateUserName() {
+ return RandomUtil.random8digitsHex() + "-" + RandomUtil.random4digitsHex() + "-" +
+ RandomUtil.random4digitsHex() + "-" + RandomUtil.random8digitsHex();
+}
+
function connect(jid, password) {
var faultTolerantConnect = retry.operation({
@@ -296,7 +307,16 @@ var XMPP = {
configDomain = config.hosts.domain;
}
var jid = configDomain || window.location.hostname;
- connect(jid, null);
+ var password = null;
+ if (config.token) {
+ password = config.token;
+ if (config.id) {
+ jid = config.id + "@" + jid;
+ } else {
+ jid = generateUserName() + "@" + jid;
+ }
+ }
+ connect(jid, password);
},
createConnection: function () {
var bosh = config.bosh || '/http-bind';