浏览代码

Integrates token authentication.

master
paweldomas 10 年前
父节点
当前提交
b1f617502e
共有 5 个文件被更改,包括 68 次插入2 次删除
  1. 1
    0
      lang/main.json
  2. 5
    1
      modules/UI/UI.js
  3. 37
    0
      modules/util/RandomUtil.js
  4. 4
    0
      modules/xmpp/strophe.emuc.js
  5. 21
    1
      modules/xmpp/xmpp.js

+ 1
- 0
lang/main.json 查看文件

194
         "password": "password",
194
         "password": "password",
195
         "userPassword": "user password",
195
         "userPassword": "user password",
196
         "token": "token",
196
         "token": "token",
197
+        "tokenAuthFailed": "Failed to authenticate with XMPP server: invalid token",
197
         "displayNameRequired": "Please enter your display name:",
198
         "displayNameRequired": "Please enter your display name:",
198
         "extensionRequired": "Extension required:",
199
         "extensionRequired": "Extension required:",
199
         "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>!"
200
         "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>!"

+ 5
- 1
modules/UI/UI.js 查看文件

315
     });
315
     });
316
     APP.xmpp.addListener(XMPPEvents.PROMPT_FOR_LOGIN, function (callback) {
316
     APP.xmpp.addListener(XMPPEvents.PROMPT_FOR_LOGIN, function (callback) {
317
         // FIXME: re-use LoginDialog which supports retries
317
         // FIXME: re-use LoginDialog which supports retries
318
-        UI.showLoginPopup(callback);
318
+        if (config.token) {
319
+            messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
320
+        } else {
321
+            UI.showLoginPopup(callback);
322
+        }
319
     });
323
     });
320
 
324
 
321
     APP.xmpp.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focusComponent, retrySec) {
325
     APP.xmpp.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focusComponent, retrySec) {

+ 37
- 0
modules/util/RandomUtil.js 查看文件

1
+
2
+/**
3
+ * Generates random hex number within the range [min, max]
4
+ * @param max the maximum value for the generated number
5
+ * @param min the minimum value for the generated number
6
+ * @returns random hex number
7
+ */
8
+function rangeRandomHex(min, max)
9
+{
10
+    return Math.floor(Math.random() * (max - min) + min).toString(16);
11
+}
12
+
13
+/**
14
+ * Exported interface.
15
+ */
16
+var RandomUtil = {
17
+    /**
18
+     * Generates hex number with length 4
19
+     */
20
+    random4digitsHex: function() {
21
+        return rangeRandomHex(4096, 65535);
22
+    },
23
+    /**
24
+     * Generates hex number with length 8
25
+     */
26
+    random8digitsHex: function() {
27
+        return rangeRandomHex(268435456, 4294967295);
28
+    },
29
+    /**
30
+     * Generates hex number with length 12
31
+     */
32
+    random12digitsHex: function() {
33
+        return rangeRandomHex(17592186044416, 281474976710655);
34
+    }
35
+};
36
+
37
+module.exports = RandomUtil;

+ 4
- 0
modules/xmpp/strophe.emuc.js 查看文件

562
                 delete this.presMap["startMuted"];
562
                 delete this.presMap["startMuted"];
563
             }
563
             }
564
 
564
 
565
+            if (config.token) {
566
+                pres.c('token', { xmlns: 'http://jitsi.org/jitmeet/auth-token'}).t(config.token).up();
567
+            }
568
+
565
             pres.up();
569
             pres.up();
566
             this.connection.send(pres);
570
             this.connection.send(pres);
567
         },
571
         },

+ 21
- 1
modules/xmpp/xmpp.js 查看文件

11
 var RTCEvents = require("../../service/RTC/RTCEvents");
11
 var RTCEvents = require("../../service/RTC/RTCEvents");
12
 var XMPPEvents = require("../../service/xmpp/XMPPEvents");
12
 var XMPPEvents = require("../../service/xmpp/XMPPEvents");
13
 var retry = require('retry');
13
 var retry = require('retry');
14
+var RandomUtil = require("../util/RandomUtil");
14
 
15
 
15
 var eventEmitter = new EventEmitter();
16
 var eventEmitter = new EventEmitter();
16
 var connection = null;
17
 var connection = null;
17
 var authenticatedUser = false;
18
 var authenticatedUser = false;
18
 
19
 
20
+/**
21
+ * Utility method that generates user name based on random hex values.
22
+ * Eg. 12345678-1234-1234-12345678
23
+ * @returns {string}
24
+ */
25
+function generateUserName() {
26
+    return RandomUtil.random8digitsHex() + "-" + RandomUtil.random4digitsHex() + "-" +
27
+        RandomUtil.random4digitsHex() + "-" + RandomUtil.random8digitsHex();
28
+}
29
+
19
 function connect(jid, password) {
30
 function connect(jid, password) {
20
 
31
 
21
     var faultTolerantConnect = retry.operation({
32
     var faultTolerantConnect = retry.operation({
296
             configDomain = config.hosts.domain;
307
             configDomain = config.hosts.domain;
297
         }
308
         }
298
         var jid = configDomain || window.location.hostname;
309
         var jid = configDomain || window.location.hostname;
299
-        connect(jid, null);
310
+        var password = null;
311
+        if (config.token) {
312
+            password = config.token;
313
+            if (config.id) {
314
+                jid = config.id + "@" + jid;
315
+            } else {
316
+                jid = generateUserName() + "@" + jid;
317
+            }
318
+        }
319
+        connect(jid, password);
300
     },
320
     },
301
     createConnection: function () {
321
     createConnection: function () {
302
         var bosh = config.bosh || '/http-bind';
322
         var bosh = config.bosh || '/http-bind';

正在加载...
取消
保存