Browse Source

Integrates token authentication.

master
paweldomas 9 years ago
parent
commit
b1f617502e
5 changed files with 68 additions and 2 deletions
  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 View File

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

@@ -315,7 +315,11 @@ function registerListeners() {
315 315
     });
316 316
     APP.xmpp.addListener(XMPPEvents.PROMPT_FOR_LOGIN, function (callback) {
317 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 325
     APP.xmpp.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focusComponent, retrySec) {

+ 37
- 0
modules/util/RandomUtil.js View File

@@ -0,0 +1,37 @@
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 View File

@@ -562,6 +562,10 @@ module.exports = function(XMPP, eventEmitter) {
562 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 569
             pres.up();
566 570
             this.connection.send(pres);
567 571
         },

+ 21
- 1
modules/xmpp/xmpp.js View File

@@ -11,11 +11,22 @@ var StreamEventTypes = require("../../service/RTC/StreamEventTypes");
11 11
 var RTCEvents = require("../../service/RTC/RTCEvents");
12 12
 var XMPPEvents = require("../../service/xmpp/XMPPEvents");
13 13
 var retry = require('retry');
14
+var RandomUtil = require("../util/RandomUtil");
14 15
 
15 16
 var eventEmitter = new EventEmitter();
16 17
 var connection = null;
17 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 30
 function connect(jid, password) {
20 31
 
21 32
     var faultTolerantConnect = retry.operation({
@@ -296,7 +307,16 @@ var XMPP = {
296 307
             configDomain = config.hosts.domain;
297 308
         }
298 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 321
     createConnection: function () {
302 322
         var bosh = config.bosh || '/http-bind';

Loading…
Cancel
Save