diff --git a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPProofValidator.cs b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPProofValidator.cs index b1aad3c2f..65e6485e2 100644 --- a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPProofValidator.cs +++ b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPProofValidator.cs @@ -70,7 +70,7 @@ internal class DPoPProofValidator : IDPoPProofValidator /// /// Validates the DPoP proof. /// - public async Task Validate(DPoPProofValidationContext context, CancellationToken cancellationToken = default) + public async Task Validate(DPoPProofValidationContext context, CT ct = default) { using var activity = Tracing.ActivitySource.StartActivity("DPoPProofValidator.Validate"); @@ -113,7 +113,7 @@ internal class DPoPProofValidator : IDPoPProofValidator } // we do replay at the end, so we only add to the reply cache if everything else is ok - await ValidateReplay(context, result, cancellationToken); + await ValidateReplay(context, result, ct); if (result.IsError) { Logger.LogInformation("Detected replay of DPoP proof token"); @@ -368,7 +368,7 @@ internal class DPoPProofValidator : IDPoPProofValidator internal async Task ValidateReplay( DPoPProofValidationContext context, DPoPProofValidationResult result, - CancellationToken cancellationToken = default) + CT ct = default) { var dPoPOptions = OptionsMonitor.Get(context.Scheme); @@ -377,7 +377,7 @@ internal class DPoPProofValidator : IDPoPProofValidator return; } - if (await ReplayCache.Exists(result.TokenIdHash!, cancellationToken)) + if (await ReplayCache.Exists(result.TokenIdHash!, ct)) { result.SetError("Detected DPoP proof token replay."); return; @@ -400,7 +400,7 @@ internal class DPoPProofValidator : IDPoPProofValidator // longer than the likelihood of proof token expiration, which is done before replay skew *= 2; var cacheDuration = dPoPOptions.ProofTokenLifetime + skew; - await ReplayCache.Add(result.TokenIdHash!, cacheDuration, cancellationToken); + await ReplayCache.Add(result.TokenIdHash!, cacheDuration, ct); } /// diff --git a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/IDPoPProofValidator.cs b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/IDPoPProofValidator.cs index 390a7d4da..a49515050 100644 --- a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/IDPoPProofValidator.cs +++ b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/IDPoPProofValidator.cs @@ -11,5 +11,5 @@ public interface IDPoPProofValidator /// /// Validates the DPoP proof. /// - Task Validate(DPoPProofValidationContext context, CancellationToken cancellationToken = default); + Task Validate(DPoPProofValidationContext context, CT ct = default); } diff --git a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/IReplayCache.cs b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/IReplayCache.cs index 94e244a0d..f8c076fd5 100644 --- a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/IReplayCache.cs +++ b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/IReplayCache.cs @@ -11,11 +11,11 @@ public interface IReplayCache /// /// Adds a hashed jti to the cache. /// - Task Add(string jtiHash, TimeSpan expiration, CancellationToken cancellationToken = default); + Task Add(string jtiHash, TimeSpan expiration, CT ct = default); /// /// Checks if a cached jti hash exists in the hash. /// - Task Exists(string jtiHash, CancellationToken cancellationToken = default); + Task Exists(string jtiHash, CT ct = default); } diff --git a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/ReplayCache.cs b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/ReplayCache.cs index 45e19eb91..ca2518462 100644 --- a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/ReplayCache.cs +++ b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/ReplayCache.cs @@ -24,7 +24,7 @@ internal class ReplayCache(DPoPHybridCacheProvider cacheProvider) : IReplayCache } } - public async Task Add(string handle, TimeSpan expiration, CancellationToken ct) + public async Task Add(string handle, TimeSpan expiration, CT ct) { using var activity = Tracing.ActivitySource.StartActivity("ReplayCache.Add"); @@ -43,7 +43,7 @@ internal class ReplayCache(DPoPHybridCacheProvider cacheProvider) : IReplayCache | HybridCacheEntryFlags.DisableUnderlyingData }; - public async Task Exists(string handle, CancellationToken ct) + public async Task Exists(string handle, CT ct) { using var activity = Tracing.ActivitySource.StartActivity("ReplayCache.Exists"); diff --git a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestBrowserClient.cs b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestBrowserClient.cs index d0a5b91ac..8c2c3019c 100644 --- a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestBrowserClient.cs +++ b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestBrowserClient.cs @@ -15,7 +15,7 @@ public class TestBrowserClient : HttpClient public HttpResponseMessage LastResponse { get; private set; } = default!; protected override async Task SendAsync(HttpRequestMessage request, - CancellationToken cancellationToken) + CT ct) { CurrentUri = request.RequestUri!; var cookieHeader = CookieContainer.GetCookieHeader(request.RequestUri!); @@ -24,7 +24,7 @@ public class TestBrowserClient : HttpClient request.Headers.Add("Cookie", cookieHeader); } - var response = await base.SendAsync(request, cancellationToken); + var response = await base.SendAsync(request, ct); if (response.Headers.Contains("Set-Cookie")) { diff --git a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestHybridCache.cs b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestHybridCache.cs index b9aa09dc2..4da5065c3 100644 --- a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestHybridCache.cs +++ b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestHybridCache.cs @@ -11,8 +11,8 @@ internal class TestHybridCache : HybridCache private readonly List<(string key, object value, HybridCacheEntryOptions? options)> _setAsyncCalls = new(); private readonly List<(string key, HybridCacheEntryOptions? options)> _getOrCreateAsyncCalls = new(); - public override async ValueTask GetOrCreateAsync(string key, TState state, Func> factory, HybridCacheEntryOptions? options = null, - IEnumerable? tags = null, CancellationToken cancellationToken = new()) + public override async ValueTask GetOrCreateAsync(string key, TState state, Func> factory, HybridCacheEntryOptions? options = null, + IEnumerable? tags = null, CT ct = new()) { _getOrCreateAsyncCalls.Add((key, options)); @@ -25,16 +25,16 @@ internal class TestHybridCache : HybridCache } public override ValueTask SetAsync(string key, T value, HybridCacheEntryOptions? options = null, IEnumerable? tags = null, - CancellationToken cancellationToken = new()) + CT ct = new()) { _setAsyncCalls.Add((key, value!, options)); _cache[key] = value!; return ValueTask.CompletedTask; } - public override ValueTask RemoveAsync(string key, CancellationToken cancellationToken = new()) => throw new NotImplementedException(); + public override ValueTask RemoveAsync(string key, CT ct = new()) => throw new NotImplementedException(); - public override ValueTask RemoveByTagAsync(string tag, CancellationToken cancellationToken = new()) => throw new NotImplementedException(); + public override ValueTask RemoveByTagAsync(string tag, CT ct = new()) => throw new NotImplementedException(); public IReadOnlyList<(string key, object value, HybridCacheEntryOptions? options)> SetAsyncCalls => _setAsyncCalls; public IReadOnlyList<(string key, HybridCacheEntryOptions? options)> GetOrCreateAsyncCalls => _getOrCreateAsyncCalls; diff --git a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestReplayCache.cs b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestReplayCache.cs index 75716d223..6e0c51784 100644 --- a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestReplayCache.cs +++ b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/TestFramework/TestReplayCache.cs @@ -14,14 +14,14 @@ public class TestReplayCache : IReplayCache // Configuration for test behavior public Func? ExistsFunc { get; set; } - public Task Add(string jtiHash, TimeSpan expiration, CancellationToken cancellationToken = default) + public Task Add(string jtiHash, TimeSpan expiration, CT ct = default) { _addCalls.Add((jtiHash, expiration)); _cache[jtiHash] = (expiration, DateTime.UtcNow); return Task.CompletedTask; } - public Task Exists(string jtiHash, CancellationToken cancellationToken = default) + public Task Exists(string jtiHash, CT ct = default) { _existsCalls.Add(jtiHash); diff --git a/bff/hosts/Hosts.Bff.InMemory/ImpersonationAccessTokenRetriever.cs b/bff/hosts/Hosts.Bff.InMemory/ImpersonationAccessTokenRetriever.cs index 40c1debf9..f1f18da42 100644 --- a/bff/hosts/Hosts.Bff.InMemory/ImpersonationAccessTokenRetriever.cs +++ b/bff/hosts/Hosts.Bff.InMemory/ImpersonationAccessTokenRetriever.cs @@ -9,7 +9,7 @@ namespace Bff; public class ImpersonationAccessTokenRetriever(IAccessTokenRetriever inner) : IAccessTokenRetriever { - public async Task GetAccessTokenAsync(AccessTokenRetrievalContext context, CancellationToken ct = default) + public async Task GetAccessTokenAsync(AccessTokenRetrievalContext context, CT ct = default) { var result = await inner.GetAccessTokenAsync(context, ct); diff --git a/bff/hosts/Hosts.Bff.MultiFrontend/ImpersonationAccessTokenRetriever.cs b/bff/hosts/Hosts.Bff.MultiFrontend/ImpersonationAccessTokenRetriever.cs index 40c1debf9..f1f18da42 100644 --- a/bff/hosts/Hosts.Bff.MultiFrontend/ImpersonationAccessTokenRetriever.cs +++ b/bff/hosts/Hosts.Bff.MultiFrontend/ImpersonationAccessTokenRetriever.cs @@ -9,7 +9,7 @@ namespace Bff; public class ImpersonationAccessTokenRetriever(IAccessTokenRetriever inner) : IAccessTokenRetriever { - public async Task GetAccessTokenAsync(AccessTokenRetrievalContext context, CancellationToken ct = default) + public async Task GetAccessTokenAsync(AccessTokenRetrievalContext context, CT ct = default) { var result = await inner.GetAccessTokenAsync(context, ct); diff --git a/bff/hosts/Hosts.Bff.MultiFrontend/Program.cs b/bff/hosts/Hosts.Bff.MultiFrontend/Program.cs index 882aeaff1..3296ec36c 100644 --- a/bff/hosts/Hosts.Bff.MultiFrontend/Program.cs +++ b/bff/hosts/Hosts.Bff.MultiFrontend/Program.cs @@ -166,7 +166,7 @@ app.MapGet("/local/self-contained", (CurrentFrontendAccessor currentFrontendAcce return data; }); -app.MapGet("/local/invokes-external-api", async (CurrentFrontendAccessor currentFrontendAccessor, IHttpClientFactory httpClientFactory, HttpContext c, CancellationToken ct) => +app.MapGet("/local/invokes-external-api", async (CurrentFrontendAccessor currentFrontendAccessor, IHttpClientFactory httpClientFactory, HttpContext c, CT ct) => { var httpClient = httpClientFactory.CreateClient("api"); var apiResult = await httpClient.GetAsync("/user-token"); @@ -235,7 +235,7 @@ RouteConfig[] BuildYarpRoutes() public class FrontendAwareIndexHtmlTransformer : IIndexHtmlTransformer { - public Task Transform(string indexHtml, BffFrontend frontend, CancellationToken ct = default) + public Task Transform(string indexHtml, BffFrontend frontend, CT ct = default) { indexHtml = indexHtml.Replace("[FrontendName]", frontend.Name); indexHtml = indexHtml.Replace("[Path]", frontend.MatchingCriteria.MatchingPath + "/"); // Note, the path must end with a slash diff --git a/bff/hosts/Hosts.Bff.Performance/Services/ApiHostedService.cs b/bff/hosts/Hosts.Bff.Performance/Services/ApiHostedService.cs index 877cb67cc..7ee61e2b1 100644 --- a/bff/hosts/Hosts.Bff.Performance/Services/ApiHostedService.cs +++ b/bff/hosts/Hosts.Bff.Performance/Services/ApiHostedService.cs @@ -9,7 +9,7 @@ public class ApiHostedService(IOptions apiSettings) : BackgroundSer { public ApiSettings Settings { get; } = apiSettings.Value; - protected override Task ExecuteAsync(CancellationToken stoppingToken) + protected override Task ExecuteAsync(CT stoppingToken) { var builder = WebApplication.CreateBuilder(); builder.AddServiceDefaults(); diff --git a/bff/hosts/Hosts.Bff.Performance/Services/BffService.cs b/bff/hosts/Hosts.Bff.Performance/Services/BffService.cs index 5526bb0d7..6fcd0ed1c 100644 --- a/bff/hosts/Hosts.Bff.Performance/Services/BffService.cs +++ b/bff/hosts/Hosts.Bff.Performance/Services/BffService.cs @@ -15,7 +15,7 @@ public abstract class BffService(string[] urlConfigKeys, IConfiguration config, public IConfiguration Config { get; } = config; public BffSettings Settings { get; } = bffSettings.Value; - protected override async Task ExecuteAsync(CancellationToken stoppingToken) + protected override async Task ExecuteAsync(CT stoppingToken) { var urls = urlConfigKeys .Select(x => Config[x]) diff --git a/bff/hosts/Hosts.Bff.Performance/Services/IdentityServerService.cs b/bff/hosts/Hosts.Bff.Performance/Services/IdentityServerService.cs index 800e0450e..4d2534b2d 100644 --- a/bff/hosts/Hosts.Bff.Performance/Services/IdentityServerService.cs +++ b/bff/hosts/Hosts.Bff.Performance/Services/IdentityServerService.cs @@ -17,7 +17,7 @@ public class IdentityServerService(IOptions settings, IC { public IdentityServerSettings Settings { get; } = settings.Value; - protected override Task ExecuteAsync(CancellationToken stoppingToken) + protected override Task ExecuteAsync(CT stoppingToken) { var builder = WebApplication.CreateBuilder(); builder.AddServiceDefaults(); diff --git a/bff/performance/Bff.Performance/TestInfra/AutoFollowRedirectHandler.cs b/bff/performance/Bff.Performance/TestInfra/AutoFollowRedirectHandler.cs index f46f50c42..d33c82d40 100644 --- a/bff/performance/Bff.Performance/TestInfra/AutoFollowRedirectHandler.cs +++ b/bff/performance/Bff.Performance/TestInfra/AutoFollowRedirectHandler.cs @@ -8,12 +8,12 @@ namespace Bff.Performance.TestInfra; public class AutoFollowRedirectHandler(Action writeOutput) : DelegatingHandler { protected override async Task SendAsync(HttpRequestMessage request, - CancellationToken cancellationToken) + CT ct) { var previousUri = request.RequestUri; for (var i = 0; i < 20; i++) { - var result = await base.SendAsync(request, cancellationToken); + var result = await base.SendAsync(request, ct); if ((result.StatusCode == HttpStatusCode.Found || result.StatusCode == HttpStatusCode.RedirectKeepVerb) && result.Headers.Location != null) { writeOutput($"Redirecting from {previousUri} to {result.Headers.Location}"); diff --git a/bff/performance/Bff.Performance/TestInfra/CloningHttpMessageHandler.cs b/bff/performance/Bff.Performance/TestInfra/CloningHttpMessageHandler.cs index 0d808f3e4..bdfb56601 100644 --- a/bff/performance/Bff.Performance/TestInfra/CloningHttpMessageHandler.cs +++ b/bff/performance/Bff.Performance/TestInfra/CloningHttpMessageHandler.cs @@ -9,13 +9,13 @@ public class CloningHttpMessageHandler(HttpClient innerHttpClient) : HttpMessage innerHttpClient ?? throw new ArgumentNullException(nameof(innerHttpClient)); protected override async Task SendAsync(HttpRequestMessage request, - CancellationToken cancellationToken) + CT ct) { // Clone the incoming request var clonedRequest = await CloneHttpRequestMessageAsync(request); // Send the cloned request using the inner HttpClient - var response = await _innerHttpClient.SendAsync(clonedRequest, cancellationToken); + var response = await _innerHttpClient.SendAsync(clonedRequest, ct); // Clone the response and return it return await CloneHttpResponseMessageAsync(response); diff --git a/bff/performance/Bff.Performance/TestInfra/RequestLoggingHandler.cs b/bff/performance/Bff.Performance/TestInfra/RequestLoggingHandler.cs index 3933808fa..fc3abae9e 100644 --- a/bff/performance/Bff.Performance/TestInfra/RequestLoggingHandler.cs +++ b/bff/performance/Bff.Performance/TestInfra/RequestLoggingHandler.cs @@ -12,17 +12,17 @@ public class RequestLoggingHandler( : DelegatingHandler { protected override async Task SendAsync(HttpRequestMessage request, - CancellationToken cancellationToken) + CT ct) { if (!shouldLog(request)) { - return await base.SendAsync(request, cancellationToken); + return await base.SendAsync(request, ct); } var stopwatch = Stopwatch.StartNew(); try { - var result = await base.SendAsync(request, cancellationToken); + var result = await base.SendAsync(request, ct); log.LogInformation("Executing {method} on {url} returned {statuscode} in {ms} ms", request.Method, diff --git a/bff/src/Bff.Blazor/ServerSideTokenStore.cs b/bff/src/Bff.Blazor/ServerSideTokenStore.cs index a2b2837ba..34cf00413 100644 --- a/bff/src/Bff.Blazor/ServerSideTokenStore.cs +++ b/bff/src/Bff.Blazor/ServerSideTokenStore.cs @@ -32,7 +32,7 @@ internal class ServerSideTokenStore( ?? throw new ArgumentException("AuthenticationStateProvider must implement IHostEnvironmentAuthenticationStateProvider"); public async Task> GetTokenAsync(ClaimsPrincipal user, UserTokenRequestParameters? parameters = null, - CancellationToken ct = default) + CT ct = default) { logger.RetrievingTokenForUser(LogLevel.Debug, user.Identity?.Name); var session = await GetSession(user); diff --git a/bff/src/Bff.Yarp/Internal/RemoteRouteHandler.cs b/bff/src/Bff.Yarp/Internal/RemoteRouteHandler.cs index 53dc68d6b..492ccd4c1 100644 --- a/bff/src/Bff.Yarp/Internal/RemoteRouteHandler.cs +++ b/bff/src/Bff.Yarp/Internal/RemoteRouteHandler.cs @@ -68,7 +68,7 @@ internal class RemoteRouteHandler : IDisposable public void ClearTransformerCacheFor(BffFrontend frontend) => _cache.TryRemove(frontend.Name, out _); - public async Task HandleAsync(HttpContext context, CancellationToken ct) + public async Task HandleAsync(HttpContext context, CT ct) { if (!_currentFrontendAccessor.TryGet(out var frontend)) { diff --git a/bff/src/Bff/Diagnostics/DiagnosticDataService.cs b/bff/src/Bff/Diagnostics/DiagnosticDataService.cs index 6c2f58848..bb804ac37 100644 --- a/bff/src/Bff/Diagnostics/DiagnosticDataService.cs +++ b/bff/src/Bff/Diagnostics/DiagnosticDataService.cs @@ -8,7 +8,7 @@ namespace Duende.Bff.Diagnostics; internal class DiagnosticDataService(DateTime serverStartTime, IEnumerable entries) { - public async Task> GetJsonBytesAsync(CancellationToken cancellationToken = default) + public async Task> GetJsonBytesAsync(CT ct = default) { var bufferWriter = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(bufferWriter, new JsonWriterOptions { Indented = false }); @@ -23,7 +23,7 @@ internal class DiagnosticDataService(DateTime serverStartTime, IEnumerable logger, TimeProvider timeProvider) : BackgroundService { - protected override async Task ExecuteAsync(CancellationToken stoppingToken) + protected override async Task ExecuteAsync(CT stoppingToken) { using var timer = new PeriodicTimer(options.Value.Diagnostics.LogFrequency, timeProvider); try @@ -40,10 +40,10 @@ internal class DiagnosticHostedService( } } - public override async Task StopAsync(CancellationToken cancellationToken) + public override async Task StopAsync(CT ct) { - await diagnosticsSummary.PrintSummaryAsync(cancellationToken); + await diagnosticsSummary.PrintSummaryAsync(ct); - await base.StopAsync(cancellationToken); + await base.StopAsync(ct); } } diff --git a/bff/src/Bff/Diagnostics/DiagnosticSummary.cs b/bff/src/Bff/Diagnostics/DiagnosticSummary.cs index 6ef3d55a4..a93dce9bb 100644 --- a/bff/src/Bff/Diagnostics/DiagnosticSummary.cs +++ b/bff/src/Bff/Diagnostics/DiagnosticSummary.cs @@ -15,10 +15,10 @@ internal class DiagnosticSummary( { private readonly ILogger _logger = loggerFactory.CreateLogger("Duende.BFF.Diagnostics.Summary"); - public async Task PrintSummaryAsync(CancellationToken cancellationToken = default) + public async Task PrintSummaryAsync(CT ct = default) { var bffOptions = options.Value; - var jsonMemory = await diagnosticDataService.GetJsonBytesAsync(cancellationToken); + var jsonMemory = await diagnosticDataService.GetJsonBytesAsync(ct); var span = jsonMemory.Span; var chunkSize = bffOptions.Diagnostics.ChunkSize; diff --git a/bff/src/Bff/DynamicFrontends/Internal/BffCacheClearingHostedService.cs b/bff/src/Bff/DynamicFrontends/Internal/BffCacheClearingHostedService.cs index 986e67fd2..a6e4d3cc1 100644 --- a/bff/src/Bff/DynamicFrontends/Internal/BffCacheClearingHostedService.cs +++ b/bff/src/Bff/DynamicFrontends/Internal/BffCacheClearingHostedService.cs @@ -77,7 +77,7 @@ internal class BffCacheClearingHostedService( } } - private async Task ProcessFrontendChangeAsync(BffFrontend changedFrontend, CT cancellationToken) + private async Task ProcessFrontendChangeAsync(BffFrontend changedFrontend, CT ct) { try { @@ -86,12 +86,12 @@ internal class BffCacheClearingHostedService( // Clear all cached entries for the client credentials cache // This is necessary to ensure that the new frontend's client credentials are used var clientCredentialsClientName = OpenIdConnectTokenManagementDefaults.ToClientName(changedFrontend.OidcSchemeName); - await hybridCache.RemoveByTagAsync(clientCredentialsClientName, cancellationToken); + await hybridCache.RemoveByTagAsync(clientCredentialsClientName, ct); // Also clear the index.html cache for the frontend - await hybridCache.RemoveAsync(StaticFilesHttpClient.BuildCacheKey(changedFrontend), cancellationToken); + await hybridCache.RemoveAsync(StaticFilesHttpClient.BuildCacheKey(changedFrontend), ct); } - catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) + catch (OperationCanceledException) when (ct.IsCancellationRequested) { // Expected when the service is stopping throw; diff --git a/bff/src/Bff/Endpoints/Internal/DefaultSilentLoginCallbackEndpoint.cs b/bff/src/Bff/Endpoints/Internal/DefaultSilentLoginCallbackEndpoint.cs index ca48d87b4..c9cee60d6 100644 --- a/bff/src/Bff/Endpoints/Internal/DefaultSilentLoginCallbackEndpoint.cs +++ b/bff/src/Bff/Endpoints/Internal/DefaultSilentLoginCallbackEndpoint.cs @@ -21,7 +21,7 @@ internal class DefaultSilentLoginCallbackEndpoint( { /// - public async Task ProcessRequestAsync(HttpContext context, CancellationToken cancellationToken = default) + public async Task ProcessRequestAsync(HttpContext context, CT ct = default) { logger.ProcessingSilentLoginCallbackRequest(LogLevel.Debug); @@ -55,7 +55,7 @@ internal class DefaultSilentLoginCallbackEndpoint( logger.SilentLoginEndpointRenderingHtml(LogLevel.Debug, origin.Sanitize(), result); - await context.Response.WriteAsync(html, Encoding.UTF8, cancellationToken); + await context.Response.WriteAsync(html, Encoding.UTF8, ct); } private bool TryGetOriginFromReferer(HttpContext context, out string referer) diff --git a/bff/src/Bff/SessionManagement/SessionStore/SessionCleanupHost.cs b/bff/src/Bff/SessionManagement/SessionStore/SessionCleanupHost.cs index ccb15c4d6..ff113b321 100644 --- a/bff/src/Bff/SessionManagement/SessionStore/SessionCleanupHost.cs +++ b/bff/src/Bff/SessionManagement/SessionStore/SessionCleanupHost.cs @@ -23,7 +23,7 @@ internal class SessionCleanupHost( private TimeSpan CleanupInterval => _options.SessionCleanupInterval; - public override Task StartAsync(CancellationToken cancellationToken) + public override Task StartAsync(CT ct) { if (!IsIUserSessionStoreCleanupRegistered()) { @@ -31,7 +31,7 @@ internal class SessionCleanupHost( throw new InvalidOperationException("No IUserSessionStoreCleanup is registered. Did you add session storage, such as EntityFramework?"); } - return base.StartAsync(cancellationToken); + return base.StartAsync(ct); } protected override async Task ExecuteAsync(CT ct) diff --git a/bff/src/Bff/SessionManagement/TicketStore/ServerSideTicketStore.cs b/bff/src/Bff/SessionManagement/TicketStore/ServerSideTicketStore.cs index 7a1c1277d..51435b27a 100644 --- a/bff/src/Bff/SessionManagement/TicketStore/ServerSideTicketStore.cs +++ b/bff/src/Bff/SessionManagement/TicketStore/ServerSideTicketStore.cs @@ -31,7 +31,7 @@ internal class ServerSideTicketStore( private readonly IDataProtector _protector = dataProtectionProvider.CreateProtector(DataProtectorPurpose); - private CT ct => accessor.HttpContext?.RequestAborted ?? CancellationToken.None; + private CT ct => accessor.HttpContext?.RequestAborted ?? CT.None; /// public async Task StoreAsync(AuthenticationTicket ticket) diff --git a/bff/test/Bff.Tests/BffFrontendSigninTests.cs b/bff/test/Bff.Tests/BffFrontendSigninTests.cs index cf6c8d5ef..918be7852 100644 --- a/bff/test/Bff.Tests/BffFrontendSigninTests.cs +++ b/bff/test/Bff.Tests/BffFrontendSigninTests.cs @@ -60,7 +60,7 @@ public class BffFrontendSigninTests : BffTestBase Bff.OnConfigureApp += app => { - app.MapGet(pathString, (HttpContext c, CancellationToken ct) => "ok"); + app.MapGet(pathString, (HttpContext c, CT ct) => "ok"); }; await InitializeAsync(); diff --git a/bff/test/Bff.Tests/BffRemoteApiTests.cs b/bff/test/Bff.Tests/BffRemoteApiTests.cs index 403bf9dad..f0182ab81 100644 --- a/bff/test/Bff.Tests/BffRemoteApiTests.cs +++ b/bff/test/Bff.Tests/BffRemoteApiTests.cs @@ -143,7 +143,7 @@ public class BffRemoteApiTests : BffTestBase public bool WasCalled = false; public Task> GetAccessTokenAsync(ClaimsPrincipal user, UserTokenRequestParameters? parameters = null, - CancellationToken ct = new CancellationToken()) + CT ct = new CT()) { WasCalled = true; // We don't care actually about the result token. Just if it was called or not. @@ -151,7 +151,7 @@ public class BffRemoteApiTests : BffTestBase } public Task RevokeRefreshTokenAsync(ClaimsPrincipal user, UserTokenRequestParameters? parameters = null, - CancellationToken ct = new CancellationToken()) => throw new NotImplementedException(); + CT ct = new CT()) => throw new NotImplementedException(); } [Fact] diff --git a/bff/test/Bff.Tests/BffScenarioTests.cs b/bff/test/Bff.Tests/BffScenarioTests.cs index 278776361..1fdbb346d 100644 --- a/bff/test/Bff.Tests/BffScenarioTests.cs +++ b/bff/test/Bff.Tests/BffScenarioTests.cs @@ -47,7 +47,7 @@ public class BffScenarioTests : BffTestBase TaskCompletionSource contentReceived, TaskCompletionSource workerIsAllowedToStart) : BackgroundService { - protected override async Task ExecuteAsync(CancellationToken stoppingToken) + protected override async Task ExecuteAsync(CT stoppingToken) { await workerIsAllowedToStart.Task; diff --git a/bff/test/Bff.Tests/Blazor/Client/AntiforgeryHandlerTests.cs b/bff/test/Bff.Tests/Blazor/Client/AntiforgeryHandlerTests.cs index aeb4a7565..30a7b2949 100644 --- a/bff/test/Bff.Tests/Blazor/Client/AntiforgeryHandlerTests.cs +++ b/bff/test/Bff.Tests/Blazor/Client/AntiforgeryHandlerTests.cs @@ -23,7 +23,7 @@ public class AntiForgeryHandlerTests var client = new HttpClient(sut); - await client.SendAsync(request, CancellationToken.None); + await client.SendAsync(request, CT.None); request.Headers.ShouldContain(h => h.Key == "X-CSRF" && h.Value.Contains("1")); } diff --git a/bff/test/Bff.Tests/ConventionTests.cs b/bff/test/Bff.Tests/ConventionTests.cs index b91af27ed..315bddc53 100644 --- a/bff/test/Bff.Tests/ConventionTests.cs +++ b/bff/test/Bff.Tests/ConventionTests.cs @@ -273,7 +273,7 @@ public class ConventionTests } var ctParam = parameters.Last(); - if (ctParam.ParameterType != typeof(System.Threading.CancellationToken)) + if (ctParam.ParameterType != typeof(CT)) { failures.Add($"{type.FullName}.{method.Name}: Last parameter should be CancellationToken."); continue; diff --git a/bff/test/Bff.Tests/SessionManagement/ServerSideTokenStoreTests.cs b/bff/test/Bff.Tests/SessionManagement/ServerSideTokenStoreTests.cs index de36a0050..fd3517d53 100644 --- a/bff/test/Bff.Tests/SessionManagement/ServerSideTokenStoreTests.cs +++ b/bff/test/Bff.Tests/SessionManagement/ServerSideTokenStoreTests.cs @@ -117,7 +117,7 @@ public class ServerSideTokenStoreTests public Task SetUserTokenAsync(UserToken token, AuthenticationProperties authenticationProperties, - UserTokenRequestParameters? parameters = null, CancellationToken ct = new CancellationToken()) + UserTokenRequestParameters? parameters = null, CT ct = new CT()) { Stored = token; return Task.CompletedTask; @@ -127,7 +127,7 @@ public class ServerSideTokenStoreTests UserTokenRequestParameters? parameters = null) => Stored = null; public Task GetSchemeAsync(UserTokenRequestParameters? parameters = null, - CancellationToken ct = new CancellationToken()) => + CT ct = new CT()) => Task.FromResult(Scheme.Bearer); } diff --git a/bff/test/Bff.Tests/TestInfra/TestHybridCache.cs b/bff/test/Bff.Tests/TestInfra/TestHybridCache.cs index 91dbda166..08a21cfbf 100644 --- a/bff/test/Bff.Tests/TestInfra/TestHybridCache.cs +++ b/bff/test/Bff.Tests/TestInfra/TestHybridCache.cs @@ -10,19 +10,19 @@ internal class TestHybridCache : HybridCache { private ConcurrentDictionary> _cache = new(); public override async ValueTask GetOrCreateAsync(string key, TState state, - Func> factory, HybridCacheEntryOptions? options = null, - IEnumerable? tags = null, CancellationToken cancellationToken = new CancellationToken()) => (T)await _cache.GetOrAdd(key, async _ => (await factory(state, cancellationToken))!); + Func> factory, HybridCacheEntryOptions? options = null, + IEnumerable? tags = null, CT ct = new CT()) => (T)await _cache.GetOrAdd(key, async _ => (await factory(state, ct))!); public override ValueTask SetAsync(string key, T value, HybridCacheEntryOptions? options = null, IEnumerable? tags = null, - CancellationToken cancellationToken = new CancellationToken()) + CT ct = new CT()) { _cache[key] = new ValueTask(value!); return ValueTask.CompletedTask; } public override ValueTask - RemoveAsync(string key, CancellationToken cancellationToken = new CancellationToken()) + RemoveAsync(string key, CT ct = new CT()) { _waitUntilRemoveAsyncCalled.Set(); _cache.TryRemove(key, out _); @@ -33,7 +33,7 @@ internal class TestHybridCache : HybridCache ManualResetEventSlim _waitUntilRemoveAsyncCalled = new ManualResetEventSlim(); public override ValueTask RemoveByTagAsync(string tag, - CancellationToken cancellationToken = new CancellationToken()) + CT ct = new CT()) { _waitUntilRemoveByTagAsyncCalled.Set(); _cache.Clear(); diff --git a/bff/test/Bff.Tests/TestInfra/TestTokenRetriever.cs b/bff/test/Bff.Tests/TestInfra/TestTokenRetriever.cs index 56fa53ac8..8a7e3eaed 100644 --- a/bff/test/Bff.Tests/TestInfra/TestTokenRetriever.cs +++ b/bff/test/Bff.Tests/TestInfra/TestTokenRetriever.cs @@ -11,7 +11,7 @@ public class TestTokenRetriever : IAccessTokenRetriever public AccessTokenRetrievalContext? UsedContext { get; set; } public Task GetAccessTokenAsync(AccessTokenRetrievalContext context, - CancellationToken ct = default) + CT ct = default) { UsedContext = context; return Task.FromResult(new NoAccessTokenResult()); diff --git a/conformance-report/src/ConformanceReport/Endpoints/ConformanceReportEndpoint.cs b/conformance-report/src/ConformanceReport/Endpoints/ConformanceReportEndpoint.cs index 4cc653be2..bbabbcd0e 100644 --- a/conformance-report/src/ConformanceReport/Endpoints/ConformanceReportEndpoint.cs +++ b/conformance-report/src/ConformanceReport/Endpoints/ConformanceReportEndpoint.cs @@ -41,7 +41,7 @@ internal sealed partial class ConformanceReportEndpoint /// /// Processes requests for the HTML conformance report. /// - public async Task GetHtmlReportAsync(HttpContext context, CancellationToken cancellationToken = default) + public async Task GetHtmlReportAsync(HttpContext context, CT ct = default) { LogProcessingRequest(); @@ -53,7 +53,7 @@ internal sealed partial class ConformanceReportEndpoint try { - var report = await _assessmentService.GenerateReportAsync(cancellationToken: cancellationToken); + var report = await _assessmentService.GenerateReportAsync(ct: ct); using var slice = Duende.ConformanceReport.Slices.ConformanceReport.Create(report); var sb = new StringBuilder(); diff --git a/conformance-report/src/ConformanceReport/Endpoints/ConformanceReportEndpointExtensions.cs b/conformance-report/src/ConformanceReport/Endpoints/ConformanceReportEndpointExtensions.cs index f3e38d3f1..cc0235f50 100644 --- a/conformance-report/src/ConformanceReport/Endpoints/ConformanceReportEndpointExtensions.cs +++ b/conformance-report/src/ConformanceReport/Endpoints/ConformanceReportEndpointExtensions.cs @@ -25,8 +25,8 @@ public static class ConformanceReportEndpointExtensions var group = endpoints.MapGroup(basePath); // HTML endpoint - requires custom authorization policy - _ = group.MapGet("", async (ConformanceReportEndpoint endpoint, HttpContext context, CancellationToken cancellationToken) => - await endpoint.GetHtmlReportAsync(context, cancellationToken)) + _ = group.MapGet("", async (ConformanceReportEndpoint endpoint, HttpContext context, CT ct) => + await endpoint.GetHtmlReportAsync(context, ct)) .RequireAuthorization(options.AuthorizationPolicyName) .WithName("GetConformanceHtmlReport") .WithDescription("Gets the conformance assessment report as an HTML page") diff --git a/conformance-report/src/ConformanceReport/IConformanceReportClientStore.cs b/conformance-report/src/ConformanceReport/IConformanceReportClientStore.cs index 4a5a4090d..da7896d14 100644 --- a/conformance-report/src/ConformanceReport/IConformanceReportClientStore.cs +++ b/conformance-report/src/ConformanceReport/IConformanceReportClientStore.cs @@ -5,5 +5,5 @@ namespace Duende.ConformanceReport; internal interface IConformanceReportClientStore { - Task> GetAllClientsAsync(CancellationToken ct = default); + Task> GetAllClientsAsync(CT ct = default); } diff --git a/conformance-report/src/ConformanceReport/Services/ConformanceReportAssessmentService.cs b/conformance-report/src/ConformanceReport/Services/ConformanceReportAssessmentService.cs index c511609b3..b082eee63 100644 --- a/conformance-report/src/ConformanceReport/Services/ConformanceReportAssessmentService.cs +++ b/conformance-report/src/ConformanceReport/Services/ConformanceReportAssessmentService.cs @@ -42,11 +42,11 @@ internal class ConformanceReportAssessmentService /// /// Generates a complete conformance assessment report. /// - /// The cancellation token. + /// The cancellation token. /// A conformance report containing the assessment results. - public async Task GenerateReportAsync(CancellationToken cancellationToken = default) + public async Task GenerateReportAsync(CT ct = default) { - var clients = await _clientStore.GetAllClientsAsync(cancellationToken); + var clients = await _clientStore.GetAllClientsAsync(ct); var clientList = clients.ToList(); ProfileResult? oauth21Result = null; @@ -87,13 +87,13 @@ internal class ConformanceReportAssessmentService /// Generates a conformance assessment report for a specific profile. /// /// The profile to assess. - /// The cancellation token. + /// The cancellation token. /// A profile result containing the assessment findings. public async Task AssessProfileAsync( ConformanceReportProfile profile, - CancellationToken cancellationToken = default) + CT ct = default) { - var clients = await _clientStore.GetAllClientsAsync(cancellationToken); + var clients = await _clientStore.GetAllClientsAsync(ct); var clientList = clients.ToList(); return profile switch diff --git a/identity-server/clients/src/ConsoleCode/SystemBrowser.cs b/identity-server/clients/src/ConsoleCode/SystemBrowser.cs index e3f0c3aba..3e041c3b2 100644 --- a/identity-server/clients/src/ConsoleCode/SystemBrowser.cs +++ b/identity-server/clients/src/ConsoleCode/SystemBrowser.cs @@ -45,7 +45,7 @@ public class SystemBrowser : IBrowser return port; } - public async Task InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default) + public async Task InvokeAsync(BrowserOptions options, CT ct = default) { using (var listener = new LoopbackHttpListener(Port, _path)) { diff --git a/identity-server/clients/src/ConsoleResourceIndicators/SystemBrowser.cs b/identity-server/clients/src/ConsoleResourceIndicators/SystemBrowser.cs index f392bc2a0..1effbbfc4 100644 --- a/identity-server/clients/src/ConsoleResourceIndicators/SystemBrowser.cs +++ b/identity-server/clients/src/ConsoleResourceIndicators/SystemBrowser.cs @@ -37,7 +37,7 @@ public class SystemBrowser : IBrowser return port; } - public async Task InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default) + public async Task InvokeAsync(BrowserOptions options, CT ct = default) { using (var listener = new LoopbackHttpListener(Port, _path)) { diff --git a/identity-server/clients/src/MvcDPoP/TestHandler.cs b/identity-server/clients/src/MvcDPoP/TestHandler.cs index 78e47ea0d..cef0d4180 100644 --- a/identity-server/clients/src/MvcDPoP/TestHandler.cs +++ b/identity-server/clients/src/MvcDPoP/TestHandler.cs @@ -8,9 +8,9 @@ public class TestHandler : DelegatingHandler private readonly ILogger _logger; public TestHandler(ILogger logger) => _logger = logger; - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync(HttpRequestMessage request, CT ct) { - var response = await base.SendAsync(request, cancellationToken); + var response = await base.SendAsync(request, ct); if (response.Headers.Contains("WWW-Authenticate")) { foreach (var value in response.Headers.WwwAuthenticate) diff --git a/identity-server/clients/src/MvcJarJwt/ClientAssertionService.cs b/identity-server/clients/src/MvcJarJwt/ClientAssertionService.cs index b4f5f4651..05bd8331a 100644 --- a/identity-server/clients/src/MvcJarJwt/ClientAssertionService.cs +++ b/identity-server/clients/src/MvcJarJwt/ClientAssertionService.cs @@ -10,7 +10,7 @@ namespace MvcJarJwt; public class ClientAssertionService(AssertionService assertionService) : IClientAssertionService { public Task GetClientAssertionAsync(ClientCredentialsClientName? clientName = null, TokenRequestParameters parameters = null, - CancellationToken ct = new()) + CT ct = new()) { var assertion = new ClientAssertion { diff --git a/identity-server/clients/src/MvcJarUriJwt/ClientAssertionService.cs b/identity-server/clients/src/MvcJarUriJwt/ClientAssertionService.cs index 7e935ff94..6ed71961c 100644 --- a/identity-server/clients/src/MvcJarUriJwt/ClientAssertionService.cs +++ b/identity-server/clients/src/MvcJarUriJwt/ClientAssertionService.cs @@ -11,7 +11,7 @@ public class ClientAssertionService(AssertionService assertionService) : IClient { public Task GetClientAssertionAsync(ClientCredentialsClientName? clientName = null, TokenRequestParameters parameters = null, - CancellationToken ct = new()) + CT ct = new()) { var assertion = new ClientAssertion { diff --git a/identity-server/clients/src/Web/ClientAssertionService.cs b/identity-server/clients/src/Web/ClientAssertionService.cs index a94c8792d..9338732ed 100644 --- a/identity-server/clients/src/Web/ClientAssertionService.cs +++ b/identity-server/clients/src/Web/ClientAssertionService.cs @@ -10,7 +10,7 @@ namespace Web; public class ClientAssertionService(AssertionService assertionService) : IClientAssertionService { public Task GetClientAssertionAsync(ClientCredentialsClientName? clientName = null, TokenRequestParameters? parameters = null, - CancellationToken ct = new CancellationToken()) + CT ct = new CT()) { var assertion = new ClientAssertion { diff --git a/identity-server/clients/src/WindowsConsoleSystemBrowser/CallbackManager.cs b/identity-server/clients/src/WindowsConsoleSystemBrowser/CallbackManager.cs index 0eeb4b435..244ffd45d 100644 --- a/identity-server/clients/src/WindowsConsoleSystemBrowser/CallbackManager.cs +++ b/identity-server/clients/src/WindowsConsoleSystemBrowser/CallbackManager.cs @@ -26,9 +26,9 @@ internal class CallbackManager } } - public async Task RunServer(CancellationToken? token = null) + public async Task RunServer(CT? token = null) { - token = CancellationToken.None; + token = CT.None; await using var server = new NamedPipeServerStream(_name, PipeDirection.In); await server.WaitForConnectionAsync(token.Value); diff --git a/identity-server/hosts/EntityFramework10/TestOperationalStoreNotification.cs b/identity-server/hosts/EntityFramework10/TestOperationalStoreNotification.cs index b54240ef8..36e79cdd5 100644 --- a/identity-server/hosts/EntityFramework10/TestOperationalStoreNotification.cs +++ b/identity-server/hosts/EntityFramework10/TestOperationalStoreNotification.cs @@ -12,7 +12,7 @@ public class TestOperationalStoreNotification : IOperationalStoreNotification { public TestOperationalStoreNotification() => Console.WriteLine("ctor"); - public Task PersistedGrantsRemovedAsync(IEnumerable persistedGrants, CancellationToken cancellationToken = default) + public Task PersistedGrantsRemovedAsync(IEnumerable persistedGrants, CT ct = default) { ArgumentNullException.ThrowIfNull(persistedGrants); foreach (var grant in persistedGrants) @@ -22,7 +22,7 @@ public class TestOperationalStoreNotification : IOperationalStoreNotification return Task.CompletedTask; } - public Task DeviceCodesRemovedAsync(IEnumerable deviceCodes, CancellationToken cancellationToken = default) + public Task DeviceCodesRemovedAsync(IEnumerable deviceCodes, CT ct = default) { ArgumentNullException.ThrowIfNull(deviceCodes); foreach (var deviceCode in deviceCodes) @@ -32,7 +32,7 @@ public class TestOperationalStoreNotification : IOperationalStoreNotification return Task.CompletedTask; } - public Task ServerSideSessionsRemovedAsync(IEnumerable userSessions, CancellationToken cancellationToken = default) + public Task ServerSideSessionsRemovedAsync(IEnumerable userSessions, CT ct = default) { ArgumentNullException.ThrowIfNull(userSessions); foreach (var session in userSessions) diff --git a/identity-server/hosts/Shared/Customization/DiscoveryHealthCheck.cs b/identity-server/hosts/Shared/Customization/DiscoveryHealthCheck.cs index f685a32cb..f3acc850b 100644 --- a/identity-server/hosts/Shared/Customization/DiscoveryHealthCheck.cs +++ b/identity-server/hosts/Shared/Customization/DiscoveryHealthCheck.cs @@ -18,7 +18,7 @@ public class DiscoveryHealthCheck : IHealthCheck _httpContextAccessor = httpContextAccessor; } - public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) + public async Task CheckHealthAsync(HealthCheckContext context, CT ct = default) { ArgumentNullException.ThrowIfNull(context); try @@ -55,7 +55,7 @@ public class DiscoveryKeysHealthCheck : IHealthCheck _httpContextAccessor = httpContextAccessor; } - public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) + public async Task CheckHealthAsync(HealthCheckContext context, CT ct = default) { ArgumentNullException.ThrowIfNull(context); try diff --git a/identity-server/src/EntityFramework.Storage/Extensions/DbContextExtensions.cs b/identity-server/src/EntityFramework.Storage/Extensions/DbContextExtensions.cs index 0989d837c..e88dceb6f 100644 --- a/identity-server/src/EntityFramework.Storage/Extensions/DbContextExtensions.cs +++ b/identity-server/src/EntityFramework.Storage/Extensions/DbContextExtensions.cs @@ -18,7 +18,7 @@ public static class DbContextExtensions /// /// Saves changes and handles concurrency exceptions. /// - public static async Task> SaveChangesWithConcurrencyCheckAsync(this IPersistedGrantDbContext context, ILogger logger, CancellationToken cancellationToken = default) + public static async Task> SaveChangesWithConcurrencyCheckAsync(this IPersistedGrantDbContext context, ILogger logger, CT ct = default) where T : class { var list = new List(); @@ -29,7 +29,7 @@ public static class DbContextExtensions { try { - await context.SaveChangesAsync(cancellationToken); + await context.SaveChangesAsync(ct); return list; } catch (DbUpdateConcurrencyException ex) diff --git a/identity-server/src/EntityFramework.Storage/Interfaces/IConfigurationDbContext.cs b/identity-server/src/EntityFramework.Storage/Interfaces/IConfigurationDbContext.cs index 1b69c0024..e4efd57fc 100644 --- a/identity-server/src/EntityFramework.Storage/Interfaces/IConfigurationDbContext.cs +++ b/identity-server/src/EntityFramework.Storage/Interfaces/IConfigurationDbContext.cs @@ -67,7 +67,7 @@ public interface IConfigurationDbContext : IDisposable /// Saves the changes. /// /// - Task SaveChangesAsync(CancellationToken cancellationToken); + Task SaveChangesAsync(CT ct); // this is here only because of this: https://github.com/DuendeSoftware/IdentityServer/issues/472 // and because Microsoft implements the old API explicitly: https://github.com/dotnet/aspnetcore/blob/v6.0.0-rc.2.21480.10/src/Identity/ApiAuthorization.IdentityServer/src/Data/ApiAuthorizationDbContext.cs @@ -76,5 +76,5 @@ public interface IConfigurationDbContext : IDisposable /// Saves the changes. /// /// - Task SaveChangesAsync() => SaveChangesAsync(CancellationToken.None); + Task SaveChangesAsync() => SaveChangesAsync(CT.None); } diff --git a/identity-server/src/EntityFramework.Storage/Interfaces/IPersistedGrantDbContext.cs b/identity-server/src/EntityFramework.Storage/Interfaces/IPersistedGrantDbContext.cs index 20dcbe24a..9a530e666 100644 --- a/identity-server/src/EntityFramework.Storage/Interfaces/IPersistedGrantDbContext.cs +++ b/identity-server/src/EntityFramework.Storage/Interfaces/IPersistedGrantDbContext.cs @@ -59,7 +59,7 @@ public interface IPersistedGrantDbContext : IDisposable /// Saves the changes. /// /// - Task SaveChangesAsync(CancellationToken cancellationToken); + Task SaveChangesAsync(CT ct); // this is here only because of this: https://github.com/DuendeSoftware/IdentityServer/issues/472 // and because Microsoft implements the old API explicitly: https://github.com/dotnet/aspnetcore/blob/v6.0.0-rc.2.21480.10/src/Identity/ApiAuthorization.IdentityServer/src/Data/ApiAuthorizationDbContext.cs @@ -68,5 +68,5 @@ public interface IPersistedGrantDbContext : IDisposable /// Saves the changes. /// /// - Task SaveChangesAsync() => SaveChangesAsync(CancellationToken.None); + Task SaveChangesAsync() => SaveChangesAsync(CT.None); } diff --git a/identity-server/src/EntityFramework.Storage/Stores/ServerSideSessionStore.cs b/identity-server/src/EntityFramework.Storage/Stores/ServerSideSessionStore.cs index 721837087..872439991 100644 --- a/identity-server/src/EntityFramework.Storage/Stores/ServerSideSessionStore.cs +++ b/identity-server/src/EntityFramework.Storage/Stores/ServerSideSessionStore.cs @@ -50,11 +50,11 @@ public class ServerSideSessionStore : IServerSideSessionStore /// - public virtual async Task CreateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default) + public virtual async Task CreateSessionAsync(ServerSideSession session, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideSessionStore.CreateSession"); - cancellationToken = cancellationToken == CancellationToken.None ? CancellationTokenProvider.CancellationToken : cancellationToken; + ct = ct == CT.None ? CancellationTokenProvider.CancellationToken : ct; var entity = new Entities.ServerSideSession { @@ -72,7 +72,7 @@ public class ServerSideSessionStore : IServerSideSessionStore try { - await Context.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(ct); Logger.LogDebug("Created new server-side session {serverSideSessionKey} in database", session.Key); } catch (DbUpdateException ex) @@ -82,14 +82,14 @@ public class ServerSideSessionStore : IServerSideSessionStore } /// - public virtual async Task GetSessionAsync(string key, CancellationToken cancellationToken = default) + public virtual async Task GetSessionAsync(string key, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideSessionStore.GetSession"); - cancellationToken = cancellationToken == CancellationToken.None ? CancellationTokenProvider.CancellationToken : cancellationToken; + ct = ct == CT.None ? CancellationTokenProvider.CancellationToken : ct; var entity = (await Context.ServerSideSessions.AsNoTracking().Where(x => x.Key == key) - .ToArrayAsync(cancellationToken)) + .ToArrayAsync(ct)) .SingleOrDefault(x => x.Key == key); var model = default(ServerSideSession); @@ -115,14 +115,14 @@ public class ServerSideSessionStore : IServerSideSessionStore } /// - public virtual async Task UpdateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default) + public virtual async Task UpdateSessionAsync(ServerSideSession session, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideSessionStore.UpdateSession"); - cancellationToken = cancellationToken == CancellationToken.None ? CancellationTokenProvider.CancellationToken : cancellationToken; + ct = ct == CT.None ? CancellationTokenProvider.CancellationToken : ct; var entity = (await Context.ServerSideSessions.Where(x => x.Key == session.Key) - .ToArrayAsync(cancellationToken)) + .ToArrayAsync(ct)) .SingleOrDefault(x => x.Key == session.Key); if (entity == null) @@ -142,7 +142,7 @@ public class ServerSideSessionStore : IServerSideSessionStore try { - await Context.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(ct); Logger.LogDebug("Updated server-side session {serverSideSessionKey} in database", session.Key); } catch (DbUpdateException ex) @@ -152,14 +152,14 @@ public class ServerSideSessionStore : IServerSideSessionStore } /// - public virtual async Task DeleteSessionAsync(string key, CancellationToken cancellationToken = default) + public virtual async Task DeleteSessionAsync(string key, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideSessionStore.DeleteSession"); - cancellationToken = cancellationToken == CancellationToken.None ? CancellationTokenProvider.CancellationToken : cancellationToken; + ct = ct == CT.None ? CancellationTokenProvider.CancellationToken : ct; var entity = (await Context.ServerSideSessions.Where(x => x.Key == key) - .ToArrayAsync(cancellationToken)) + .ToArrayAsync(ct)) .SingleOrDefault(x => x.Key == key); if (entity == null) @@ -172,7 +172,7 @@ public class ServerSideSessionStore : IServerSideSessionStore try { - await Context.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(ct); Logger.LogDebug("Deleted server-side session {serverSideSessionKey} in database", key); } catch (DbUpdateException ex) @@ -184,16 +184,16 @@ public class ServerSideSessionStore : IServerSideSessionStore /// - public virtual async Task> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default) + public virtual async Task> GetSessionsAsync(SessionFilter filter, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideSessionStore.GetSessions"); - cancellationToken = cancellationToken == CancellationToken.None ? CancellationTokenProvider.CancellationToken : cancellationToken; + ct = ct == CT.None ? CancellationTokenProvider.CancellationToken : ct; filter.Validate(); var entities = await Filter(Context.ServerSideSessions.AsNoTracking().AsQueryable(), filter) - .ToArrayAsync(cancellationToken); + .ToArrayAsync(ct); entities = Filter(entities.AsQueryable(), filter).ToArray(); var results = entities.Select(entity => new ServerSideSession @@ -215,23 +215,23 @@ public class ServerSideSessionStore : IServerSideSessionStore } /// - public virtual async Task DeleteSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default) + public virtual async Task DeleteSessionsAsync(SessionFilter filter, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideSessionStore.DeleteSessions"); - cancellationToken = cancellationToken == CancellationToken.None ? CancellationTokenProvider.CancellationToken : cancellationToken; + ct = ct == CT.None ? CancellationTokenProvider.CancellationToken : ct; filter.Validate(); var entities = await Filter(Context.ServerSideSessions.AsQueryable(), filter) - .ToArrayAsync(cancellationToken); + .ToArrayAsync(ct); entities = Filter(entities.AsQueryable(), filter).ToArray(); Context.ServerSideSessions.RemoveRange(entities); try { - await Context.SaveChangesAsync(cancellationToken); + await Context.SaveChangesAsync(ct); Logger.LogDebug("Removed {serverSideSessionCount} server-side sessions from database for {@filter}", entities.Length, filter); } catch (DbUpdateException ex) @@ -256,23 +256,23 @@ public class ServerSideSessionStore : IServerSideSessionStore /// - public virtual async Task> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default) + public virtual async Task> GetAndRemoveExpiredSessionsAsync(int count, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideSessionStore.GetAndRemoveExpiredSessions"); - cancellationToken = cancellationToken == CancellationToken.None ? CancellationTokenProvider.CancellationToken : cancellationToken; + ct = ct == CT.None ? CancellationTokenProvider.CancellationToken : ct; var entities = await Context.ServerSideSessions .Where(x => x.Expires < DateTime.UtcNow) .OrderBy(x => x.Id) .Take(count) - .ToArrayAsync(cancellationToken); + .ToArrayAsync(ct); if (entities.Length > 0) { Context.ServerSideSessions.RemoveRange(entities); - var list = await Context.SaveChangesWithConcurrencyCheckAsync(Logger, cancellationToken); + var list = await Context.SaveChangesWithConcurrencyCheckAsync(Logger, ct); entities = entities.Except(list).ToArray(); Logger.LogDebug("Found and removed {serverSideSessionCount} expired server-side sessions", entities.Length); @@ -295,11 +295,11 @@ public class ServerSideSessionStore : IServerSideSessionStore } /// - public virtual async Task> QuerySessionsAsync(SessionQuery filter = null, CancellationToken cancellationToken = default) + public virtual async Task> QuerySessionsAsync(SessionQuery filter = null, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideSessionStore.QuerySessions"); - cancellationToken = cancellationToken == CancellationToken.None ? CancellationTokenProvider.CancellationToken : cancellationToken; + ct = ct == CT.None ? CancellationTokenProvider.CancellationToken : ct; // it's possible that this implementation could have been done differently (e.g. use the page number for the token) // but it was done deliberately in such a way to allow document databases to mimic the logic @@ -318,7 +318,7 @@ public class ServerSideSessionStore : IServerSideSessionStore countRequested = 25; } - var totalCount = await query.CountAsync(cancellationToken); + var totalCount = await query.CountAsync(ct); var pagination = new SessionPaginationContext { CountRequested = countRequested, @@ -330,7 +330,7 @@ public class ServerSideSessionStore : IServerSideSessionStore if (filter.RequestPriorResults) { - await PreviousPage(query, first, pagination, cancellationToken); + await PreviousPage(query, first, pagination, ct); if (AtStartWithDeletedItems(pagination)) { @@ -338,12 +338,12 @@ public class ServerSideSessionStore : IServerSideSessionStore // we need to start over and re-query from the beginning. filter.ResultsToken = null; filter.RequestPriorResults = false; - return await QuerySessionsAsync(filter, cancellationToken); + return await QuerySessionsAsync(filter, ct); } } else { - await NextPage(query, last, pagination, cancellationToken); + await NextPage(query, last, pagination, ct); } // this handles prior entries being deleted since paging begun @@ -401,14 +401,14 @@ public class ServerSideSessionStore : IServerSideSessionStore Ticket = entity.Data, }).ToArray(); - private static async Task NextPage(IQueryable query, int last, SessionPaginationContext pagination, CancellationToken cancellationToken) + private static async Task NextPage(IQueryable query, int last, SessionPaginationContext pagination, CT ct) { pagination.Items = await query.OrderBy(x => x.Id) // if lastResultsId is zero, then this will just start at beginning .Where(x => x.Id > last) // and we +1 to see if there's a next page .Take(pagination.CountRequested + 1) - .ToArrayAsync(cancellationToken); + .ToArrayAsync(ct); // if we have the one extra, we have a next page pagination.HasNext = pagination.Items.Length > pagination.CountRequested; @@ -423,20 +423,20 @@ public class ServerSideSessionStore : IServerSideSessionStore if (pagination.Items.Length > 0) { var priorCountId = pagination.Items[0].Id; - var priorCount = await query.CountAsync(x => x.Id < last, cancellationToken); + var priorCount = await query.CountAsync(x => x.Id < last, ct); pagination.HasPrev = priorCount > 0; pagination.CurrentPage = 1 + (int)Math.Ceiling((1.0 * priorCount) / pagination.CountRequested); } } - private static async Task PreviousPage(IQueryable query, int first, SessionPaginationContext pagination, CancellationToken cancellationToken) + private static async Task PreviousPage(IQueryable query, int first, SessionPaginationContext pagination, CT ct) { // sets query at the prior record from the last results, but in reverse order pagination.Items = await query.OrderByDescending(x => x.Id) .Where(x => x.Id < first) // and we +1 to see if there's a prev page .Take(pagination.CountRequested + 1) - .ToArrayAsync(cancellationToken); + .ToArrayAsync(ct); // put them back into ID order pagination.Items = pagination.Items.OrderBy(x => x.Id).ToArray(); @@ -454,7 +454,7 @@ public class ServerSideSessionStore : IServerSideSessionStore if (pagination.Items.Length > 0) { var postCountId = pagination.Items[pagination.Items.Length - 1].Id; - var postCount = await query.CountAsync(x => x.Id > postCountId, cancellationToken); + var postCount = await query.CountAsync(x => x.Id > postCountId, ct); pagination.HasNext = postCount > 0; pagination.CurrentPage = pagination.TotalPages - (int)Math.Ceiling((1.0 * postCount) / pagination.CountRequested); } diff --git a/identity-server/src/EntityFramework.Storage/TokenCleanup/IOperationalStoreNotification.cs b/identity-server/src/EntityFramework.Storage/TokenCleanup/IOperationalStoreNotification.cs index 8153e6de6..c8489fe3a 100644 --- a/identity-server/src/EntityFramework.Storage/TokenCleanup/IOperationalStoreNotification.cs +++ b/identity-server/src/EntityFramework.Storage/TokenCleanup/IOperationalStoreNotification.cs @@ -17,15 +17,15 @@ public interface IOperationalStoreNotification /// Notification for persisted grants being removed. /// /// - /// + /// /// - Task PersistedGrantsRemovedAsync(IEnumerable persistedGrants, CancellationToken cancellationToken = default); + Task PersistedGrantsRemovedAsync(IEnumerable persistedGrants, CT ct = default); /// /// Notification for device codes being removed. /// /// - /// + /// /// - Task DeviceCodesRemovedAsync(IEnumerable deviceCodes, CancellationToken cancellationToken = default); + Task DeviceCodesRemovedAsync(IEnumerable deviceCodes, CT ct = default); } diff --git a/identity-server/src/EntityFramework.Storage/TokenCleanup/ITokenCleanupService.cs b/identity-server/src/EntityFramework.Storage/TokenCleanup/ITokenCleanupService.cs index 6a68c832b..5b5fc8a6e 100644 --- a/identity-server/src/EntityFramework.Storage/TokenCleanup/ITokenCleanupService.cs +++ b/identity-server/src/EntityFramework.Storage/TokenCleanup/ITokenCleanupService.cs @@ -16,8 +16,8 @@ public interface ITokenCleanupService /// Removes expired persisted grants, expired device codes, and optionally /// consumed persisted grants from the stores. /// - /// A token that propagates notification + /// A token that propagates notification /// that the cleanup operation should be canceled. /// - Task CleanupGrantsAsync(CancellationToken cancellationToken = default); + Task CleanupGrantsAsync(CT ct = default); } diff --git a/identity-server/src/EntityFramework.Storage/TokenCleanup/TokenCleanupService.cs b/identity-server/src/EntityFramework.Storage/TokenCleanup/TokenCleanupService.cs index 441544df0..0a0e0d4dc 100644 --- a/identity-server/src/EntityFramework.Storage/TokenCleanup/TokenCleanupService.cs +++ b/identity-server/src/EntityFramework.Storage/TokenCleanup/TokenCleanupService.cs @@ -43,15 +43,15 @@ public class TokenCleanupService : ITokenCleanupService } /// - public async Task CleanupGrantsAsync(CancellationToken cancellationToken = default) + public async Task CleanupGrantsAsync(CT ct = default) { try { _logger.LogTrace("Querying for expired grants to remove"); - await RemoveGrantsAsync(cancellationToken); - await RemoveDeviceCodesAsync(cancellationToken); - await RemovePushedAuthorizationRequestsAsync(cancellationToken); + await RemoveGrantsAsync(ct); + await RemoveDeviceCodesAsync(ct); + await RemovePushedAuthorizationRequestsAsync(ct); } catch (Exception ex) { @@ -63,12 +63,12 @@ public class TokenCleanupService : ITokenCleanupService /// Removes the stale persisted grants. /// /// - protected virtual async Task RemoveGrantsAsync(CancellationToken cancellationToken = default) + protected virtual async Task RemoveGrantsAsync(CT ct = default) { - await RemoveExpiredPersistedGrantsAsync(cancellationToken); + await RemoveExpiredPersistedGrantsAsync(ct); if (_options.RemoveConsumedTokens) { - await RemoveConsumedPersistedGrantsAsync(cancellationToken); + await RemoveConsumedPersistedGrantsAsync(ct); } } @@ -76,7 +76,7 @@ public class TokenCleanupService : ITokenCleanupService /// Removes the expired persisted grants. /// /// - protected virtual async Task RemoveExpiredPersistedGrantsAsync(CancellationToken cancellationToken = default) + protected virtual async Task RemoveExpiredPersistedGrantsAsync(CT ct = default) { var found = int.MaxValue; @@ -92,7 +92,7 @@ public class TokenCleanupService : ITokenCleanupService var expiredGrants = await query .Take(_options.TokenCleanupBatchSize) .AsNoTracking() - .ToArrayAsync(cancellationToken); + .ToArrayAsync(ct); found = expiredGrants.Length; @@ -114,7 +114,7 @@ public class TokenCleanupService : ITokenCleanupService // To be on the safe side, filter out any possibly newly added item within the interval .Where(pg => foundIds.Contains(pg.Id)) // And delete them. - .ExecuteDeleteAsync(cancellationToken); + .ExecuteDeleteAsync(ct); if (deleteCount != found) { @@ -135,7 +135,7 @@ public class TokenCleanupService : ITokenCleanupService if (_operationalStoreNotification != null) { - await _operationalStoreNotification.PersistedGrantsRemovedAsync(expiredGrants, cancellationToken); + await _operationalStoreNotification.PersistedGrantsRemovedAsync(expiredGrants, ct); } } } @@ -145,7 +145,7 @@ public class TokenCleanupService : ITokenCleanupService /// Removes the consumed persisted grants. /// /// - protected virtual async Task RemoveConsumedPersistedGrantsAsync(CancellationToken cancellationToken = default) + protected virtual async Task RemoveConsumedPersistedGrantsAsync(CT ct = default) { var found = int.MaxValue; @@ -161,7 +161,7 @@ public class TokenCleanupService : ITokenCleanupService var consumedGrants = await query .Take(_options.TokenCleanupBatchSize) .AsNoTracking() - .ToArrayAsync(cancellationToken); + .ToArrayAsync(ct); found = consumedGrants.Length; @@ -176,7 +176,7 @@ public class TokenCleanupService : ITokenCleanupService pg.ConsumedTime >= consumedGrants.First().ConsumedTime && pg.ConsumedTime <= consumedGrants.Last().ConsumedTime) .Where(pg => foundIds.Contains(pg.Id)) - .ExecuteDeleteAsync(cancellationToken); + .ExecuteDeleteAsync(ct); if (deleteCount != found) { @@ -197,7 +197,7 @@ public class TokenCleanupService : ITokenCleanupService if (_operationalStoreNotification != null) { - await _operationalStoreNotification.PersistedGrantsRemovedAsync(consumedGrants, cancellationToken); + await _operationalStoreNotification.PersistedGrantsRemovedAsync(consumedGrants, ct); } } } @@ -208,7 +208,7 @@ public class TokenCleanupService : ITokenCleanupService /// Removes the stale device codes. /// /// - protected virtual async Task RemoveDeviceCodesAsync(CancellationToken cancellationToken = default) + protected virtual async Task RemoveDeviceCodesAsync(CT ct = default) { var found = int.MaxValue; @@ -221,7 +221,7 @@ public class TokenCleanupService : ITokenCleanupService var expiredCodes = await query .Take(_options.TokenCleanupBatchSize) .AsNoTracking() - .ToArrayAsync(cancellationToken); + .ToArrayAsync(ct); found = expiredCodes.Length; @@ -234,7 +234,7 @@ public class TokenCleanupService : ITokenCleanupService var deleteCount = await query .Where(c => c.Expiration >= expiredCodes.First().Expiration && c.Expiration <= expiredCodes.Last().Expiration) .Where(c => foundCodes.Contains(c.DeviceCode)) - .ExecuteDeleteAsync(cancellationToken); + .ExecuteDeleteAsync(ct); if (deleteCount != found) { @@ -255,7 +255,7 @@ public class TokenCleanupService : ITokenCleanupService if (_operationalStoreNotification != null) { - await _operationalStoreNotification.DeviceCodesRemovedAsync(expiredCodes, cancellationToken); + await _operationalStoreNotification.DeviceCodesRemovedAsync(expiredCodes, ct); } } } @@ -264,7 +264,7 @@ public class TokenCleanupService : ITokenCleanupService /// /// Removes stale pushed authorization requests. /// - protected virtual async Task RemovePushedAuthorizationRequestsAsync(CancellationToken cancellationToken = default) + protected virtual async Task RemovePushedAuthorizationRequestsAsync(CT ct = default) { var found = int.MaxValue; @@ -276,7 +276,7 @@ public class TokenCleanupService : ITokenCleanupService { found = await query .Take(_options.TokenCleanupBatchSize) - .ExecuteDeleteAsync(cancellationToken); + .ExecuteDeleteAsync(ct); if (found > 0) { diff --git a/identity-server/src/EntityFramework/TokenCleanupHost.cs b/identity-server/src/EntityFramework/TokenCleanupHost.cs index 500b63730..60153bb24 100644 --- a/identity-server/src/EntityFramework/TokenCleanupHost.cs +++ b/identity-server/src/EntityFramework/TokenCleanupHost.cs @@ -38,7 +38,7 @@ public class TokenCleanupHost : IHostedService /// /// Starts the token cleanup polling. /// - public Task StartAsync(CancellationToken cancellationToken) + public Task StartAsync(CT ct) { if (_options.EnableTokenCleanup) { @@ -49,9 +49,9 @@ public class TokenCleanupHost : IHostedService _logger.LogDebug("Starting grant removal"); - _source = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + _source = CancellationTokenSource.CreateLinkedTokenSource(ct); - Task.Factory.StartNew(() => StartInternalAsync(_source.Token), cancellationToken, TaskCreationOptions.None, TaskScheduler.Default); + Task.Factory.StartNew(() => StartInternalAsync(_source.Token), ct, TaskCreationOptions.None, TaskScheduler.Default); } return Task.CompletedTask; @@ -60,7 +60,7 @@ public class TokenCleanupHost : IHostedService /// /// Stops the token cleanup polling. /// - public async Task StopAsync(CancellationToken cancellationToken) + public async Task StopAsync(CT ct) { if (_options.EnableTokenCleanup) { @@ -76,7 +76,7 @@ public class TokenCleanupHost : IHostedService } } - private async Task StartInternalAsync(CancellationToken cancellationToken) + private async Task StartInternalAsync(CT ct) { // Start the first run at a random interval. var delay = _options.FuzzTokenCleanupStart @@ -87,7 +87,7 @@ public class TokenCleanupHost : IHostedService while (true) { - if (cancellationToken.IsCancellationRequested) + if (ct.IsCancellationRequested) { _logger.LogDebug("CancellationRequested. Exiting."); break; @@ -95,7 +95,7 @@ public class TokenCleanupHost : IHostedService try { - await Task.Delay(delay, cancellationToken); + await Task.Delay(delay, ct); } catch (TaskCanceledException) { @@ -108,27 +108,27 @@ public class TokenCleanupHost : IHostedService break; } - if (cancellationToken.IsCancellationRequested) + if (ct.IsCancellationRequested) { _logger.LogDebug("CancellationRequested. Exiting."); break; } - await RemoveExpiredGrantsAsync(cancellationToken); + await RemoveExpiredGrantsAsync(ct); // For all subsequent runs use the configured interval. delay = CleanupInterval; } } - private async Task RemoveExpiredGrantsAsync(CancellationToken cancellationToken = default) + private async Task RemoveExpiredGrantsAsync(CT ct = default) { try { await using (var serviceScope = _serviceProvider.GetRequiredService().CreateAsyncScope()) { var tokenCleanupService = serviceScope.ServiceProvider.GetRequiredService(); - await tokenCleanupService.CleanupGrantsAsync(cancellationToken); + await tokenCleanupService.CleanupGrantsAsync(ct); } } catch (Exception ex) diff --git a/identity-server/src/IdentityServer/Hosting/ServerSideSessionCleanupHost.cs b/identity-server/src/IdentityServer/Hosting/ServerSideSessionCleanupHost.cs index 3f8886a0b..ac7e87540 100644 --- a/identity-server/src/IdentityServer/Hosting/ServerSideSessionCleanupHost.cs +++ b/identity-server/src/IdentityServer/Hosting/ServerSideSessionCleanupHost.cs @@ -19,13 +19,13 @@ public class ServerSideSessionCleanupHost( ILogger logger) : BackgroundService { /// - public override Task StartAsync(CancellationToken cancellationToken) => + public override Task StartAsync(CT ct) => !options.ServerSideSessions.RemoveExpiredSessions ? Task.CompletedTask - : base.StartAsync(cancellationToken); + : base.StartAsync(ct); /// - protected override async Task ExecuteAsync(CancellationToken stoppingToken) + protected override async Task ExecuteAsync(CT stoppingToken) { logger.LogDebug("Starting server-side session removal"); @@ -68,7 +68,7 @@ public class ServerSideSessionCleanupHost( logger.LogDebug("Stopping server-side session removal"); } - private async Task RunAsync(CancellationToken cancellationToken = default) + private async Task RunAsync(CT ct = default) { // this is here for testing if (!options.ServerSideSessions.RemoveExpiredSessions) @@ -88,7 +88,7 @@ public class ServerSideSessionCleanupHost( while (found > 0) { - var sessions = await serverSideTicketStore.GetAndRemoveExpiredSessionsAsync(scopedOptions.ServerSideSessions.RemoveExpiredSessionsBatchSize, cancellationToken); + var sessions = await serverSideTicketStore.GetAndRemoveExpiredSessionsAsync(scopedOptions.ServerSideSessions.RemoveExpiredSessionsBatchSize, ct); found = sessions.Count; if (found <= 0) diff --git a/identity-server/src/IdentityServer/Licensing/V2/Diagnostics/DiagnosticHostedService.cs b/identity-server/src/IdentityServer/Licensing/V2/Diagnostics/DiagnosticHostedService.cs index 2d7b355ab..b68745268 100644 --- a/identity-server/src/IdentityServer/Licensing/V2/Diagnostics/DiagnosticHostedService.cs +++ b/identity-server/src/IdentityServer/Licensing/V2/Diagnostics/DiagnosticHostedService.cs @@ -10,7 +10,7 @@ namespace Duende.IdentityServer.Licensing.V2.Diagnostics; internal class DiagnosticHostedService(DiagnosticSummary diagnosticSummary, IOptions options, ILogger logger) : BackgroundService { - protected override async Task ExecuteAsync(CancellationToken stoppingToken) + protected override async Task ExecuteAsync(CT stoppingToken) { using var timer = new PeriodicTimer(options.Value.Diagnostics.LogFrequency); try @@ -35,12 +35,12 @@ internal class DiagnosticHostedService(DiagnosticSummary diagnosticSummary, IOpt } // Added for testing purposes to be able to call ExecuteAsync directly. - internal Task ExecuteForTestOnly(CancellationToken stoppingToken) => ExecuteAsync(stoppingToken); + internal Task ExecuteForTestOnly(CT stoppingToken) => ExecuteAsync(stoppingToken); - public override async Task StopAsync(CancellationToken cancellationToken) + public override async Task StopAsync(CT ct) { await diagnosticSummary.PrintSummary(); - await base.StopAsync(cancellationToken); + await base.StopAsync(ct); } } diff --git a/identity-server/src/IdentityServer/Services/Default/DefaultCancellationTokenProvider.cs b/identity-server/src/IdentityServer/Services/Default/DefaultCancellationTokenProvider.cs index d301b06a0..451a5e148 100644 --- a/identity-server/src/IdentityServer/Services/Default/DefaultCancellationTokenProvider.cs +++ b/identity-server/src/IdentityServer/Services/Default/DefaultCancellationTokenProvider.cs @@ -22,5 +22,5 @@ internal class DefaultCancellationTokenProvider : ICancellationTokenProvider /// /// Provides access to the cancellation token from the http context /// - public CancellationToken CancellationToken => _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None; + public CT CancellationToken => _httpContextAccessor.HttpContext?.RequestAborted ?? CT.None; } diff --git a/identity-server/src/IdentityServer/Services/Default/DefaultSessionManagementService.cs b/identity-server/src/IdentityServer/Services/Default/DefaultSessionManagementService.cs index c072e0c97..1b4d0015b 100644 --- a/identity-server/src/IdentityServer/Services/Default/DefaultSessionManagementService.cs +++ b/identity-server/src/IdentityServer/Services/Default/DefaultSessionManagementService.cs @@ -33,11 +33,11 @@ public class DefaultSessionManagementService : ISessionManagementService } /// - public Task> QuerySessionsAsync(SessionQuery filter = null, CancellationToken cancellationToken = default) + public Task> QuerySessionsAsync(SessionQuery filter = null, CT ct = default) { using var activity = Tracing.ServiceActivitySource.StartActivity("DefaultSessionManagementService.QuerySessions"); - return _serverSideTicketStore.QuerySessionsAsync(filter, cancellationToken); + return _serverSideTicketStore.QuerySessionsAsync(filter, ct); } private static readonly string[] OnlyTokenTypes = new[] { @@ -48,7 +48,7 @@ public class DefaultSessionManagementService : ISessionManagementService }; /// - public async Task RemoveSessionsAsync(RemoveSessionsContext context, CancellationToken cancellationToken = default) + public async Task RemoveSessionsAsync(RemoveSessionsContext context, CT ct = default) { using var activity = Tracing.ServiceActivitySource.StartActivity("DefaultSessionManagementService.RemoveSessions"); @@ -91,7 +91,7 @@ public class DefaultSessionManagementService : ISessionManagementService SubjectId = context.SubjectId, SessionId = context.SessionId, }, - cancellationToken); + ct); foreach (var session in sessions) { @@ -113,7 +113,7 @@ public class DefaultSessionManagementService : ISessionManagementService { SubjectId = context.SubjectId, SessionId = context.SessionId, - }, cancellationToken); + }, ct); } } } diff --git a/identity-server/src/IdentityServer/Services/DiagnosticDataService.cs b/identity-server/src/IdentityServer/Services/DiagnosticDataService.cs index 1baaaef1d..590e4725f 100644 --- a/identity-server/src/IdentityServer/Services/DiagnosticDataService.cs +++ b/identity-server/src/IdentityServer/Services/DiagnosticDataService.cs @@ -22,7 +22,7 @@ public class DiagnosticDataService _entries = entries; } - public async Task> GetJsonBytesAsync(CancellationToken cancellationToken = default) + public async Task> GetJsonBytesAsync(CT ct = default) { var bufferWriter = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(bufferWriter, new JsonWriterOptions { Indented = false }); @@ -37,14 +37,14 @@ public class DiagnosticDataService writer.WriteEndObject(); - await writer.FlushAsync(cancellationToken); + await writer.FlushAsync(ct); return bufferWriter.WrittenMemory; } - public async Task GetJsonStringAsync(CancellationToken cancellationToken = default) + public async Task GetJsonStringAsync(CT ct = default) { - var bytes = await GetJsonBytesAsync(cancellationToken); + var bytes = await GetJsonBytesAsync(ct); return Encoding.UTF8.GetString(bytes.Span); } } diff --git a/identity-server/src/IdentityServer/Services/ISessionManagementService.cs b/identity-server/src/IdentityServer/Services/ISessionManagementService.cs index 82075d173..92484cce6 100644 --- a/identity-server/src/IdentityServer/Services/ISessionManagementService.cs +++ b/identity-server/src/IdentityServer/Services/ISessionManagementService.cs @@ -17,12 +17,12 @@ public interface ISessionManagementService /// /// Queries all the session related data for a user. /// - Task> QuerySessionsAsync(SessionQuery? filter = null, CancellationToken cancellationToken = default); + Task> QuerySessionsAsync(SessionQuery? filter = null, CT ct = default); /// /// Removes all the session related data for a user. /// - Task RemoveSessionsAsync(RemoveSessionsContext context, CancellationToken cancellationToken = default); + Task RemoveSessionsAsync(RemoveSessionsContext context, CT ct = default); } /// diff --git a/identity-server/src/IdentityServer/Stores/Default/ServerSideTicketStore.cs b/identity-server/src/IdentityServer/Stores/Default/ServerSideTicketStore.cs index b19e7ad69..115bb27cb 100644 --- a/identity-server/src/IdentityServer/Stores/Default/ServerSideTicketStore.cs +++ b/identity-server/src/IdentityServer/Stores/Default/ServerSideTicketStore.cs @@ -185,22 +185,22 @@ public class ServerSideTicketStore : IServerSideTicketStore } /// - public async Task> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default) + public async Task> GetSessionsAsync(SessionFilter filter, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideTicketStore.GetSessions"); - var sessions = await _store.GetSessionsAsync(filter, cancellationToken); + var sessions = await _store.GetSessionsAsync(filter, ct); return AsUserSessions(sessions); } /// - public async Task> QuerySessionsAsync(SessionQuery filter = null, CancellationToken cancellationToken = default) + public async Task> QuerySessionsAsync(SessionQuery filter = null, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideTicketStore.QuerySessions"); - var results = await _store.QuerySessionsAsync(filter, cancellationToken); + var results = await _store.QuerySessionsAsync(filter, ct); var tickets = AsUserSessions(results.Results); @@ -219,11 +219,11 @@ public class ServerSideTicketStore : IServerSideTicketStore } /// - public async Task> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default) + public async Task> GetAndRemoveExpiredSessionsAsync(int count, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("ServerSideTicketStore.GetAndRemoveExpiredSessions"); - var sessions = await _store.GetAndRemoveExpiredSessionsAsync(count, cancellationToken); + var sessions = await _store.GetAndRemoveExpiredSessionsAsync(count, ct); return AsUserSessions(sessions); } diff --git a/identity-server/src/IdentityServer/Stores/IServerSideTicketStore.cs b/identity-server/src/IdentityServer/Stores/IServerSideTicketStore.cs index b402729d2..dc5b1982f 100644 --- a/identity-server/src/IdentityServer/Stores/IServerSideTicketStore.cs +++ b/identity-server/src/IdentityServer/Stores/IServerSideTicketStore.cs @@ -17,15 +17,15 @@ public interface IServerSideTicketStore : ITicketStore /// /// Gets sessions for a specific subject id and/or session id /// - Task> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default); + Task> GetSessionsAsync(SessionFilter filter, CT ct = default); /// /// Queries user sessions based on filter /// - Task> QuerySessionsAsync(SessionQuery filter, CancellationToken cancellationToken = default); + Task> QuerySessionsAsync(SessionQuery filter, CT ct = default); /// /// Removes and returns expired sessions /// - Task> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default); + Task> GetAndRemoveExpiredSessionsAsync(int count, CT ct = default); } diff --git a/identity-server/src/IdentityServer/Stores/InMemory/InMemoryServerSideSessionStore.cs b/identity-server/src/IdentityServer/Stores/InMemory/InMemoryServerSideSessionStore.cs index 8af79ec96..f5bd14def 100644 --- a/identity-server/src/IdentityServer/Stores/InMemory/InMemoryServerSideSessionStore.cs +++ b/identity-server/src/IdentityServer/Stores/InMemory/InMemoryServerSideSessionStore.cs @@ -18,7 +18,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore /// - public Task CreateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default) + public Task CreateSessionAsync(ServerSideSession session, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.CreateSession"); @@ -30,7 +30,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore } /// - public Task GetSessionAsync(string key, CancellationToken cancellationToken = default) + public Task GetSessionAsync(string key, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.GetSession"); @@ -39,7 +39,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore } /// - public Task UpdateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default) + public Task UpdateSessionAsync(ServerSideSession session, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.UpdateSession"); @@ -48,7 +48,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore } /// - public Task DeleteSessionAsync(string key, CancellationToken cancellationToken = default) + public Task DeleteSessionAsync(string key, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.DeleteSession"); @@ -59,7 +59,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore /// - public Task> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default) + public Task> GetSessionsAsync(SessionFilter filter, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.GetSessions"); @@ -80,7 +80,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore } /// - public Task DeleteSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default) + public Task DeleteSessionsAsync(SessionFilter filter, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.DeleteSessions"); @@ -108,7 +108,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore /// - public Task> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default) + public Task> GetAndRemoveExpiredSessionsAsync(int count, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.GetAndRemoveExpiredSession"); @@ -129,7 +129,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore /// - public Task> QuerySessionsAsync(SessionQuery filter = null, CancellationToken cancellationToken = default) + public Task> QuerySessionsAsync(SessionQuery filter = null, CT ct = default) { using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.QuerySessions"); @@ -219,7 +219,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore // we need to start over and re-query from the beginning. filter.ResultsToken = null; filter.RequestPriorResults = false; - return QuerySessionsAsync(filter, cancellationToken); + return QuerySessionsAsync(filter, ct); } } else diff --git a/identity-server/src/Storage/Services/ICancellationTokenProvider.cs b/identity-server/src/Storage/Services/ICancellationTokenProvider.cs index b0a60531c..adcbd3166 100644 --- a/identity-server/src/Storage/Services/ICancellationTokenProvider.cs +++ b/identity-server/src/Storage/Services/ICancellationTokenProvider.cs @@ -14,5 +14,5 @@ public interface ICancellationTokenProvider /// /// Returns the current CancellationToken, or null if none present. /// - CancellationToken CancellationToken { get; } + CT CancellationToken { get; } } diff --git a/identity-server/src/Storage/Services/NoneCancellationTokenProvider.cs b/identity-server/src/Storage/Services/NoneCancellationTokenProvider.cs index f99ae0ad2..db480ae91 100644 --- a/identity-server/src/Storage/Services/NoneCancellationTokenProvider.cs +++ b/identity-server/src/Storage/Services/NoneCancellationTokenProvider.cs @@ -10,5 +10,5 @@ namespace Duende.IdentityServer.Services; public class NoneCancellationTokenProvider : ICancellationTokenProvider { /// - public CancellationToken CancellationToken => CancellationToken.None; + public CT CancellationToken => CT.None; } diff --git a/identity-server/src/Storage/Stores/IServerSideSessionStore.cs b/identity-server/src/Storage/Stores/IServerSideSessionStore.cs index 7a12f1436..771310af9 100644 --- a/identity-server/src/Storage/Stores/IServerSideSessionStore.cs +++ b/identity-server/src/Storage/Stores/IServerSideSessionStore.cs @@ -16,43 +16,43 @@ public interface IServerSideSessionStore /// /// Retrieves a session /// - Task GetSessionAsync(string key, CancellationToken cancellationToken = default); + Task GetSessionAsync(string key, CT ct = default); /// /// Creates a session /// - Task CreateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default); + Task CreateSessionAsync(ServerSideSession session, CT ct = default); /// /// Updates a session /// - Task UpdateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default); + Task UpdateSessionAsync(ServerSideSession session, CT ct = default); /// /// Deletes a session /// - Task DeleteSessionAsync(string key, CancellationToken cancellationToken = default); + Task DeleteSessionAsync(string key, CT ct = default); /// /// Gets sessions for a specific subject id and/or session id /// - Task> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default); + Task> GetSessionsAsync(SessionFilter filter, CT ct = default); /// /// Deletes sessions for a specific subject id and/or session id /// - Task DeleteSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default); + Task DeleteSessionsAsync(SessionFilter filter, CT ct = default); /// /// Removes and returns expired sessions /// - Task> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default); + Task> GetAndRemoveExpiredSessionsAsync(int count, CT ct = default); /// /// Queries sessions based on filter /// - Task> QuerySessionsAsync(SessionQuery? filter = null, CancellationToken cancellationToken = default); + Task> QuerySessionsAsync(SessionQuery? filter = null, CT ct = default); } diff --git a/identity-server/test/IdentityServer.IntegrationTests/Common/BrowserHandler.cs b/identity-server/test/IdentityServer.IntegrationTests/Common/BrowserHandler.cs index 9df939f5d..eb0611fa3 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/Common/BrowserHandler.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/Common/BrowserHandler.cs @@ -22,9 +22,9 @@ public class BrowserHandler : DelegatingHandler { } - protected async override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected async override Task SendAsync(HttpRequestMessage request, CT ct) { - var response = await SendCookiesAsync(request, cancellationToken); + var response = await SendCookiesAsync(request, ct); var redirectCount = 0; @@ -45,7 +45,7 @@ public class BrowserHandler : DelegatingHandler request = new HttpRequestMessage(HttpMethod.Get, location); - response = await SendCookiesAsync(request, cancellationToken).ConfigureAwait(false); + response = await SendCookiesAsync(request, ct).ConfigureAwait(false); redirectCount++; } @@ -64,7 +64,7 @@ public class BrowserHandler : DelegatingHandler } } - protected async Task SendCookiesAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected async Task SendCookiesAsync(HttpRequestMessage request, CT ct) { if (AllowCookies) { @@ -75,7 +75,7 @@ public class BrowserHandler : DelegatingHandler } } - var response = await base.SendAsync(request, cancellationToken); + var response = await base.SendAsync(request, ct); if (AllowCookies && response.Headers.Contains("Set-Cookie")) { diff --git a/identity-server/test/IdentityServer.IntegrationTests/Common/IdentityServerPipeline.cs b/identity-server/test/IdentityServer.IntegrationTests/Common/IdentityServerPipeline.cs index cdba9cef4..ea71ba6cc 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/Common/IdentityServerPipeline.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/Common/IdentityServerPipeline.cs @@ -602,7 +602,7 @@ public class MockMessageHandler : DelegatingHandler public Func OnInvoke { get; set; } public HttpResponseMessage Response { get; set; } = new HttpResponseMessage(HttpStatusCode.OK); - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync(HttpRequestMessage request, CT ct) { InvokeWasCalled = true; diff --git a/identity-server/test/IdentityServer.IntegrationTests/Common/MessageHandlerWrapper.cs b/identity-server/test/IdentityServer.IntegrationTests/Common/MessageHandlerWrapper.cs index 0cdc7493d..bb2df1fd8 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/Common/MessageHandlerWrapper.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/Common/MessageHandlerWrapper.cs @@ -13,9 +13,9 @@ public class MessageHandlerWrapper : DelegatingHandler { } - protected async override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected async override Task SendAsync(HttpRequestMessage request, CT ct) { - Response = await base.SendAsync(request, cancellationToken); + Response = await base.SendAsync(request, ct); return Response; } } diff --git a/identity-server/test/IdentityServer.IntegrationTests/Common/MtlsMessageHandler.cs b/identity-server/test/IdentityServer.IntegrationTests/Common/MtlsMessageHandler.cs index 4379be4f6..3cf03e47e 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/Common/MtlsMessageHandler.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/Common/MtlsMessageHandler.cs @@ -16,7 +16,7 @@ public class MtlsMessageHandler : DelegatingHandler public MtlsMessageHandler(HttpMessageHandler innerHandler, X509Certificate2 clientCertificate) : base(innerHandler) => _clientCertificate = clientCertificate; - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync(HttpRequestMessage request, CT ct) { // Add the client certificate as a base64 encoded header for the test middleware to pick up if (_clientCertificate != null) @@ -26,6 +26,6 @@ public class MtlsMessageHandler : DelegatingHandler request.Headers.Add("X-Test-Client-Certificate", certBase64); } - return await base.SendAsync(request, cancellationToken); + return await base.SendAsync(request, ct); } } diff --git a/identity-server/test/IdentityServer.IntegrationTests/Common/MtlsTestMiddleware.cs b/identity-server/test/IdentityServer.IntegrationTests/Common/MtlsTestMiddleware.cs index 584a30dcf..c42a94fd2 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/Common/MtlsTestMiddleware.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/Common/MtlsTestMiddleware.cs @@ -71,6 +71,6 @@ public class TlsConnectionFeature : ITlsConnectionFeature { public X509Certificate2 ClientCertificate { get; set; } - public Task GetClientCertificateAsync(CancellationToken cancellationToken) + public Task GetClientCertificateAsync(CT ct) => Task.FromResult(ClientCertificate); } diff --git a/identity-server/test/IdentityServer.IntegrationTests/Common/NetworkHandler.cs b/identity-server/test/IdentityServer.IntegrationTests/Common/NetworkHandler.cs index 12846e013..54765cb85 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/Common/NetworkHandler.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/Common/NetworkHandler.cs @@ -56,7 +56,7 @@ public class NetworkHandler : HttpMessageHandler public NetworkHandler(Func action) => _action = action; - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync(HttpRequestMessage request, CT ct) { Request = request; Body = await SafeReadContentFrom(request); diff --git a/identity-server/test/IdentityServer.IntegrationTests/EntityFramework/NetworkDelaySimulationInterceptor.cs b/identity-server/test/IdentityServer.IntegrationTests/EntityFramework/NetworkDelaySimulationInterceptor.cs index c417cd2be..91418b041 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/EntityFramework/NetworkDelaySimulationInterceptor.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/EntityFramework/NetworkDelaySimulationInterceptor.cs @@ -12,9 +12,9 @@ public class NetworkDelaySimulationInterceptor(TimeSpan delay) : DbCommandInterc DbCommand command, CommandEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default) + CT ct = default) { - await Task.Delay(delay, cancellationToken); + await Task.Delay(delay, ct); return result; } diff --git a/identity-server/test/IdentityServer.IntegrationTests/EntityFramework/Storage/MockOperationalStoreNotification.cs b/identity-server/test/IdentityServer.IntegrationTests/EntityFramework/Storage/MockOperationalStoreNotification.cs index 14a34c9ca..b9bd35bd3 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/EntityFramework/Storage/MockOperationalStoreNotification.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/EntityFramework/Storage/MockOperationalStoreNotification.cs @@ -15,14 +15,14 @@ public class MockOperationalStoreNotification : IOperationalStoreNotification public Action> OnPersistedGrantsRemoved = _ => { }; public Action> OnDeviceFlowCodesRemoved = _ => { }; - public Task PersistedGrantsRemovedAsync(IEnumerable persistedGrants, CancellationToken cancellationToken = default) + public Task PersistedGrantsRemovedAsync(IEnumerable persistedGrants, CT ct = default) { OnPersistedGrantsRemoved(persistedGrants); PersistedGrantNotifications.Add(persistedGrants); return Task.CompletedTask; } - public Task DeviceCodesRemovedAsync(IEnumerable deviceCodes, CancellationToken cancellationToken = default) + public Task DeviceCodesRemovedAsync(IEnumerable deviceCodes, CT ct = default) { OnDeviceFlowCodesRemoved(deviceCodes); DeviceFlowCodeNotifications.Append(deviceCodes); diff --git a/identity-server/test/IdentityServer.IntegrationTests/TestFramework/TestBrowserClient.cs b/identity-server/test/IdentityServer.IntegrationTests/TestFramework/TestBrowserClient.cs index 4c86409b8..61bfda2a0 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/TestFramework/TestBrowserClient.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/TestFramework/TestBrowserClient.cs @@ -23,7 +23,7 @@ public class TestBrowserClient : HttpClient { } - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync(HttpRequestMessage request, CT ct) { CurrentUri = request.RequestUri; var cookieHeader = CookieContainer.GetCookieHeader(request.RequestUri); @@ -32,7 +32,7 @@ public class TestBrowserClient : HttpClient request.Headers.Add("Cookie", cookieHeader); } - var response = await base.SendAsync(request, cancellationToken); + var response = await base.SendAsync(request, ct); if (response.Headers.Contains("Set-Cookie")) { diff --git a/identity-server/test/IdentityServer.UnitTests/Common/NetworkHandler.cs b/identity-server/test/IdentityServer.UnitTests/Common/NetworkHandler.cs index 77ed91185..c2997657e 100644 --- a/identity-server/test/IdentityServer.UnitTests/Common/NetworkHandler.cs +++ b/identity-server/test/IdentityServer.UnitTests/Common/NetworkHandler.cs @@ -56,7 +56,7 @@ public class NetworkHandler : HttpMessageHandler public NetworkHandler(Func action) => _action = action; - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync(HttpRequestMessage request, CT ct) { Request = request; Body = await SafeReadContentFrom(request);