From 721bce5b35ebda14f07c2024d2d88e5a10edc712 Mon Sep 17 00:00:00 2001 From: Steven Volckaert Date: Fri, 8 Mar 2024 10:38:45 +0100 Subject: [PATCH] Add netstandard2.0 support (#24) * Add netstandard2.0 target framework * Add net48 target framework, so Auth0Net.DependencyInjection for netstandard2.0 gets tested * Update version to 3.1.1 * Replace `IsExternalInit` polyfill with package reference `Polyfill` * Move package reference `Polyfill` to project `Auth0Net.DependencyInjection` --------- Co-authored-by: Steven Volckaert --- .../Auth0Extensions.cs | 26 +++++++++++-------- .../Auth0Net.DependencyInjection.csproj | 12 +++++++-- .../Auth0Net.DependencyInjection.Tests.csproj | 3 ++- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/Auth0Net.DependencyInjection/Auth0Extensions.cs b/src/Auth0Net.DependencyInjection/Auth0Extensions.cs index 548825c..688f5b6 100644 --- a/src/Auth0Net.DependencyInjection/Auth0Extensions.cs +++ b/src/Auth0Net.DependencyInjection/Auth0Extensions.cs @@ -46,18 +46,18 @@ public static IHttpClientBuilder AddAuth0AuthenticationClientCore(this IServiceC /// An that can be used to configure the . public static IHttpClientBuilder AddAuth0AuthenticationClient(this IServiceCollection services, Action config) { - if(services.Any(x=> x.ServiceType == typeof(IAuthenticationApiClient))) + if (services.Any(x => x.ServiceType == typeof(IAuthenticationApiClient))) throw new InvalidOperationException("AuthenticationApiClient has already been registered!"); services.AddOptions() .Configure(config) .Validate(x => !string.IsNullOrWhiteSpace(x.ClientId) && !string.IsNullOrWhiteSpace(x.Domain) && !string.IsNullOrWhiteSpace(x.ClientSecret), "Auth0 Configuration cannot have empty values"); - + return services.AddAuth0AuthenticationClientInternal(true); } - - + + /// /// Adds a integrated with as well as the and related services to the . /// @@ -69,14 +69,14 @@ public static IHttpClientBuilder AddAuth0AuthenticationClient(this IServiceColle /// An that can be used to configure the . public static IHttpClientBuilder AddAuth0AuthenticationClient(this IServiceCollection services, Action config) { - if(services.Any(x=> x.ServiceType == typeof(IAuthenticationApiClient))) + if (services.Any(x => x.ServiceType == typeof(IAuthenticationApiClient))) throw new InvalidOperationException("AuthenticationApiClient has already been registered!"); services.AddOptions() .Configure(config) .Validate(x => !string.IsNullOrWhiteSpace(x.ClientId) && !string.IsNullOrWhiteSpace(x.Domain) && !string.IsNullOrWhiteSpace(x.ClientSecret), "Auth0 Configuration cannot have empty values"); - + return services.AddAuth0AuthenticationClientInternal(true); } @@ -91,15 +91,17 @@ private static IHttpClientBuilder AddAuth0AuthenticationClientInternal(this ISer services.AddSingleton(); return services.AddHttpClient() - .ConfigurePrimaryHttpMessageHandler(() => +#if !NETSTANDARD2_0 + .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler() { PooledConnectionLifetime = TimeSpan.FromMinutes(2) }) +#endif .SetHandlerLifetime(Timeout.InfiniteTimeSpan); } - - + + /// /// Adds a integrated with to the . @@ -114,11 +116,13 @@ public static IHttpClientBuilder AddAuth0ManagementClient(this IServiceCollectio services.AddSingleton(); return services.AddHttpClient() - .ConfigurePrimaryHttpMessageHandler(() => +#if !NETSTANDARD2_0 + .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler() { PooledConnectionLifetime = TimeSpan.FromMinutes(2) }) +#endif .SetHandlerLifetime(Timeout.InfiniteTimeSpan); } @@ -136,7 +140,7 @@ public static IHttpClientBuilder AddAccessToken(this IHttpClientBuilder builder, if (c.AudienceResolver is null && string.IsNullOrWhiteSpace(c.Audience)) throw new ArgumentException("Audience or AudienceResolver must be set"); - return builder.AddHttpMessageHandler(provider => + return builder.AddHttpMessageHandler(provider => new Auth0TokenHandler(provider.GetRequiredService(), c)); } diff --git a/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj b/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj index 007869f..4f68017 100644 --- a/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj +++ b/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj @@ -1,13 +1,14 @@  - net6.0;net7.0;net8.0 + netstandard2.0;net6.0;net7.0;net8.0 true enable enable - 3.1.0 + 3.1.1 Hawxy Dependency Injection, HttpClientFactory & ASP.NET Core extensions for Auth0.NET + latest true Hawxy 2020-2023 icon.png @@ -26,6 +27,13 @@ + + + + + + + diff --git a/tests/Auth0Net.DependencyInjection.Tests/Auth0Net.DependencyInjection.Tests.csproj b/tests/Auth0Net.DependencyInjection.Tests/Auth0Net.DependencyInjection.Tests.csproj index 9a64cf3..bc11fa1 100644 --- a/tests/Auth0Net.DependencyInjection.Tests/Auth0Net.DependencyInjection.Tests.csproj +++ b/tests/Auth0Net.DependencyInjection.Tests/Auth0Net.DependencyInjection.Tests.csproj @@ -1,8 +1,9 @@  - net6.0;net7.0;net8.0 false + net48;net6.0;net7.0;net8.0 + latest