diff --git a/README.md b/README.md index bdeca4d..ddcbdbb 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ IServiceCollection serviceCollection; // you may need to add these dependencies serviceCollection.AddMemoryCache(); -using Microsoft.Extensions.Internal; -serviceCollection.TryAddSingleton(); +using System; +serviceCollection.TryAddSingleton(TimeProvider.System); // configure AppStoreConnect services serviceCollection.AddAppleAppStoreConnect(optionsBuilder => optionsBuilder diff --git a/src/Apple.AppStoreConnect/Apple.AppStoreConnect.csproj b/src/Apple.AppStoreConnect/Apple.AppStoreConnect.csproj index 38e7dd8..ca85192 100644 --- a/src/Apple.AppStoreConnect/Apple.AppStoreConnect.csproj +++ b/src/Apple.AppStoreConnect/Apple.AppStoreConnect.csproj @@ -32,6 +32,7 @@ + @@ -41,6 +42,7 @@ + diff --git a/src/Apple.AppStoreConnect/DefaultJwtGenerator.cs b/src/Apple.AppStoreConnect/DefaultJwtGenerator.cs index 97014ef..86b6bf0 100644 --- a/src/Apple.AppStoreConnect/DefaultJwtGenerator.cs +++ b/src/Apple.AppStoreConnect/DefaultJwtGenerator.cs @@ -1,6 +1,5 @@ using Apple.AppStoreConnect.Interfaces; using Microsoft.Extensions.Caching.Memory; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; @@ -14,19 +13,19 @@ namespace Apple.AppStoreConnect; public partial class DefaultJwtGenerator : IJwtGenerator { private readonly IMemoryCache _cache; - private readonly ISystemClock _clock; + private readonly TimeProvider _timeProvider; private readonly IOptions _appleAuthenticationOptions; private readonly ILogger _logger; public DefaultJwtGenerator( IMemoryCache cache, - ISystemClock clock, + TimeProvider timeProvider, IOptions appleAuthenticationOptions, ILogger logger ) { _cache = cache; - _clock = clock; + _timeProvider = timeProvider; _appleAuthenticationOptions = appleAuthenticationOptions; _logger = logger; } @@ -78,7 +77,7 @@ AppleAuthenticationOptions options AppleAuthenticationOptions appleAuthenticationOptions, CancellationToken cancellationToken ) { - var now = _clock.UtcNow; + var now = _timeProvider.GetUtcNow(); var expiresAt = now.Add(appleAuthenticationOptions.JwtExpiresAfter); Log.GeneratingNewJwtToken(_logger, appleAuthenticationOptions.KeyId, expiresAt); diff --git a/src/Test.Apple.AppStoreConnect/DefaultJwtGeneratorTest.cs b/src/Test.Apple.AppStoreConnect/DefaultJwtGeneratorTest.cs index 001283f..33bde17 100644 --- a/src/Test.Apple.AppStoreConnect/DefaultJwtGeneratorTest.cs +++ b/src/Test.Apple.AppStoreConnect/DefaultJwtGeneratorTest.cs @@ -3,9 +3,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.FileProviders; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Microsoft.Extensions.Time.Testing; using System; using System.IO; using System.Threading.Tasks; @@ -43,7 +43,7 @@ public async Task GenerateJwtTokenWorks() .AddConsole() .AddDebug() ) - .AddSingleton(); + .AddSingleton(); serviceCollection.TryAddEnumerable(ServiceDescriptor .Singleton, AppleAuthenticationPostConfigure>() @@ -90,7 +90,8 @@ public async Task TwoGenerateJwtTokenWorks(int delay) .AddConsole() .AddDebug() ) - .AddSingleton(); + .AddSingleton() + .AddSingleton(s => s.GetRequiredService()); serviceCollection.TryAddEnumerable(ServiceDescriptor .Singleton, AppleAuthenticationPostConfigure>() diff --git a/src/Test.Apple.AppStoreConnect/Test.Apple.AppStoreConnect.csproj b/src/Test.Apple.AppStoreConnect/Test.Apple.AppStoreConnect.csproj index 1b6a8e6..054eaaf 100644 --- a/src/Test.Apple.AppStoreConnect/Test.Apple.AppStoreConnect.csproj +++ b/src/Test.Apple.AppStoreConnect/Test.Apple.AppStoreConnect.csproj @@ -28,6 +28,7 @@ + @@ -35,6 +36,7 @@ +