autologin - Auto login Rocket.Chat with LDAP -
i integrating rocket.chat system share user account through ldap database. created shortcut go rocket.chat our system, when user click shortcut, our system open rocket.chat page url type: http://rocketchat.host:3000/?username={username}&password={password}
username
, password
current account.
we changed 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 url our system passed meteor.loginwithpassword(username, password, function () { console.log('loginwithpassword callback, username: ' + username + "; password:" + password); }); // call login direct meteor.login // query "username" , "password" input fields login pass data , 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 changed in minified javascript file of rocket.chat @ {bundle}\programs\web.browser\{sso number}.js
sso number
randomize number 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 following code @ 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 logged in rocket.chat login form (case 1), work ok. if account hasn't been yet (case 2), fail.
case 1 : chrome log:
case 2 : chrome log:
question: know rocket.chat has issue ldap first login meteor.loginwithpassword()
api, won't work simulated login ui. , know these logs mean "login form" wasn't found. question why login ui simulation not work? how can fix it?
thanks!
Comments
Post a Comment