-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuration of HttpClients used by DownstreamWebApi #1735
Conversation
allow the consumer access to the IHttpClientBuilder, allowing them to things like Polly policies etc. changed to add named clients, which DownstreamWebApi then gets from IHttpClientFactory, allowing the consumer to configure HttpClient per downstream service
…pClient It seems the typed HttpClient expects HttpClient present in the constructor. Register the IDownstreamWebApi as a Transient service like the AddHttpClient would, and only register the named HttpClient.
using TryAddTransient instead of AddTransient
Alternatively, if changing the API of builder.Services.AddMicrosoftIdentityWebApi(builder.Configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamWebApi("AnotherApi", builder.Configuration.GetSection("AnotherApi"))
.AddDistributedTokenCaches();
builder.Services.AddHttpClient("DownstreamApi")
.AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(5),
TimeSpan.FromSeconds(10)
}));
builder.Services.AddHttpClient("AnotherApi")
.AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2)
})); |
@h3rmanj @jennyf19: let's work on collecting all the issues and PRs around IDownstreamWebApi and add the right design for IDownstreamRestApi |
@h3rmanj : what you wrote in #1735 (comment) would work in Microsoft.Identity.Web 2.0.5-preview (with AddDownstrreamRestApi) |
Implemented in 2.5.0 |
Addresses #1740
The MS docs recommends implementing resilient http requests using libraries like Polly. At the same time, the recommended way to make authenticated api calls is through the IDownstreamWebApi interface. This PR closes the gaps in the docs and allows the consumer access to the IHttpClientBuilder, allowing them to add Polly policies for their downstream apis etc.
Changed to add named HttpClients, which DownstreamWebApi then gets from IHttpClientFactory, allowing the consumer to optionally configure HttpClient per downstream service.
Example usage with this: