The CreatorCon Call for Content is officially open! Get started here.

Redirecting Users to the KB Article they were previously on after login

Jackie23
Kilo Guru

We have an issue where users try to access KB Articles before logging in, usually from a direct link someone else sends, and after they log in and successfully authenticate it takes them back to our homepage instead of the KB Article they were on. 

We had this same problem a while ago for Catalog Items and successfully routed them back to the item after logging in with SSO Authentication. We used the same logic and scripting for KB Articles, but that doesn't work for this. We put the script below behind the login button in the header, which should be the same on both Items and KB Articles. 

 

Again, this worked for redirection back to Catalog Items but not for redirection back to KB Articles.

 

Jackie23_0-1716212386217.png

 

Has anyone had this issue, or can think of another route to take? 


Thanks.

1 ACCEPTED SOLUTION

sharepointau
Giga Guru

Yes. This can be mitigated by checking to see if the URL is navigating to the knowledge table.

 

You can update your code above like this:

var c=this; 
$scope.openLogin = function() {
        if (!c.data.is_logged_in) {
            /*START GET URL FOR KB ARTICLE*/
            var originalURL = $window.location.href; //Get current URL
            var kbSubstr = "sys_kb_id";
            var redirectToURL, modifiedURL;
           
            if (originalURL.includes(kbSubstr) === true) {//determine if URL is for KB Article
                modifiedURL = originalURL.replace("/en", ""); //remove "/en" from the URL
                redirectToURL = modifiedURL; //return correct URL
            } else {
                redirectToURL = originalURL;//set redirect to origin URL
            }
            /*END GET URL FOR KB ARTICLE*/

            c.server.get({
                action: "set_sso_destination",
                pageURI: redirectToURL //Set URL to return to after login was $window.location.href
            }).then(function() {
                window.location = "/login_with_sso.do";
            });
        }

View solution in original post

2 REPLIES 2

sharepointau
Giga Guru

Yes. This can be mitigated by checking to see if the URL is navigating to the knowledge table.

 

You can update your code above like this:

var c=this; 
$scope.openLogin = function() {
        if (!c.data.is_logged_in) {
            /*START GET URL FOR KB ARTICLE*/
            var originalURL = $window.location.href; //Get current URL
            var kbSubstr = "sys_kb_id";
            var redirectToURL, modifiedURL;
           
            if (originalURL.includes(kbSubstr) === true) {//determine if URL is for KB Article
                modifiedURL = originalURL.replace("/en", ""); //remove "/en" from the URL
                redirectToURL = modifiedURL; //return correct URL
            } else {
                redirectToURL = originalURL;//set redirect to origin URL
            }
            /*END GET URL FOR KB ARTICLE*/

            c.server.get({
                action: "set_sso_destination",
                pageURI: redirectToURL //Set URL to return to after login was $window.location.href
            }).then(function() {
                window.location = "/login_with_sso.do";
            });
        }

This worked, thank you!