The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Redirecting \$m.do#/login to SSO login page using global UI Script

lasse3
Mega Guru

I have a challenge where I need to redirect the login page of the mobile login page of ServiceNow to use SSO instead. Shortly the customer dislikes the behaviour of the mobile login page and would like to forward it to the default IDP using Multi-Provider SSO.

It is only the mobile login that should be forwarded, as for the desktop version different login screens are presented depending on which service portal etc. the user enters. So redirecting everything by setting the glide option glide.authenticate.sso.redirect.idp to the sys_id of the IdP seems not to be an option.

I tried to accomplish this by adding a global UI script that looks like this:

var u = window.location.href.toString();

console.log('Evaluating if mobile URL - ' + u);

if(u.indexOf('$m.do#/login') > -1) {

  var ssourl = gs.getProperty('glide.servlet.uri') + '/login_locate_sso.do';

  console.log('Redirecting to ' + ssourl);

  //top.window.location.href = ssourl;

}

When entering $m.do#/login I would expect to see both of the log statements above, but if I monitor the javascript console the only thing that is outputtet if I go to $m.do#/login is: "ServiceNow Mobile is running!"

If I go to any other desktop page the "Evaluating if mobile URL -" log statement is added to the console as expected.

Am I missing something here or is custom ui scripts simply not included in the mobile UI? Is there another way to accomplish what I want?

1 ACCEPTED SOLUTION

lasse3
Mega Guru

So I have solved my own issue. Instead of using a UI Script I used the glide.authenticate.sso.redirect.idp to redirect everything to SSO per default. I then cloned the "Login" widget of the Service Portal and named it "External Login". I then removed the code redirecting to SSO, which is this part:



if (!c.data.is_logged_in && c.data.multisso_enabled &&c.data.default_idp) {


    c.server.get({


    action: "set_sso_destination",


    pageURI: c.data.pageURI


    }).then(function() {


    $window.location = "/login_with_sso.do?glide_sso_id=" + c.data.default_idp;


    });


}



I then replaced the Login widget with the External Login widget on the Service Portals where I did not want SSO.


View solution in original post

1 REPLY 1

lasse3
Mega Guru

So I have solved my own issue. Instead of using a UI Script I used the glide.authenticate.sso.redirect.idp to redirect everything to SSO per default. I then cloned the "Login" widget of the Service Portal and named it "External Login". I then removed the code redirecting to SSO, which is this part:



if (!c.data.is_logged_in && c.data.multisso_enabled &&c.data.default_idp) {


    c.server.get({


    action: "set_sso_destination",


    pageURI: c.data.pageURI


    }).then(function() {


    $window.location = "/login_with_sso.do?glide_sso_id=" + c.data.default_idp;


    });


}



I then replaced the Login widget with the External Login widget on the Service Portals where I did not want SSO.