diff --git a/src/Auth0Net.DependencyInjection/Auth0Extensions.cs b/src/Auth0Net.DependencyInjection/Auth0Extensions.cs index 9d65e31..b5f3aa0 100644 --- a/src/Auth0Net.DependencyInjection/Auth0Extensions.cs +++ b/src/Auth0Net.DependencyInjection/Auth0Extensions.cs @@ -5,6 +5,7 @@ using Auth0Net.DependencyInjection.Injectables; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using IHttpClientFactory = System.Net.Http.IHttpClientFactory; namespace Auth0Net.DependencyInjection; @@ -13,6 +14,8 @@ namespace Auth0Net.DependencyInjection; /// public static class Auth0Extensions { + + private const string ManagementHttpClientKey = nameof(ManagementHttpClientKey); /// /// Adds an integrated with . @@ -117,7 +120,13 @@ public static IHttpClientBuilder AddAuth0ManagementClient(this IServiceCollectio { services.AddSingleton(); - return services.AddHttpClient() + services.AddSingleton(x => + { + var factory = x.GetRequiredService(); + return new HttpClientManagementConnection(factory.CreateClient(ManagementHttpClientKey)); + }); + + return services.AddHttpClient(ManagementHttpClientKey) #if NET8_0 .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler() @@ -130,7 +139,7 @@ public static IHttpClientBuilder AddAuth0ManagementClient(this IServiceCollectio } /// - /// Adds a to the that will automatically add a Auth0 Machine-to-Machine Access Token to the Authorization header. + /// Adds a to the that will automatically add a Auth0 Machine-to-Machine Access Token to the Authorization header. /// /// The you wish to configure. /// A delegate that is used to configure the instance of . @@ -148,7 +157,7 @@ public static IHttpClientBuilder AddAccessToken(this IHttpClientBuilder builder, } /// - /// Adds a to the that will automatically add a Auth0 Management Access Token token to the Authorization header. + /// Adds a to the that will automatically add a Auth0 Management Access Token token to the Authorization header. /// /// /// The domain used to resolve the token is the same as set in , unless overriden. diff --git a/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj b/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj index 17907ec..ccfcddb 100644 --- a/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj +++ b/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj @@ -5,7 +5,7 @@ true enable enable - 5.2.0 + 5.2.1 Hawxy Dependency Injection, HttpClientFactory & ASP.NET Core extensions for Auth0.NET latest @@ -21,8 +21,8 @@ - - + +