Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • Sending back a 401 HTTP response code from the executeFetch?

    Hello,

    There is a certain situation where we would like the client to re-authenticate via RPCManager.setLoginRequiredCallback in the client-side code. For example, if the server turns off and on, we want the user to be prompted to re-login if they send certain DSRequests to the server.

    In the server-side code, we want to send back a 401 HTTP response code instead of a normal DSResponse in the executeFetch. This will trigger the client-side code to show the login prompt. How do we cancel the normal DSResponse in the server-side code, and instead send back an HTTP response with the 401 code? The DSResponse.setStatus() does not do it because the HTTP response is still a 200 regardless of the DSResponse status. Thanks.
    Last edited by user316; 16th Aug 2019, 07:02.

  • #2
    Also, what do I need to put in the header or body of the HTTP response so that it triggers the setLoginRequiredCallback? It seems I got it to return the 401 code, but this alone isn't triggering the login page.

    I used this code:

    req.getRPCManager().doCustomResponse();

    HttpServletResponse httpServlet = req.getContext().response;
    httpServlet.setStatus(401);

    Comment


    • #3
      I actually got it to work, or to at least show the login prompt. This was my code:

      req.getRPCManager().doCustomResponse();

      HttpServletResponse httpServlet = req.getContext().response;
      httpServlet.getOutputStream().print("<SCRIPT>//'"]]>>isc_loginRequired");
      httpServlet.setStatus(401);

      Comment


      • #4
        Just to close the loop here: yes, that's the correct way to do your own HTTP response, and sending the loginRequired marker is the right way to trigger the relogin flow.

        Comment

        Working...
        X