microsoft-identity-web icon indicating copy to clipboard operation
microsoft-identity-web copied to clipboard

[Feature Request] Allow configuration of HttpClients for IDownstreamWebApi

Open h3rmanj opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. I'd like to add Polly policies, described in these docs on how to implement resilient http requests.

However I can't really access the HttpClientBuilder when using the recommended way to call downstream apis.

There seems to be some incompatibility in whats recommended, and I'd like the gap to be closed.

Describe the solution you'd like Some way to configure the HttpClients used by IDownstreamWebApi. I've proposed a solution in #1735 which allows the user to pass a configureHttpClientBuilder to AddDownstreamWebApi().

Additional context This was partly pointed out in #891 but wasn't really addressed when closed.

h3rmanj avatar May 24 '22 14:05 h3rmanj

Not sure if this helps, but this is what I´m doing to achieve what you need. Basically, I´m overwriting the HttpClient used by AddDownstreamWebApi() and then adding my Polly stuff in the HttpClientBuilder returned. In my case, it also helps to change some headers, as I´m calling SharePoint REST API, and returned XML by default

services
                .AddHttpClient<IDownstreamWebApi, DownstreamWebApi>(client =>
                {
                    client.DefaultRequestHeaders.Add("Accept", "application/json");
                })
                .AddMyPollyStuff();

luismanez avatar Jun 29 '22 05:06 luismanez

I didn't think of that, looks like a good solution/workaround in scenarios where one policy is enough.

In my case I call multiple downstream APIs, each with different needs, so I need to be able to specify a policy per API.

h3rmanj avatar Jun 29 '22 09:06 h3rmanj

We would really like this for our project too.

bosteelsd avatar Nov 09 '22 08:11 bosteelsd

It's coming in v2 with the new DownstreamRestApi interface https://github.com/AzureAD/microsoft-identity-web/pull/1735#issuecomment-1308012205

h3rmanj avatar Nov 09 '22 09:11 h3rmanj

done in 2.5.0.

jennyf19 avatar Feb 28 '23 04:02 jennyf19