Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target framework netstandard 2.0 so Auth0Net.DependencyInjection can be used in .NET Framework and .NET 5.0 #24

Merged
merged 5 commits into from
Mar 8, 2024
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
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
Loading