Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

CAS Plugin: Add direct login redirect for a CAS-enabled RC instance

Open konsumate opened this issue 10 years ago • 11 comments

The current CAS sso-login consists in clicking a "CAS" button on the login page.

This behaviour shall not be changed, but an additional route under the CAS Plugin path could easily auto-login the user by initiating a redirect, instead of waiting for the user to click a button on the login page.

konsumate avatar Feb 24 '16 16:02 konsumate

+1, this feature is required.. has anyone succeeded with this type redirect..?

madhusudan avatar Jan 14 '17 07:01 madhusudan

+1, highly needed!

bsubasic avatar Sep 20 '17 15:09 bsubasic

Any news on this issue ? (Wich is a duplicate of https://github.com/RocketChat/Rocket.Chat/issues/3052 )

jblobel avatar Sep 21 '17 13:09 jblobel

So this snippet will try to use a hidden iframe to autologin - it only works if the user is already logged into the CAS - if not, the regular login path is still avaliable. This should go under custom scripts for logged out users.

(function() {
    const credentialToken = Random.id();
    const login_url = RocketChat.settings.get('CAS_login_url');
    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);
})();

MarZab avatar Oct 23 '17 20:10 MarZab

This feature is highly needed! I backed this issue on Bountysource: https://www.bountysource.com/issues/31231979-cas-plugin-add-direct-login-redirect-for-a-cas-enabled-rc-instance

tgrosser avatar Jan 29 '18 16:01 tgrosser

+1 Feature highly needed as well. Many user don't even know what they have to do. They don't read tips dislayed, nor reads documentation.

conanedogawa2 avatar Sep 08 '19 11:09 conanedogawa2

in custom script we can add a such js:

window.onload = (event) => {
  setTimeout(function() { 
  	document.querySelector('#login-card .external-login.cas span').click();
  }, 500);
};

But some browsers (like Firefox) are blocking window opened directly.

So having a specific Route for direct CAS login will be great ! I can help if you tell me where we can configure a new route.

jgribonvald avatar Apr 08 '20 15:04 jgribonvald

+1 We really need this.

FredNass avatar Jun 05 '20 08:06 FredNass

@MarZab

Marko thanks for this code. We changed it a bit to have it working every time.

In "Custom Script for Logged Out Users" we set:

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" we set:

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);

And it works great now. :-)

FredNass avatar Jun 05 '20 09:06 FredNass

@MarZab

Marko thanks for this code. We changed it a bit to have it working every time.

In "Custom Script for Logged Out Users" we set:

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" we set:

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);

And it works great now. :-)

How can i adapt this for sso (keycloak) ... So far there is no proper solution for this issue.

rtest12 avatar Feb 25 '22 20:02 rtest12

I ended up with the following Custom Script for Logged Out Users to get my Keycloak SAML auto login.

if ( window.location.search != '?direct=1' ) {
  setTimeout(function() { 
    document.querySelector('button[title=Saml]').click();
  }, 500);
}

I tried window.onload but it looks like loading is already completed (judging by document.readyState) when the scripts runs. I also added a cheap check if query string ends like ?direct=1 for manually preventing the auto clicking on demand.

b2ag avatar Mar 24 '23 02:03 b2ag