ServiceCallout does not follow url redirects

Hi all,
I am trying to call in a SC a target url which is an oidc url (so it's made by a couple of redirects which will generate at the end a code). Unfortunatelly SC seems not be able to automatically follow the redirects and, even if I try to made several SC trying to generating dinamically the target url looking at 'location' and 'Location' in response headers, i am blocked to the second SC as if it doesn't see the cookies even if i send it.

I even tried this JS solution by @dchiesa1 (https://www.googlecloudcommunity.com/gc/Apigee/ServiceCallout-does-not-follow-URL-Redirects-Http-302...) but same error, can enyone help me? 🙂 Thanks!

0 1 80
1 REPLY 1

"Same error" means the target does not receive cookies?  

If you used the JS approach I showed, Have you set the cookies in the outgoing request?  You would need to explicitly set the headers in the request to contain the cookies you want. The ServiceCallout policy does not follow redirects automatically, and if you want to "follow them" manually, you must take care of all of these details.  Likewise with httpClient in the JS callout.  You will need to set outbound headers explicitly. 

BTW, when I build API proxies to "mediate" oidC, I just configure my API proxies to propagate the redirect to the client.  the browser client manages the cookies and the Location and all of that.  The only thing you may need to do is rewrite the target URL, so that the client redirects back through an Apigee API proxy.  Even that is not always required. 

If you explained more about what you are REALLY trying to do, someone here may be able to help find a more elegant solution than teaching the Apigee API proxy to impersonate a browser and follow redirects.