AnsweredAssumed Answered

Share webscript redirect to Login Page if not authenticated in Alfresco 5.0.2

Question asked by kavilash23 on Dec 22, 2015
Latest reply on Jan 27, 2016 by muralidharand
Hi Guys,

I have a Share webscript (/service/details/{dId}) which when called in turn makes a call to a Repository webscript. If the repo webscript returns a status 401 (which is returned when a user is not authenticated in alfresco) redirects the user to the share login page. See my code snippet below. While this code works in alfresco 4.2.x, the redirect to the share login page is not working. I just get the surf error "The Web Script /share/page/service/details/xxxx has responded with a status of 500 - Internal Error.

var webscript = "/seed/noderef/" + docId;
var connector = remote.connect("alfresco");
var result = connector.get(webscript);
if (result.status == 401) {
    // if fail to login to alfresco
    // should redirect to login page and retry
    redirectUrl = url.context + "/page?alfRedirectUrl=" + url.full;
    //redirectUrl = ""
    payLoad["redirectUrl"] = redirectUrl;
    model.output = packageInResponseJSON(false, status.code, "Redirecting to login page", payLoad);
    // redirect
    status.code = 307; 
    status.location = redirectUrl;

Any advice much appreciated.