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

Created on 24 Feb 2016  路  9Comments  路  Source: RocketChat/Rocket.Chat

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.

Auth - CAS

Most helpful comment

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

All 9 comments

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

+1, highly needed!

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

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

+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.

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.

+1 We really need this.

@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. :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neha1deshmukh picture neha1deshmukh  路  3Comments

mddvul22 picture mddvul22  路  3Comments

lunitic picture lunitic  路  3Comments

Buzzele picture Buzzele  路  3Comments

royalaid picture royalaid  路  3Comments