Skip to content

Commit

Permalink
Add netstandard2.0 support (#24)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
stevenvolckaert and Steven Volckaert authored Mar 8, 2024
1 parent d4e105f commit 721bce5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
26 changes: 15 additions & 11 deletions src/Auth0Net.DependencyInjection/Auth0Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ public static IHttpClientBuilder AddAuth0AuthenticationClientCore(this IServiceC
/// <returns>An <see cref="IHttpClientBuilder" /> that can be used to configure the <see cref="HttpClientAuthenticationConnection"/>.</returns>
public static IHttpClientBuilder AddAuth0AuthenticationClient(this IServiceCollection services, Action<Auth0Configuration> 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<Auth0Configuration>()
.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);
}


/// <summary>
/// Adds a <see cref="AuthenticationApiClient" /> integrated with <see cref="IHttpClientBuilder" /> as well as the <see cref="IAuth0TokenCache" /> and related services to the <see cref="IServiceCollection" />.
/// </summary>
Expand All @@ -69,14 +69,14 @@ public static IHttpClientBuilder AddAuth0AuthenticationClient(this IServiceColle
/// <returns>An <see cref="IHttpClientBuilder" /> that can be used to configure the <see cref="HttpClientAuthenticationConnection"/>.</returns>
public static IHttpClientBuilder AddAuth0AuthenticationClient(this IServiceCollection services, Action<Auth0Configuration, IServiceProvider> 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<Auth0Configuration>()
.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);
}

Expand All @@ -91,15 +91,17 @@ private static IHttpClientBuilder AddAuth0AuthenticationClientInternal(this ISer

services.AddSingleton<IAuthenticationApiClient, InjectableAuthenticationApiClient>();
return services.AddHttpClient<IAuthenticationConnection, HttpClientAuthenticationConnection>()
.ConfigurePrimaryHttpMessageHandler(() =>
#if !NETSTANDARD2_0
.ConfigurePrimaryHttpMessageHandler(() =>
new SocketsHttpHandler()
{
PooledConnectionLifetime = TimeSpan.FromMinutes(2)
})
#endif
.SetHandlerLifetime(Timeout.InfiniteTimeSpan);
}



/// <summary>
/// Adds a <see cref="ManagementApiClient" /> integrated with <see cref="IHttpClientBuilder" /> to the <see cref="IServiceCollection" />.
Expand All @@ -114,11 +116,13 @@ public static IHttpClientBuilder AddAuth0ManagementClient(this IServiceCollectio
services.AddSingleton<IManagementApiClient, InjectableManagementApiClient>();

return services.AddHttpClient<IManagementConnection, HttpClientManagementConnection>()
.ConfigurePrimaryHttpMessageHandler(() =>
#if !NETSTANDARD2_0
.ConfigurePrimaryHttpMessageHandler(() =>
new SocketsHttpHandler()
{
PooledConnectionLifetime = TimeSpan.FromMinutes(2)
})
#endif
.SetHandlerLifetime(Timeout.InfiniteTimeSpan);
}

Expand All @@ -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<IAuth0TokenCache>(), c));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>3.1.0</Version>
<Version>3.1.1</Version>
<Authors>Hawxy</Authors>
<Description>Dependency Injection, HttpClientFactory &amp; ASP.NET Core extensions for Auth0.NET</Description>
<LangVersion>latest</LangVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Copyright>Hawxy 2020-2023</Copyright>
<PackageIcon>icon.png</PackageIcon>
Expand All @@ -26,6 +27,13 @@
<PackageReference Include="ZiggyCreatures.FusionCache" Version="0.24.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Polyfill" Version="3.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<TargetFrameworks>net48;net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 721bce5

Please sign in to comment.