diff --git a/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Additional.cs b/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Additional.cs index 23781ea9ff..1644a66a23 100644 --- a/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Additional.cs +++ b/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Additional.cs @@ -10,6 +10,8 @@ using Microsoft.Extensions.Http; using System; using System.Net.Http; +using IdentityServer4; +using Microsoft.Extensions.Logging; namespace Microsoft.Extensions.DependencyInjection { @@ -332,7 +334,7 @@ public static IIdentityServerBuilder AddBackChannelLogoutService(this IIdenti /// public static IHttpClientBuilder AddBackChannelLogoutHttpClient(this IIdentityServerBuilder builder, Action configureClient = null) { - var name = typeof(BackChannelLogoutHttpClient).Name; + const string name = IdentityServerConstants.HttpClients.BackChannelLogoutHttpClient; IHttpClientBuilder httpBuilder; if (configureClient != null) @@ -344,13 +346,13 @@ public static IHttpClientBuilder AddBackChannelLogoutHttpClient(this IIdentitySe httpBuilder = builder.Services.AddHttpClient(name); } - httpBuilder.Services.AddTransient(s => + builder.Services.AddTransient(s => { var httpClientFactory = s.GetRequiredService(); var httpClient = httpClientFactory.CreateClient(name); - - var typedClientFactory = s.GetRequiredService>(); - return typedClientFactory.CreateClient(httpClient); + var loggerFactory = s.GetRequiredService(); + + return new BackChannelLogoutHttpClient(httpClient, loggerFactory); }); return httpBuilder; @@ -366,7 +368,7 @@ public static IHttpClientBuilder AddBackChannelLogoutHttpClient(this IIdentitySe /// public static IHttpClientBuilder AddJwtRequestUriHttpClient(this IIdentityServerBuilder builder, Action configureClient = null) { - var name = typeof(JwtRequestUriHttpClient).Name; + const string name = IdentityServerConstants.HttpClients.JwtRequestUriHttpClient; IHttpClientBuilder httpBuilder; if (configureClient != null) @@ -377,14 +379,14 @@ public static IHttpClientBuilder AddJwtRequestUriHttpClient(this IIdentityServer { httpBuilder = builder.Services.AddHttpClient(name); } - - httpBuilder.Services.AddTransient(s => + + builder.Services.AddTransient(s => { var httpClientFactory = s.GetRequiredService(); var httpClient = httpClientFactory.CreateClient(name); + var loggerFactory = s.GetRequiredService(); - var typedClientFactory = s.GetRequiredService>(); - return typedClientFactory.CreateClient(httpClient); + return new JwtRequestUriHttpClient(httpClient, loggerFactory); }); return httpBuilder; diff --git a/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Core.cs b/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Core.cs index d744bdd1fb..5230d4f863 100644 --- a/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Core.cs +++ b/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Core.cs @@ -175,8 +175,6 @@ public static IIdentityServerBuilder AddPluggableServices(this IIdentityServerBu builder.AddJwtRequestUriHttpClient(); builder.AddBackChannelLogoutHttpClient(); - //builder.Services.AddHttpClient(); - //builder.Services.AddHttpClient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/src/IdentityServer4/src/IdentityServerConstants.cs b/src/IdentityServer4/src/IdentityServerConstants.cs index 63a2b8f150..1ac156202a 100644 --- a/src/IdentityServer4/src/IdentityServerConstants.cs +++ b/src/IdentityServer4/src/IdentityServerConstants.cs @@ -158,5 +158,11 @@ public static class UserCodeTypes { public const string Numeric = "Numeric"; } + + public static class HttpClients + { + public const string JwtRequestUriHttpClient = "IdentityServer:JwtRequestUriClient"; + public const string BackChannelLogoutHttpClient = "IdentityServer:BackChannelLogoutClient"; + } } } \ No newline at end of file diff --git a/src/IdentityServer4/src/Services/Default/BackChannelLogoutHttpClient.cs b/src/IdentityServer4/src/Services/Default/BackChannelLogoutHttpClient.cs index 1a37d78181..2b0af5a245 100644 --- a/src/IdentityServer4/src/Services/Default/BackChannelLogoutHttpClient.cs +++ b/src/IdentityServer4/src/Services/Default/BackChannelLogoutHttpClient.cs @@ -22,11 +22,11 @@ public class BackChannelLogoutHttpClient /// Constructor for BackChannelLogoutHttpClient. /// /// - /// - public BackChannelLogoutHttpClient(HttpClient client, ILogger logger) + /// + public BackChannelLogoutHttpClient(HttpClient client, ILoggerFactory loggerFactory) { _client = client; - _logger = logger; + _logger = loggerFactory.CreateLogger(); } /// diff --git a/src/IdentityServer4/src/Services/Default/JwtRequestUriHttpClient.cs b/src/IdentityServer4/src/Services/Default/JwtRequestUriHttpClient.cs index d8bf2f5b3f..71cc2bcbf9 100644 --- a/src/IdentityServer4/src/Services/Default/JwtRequestUriHttpClient.cs +++ b/src/IdentityServer4/src/Services/Default/JwtRequestUriHttpClient.cs @@ -21,11 +21,11 @@ public class JwtRequestUriHttpClient /// Constructor for DefaultJwtRequestUriHttpClient. /// /// - /// - public JwtRequestUriHttpClient(HttpClient client, ILogger logger) + /// + public JwtRequestUriHttpClient(HttpClient client, ILoggerFactory loggerFactory) { _client = client; - _logger = logger; + _logger = loggerFactory.CreateLogger(); } /// diff --git a/src/IdentityServer4/test/IdentityServer.UnitTests/Validation/Setup/Factory.cs b/src/IdentityServer4/test/IdentityServer.UnitTests/Validation/Setup/Factory.cs index 5c0bcd6f5b..0cd9c7e2e9 100644 --- a/src/IdentityServer4/test/IdentityServer.UnitTests/Validation/Setup/Factory.cs +++ b/src/IdentityServer4/test/IdentityServer.UnitTests/Validation/Setup/Factory.cs @@ -205,7 +205,7 @@ public static AuthorizeRequestValidator CreateAuthorizeRequestValidator( if (jwtRequestUriHttpClient == null) { - jwtRequestUriHttpClient = new JwtRequestUriHttpClient(new HttpClient(new NetworkHandler(new Exception("no jwt request uri response configured"))), new LoggerFactory().CreateLogger()); + jwtRequestUriHttpClient = new JwtRequestUriHttpClient(new HttpClient(new NetworkHandler(new Exception("no jwt request uri response configured"))), new LoggerFactory()); }