I am attempting to get a modified sample project working with the HeaderLoginModule and HeaderAuthenticator to protect an adapter and then call an adapter function from the sample project by setting the headers and using the WLResourceRequest JavaScript API. I believe that based on my configuration of the loginModule, where I am setting a user-name-header value, and setting this in the header of the WLResourceRequest and then calling send(), that this should provide the user object and then the adapter should be accessible. For some reason though I still get 500 and the log shows 401/unauthorized.
Here are the steps I used to set up this sample:
1) git clone the Cordova sample project at https://github.com/MobileFirst-Platform-Developer-Center/Cordova
2) Added the following sections to authenticationConfig.xml (within the appropriate sections)
<loginModule name="HeaderLoginModule" audit="true">
<className>com.worklight.core.auth.ext.HeaderLoginModule</className>
<parameter name="user-name-header" value="plentyid"/>
<parameter name="display-name-header" value="customername"/>
</loginModule>
<realm name="MyRealm" loginModule="HeaderLoginModule">
<className>com.worklight.core.auth.ext.HeaderAuthenticator</className>
</realm>
<mobileSecurityTest name="MyMobileSecurityTest">
<testUser realm="MyRealm" />
<testDeviceId provisioningType="none" />
</mobileSecurityTest>
3) Secured the adapter with the security test by changing this line in the adapter XML file
<procedure name="getFeed" securityTest="MyMobileSecurityTest"/>
4) Changed the getRSSFeed function as follows
getRSSFeed: function(){
var resourceRequest = new WLResourceRequest(
"/adapters/RSSAdapter/getFeed",
WLResourceRequest.GET);
resourceRequest.addHeader("plentyid","1234");
resourceRequest.addHeader("customername","John Smith");
resourceRequest.setHeader("plentyid","1234");
resourceRequest.setHeader("customername","John Smith");
WL.Logger.info(resourceRequest.getHeaders());
resourceRequest.send().then(app.getRSSFeedSuccess,app.getRSSFeedError);
}
** I will say on the above I could not tell whether to addHeader or setHeader from the documentation. I tried both separately, then both together. They seem to be set from looking at the call to getHeaders().
Thanks for any help with figuring out why this is still 401/Unauthorized when clicking the Adapter button in the app after I mfp push both the RSSAdapter project (MFP) and the Cordova project (app).