Integrates token authentication.
This commit is contained in:
parent
a5e15025f8
commit
b1f617502e
|
@ -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>!"
|
||||
|
|
|
@ -315,7 +315,11 @@ function registerListeners() {
|
|||
});
|
||||
APP.xmpp.addListener(XMPPEvents.PROMPT_FOR_LOGIN, function (callback) {
|
||||
// FIXME: re-use LoginDialog which supports retries
|
||||
if (config.token) {
|
||||
messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
|
||||
} else {
|
||||
UI.showLoginPopup(callback);
|
||||
}
|
||||
});
|
||||
|
||||
APP.xmpp.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focusComponent, retrySec) {
|
||||
|
|
|
@ -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;
|
|
@ -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);
|
||||
},
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue