OpenAM 13 – Getting contextPath while customizing DataStore1.html

This topic has 1 reply, 1 voice, and was last updated 1 month, 1 week ago by l.scorcia.

  • Author
    Posts
  • #27580
     l.scorcia
    Participant

    Hello everyone,
    I am trying to customize the UI of our OpenAM 13 setup by editing DataStore1.html and some other html template and I need to build an absolute url to OpenAM (i.e. current URI is https://login.domain.com:8080/openam/XUI/#login, I need to get https://login.domain.com:8080/openam), in order to pass it to the RelayState parameter of spSSOInit.jsp .

    Now, this is not impossible to get using the various window.location properties, but I was trying to keep it independent of the actual deployment, so I was wondering if there is a direct way to get the current protocol+host+port+contextPath from some property available to the UI via Handlebars or global variables or something else. If it were a JSP I would just use ‘${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}’, but here we’re in a static html template and I don’t know if there is some way to get the required pieces, especially the contextPath. Do you have any suggestions?

    Thanks in advance,
    Luca

    #27670
     l.scorcia
    Participant

    Well, in case anyone else need this in the future, I haven’t been able to get it using Handlebars’ data but it turns out it can actually be done in javascript using the XUI scripts!

    require(["org/forgerock/commons/ui/common/util/Constants"], 
      function (constants) { 
        console.log(constants.context); 
      });

    This returns the application context, i.e. for https :// login.domain.com:8080/openam/XUI/#login (spaces added for antispam filter) this returns openam .
    The scheme/host/port can also be retrieved using a similar snippet:

    require(["Router"], 
      function (router) { 
        console.log(router.getCurrentUrlBasePart()); 
      });

    returns http :// login.domain.com:8080 (spaces added for antispam filter).

    Have a nice day,
    Luca

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

©2020 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?