Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

switch to named HTTP clients from factory (instead of typed) #4227

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Microsoft.Extensions.Http;
using System;
using System.Net.Http;
using IdentityServer4;
using Microsoft.Extensions.Logging;

namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -332,7 +334,7 @@ public static IIdentityServerBuilder AddBackChannelLogoutService<T>(this IIdenti
/// <returns></returns>
public static IHttpClientBuilder AddBackChannelLogoutHttpClient(this IIdentityServerBuilder builder, Action<HttpClient> configureClient = null)
{
var name = typeof(BackChannelLogoutHttpClient).Name;
const string name = IdentityServerConstants.HttpClients.BackChannelLogoutHttpClient;
IHttpClientBuilder httpBuilder;

if (configureClient != null)
Expand All @@ -344,13 +346,13 @@ public static IHttpClientBuilder AddBackChannelLogoutHttpClient(this IIdentitySe
httpBuilder = builder.Services.AddHttpClient(name);
}

httpBuilder.Services.AddTransient<BackChannelLogoutHttpClient>(s =>
builder.Services.AddTransient<BackChannelLogoutHttpClient>(s =>
{
var httpClientFactory = s.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient(name);

var typedClientFactory = s.GetRequiredService<ITypedHttpClientFactory<BackChannelLogoutHttpClient>>();
return typedClientFactory.CreateClient(httpClient);
var loggerFactory = s.GetRequiredService<ILoggerFactory>();

return new BackChannelLogoutHttpClient(httpClient, loggerFactory);
});

return httpBuilder;
Expand All @@ -366,7 +368,7 @@ public static IHttpClientBuilder AddBackChannelLogoutHttpClient(this IIdentitySe
/// <returns></returns>
public static IHttpClientBuilder AddJwtRequestUriHttpClient(this IIdentityServerBuilder builder, Action<HttpClient> configureClient = null)
{
var name = typeof(JwtRequestUriHttpClient).Name;
const string name = IdentityServerConstants.HttpClients.JwtRequestUriHttpClient;
IHttpClientBuilder httpBuilder;

if (configureClient != null)
Expand All @@ -377,14 +379,14 @@ public static IHttpClientBuilder AddJwtRequestUriHttpClient(this IIdentityServer
{
httpBuilder = builder.Services.AddHttpClient(name);
}

httpBuilder.Services.AddTransient<JwtRequestUriHttpClient>(s =>
builder.Services.AddTransient<JwtRequestUriHttpClient>(s =>
{
var httpClientFactory = s.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient(name);
var loggerFactory = s.GetRequiredService<ILoggerFactory>();

var typedClientFactory = s.GetRequiredService<ITypedHttpClientFactory<JwtRequestUriHttpClient>>();
return typedClientFactory.CreateClient(httpClient);
return new JwtRequestUriHttpClient(httpClient, loggerFactory);
});

return httpBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ public static IIdentityServerBuilder AddPluggableServices(this IIdentityServerBu

builder.AddJwtRequestUriHttpClient();
builder.AddBackChannelLogoutHttpClient();
//builder.Services.AddHttpClient<BackChannelLogoutHttpClient>();
//builder.Services.AddHttpClient<JwtRequestUriHttpClient>();

builder.Services.AddTransient<IClientSecretValidator, ClientSecretValidator>();
builder.Services.AddTransient<IApiSecretValidator, ApiSecretValidator>();
Expand Down
6 changes: 6 additions & 0 deletions src/IdentityServer4/src/IdentityServerConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class BackChannelLogoutHttpClient
/// Constructor for BackChannelLogoutHttpClient.
/// </summary>
/// <param name="client"></param>
/// <param name="logger"></param>
public BackChannelLogoutHttpClient(HttpClient client, ILogger<BackChannelLogoutHttpClient> logger)
/// <param name="loggerFactory"></param>
public BackChannelLogoutHttpClient(HttpClient client, ILoggerFactory loggerFactory)
{
_client = client;
_logger = logger;
_logger = loggerFactory.CreateLogger<BackChannelLogoutHttpClient>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class JwtRequestUriHttpClient
/// Constructor for DefaultJwtRequestUriHttpClient.
/// </summary>
/// <param name="client"></param>
/// <param name="logger"></param>
public JwtRequestUriHttpClient(HttpClient client, ILogger<JwtRequestUriHttpClient> logger)
/// <param name="loggerFactory"></param>
public JwtRequestUriHttpClient(HttpClient client, ILoggerFactory loggerFactory)
{
_client = client;
_logger = logger;
_logger = loggerFactory.CreateLogger<JwtRequestUriHttpClient>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>());
jwtRequestUriHttpClient = new JwtRequestUriHttpClient(new HttpClient(new NetworkHandler(new Exception("no jwt request uri response configured"))), new LoggerFactory());
}


Expand Down