Setting client auth when target.url is set by javascript

My app requires target endpoint to be set dynamically based on KVM variable. Is there a way to do this? I tried following link: https://docs.apigee.com/api-platform/reference/policies/javascript-policy. This works but fails when the target.url requires mutual client auth certificate. I tried setting the SSLInfo in the javascript policy but no luck.

SSLInfo settings were independently verified part of HTTPTargetConnection with hardcoded URL.

Any help would be much appreciated.

0 2 126
2 REPLIES 2

Depending on how many backends / different TLS certificates you have, you could potentially use the KVM value in a route rule to determine the correct target server, then have the TLS info in the proxy XML.

Thank you. It turns out that URI and query parameters have to be explicitly copied from request when setting the target URL in the javascript below. This resolved the issue. Not sure if there what is the overhead with executing the .js and if there is any better way to do this?

var requestURI = context.getVariable('request.uri');

var proxyBasePath = context.getVariable('proxy.basepath');

var resourcePath = requestURI.substring(proxyBasePath.length);

var targetURL = 'https://mybackendservice.com' + resourcePath;

context.setVariable('target.url', targetURL);