Skip to content

Commit 79a458b

Browse files
authored
v5.0.0 (#30)
* v5.0.0 * Fix build * . * Update README --------- Co-authored-by: JT <[email protected]>
1 parent 16b8606 commit 79a458b

File tree

11 files changed

+83
-28
lines changed

11 files changed

+83
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This library hopes to solve that problem, featuring:
1818

1919
:white_check_mark: `IHttpClientBuilder` extensions, providing handlers to automatically append access tokens to outgoing requests.
2020

21-
This library is compatible with all .NET Standard 2.0 runtimes (.NET 8+ recommended) and is suitable for use in ASP.NET Core and standalone .NET Generic Host applications.
21+
This library is compatible with .NET 8+ as well as .NET Framework 4.8 and is suitable for use in ASP.NET Core and standalone .NET Generic Host applications.
2222

2323
## Install
2424

build/Build.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Nuke.Common.Tools.DotNet;
1111
using Nuke.Common.Utilities.Collections;
1212
using static Nuke.Common.EnvironmentInfo;
13-
using static Nuke.Common.IO.FileSystemTasks;
1413
using static Nuke.Common.IO.PathConstruction;
1514
using static Nuke.Common.Tools.DotNet.DotNetTasks;
1615

build/_build.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Nuke.Common" Version="8.1.4" />
14+
<PackageReference Include="Nuke.Common" Version="9.0.4" />
1515
</ItemGroup>
1616

1717
</Project>

samples/Sample.AspNetCore/Sample.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Grpc.AspNetCore" Version="2.66.0" />
11+
<PackageReference Include="Grpc.AspNetCore" Version="2.67.0" />
1212
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
1313
</ItemGroup>
1414

samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Google.Protobuf" Version="3.28.3" />
13-
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.66.0" />
14-
<PackageReference Include="Grpc.Tools" Version="2.67.0">
12+
<PackageReference Include="Google.Protobuf" Version="3.29.2" />
13+
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.67.0" />
14+
<PackageReference Include="Grpc.Tools" Version="2.68.1">
1515
<PrivateAssets>all</PrivateAssets>
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
</PackageReference>

src/Auth0Net.DependencyInjection/Auth0Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private static IHttpClientBuilder AddAuth0AuthenticationClientInternal(this ISer
9191

9292
services.AddSingleton<IAuthenticationApiClient, InjectableAuthenticationApiClient>();
9393
return services.AddHttpClient<IAuthenticationConnection, HttpClientAuthenticationConnection>()
94-
#if !NETSTANDARD2_0
94+
#if !NETFRAMEWORK
9595
.ConfigurePrimaryHttpMessageHandler(() =>
9696
new SocketsHttpHandler()
9797
{
@@ -116,7 +116,7 @@ public static IHttpClientBuilder AddAuth0ManagementClient(this IServiceCollectio
116116
services.AddSingleton<IManagementApiClient, InjectableManagementApiClient>();
117117

118118
return services.AddHttpClient<IManagementConnection, HttpClientManagementConnection>()
119-
#if !NETSTANDARD2_0
119+
#if !NETFRAMEWORK
120120
.ConfigurePrimaryHttpMessageHandler(() =>
121121
new SocketsHttpHandler()
122122
{

src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net48;net8.0;net9.0</TargetFrameworks>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
8-
<Version>4.0.0</Version>
8+
<Version>5.0.0</Version>
99
<Authors>Hawxy</Authors>
1010
<Description>Dependency Injection, HttpClientFactory &amp; ASP.NET Core extensions for Auth0.NET</Description>
1111
<LangVersion>latest</LangVersion>
1212
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
13-
<Copyright>Hawxy (JT) 2020-2024</Copyright>
13+
<Copyright>Hawxy (JT) 2020-2025</Copyright>
1414
<PackageIcon>icon.png</PackageIcon>
1515
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1616
<PackageProjectUrl>https://github.com/Hawxy/Auth0Net.DependencyInjection</PackageProjectUrl>
@@ -21,30 +21,31 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="Auth0.AuthenticationApi" Version="7.29.0" />
25-
<PackageReference Include="Auth0.ManagementApi" Version="7.29.0" />
24+
<PackageReference Include="Auth0.AuthenticationApi" Version="7.32.0" />
25+
<PackageReference Include="Auth0.ManagementApi" Version="7.32.0" />
2626
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.2.25" PrivateAssets="All" />
27-
<PackageReference Include="ZiggyCreatures.FusionCache" Version="1.4.1" />
28-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
27+
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.0.0" />
28+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.1" />
2929
</ItemGroup>
3030

31-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
32-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
31+
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
3332
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
33+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
3434
<PackageReference Include="Polyfill" Version="7.4.1" PrivateAssets="all" />
3535
</ItemGroup>
3636

3737
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
3838
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
39+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.0.0" />
3940
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
4041
</ItemGroup>
4142

4243
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
4344
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
45+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
4446
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
4547
</ItemGroup>
46-
47-
48+
4849
<ItemGroup>
4950
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
5051
<_Parameter1>$(MSBuildProjectName).Tests</_Parameter1>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#if NET8_0_OR_GREATER
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.Net;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Http.Resilience;
6+
using Polly;
7+
8+
namespace Auth0Net.DependencyInjection.HttpClient;
9+
10+
/// <summary>
11+
/// Extensions used to enhance Auth0 client resilience.
12+
/// </summary>
13+
public static class Auth0ResilienceExtensions
14+
{
15+
/// <summary>
16+
/// Adds enhanced rate limiting support to the Auth0 Client. This API is experimental.
17+
/// </summary>
18+
/// <param name="builder"></param>
19+
/// <returns></returns>
20+
[Experimental("Auth0DIExperimental")]
21+
public static IHttpResiliencePipelineBuilder AddAuth0RateLimitResilience(this IHttpClientBuilder builder)
22+
{
23+
return builder.AddResilienceHandler("RateLimitRetry",
24+
static builder =>
25+
{
26+
// See: https://www.pollydocs.org/strategies/retry.html
27+
builder.AddRetry(new HttpRetryStrategyOptions
28+
{
29+
// Disable the default handling of Retry-After header
30+
ShouldRetryAfterHeader = false,
31+
DelayGenerator = static args =>
32+
{
33+
if(args.Outcome.Result?.StatusCode is (HttpStatusCode)429
34+
&& args.Outcome.Result.Headers.TryGetValues("x-ratelimit-reset", out var headers)
35+
&& long.TryParse(headers.First(), out var ticks))
36+
{
37+
var retryAt = DateTimeOffset.FromUnixTimeSeconds(ticks);
38+
var timeSpan = retryAt - DateTimeOffset.UtcNow;
39+
return new ValueTask<TimeSpan?>(timeSpan);
40+
}
41+
42+
return new ValueTask<TimeSpan?>((TimeSpan?)null);
43+
},
44+
45+
MaxRetryAttempts = 10,
46+
Delay = TimeSpan.FromSeconds(2)
47+
});
48+
});
49+
}
50+
}
51+
52+
#endif

src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Net.Http.Headers;
1+
using System.Net.Http;
2+
using System.Net.Http.Headers;
23
using Auth0Net.DependencyInjection.Cache;
34
using Microsoft.Extensions.Options;
45

src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandlerConfig.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Auth0Net.DependencyInjection.HttpClient;
1+
using System.Net.Http;
2+
3+
namespace Auth0Net.DependencyInjection.HttpClient;
24

35
/// <summary>
46
/// Configuration used by the underlying <see cref="Auth0TokenHandler"/>.

0 commit comments

Comments
 (0)