diff --git a/build/_build.csproj b/build/_build.csproj index 9cc739d..1ed7e65 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net10.0 CS0649;CS0169 .. @@ -11,7 +11,7 @@ - + diff --git a/samples/Sample.AspNetCore/Program.cs b/samples/Sample.AspNetCore/Program.cs index fa8bfb0..624614b 100644 --- a/samples/Sample.AspNetCore/Program.cs +++ b/samples/Sample.AspNetCore/Program.cs @@ -1,6 +1,4 @@ using Auth0.ManagementApi; -using Auth0.ManagementApi.Models; -using Auth0.ManagementApi.Paging; using Auth0Net.DependencyInjection; using Auth0Net.DependencyInjection.HttpClient; using Microsoft.AspNetCore.Authentication.JwtBearer; @@ -43,7 +41,7 @@ }); // Adds the ManagementApiClient with automatic injection of the management token based on the configuration set above. -builder.Services.AddAuth0ManagementClient().AddManagementAccessToken(); +builder.Services.AddAuth0ManagementClient(); builder.Services.AddGrpc(); @@ -56,9 +54,9 @@ app.MapGet("/users", async ([FromServices] IManagementApiClient client) => { - var user = await client.Users.GetAllAsync(new GetUsersRequest(), new PaginationInfo()); + var user = await client.Users.ListAsync(new ListUsersRequestParameters() { }); - return user.Select(x => new Sample.AspNetCore.User(x.UserId, x.FullName, x.Email)).ToArray(); + return user.CurrentPage.Select(x => new Sample.AspNetCore.User(x.UserId, x.Name, x.Email)).ToArray(); }); diff --git a/samples/Sample.AspNetCore/Protos/UsersService.cs b/samples/Sample.AspNetCore/Protos/UsersService.cs index bcf402e..8b576d1 100644 --- a/samples/Sample.AspNetCore/Protos/UsersService.cs +++ b/samples/Sample.AspNetCore/Protos/UsersService.cs @@ -1,8 +1,4 @@ -using System.Linq; -using System.Threading.Tasks; -using Auth0.ManagementApi; -using Auth0.ManagementApi.Models; -using Auth0.ManagementApi.Paging; +using Auth0.ManagementApi; using Grpc.Core; using User; @@ -18,13 +14,13 @@ public UsersService(IManagementApiClient client) public override async Task GetUser(UserRequest request, ServerCallContext context) { - var users = await _client.Users.GetAllAsync(new GetUsersRequest(), new PaginationInfo()); + var users = await _client.Users.ListAsync(new ListUsersRequestParameters() { PerPage = 10}); return new UserResponse { Users = { - users.Select(x=> new UserDto {UserId = x.UserId, Email = x.Email, FullName = x.FullName}) + users.CurrentPage.Select(x=> new UserDto {UserId = x.UserId, Email = x.Email, FullName = x.Name}) } }; } diff --git a/samples/Sample.AspNetCore/Sample.AspNetCore.csproj b/samples/Sample.AspNetCore/Sample.AspNetCore.csproj index d486b33..9e173ad 100644 --- a/samples/Sample.AspNetCore/Sample.AspNetCore.csproj +++ b/samples/Sample.AspNetCore/Sample.AspNetCore.csproj @@ -1,7 +1,7 @@  - net9.0 + net10.0 ed89c14f-ea75-4b37-83e7-078870067ffc enable enable diff --git a/samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj b/samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj index 67849bc..98ba524 100644 --- a/samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj +++ b/samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj @@ -2,7 +2,7 @@ Exe - net9.0 + net10.0 enable enable 096fd757-814d-4d2a-a02e-ef4f19cdc656 @@ -15,7 +15,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/Auth0Net.DependencyInjection/Auth0Extensions.cs b/src/Auth0Net.DependencyInjection/Auth0Extensions.cs index b5f3aa0..e5d1f0e 100644 --- a/src/Auth0Net.DependencyInjection/Auth0Extensions.cs +++ b/src/Auth0Net.DependencyInjection/Auth0Extensions.cs @@ -1,11 +1,10 @@ using Auth0.AuthenticationApi; using Auth0.ManagementApi; using Auth0Net.DependencyInjection.Cache; +using Auth0Net.DependencyInjection.Factory; using Auth0Net.DependencyInjection.HttpClient; using Auth0Net.DependencyInjection.Injectables; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using IHttpClientFactory = System.Net.Http.IHttpClientFactory; namespace Auth0Net.DependencyInjection; @@ -14,8 +13,6 @@ namespace Auth0Net.DependencyInjection; /// public static class Auth0Extensions { - - private const string ManagementHttpClientKey = nameof(ManagementHttpClientKey); /// /// Adds an integrated with . @@ -26,7 +23,7 @@ public static class Auth0Extensions /// The . /// The root domain for your Auth0 tenant. /// An that can be used to configure the . - public static IHttpClientBuilder AddAuth0AuthenticationClientCore(this IServiceCollection services, string domain) + public static IHttpClientBuilder AddAuth0AuthenticationClient(this IServiceCollection services, string domain) { if (services.Any(x => x.ServiceType == typeof(IAuthenticationApiClient))) throw new InvalidOperationException("AuthenticationApiClient has already been registered!"); @@ -105,9 +102,7 @@ private static IHttpClientBuilder AddAuth0AuthenticationClientInternal(this ISer ; } - - - + /// /// Adds a integrated with to the . /// @@ -115,18 +110,10 @@ private static IHttpClientBuilder AddAuth0AuthenticationClientInternal(this ISer /// The domain used to construct the Management connection is the same as set in . /// /// The . - /// An that can be used to configure the . - public static IHttpClientBuilder AddAuth0ManagementClient(this IServiceCollection services) + /// An that can be used to configure the . + public static IHttpClientBuilder AddAuth0ManagementClient(this IServiceCollection services, Action? config = null) { - services.AddSingleton(); - - services.AddSingleton(x => - { - var factory = x.GetRequiredService(); - return new HttpClientManagementConnection(factory.CreateClient(ManagementHttpClientKey)); - }); - - return services.AddHttpClient(ManagementHttpClientKey) + var httpClientBuilder = services.AddHttpClient(ManagementClientFactory.Auth0ManagementApiClient) #if NET8_0 .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler() @@ -136,6 +123,17 @@ public static IHttpClientBuilder AddAuth0ManagementClient(this IServiceCollectio .SetHandlerLifetime(Timeout.InfiniteTimeSpan) #endif ; + + var optionsBuilder = services.AddOptions(); + + if(config != null) + optionsBuilder.Configure(config); + + services.AddSingleton(); + + services.AddSingleton(sp => sp.GetRequiredService().Create()); + + return httpClientBuilder; } /// @@ -155,24 +153,4 @@ public static IHttpClientBuilder AddAccessToken(this IHttpClientBuilder builder, return builder.AddHttpMessageHandler(provider => new Auth0TokenHandler(provider.GetRequiredService(), c)); } - - /// - /// 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. - /// - /// The you wish to configure. - /// Additional configuration for the management client for custom domain scenarios. - /// An that can be used to configure the . - public static IHttpClientBuilder AddManagementAccessToken(this IHttpClientBuilder builder, Action? config = null) - { - var c = new Auth0ManagementTokenConfiguration(); - config?.Invoke(c); - - return builder.AddHttpMessageHandler(p => - new Auth0ManagementTokenHandler( - p.GetRequiredService(), - p.GetRequiredService>(), c)); - } } \ No newline at end of file diff --git a/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj b/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj index ccfcddb..0704f84 100644 --- a/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj +++ b/src/Auth0Net.DependencyInjection/Auth0Net.DependencyInjection.csproj @@ -1,11 +1,11 @@ - + net48;net8.0;net9.0;net10.0 true enable enable - 5.2.1 + 6.0.0 Hawxy Dependency Injection, HttpClientFactory & ASP.NET Core extensions for Auth0.NET latest @@ -22,37 +22,31 @@ - - - + + + + - - + - - - - - - diff --git a/src/Auth0Net.DependencyInjection/Auth0ResilienceExtensions.cs b/src/Auth0Net.DependencyInjection/Auth0ResilienceExtensions.cs deleted file mode 100644 index 8019dbd..0000000 --- a/src/Auth0Net.DependencyInjection/Auth0ResilienceExtensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -#if NET8_0_OR_GREATER -using System.Net; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Http.Resilience; -using Polly; - -namespace Auth0Net.DependencyInjection; - -/// -/// Extensions used to enhance Auth0 client resilience. -/// -public static class Auth0ResilienceExtensions -{ - /// - /// Adds enhanced rate limiting support to the Auth0 Client. - /// - /// The underlying - /// The max number of retry attempts to Auth0. Defaults to 10. - /// - public static IHttpResiliencePipelineBuilder AddAuth0RateLimitResilience(this IHttpClientBuilder builder, int maxRetryAttempts = 4) - { - return builder.AddResilienceHandler("RateLimitRetry", - pipelineBuilder => - { - pipelineBuilder.AddRetry(new HttpRetryStrategyOptions - { - // Disable the default handling of Retry-After header - ShouldRetryAfterHeader = false, - DelayGenerator = static args => - { - if(args.Outcome.Result?.StatusCode is (HttpStatusCode)429 - && args.Outcome.Result.Headers.TryGetValues("x-ratelimit-reset", out var headers) - && long.TryParse(headers.First(), out var ticks)) - { - var retryAt = DateTimeOffset.FromUnixTimeSeconds(ticks); - var timeSpan = retryAt - DateTimeOffset.UtcNow; - return new ValueTask(timeSpan); - } - - return new ValueTask((TimeSpan?)null); - }, - MaxRetryAttempts = maxRetryAttempts, - Delay = TimeSpan.FromSeconds(2) - }); - }); - } -} - -#endif \ No newline at end of file diff --git a/src/Auth0Net.DependencyInjection/Cache/Auth0Configuration.cs b/src/Auth0Net.DependencyInjection/Cache/Auth0Configuration.cs index d28df9b..b469369 100644 --- a/src/Auth0Net.DependencyInjection/Cache/Auth0Configuration.cs +++ b/src/Auth0Net.DependencyInjection/Cache/Auth0Configuration.cs @@ -1,4 +1,6 @@ -namespace Auth0Net.DependencyInjection.Cache; +using ZiggyCreatures.Caching.Fusion; + +namespace Auth0Net.DependencyInjection.Cache; /// /// Configuration for the Auth0 Clients and Auth0 Token Cache. @@ -6,7 +8,7 @@ public sealed class Auth0Configuration { /// - /// The default or custom root domain for your Auth0 tenant. + /// The default or custom root domain for your Auth0 tenant. /// public string Domain { get; set; } = null!; /// @@ -17,16 +19,33 @@ public sealed class Auth0Configuration /// The Client Secret of the Auth0 Machine-to-Machine application. /// public string? ClientSecret { get; set; } + + /// + /// This package uses FusionCache internally for token caching. + /// If you have an existing FusionCache configuration you'd like to use (ie one setup with a distributed cache), pass the name of it here. + /// For the default FusionCache instance registered with ".AddFusionCache()", use + /// + public string? FusionCacheInstance { get; set; } + } /// /// Configuration for the Auth0 Management API. /// -public sealed class Auth0ManagementTokenConfiguration +public sealed class Auth0ManagementClientConfiguration { /// - /// This option will replace the use of to compute the audience for the Management API token. - /// Useful when using custom domains. + /// Sets the audience for the Management API token. This is your default Auth0 domain within your tenant and should be set if you're using a custom domain. /// public string? Audience { get; set; } + + /// + /// Sets the max number of retries for the management client. Default is 2. + /// + public int? MaxRetries { get; set; } + + /// + /// Sets the timeout for the management client. Default is 30 seconds. + /// + public TimeSpan? Timeout { get; set; } } \ No newline at end of file diff --git a/src/Auth0Net.DependencyInjection/Cache/Auth0TokenCache.cs b/src/Auth0Net.DependencyInjection/Cache/Auth0TokenCache.cs index c65e715..37fc6ad 100644 --- a/src/Auth0Net.DependencyInjection/Cache/Auth0TokenCache.cs +++ b/src/Auth0Net.DependencyInjection/Cache/Auth0TokenCache.cs @@ -26,7 +26,10 @@ public sealed class Auth0TokenCache : IAuth0TokenCache public Auth0TokenCache(IAuthenticationApiClient client, IFusionCacheProvider provider, ILogger logger, IOptions config) { _client = client; - _cache = provider.GetCache(Constants.FusionCacheInstance); + _cache = !string.IsNullOrEmpty(config.Value.FusionCacheInstance) + ? provider.GetCache(config.Value.FusionCacheInstance) + : provider.GetCache(Constants.FusionCacheInstance); + _logger = logger; _config = config.Value; } @@ -42,8 +45,8 @@ public async ValueTask GetTokenAsync(string audience, CancellationToken var tokenRequest = new ClientCredentialsTokenRequest { - ClientId = _config.ClientId, - ClientSecret = _config.ClientSecret, + ClientId = _config.ClientId!, + ClientSecret = _config.ClientSecret!, Audience = audience }; @@ -64,9 +67,6 @@ public async ValueTask GetTokenAsync(string audience, CancellationToken /// public ValueTask GetTokenAsync(Uri audience, CancellationToken token = default) => GetTokenAsync(audience.ToString(), token); - - /// - public ValueTask GetManagementTokenAsync(CancellationToken token = default) => GetTokenAsync(UriHelpers.GetValidManagementUri(_config.Domain), token); } internal static partial class Log diff --git a/src/Auth0Net.DependencyInjection/Cache/IAuth0TokenCache.cs b/src/Auth0Net.DependencyInjection/Cache/IAuth0TokenCache.cs index 8e6a424..b144912 100644 --- a/src/Auth0Net.DependencyInjection/Cache/IAuth0TokenCache.cs +++ b/src/Auth0Net.DependencyInjection/Cache/IAuth0TokenCache.cs @@ -5,7 +5,6 @@ namespace Auth0Net.DependencyInjection.Cache; /// public interface IAuth0TokenCache { - /// /// Get a JSON Web Token (JWT) Access Token for the requested audience /// @@ -21,10 +20,5 @@ public interface IAuth0TokenCache /// An optional token that can cancel this request /// The JWT ValueTask GetTokenAsync(Uri audience, CancellationToken token = default); - /// - /// Get a JSON Web Token (JWT) Access Token for the management API. - /// - /// An optional token that can cancel this request - /// The JWT - ValueTask GetManagementTokenAsync(CancellationToken token = default); + } \ No newline at end of file diff --git a/src/Auth0Net.DependencyInjection/Factory/ManagementClientFactory.cs b/src/Auth0Net.DependencyInjection/Factory/ManagementClientFactory.cs new file mode 100644 index 0000000..f3b7e51 --- /dev/null +++ b/src/Auth0Net.DependencyInjection/Factory/ManagementClientFactory.cs @@ -0,0 +1,47 @@ +using System.Net.Http; +using Auth0.ManagementApi; +using Auth0Net.DependencyInjection.Cache; +using Auth0Net.DependencyInjection.HttpClient; +using Microsoft.Extensions.Options; + +namespace Auth0Net.DependencyInjection.Factory; + +internal sealed class ManagementClientFactory +{ + private readonly IHttpClientFactory _httpClientFactory; + private readonly IOptions _rootConfig; + private readonly IOptions _managementConfig; + private readonly IAuth0TokenCache _cache; + + public const string Auth0ManagementApiClient = nameof(Auth0ManagementApiClient); + + public ManagementClientFactory( + IHttpClientFactory httpClientFactory, + IOptions rootConfig, + IOptions managementConfig, + IAuth0TokenCache cache) + { + _httpClientFactory = httpClientFactory; + _rootConfig = rootConfig; + _managementConfig = managementConfig; + _cache = cache; + } + + public ManagementClient Create() + { + var audience = _managementConfig.Value.Audience ?? _rootConfig.Value.Domain; + + var clientOptions = new ManagementClientOptions + { + Domain = _rootConfig.Value.Domain, + HttpClient = _httpClientFactory.CreateClient(Auth0ManagementApiClient), + TokenProvider = new Auth0ManagementTokenProvider( + _cache, + UriHelpers.GetValidManagementUri(audience).ToString()), + MaxRetries = _managementConfig.Value.MaxRetries, + Timeout = _managementConfig.Value.Timeout, + }; + + return new ManagementClient(clientOptions); + } +} \ No newline at end of file diff --git a/src/Auth0Net.DependencyInjection/HttpClient/Auth0ManagementTokenProvider.cs b/src/Auth0Net.DependencyInjection/HttpClient/Auth0ManagementTokenProvider.cs new file mode 100644 index 0000000..e25f596 --- /dev/null +++ b/src/Auth0Net.DependencyInjection/HttpClient/Auth0ManagementTokenProvider.cs @@ -0,0 +1,20 @@ +using Auth0.ManagementApi; +using Auth0Net.DependencyInjection.Cache; + +namespace Auth0Net.DependencyInjection.HttpClient; +internal sealed class Auth0ManagementTokenProvider : ITokenProvider +{ + private readonly IAuth0TokenCache _cache; + private readonly string _audience; + + public Auth0ManagementTokenProvider(IAuth0TokenCache cache, string audience) + { + _cache = cache; + _audience = audience; + } + + public async Task GetTokenAsync(CancellationToken cancellationToken) + { + return await _cache.GetTokenAsync(_audience, cancellationToken); + } +} \ No newline at end of file diff --git a/src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandler.cs b/src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandler.cs index d5b4869..0f67873 100644 --- a/src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandler.cs +++ b/src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandler.cs @@ -6,7 +6,7 @@ namespace Auth0Net.DependencyInjection.HttpClient; /// -/// A that adds a authentication header with a Auth0-generated JWT token for the given audience. +/// A that adds an authentication header with an Auth0-generated JWT token for the given audience. /// public class Auth0TokenHandler : DelegatingHandler { @@ -33,12 +33,4 @@ protected override async Task SendAsync(HttpRequestMessage request.Headers.Authorization = new AuthenticationHeaderValue(Scheme, await _cache.GetTokenAsync(audience, cancellationToken)); return await base.SendAsync(request, cancellationToken); } -} - -internal sealed class Auth0ManagementTokenHandler : Auth0TokenHandler -{ - public Auth0ManagementTokenHandler(IAuth0TokenCache cache, IOptions options, Auth0ManagementTokenConfiguration clientConfig) - : base(cache, new Auth0TokenHandlerConfig(UriHelpers.GetValidManagementUri(clientConfig.Audience ?? options.Value.Domain).ToString())) - { - } } \ No newline at end of file diff --git a/src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandlerConfig.cs b/src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandlerConfig.cs index 493874c..491ae9e 100644 --- a/src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandlerConfig.cs +++ b/src/Auth0Net.DependencyInjection/HttpClient/Auth0TokenHandlerConfig.cs @@ -20,17 +20,5 @@ public sealed class Auth0TokenHandlerConfig /// A value set in will take precedence over any resolver set here - be careful not to mix the two. /// public Func? AudienceResolver { get; set; } - - /// - /// Initializes a new instance of with no Audience set. - /// - public Auth0TokenHandlerConfig() { } - - /// - /// Initializes a new instance of . - /// - public Auth0TokenHandlerConfig(string audience) - { - Audience = audience; - } + } \ No newline at end of file diff --git a/src/Auth0Net.DependencyInjection/Injectables/InjectableManagementApiClient.cs b/src/Auth0Net.DependencyInjection/Injectables/InjectableManagementApiClient.cs deleted file mode 100644 index 65f65f8..0000000 --- a/src/Auth0Net.DependencyInjection/Injectables/InjectableManagementApiClient.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Auth0.ManagementApi; -using Auth0Net.DependencyInjection.Cache; -using Auth0Net.DependencyInjection.HttpClient; -using Microsoft.Extensions.Options; - -namespace Auth0Net.DependencyInjection.Injectables; - -internal sealed class InjectableManagementApiClient : ManagementApiClient -{ - public InjectableManagementApiClient(IOptions config, IManagementConnection managementConnection) - : base(null, UriHelpers.GetValidManagementUri(config.Value.Domain), managementConnection) - { - } -} \ No newline at end of file diff --git a/tests/Auth0Net.DependencyInjection.Tests/Auth0Net.DependencyInjection.Tests.csproj b/tests/Auth0Net.DependencyInjection.Tests/Auth0Net.DependencyInjection.Tests.csproj index c35a0f1..435fb1c 100644 --- a/tests/Auth0Net.DependencyInjection.Tests/Auth0Net.DependencyInjection.Tests.csproj +++ b/tests/Auth0Net.DependencyInjection.Tests/Auth0Net.DependencyInjection.Tests.csproj @@ -8,7 +8,7 @@ - + diff --git a/tests/Auth0Net.DependencyInjection.Tests/CacheTests.cs b/tests/Auth0Net.DependencyInjection.Tests/CacheTests.cs index 177d66a..2a91f09 100644 --- a/tests/Auth0Net.DependencyInjection.Tests/CacheTests.cs +++ b/tests/Auth0Net.DependencyInjection.Tests/CacheTests.cs @@ -59,11 +59,52 @@ public async Task Cache_WorksAsExpected() A.CallTo(() => authClient.GetTokenAsync(A.Ignored, A.Ignored)) .MustHaveHappenedTwiceExactly(); + + } + + + [Fact] + public async Task Cache_UsesFusionCacheInstance_WhenConfigured() + { + const string customCacheName = "my-custom-cache"; + + var config = A.Fake>(); + A.CallTo(() => config.Value).Returns(new Auth0Configuration + { + ClientId = Guid.NewGuid().ToString(), + ClientSecret = Guid.NewGuid().ToString(), + Domain = "https://hawxy.au.auth0.com/", + FusionCacheInstance = customCacheName + }); + var authClient = A.Fake(); + A.CallTo(() => authClient.GetTokenAsync(A.Ignored, A.Ignored)) + .Returns(new AccessTokenResponse { AccessToken = "token", ExpiresIn = 60 }); + var provider = new CapturingFusionCacheProvider(); + _ = new Auth0TokenCache(authClient, provider, new NullLogger(), config); + Assert.Equal(customCacheName, provider.LastRequestedCacheName); } + [Fact] + public async Task Cache_UsesDefaultFusionCacheInstance_WhenNotConfigured() + { + var config = A.Fake>(); + A.CallTo(() => config.Value).Returns(new Auth0Configuration + { + ClientId = Guid.NewGuid().ToString(), + ClientSecret = Guid.NewGuid().ToString(), + Domain = "https://hawxy.au.auth0.com/", + }); + + var authClient = A.Fake(); + + var provider = new CapturingFusionCacheProvider(); + _ = new Auth0TokenCache(authClient, provider, new NullLogger(), config); + + Assert.Equal(Constants.FusionCacheInstance, provider.LastRequestedCacheName); + } private sealed class FusionCacheTestProvider : IFusionCacheProvider { @@ -77,4 +118,20 @@ public IFusionCache GetCacheOrNull(string cacheName) throw new NotImplementedException(); } } + + private sealed class CapturingFusionCacheProvider : IFusionCacheProvider + { + public string? LastRequestedCacheName { get; private set; } + + public IFusionCache GetCache(string cacheName) + { + LastRequestedCacheName = cacheName; + return new FusionCache(new FusionCacheOptions()); + } + + public IFusionCache GetCacheOrNull(string cacheName) + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/tests/Auth0Net.DependencyInjection.Tests/ExtensionTests.cs b/tests/Auth0Net.DependencyInjection.Tests/ExtensionTests.cs index f165e97..8f17508 100644 --- a/tests/Auth0Net.DependencyInjection.Tests/ExtensionTests.cs +++ b/tests/Auth0Net.DependencyInjection.Tests/ExtensionTests.cs @@ -16,7 +16,7 @@ public class ExtensionTests [Fact] public void AddAuth0AuthenticationClientCore_Throws_OnInvalidDomain() { - var services = new ServiceCollection().AddAuth0AuthenticationClientCore("").Services.BuildServiceProvider(); + var services = new ServiceCollection().AddAuth0AuthenticationClient("").Services.BuildServiceProvider(); Assert.Throws(() => services.GetRequiredService()); } @@ -31,7 +31,7 @@ public void AddAuth0AuthenticationClientCore_Throws_AuthenticationClientAlreadyR x.ClientSecret = ""; }).Services; - Assert.Throws(() => services.AddAuth0AuthenticationClientCore("test-url.au.auth0.com")); + Assert.Throws(() => services.AddAuth0AuthenticationClient("test-url.au.auth0.com")); } [Fact] @@ -39,7 +39,7 @@ public void AddAuth0AuthenticationClientCore_Resolves_AuthenticationClient() { var domain = "test-url.au.auth0.com"; - var services = new ServiceCollection().AddAuth0AuthenticationClientCore(domain).Services; + var services = new ServiceCollection().AddAuth0AuthenticationClient(domain).Services; var serviceDescriptor = services.FirstOrDefault(x => x.ServiceType == typeof(IAuthenticationApiClient) && x.ImplementationType == typeof(InjectableAuthenticationApiClient)); @@ -64,7 +64,7 @@ public void AddAuth0AuthenticationClientCore_Resolves_AuthenticationClient() [Fact] public void AddAuth0AuthenticationClient_Throws_AuthenticationClientAlreadyRegistered() { - var services = new ServiceCollection().AddAuth0AuthenticationClientCore("").Services; + var services = new ServiceCollection().AddAuth0AuthenticationClient("").Services; Assert.Throws(() => services.AddAuth0AuthenticationClient(x => { @@ -182,13 +182,8 @@ public void AddManagementClient_Can_BeResolved() var defaultDomain = "tenant.au.auth0.com"; - collection.AddAuth0ManagementClient() - .AddManagementAccessToken(c => - { - c.Audience = defaultDomain; - }); - - collection.AddHttpClient().AddManagementAccessToken(); + collection.AddAuth0ManagementClient(); + collection.AddHttpClient(); var services = collection.BuildServiceProvider();