Repository navigation
Description
Is your feature request related to a problem? Please describe.
I want to be able to configure the HttpClient made inside the AddDownstreamWebApi call.
I'd like access to HttpClient to be able to set default headers etc. client.DefaultRequestHeaders.
I'd like access to IHttpClientBuilder to be able to call ConfigurePrimaryHttpMessageHandler.
Describe the solution you'd like
The default DownstreamWebApi implementation is nice. But a bit restrictive.
microsoft-identity-web/src/Microsoft.Identity.Web/DownstreamWebApiSupport/DownstreamWebApi.cs
Line 18 in 1a073ed
| public class DownstreamWebApi : IDownstreamWebApi |
Can't we just get a named client with the token stuff sorted :)
Example: (probably not a good api, but should highlight the idea)
// config
services.AddMicrosoftIdentityWebAppAuthentication(Configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddDownstreamHttpClient("MyDownstreamApi",
client =>
{
client.DefaultRequestHeaders.Add(HeaderNames.Accept, MediaTypeNames.Application.Json);
},
builder =>
{
builder.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
});
})
.AddInMemoryTokenCaches();
// usage
using var httpClient = _httpClientFactory.CreateClient("MyDownstreamApi");
// .. do stuffYou would then wrap the usage in a service and everyone would be happy ๐ฎ
This could probably also work for typed clients.
Describe alternatives you've considered
Alternatively we would have to use ITokenAcquisition and write our own http client and copy this
microsoft-identity-web/src/Microsoft.Identity.Web/DownstreamWebApiSupport/DownstreamWebApi.cs
Line 47 in 1a073ed
| public async Task<HttpResponseMessage> CallWebApiForUserAsync( |
But that might change in future versions
Activity
jennyf19 commentedon Jan 8, 2022
Included in the [1.22.0 release](https://github.com/AzureAD/microsoft-identity-web/releases/tag/1.22.00
jmprieur commentedon Jan 8, 2022
Eskild Diderichsen (@snebjorn): you can now customize the HttpRequestMessage. The documentation is Customizing the headers (or the HttpMessageRequest) when using IDownstreamWebApi
snebjorn commentedon Jan 10, 2022
Excellent! Thank you โค๏ธ