Service Callout Different Behavior on Dynamic vs Static Target URL

Need a bit of help here as I'm new to Apigee, and have been struggling quite a bit.

To provide context, I'm calling a Service Callout to fetch a JWKS/public key, this works perfectly fine when I statically define my "target.url".  However, when I use a Javascript policy to dynamically update my servicecallout.Service-Callout-1.target.url  like such:
context.setVariable('servicecallout.Service-Callout-1.target.url', targetUrl), 

I'm getting a different response, and it seems to be hitting the root url instead. I've also tried to define my target url with template messaging like: <URL>https://authserverhere.com/{JWKSPath}</URL>, with no luck.

Any clue on what I'm wrong here? Thank you in advance!

0 2 119
2 REPLIES 2

what is contained in the JS variable "targetUrl" ? Does that include the path?

What does the rest of the SC policy look like?

I'm getting a different response, and it seems to be hitting the root url instead.

Maybe you could point your SC policy to something that can help diagnose, like an echo server that tells you the path and verb it requested. You can try echo.dinochiesa.net for that.

I've also tried to define my target url with template messaging like: <URL>https://authserverhere.com/{JWKSPath}</URL>, with no luck.

This should work, it works for me. What is the value of the context variable named "JWKSPath" here? Have you double-checked that?

Also, why are you using a ServiceCallout to connect to a JWKS endpoint anyway? Can you not just specify the URI in the JWKS element?

Thanks for the echo server approach, it allowed me to determine that the issue was due to not properly setting the request url path. 


Also, why are you using a ServiceCallout to connect to a JWKS endpoint anyway? Can you not just specify the URI in the JWKS element?

I was under the impression that the JWKS uri can only be statically defined. In my situation, I need to support multiple authorization servers, which requires a dynamic URI. Is there an approach where I can dynamically define this property?