Get Headers and Cookies in JavaScript InfoMap Mechanism

In a previous post, I shared a way to get headers in OTP mapping rules and in the AuthSvcCred Mapping rules.

Since the infomap module is a little bit different, I have included an example of how you can do it there:


//Get from headers...
var headerValue = context.get(Scope.REQUEST, 
                   "urn:ibm:security:asf:request:header", "customHeader");
IDMappingExtUtils.traceString("Header Value Acquired: " + headerValue);

//Get from headers...
var headerMap = context.get(Scope.REQUEST, "internal:authsvc:request", "headersMap");
IDMappingExtUtils.traceString("Header Value Acquired: " + headerMap);
var cookieString = "Cookies";
var userAgentString = "User-Agent: ";

//Get a Header
var userAgentArray = headerMap.get("User-Agent");
if (userAgentArray != null && userAgentArray.length == 1 )
    userAgentString += userAgentArray[0];

//Get the Cookie Header
var cookiesArray = headerMap.get("Cookie");
if (cookiesArray != null && cookiesArray.length == 1)
    cookieString = " : " + cookiesArray[0]; 

//Output to the template - using the ERROR_MESSAGE Macro. 

macros.put("@ERROR_MESSAGE@", "User-Agent: " + userAgentString +
                                  " CookieString: " + cookieString);


Here is the output into my MACRO for easy debugging:

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:50.0) 
Gecko/20100101 Firefox/50.0 Num Cookies: 1 Values: Cookies : 
4f55-8a8d-bb831e86e24b; AnotherCookie=AUeXJbfnWt33PIMZ3tvfyP0SuvRc

Fairly simple, and then it’s a standard JavaScript process to process the cookies by name. Of which there are countless examples on the internet, for example:

Some of the useful things that this can enable:

  • Custom behaviour for remember me.
  • Reading in the fingerprint cookie (ac.uuid) to make an infoMap call to Context Based Access.
  • Reading in the referrer header for prefilling details on a page.

Comments are closed.

Website Built with

Up ↑

%d bloggers like this: