8

I am integrating Rocket.Chat into my system that share user account through LDAP database. We created a shortcut to go Rocket.Chat from our system, when user click to this shortcut, our system will open Rocket.Chat page with url type: http://rocketchat.host:3000/?username={username}&password={password} with username and password is current account.

We changed something on compiled bundle of Rocket.Chat:

// Changed file: {bundle}\programs\web.browser\head.html

<title>Rocket.Chat</title>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="expires" content="-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="fragment" content="!" />
<meta name="distribution" content="global" />
<meta name="rating" content="general" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="msapplication-TileColor" content="#04436a">
<meta name="msapplication-TileImage" content="images/logo/mstile-144x144.png?v=3">
<meta name="msapplication-config" content="images/logo/browserconfig.xml?v=3">
<meta name="theme-color" content="#04436a">
<link rel="manifest" href="images/logo/manifest.json?v=3">
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/nocfbnnmjnndkbipkabodnheejiegccf">
<link rel="icon" sizes="any" type="image/svg+xml" href="assets/favicon.svg?v=3">
<link rel="icon" sizes="256x256" type="image/png" href="assets/favicon_256.png?v=3">
<link rel="icon" sizes="192x192" type="image/png" href="assets/favicon_192.png?v=3">
<link rel="icon" sizes="128x128" type="image/png" href="assets/favicon_128.png?v=3">
<link rel="icon" sizes="96x96" type="image/png" href="assets/favicon_96.png?v=3">
<link rel="icon" sizes="64x64" type="image/png" href="assets/favicon_64.png?v=3">
<link rel="shortcut icon" sizes="16x16 32x32 48x48" type="image/x-icon" href="assets/favicon_ico.ico?v=3" />
<link rel="apple-touch-icon" sizes="57x57" href="images/logo/apple-touch-icon-57x57.png?v=3">
<link rel="apple-touch-icon" sizes="60x60" href="images/logo/apple-touch-icon-60x60.png?v=3">
<link rel="apple-touch-icon" sizes="72x72" href="images/logo/apple-touch-icon-72x72.png?v=3">
<link rel="apple-touch-icon" sizes="76x76" href="images/logo/apple-touch-icon-76x76.png?v=3">
<link rel="apple-touch-icon" sizes="114x114" href="images/logo/apple-touch-icon-114x114.png?v=3">
<link rel="apple-touch-icon" sizes="120x120" href="images/logo/apple-touch-icon-120x120.png?v=3">
<link rel="apple-touch-icon" sizes="144x144" href="images/logo/apple-touch-icon-144x144.png?v=3">
<link rel="apple-touch-icon" sizes="152x152" href="images/logo/apple-touch-icon-152x152.png?v=3">
<link rel="apple-touch-icon" sizes="180x180" href="images/logo/apple-touch-icon-180x180.png?v=3">
<script type="text/javascript">
    // alert("test js");
</script>

<script type="text/javascript">
    function getURLParameter(name) {
        console.log("location.search: " + location.search);
        var result = decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
        console.log("getURLParameter, " + name + ": " + result);
        return result;
    }
    var username = getURLParameter('username'),
        password = getURLParameter('password'); // Query parameter from url that our system passed


    Meteor.loginWithPassword(username, password, function () {
        console.log('loginWithPassword callback, username: ' + username + "; password:" + password);    
    }); // Call login direct to Meteor.login

    // Query "username" and "password" input fields from login from then pass data and simulate click login button
    document.addEventListener("DOMContentLoaded", function(event) { 
        document.getElementById('username').value = username;
        document.getElementById('password').value = password;
        document.getElementById('loginButton').click();
    });
</script>

We also changed in minified javascript file of Rocket.Chat at {bundle}\programs\web.browser\{sso number}.js where sso number is randomize number that build tool generate :

Original:

...
function(){o.loginLayout.onRendered(function(){$("#initial-page-loading").remove()})}.call(this)
...

To:

...
function(){o.loginLayout.onRendered(function(){function e(e){return decodeURIComponent((new RegExp("[?|&]"+e+"=([^&;]+?)(&|#|;|$)").exec(location.search)||[null,""])[1].replace(/\+/g,"%20"))||null}$("#initial-pageloading").remove();varn=e("username"),t=e("password");console.log("username,password="+n+","+t),console.log("getElementById(username)="+$("input[name=emailOrUsername]").val()),"null"!=n&&"null"!=t&&($("input[name=emailOrUsername]").val(n),$("input[name=pass]").val(t),$(".login")[0].click())})}.call(this)
...

It corresponds to the following code at file "{source code}\packages\rocketchat-ui-login\login\layout.js" on Rocket.Chat source code:

Template.loginLayout.onRendered(function() {
$('#initial-page-loading').remove();

function getURLParameter(name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}
var username = getURLParameter('username'),
    password = getURLParameter('password');

console.log("username,password="+username+","+password);
console.log("getElementById(username)="+$('input[name=emailOrUsername]').val());

if (username != 'null' && password != 'null') {
    $('input[name=emailOrUsername]').val(username);
    $('input[name=pass]').val(password);
    $('.login')[0].click();
}
});

With account has been previously logged in by Rocket.Chat login form (case 1), it work ok. But if account hasn't been yet (case 2), it fail.

Case 1 : This Chrome log:

Case 1 log

Case 2 : Chrome log:

Case 2 log

Question: I know Rocket.Chat has issue with LDAP is with first login by Meteor.loginWithPassword() api, it won't work then I simulated login UI. And I know these logs mean "login form" wasn't found. My question is why my login UI simulation not work? How can I fix it?

Thanks!

0 Answers0