Custom script working once every ten times

Hello,

Description

We’ve set up a custom script to automatically press the Connection button on login page to operate a seamless SSO login connection, but the custom script only works once every 10 times or so.

When it does work, the iframe inserted by the custom script can be found in the source code of the login page.
When it does not work, the iframe inserted by the custom script is not found in the source code of the login page.

Server Setup Information

  • Version of Rocket.Chat Server: v3.1.1
  • Operating System: CentOS
  • Deployment Method: Docker image
  • Number of Running Instances: 1
  • DB Replicaset Oplog: ?
  • NodeJS Version: v12.16.1
  • MongoDB Version: 3.6.17
  • Proxy: Apache
  • Firewalls involved: no

Any additional Information

Here is the custom script that we’ve set up in the “custom scripts for logged out users” in the Layout section of the settings:

window.onload = (event) => {  
const credentialToken = Random.id();
const login_url = "https://auth.domain.com/login";
if (!login_url) return;

const appUrl = Meteor.absoluteUrl().replace(/\/$/, '') + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX;
const delim = (login_url.split('?').length > 1) ? '&' : '?';

var i = document.createElement('iframe');
i.style.display = 'none';
i.onload = function() { 
    Accounts.callLoginMethod({
        methodArguments: [{ cas: { credentialToken } }],
    });
};
i.src = `${ login_url }${ delim }service=${ appUrl }/_cas/${ credentialToken }`;
document.body.appendChild(i);
};

Are you aware of any bugs related to custom scripts in this RC version?

Regards,
Frédéric.

Ok, we figured it out. So here’s what needs to be done:

In “Custom Script for Logged Out Users”:

const credentialToken = Random.id();
const login_url = "https://cas.domain.com/login";

const appUrl = Meteor.absoluteUrl().replace(/\/$/, '') + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX;
const delim = (login_url.split('?').length > 1) ? '&' : '?';

var i = document.createElement('iframe');
i.style.display = 'none';
i.onload = function() { 
    Accounts.callLoginMethod({
        methodArguments: [{ cas: { credentialToken } }],
    });
};
i.src = `${ login_url }${ delim }service=${ appUrl }/_cas/${ credentialToken }`;
document.body.appendChild(i);

In “Custom Script for Logout Flow”:

const logout_url = "https://cas.domain.com/logout";

var i = document.createElement('iframe');
i.style.display = 'none';
i.src = `${ logout_url }`;
document.body.appendChild(i);

This way, you get seamless login with SSO CAS module.