Skip to content

Commit

Permalink
Fix Authentication with Internal server when using SAML/SSO and fix
Browse files Browse the repository at this point in the history
"relgoin" button.

Signed-off-by: Tobia De Koninck <[email protected]>
  • Loading branch information
LEDfan committed Oct 19, 2017
1 parent 7ebb41a commit 32bd542
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
array('name' => 'settings#setUser', 'url' => '/settings/user', 'verb' => 'POST'),
array('name' => 'settings#getIceServers', 'url' => '/settings/iceServers', 'verb' => 'GET'),
array('name' => 'settings#getUsers', 'url' => '/settings/users', 'verb' => 'GET'),
array('name' => 'settings#getServerType', 'url' => '/settings/servertype', 'verb' => 'GET'),

array('name' => 'externalApi#index', 'url' => '/ajax/externalApi.php', 'verb' => 'POST'),
// array('name' => 'externalApi#check_password', 'url' => '/api/v2/checkPassword', 'verb' => 'POST'),
Expand Down
66 changes: 65 additions & 1 deletion js/ojsxc.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@
password: password
},
success: function(d) {
if (d.result === 'success' && d.data && d.data.serverType !== 'internal' && d.data.xmpp.url !== '' && d.data.xmpp.url !== null) {
if (d.result === 'success' && d.data && d.data.serverType !== 'internal' && d.data.xmpp.url !== '' && d.data.xmpp.url !== null) { jsxc.storage.setItem('serverType', d.data.serverType);
cb(d.data);
} else if (d.data && d.data.serverType === 'internal') {
// fake successful connection
// jsxc.storage.setItem('serverType', 'internal');
jsxc.gui.showLoginBox = function(){};
jsxc.bid = username.toLowerCase() + '@' + window.location.host;

jsxc.storage.setItem('jid', jsxc.bid + '/internal');
Expand Down Expand Up @@ -323,6 +325,9 @@
$(document).on('connected.jsxc', function() {
// reset default avatar cache
jsxc.storage.removeUserItem('defaultAvatars');
// when we are connected it doesn't matter anymore whether we logged in without chat since the user
// must have manually logged in
jsxc.storage.setItem('login_without_chat', false);
});

$(document).on('status.contacts.count status.contact.updated', function() {
Expand Down Expand Up @@ -370,6 +375,7 @@
if (jsxc.el_exists(jsxc.options.loginForm.form) && jsxc.el_exists(jsxc.options.loginForm.jid) && jsxc.el_exists(jsxc.options.loginForm.pass)) {

var link = $('<a/>').text($.t('Log_in_without_chat')).attr('href', '#').click(function() {
jsxc.storage.setItem('login_without_chat', true);
jsxc.submitLoginForm();
});

Expand All @@ -389,4 +395,62 @@
observeContactsMenu();
}
});

$(document).on('ready.roster.jsxc', function(event, state) { // TODO this may be removed
$(document).on( "click", '#jsxc_roster p', function() {
if (jsxc.storage.getItem('serverType') === 'internal') {
startInternalBackend();
}
});
});

function startInternalBackend() {
jsxc.bid = OC.currentUser.toLowerCase() + '@' + window.location.host;

jsxc.storage.setItem('jid', jsxc.bid + '/internal');
jsxc.storage.setItem('sid', 'internal');
jsxc.storage.setItem('rid', '123456');

jsxc.options.set('xmpp', {
url: OC.generateUrl('apps/ojsxc/http-bind')
});

jsxc.start(jsxc.bid + '/internal', 'internal', '123456');
jsxc.gui.restore();
jsxc.gui.roster.toggle(jsxc.CONST.SHOWN);
$(document).trigger('attached.jsxc');
}

if (jsxc.storage.getItem('serverType') === 'internal') {
// when the page is (re) loaded and we already know we are using the internal backend we must override
// the show loginBox method so that the form isn't shown when clicking the relogin link
jsxc.gui.showLoginBox = function () {};
}

$(document).on('stateChange.jsxc', function _handler(event, state) {
if (state === jsxc.CONST.STATE.SUSPEND) {
/**
* The first time we go into suspend mode we check if we are using the internal backend.
* If this is the case and the user dexplicitlylicity press the "login_without_chat" button when logging
* into Nextcloud we know we are using another authentication mechanism (like SAML/SSO) and thus have
* to manually start the connection.
*/
$(document).off('stateChange.jsxc', _handler);
if (jsxc.storage.getItem('serverType') === null) {
$.ajax({
url: OC.generateUrl('apps/ojsxc/settings/servertype'),
success: function (data) {
jsxc.storage.setItem('serverType', data.serverType);
jsxc.gui.showLoginBox = function(){};
if (data.serverType === 'internal' && jsxc.storage.getItem('login_without_chat') !== true) {
startInternalBackend();
}
}
});
} else if (jsxc.storage.getItem('serverType') === 'internal' && jsxc.storage.getItem('login_without_chat') !== true) {
jsxc.gui.showLoginBox = function(){};
startInternalBackend();
}
}
});
}(jQuery));
8 changes: 8 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ public function getUsers($search = '')
return $response;
}

/**
* @NoAdminRequired
*/
public function getServerType()
{
return ["serverType" => $this->getAppValue('serverType', 'internal')];
}

private function getCurrentUser()
{
$currentUser = false;
Expand Down

0 comments on commit 32bd542

Please sign in to comment.