Apply CT alias and ct param rename across all remaining source files

This commit is contained in:
Damian Hickey 2026-02-20 11:53:02 +01:00
parent 7f04aba927
commit 1124e9df55
76 changed files with 240 additions and 240 deletions

View file

@ -70,7 +70,7 @@ internal class DPoPProofValidator : IDPoPProofValidator
/// <summary>
/// Validates the DPoP proof.
/// </summary>
public async Task<DPoPProofValidationResult> Validate(DPoPProofValidationContext context, CancellationToken cancellationToken = default)
public async Task<DPoPProofValidationResult> 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);
}
/// <summary>

View file

@ -11,5 +11,5 @@ public interface IDPoPProofValidator
/// <summary>
/// Validates the DPoP proof.
/// </summary>
Task<DPoPProofValidationResult> Validate(DPoPProofValidationContext context, CancellationToken cancellationToken = default);
Task<DPoPProofValidationResult> Validate(DPoPProofValidationContext context, CT ct = default);
}

View file

@ -11,11 +11,11 @@ public interface IReplayCache
/// <summary>
/// Adds a hashed jti to the cache.
/// </summary>
Task Add(string jtiHash, TimeSpan expiration, CancellationToken cancellationToken = default);
Task Add(string jtiHash, TimeSpan expiration, CT ct = default);
/// <summary>
/// Checks if a cached jti hash exists in the hash.
/// </summary>
Task<bool> Exists(string jtiHash, CancellationToken cancellationToken = default);
Task<bool> Exists(string jtiHash, CT ct = default);
}

View file

@ -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<bool> Exists(string handle, CancellationToken ct)
public async Task<bool> Exists(string handle, CT ct)
{
using var activity = Tracing.ActivitySource.StartActivity("ReplayCache.Exists");

View file

@ -15,7 +15,7 @@ public class TestBrowserClient : HttpClient
public HttpResponseMessage LastResponse { get; private set; } = default!;
protected override async Task<HttpResponseMessage> 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"))
{

View file

@ -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<T> GetOrCreateAsync<TState, T>(string key, TState state, Func<TState, CancellationToken, ValueTask<T>> factory, HybridCacheEntryOptions? options = null,
IEnumerable<string>? tags = null, CancellationToken cancellationToken = new())
public override async ValueTask<T> GetOrCreateAsync<TState, T>(string key, TState state, Func<TState, CT, ValueTask<T>> factory, HybridCacheEntryOptions? options = null,
IEnumerable<string>? tags = null, CT ct = new())
{
_getOrCreateAsyncCalls.Add((key, options));
@ -25,16 +25,16 @@ internal class TestHybridCache : HybridCache
}
public override ValueTask SetAsync<T>(string key, T value, HybridCacheEntryOptions? options = null, IEnumerable<string>? 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;

View file

@ -14,14 +14,14 @@ public class TestReplayCache : IReplayCache
// Configuration for test behavior
public Func<string, bool>? 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<bool> Exists(string jtiHash, CancellationToken cancellationToken = default)
public Task<bool> Exists(string jtiHash, CT ct = default)
{
_existsCalls.Add(jtiHash);

View file

@ -9,7 +9,7 @@ namespace Bff;
public class ImpersonationAccessTokenRetriever(IAccessTokenRetriever inner) : IAccessTokenRetriever
{
public async Task<AccessTokenResult> GetAccessTokenAsync(AccessTokenRetrievalContext context, CancellationToken ct = default)
public async Task<AccessTokenResult> GetAccessTokenAsync(AccessTokenRetrievalContext context, CT ct = default)
{
var result = await inner.GetAccessTokenAsync(context, ct);

View file

@ -9,7 +9,7 @@ namespace Bff;
public class ImpersonationAccessTokenRetriever(IAccessTokenRetriever inner) : IAccessTokenRetriever
{
public async Task<AccessTokenResult> GetAccessTokenAsync(AccessTokenRetrievalContext context, CancellationToken ct = default)
public async Task<AccessTokenResult> GetAccessTokenAsync(AccessTokenRetrievalContext context, CT ct = default)
{
var result = await inner.GetAccessTokenAsync(context, ct);

View file

@ -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<string?> Transform(string indexHtml, BffFrontend frontend, CancellationToken ct = default)
public Task<string?> 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

View file

@ -9,7 +9,7 @@ public class ApiHostedService(IOptions<ApiSettings> 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();

View file

@ -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])

View file

@ -17,7 +17,7 @@ public class IdentityServerService(IOptions<IdentityServerSettings> 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();

View file

@ -8,12 +8,12 @@ namespace Bff.Performance.TestInfra;
public class AutoFollowRedirectHandler(Action<string> writeOutput) : DelegatingHandler
{
protected override async Task<HttpResponseMessage> 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}");

View file

@ -9,13 +9,13 @@ public class CloningHttpMessageHandler(HttpClient innerHttpClient) : HttpMessage
innerHttpClient ?? throw new ArgumentNullException(nameof(innerHttpClient));
protected override async Task<HttpResponseMessage> 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);

View file

@ -12,17 +12,17 @@ public class RequestLoggingHandler(
: DelegatingHandler
{
protected override async Task<HttpResponseMessage> 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,

View file

@ -32,7 +32,7 @@ internal class ServerSideTokenStore(
?? throw new ArgumentException("AuthenticationStateProvider must implement IHostEnvironmentAuthenticationStateProvider");
public async Task<TokenResult<TokenForParameters>> GetTokenAsync(ClaimsPrincipal user, UserTokenRequestParameters? parameters = null,
CancellationToken ct = default)
CT ct = default)
{
logger.RetrievingTokenForUser(LogLevel.Debug, user.Identity?.Name);
var session = await GetSession(user);

View file

@ -68,7 +68,7 @@ internal class RemoteRouteHandler : IDisposable
public void ClearTransformerCacheFor(BffFrontend frontend) => _cache.TryRemove(frontend.Name, out _);
public async Task<bool> HandleAsync(HttpContext context, CancellationToken ct)
public async Task<bool> HandleAsync(HttpContext context, CT ct)
{
if (!_currentFrontendAccessor.TryGet(out var frontend))
{

View file

@ -8,7 +8,7 @@ namespace Duende.Bff.Diagnostics;
internal class DiagnosticDataService(DateTime serverStartTime, IEnumerable<IDiagnosticEntry> entries)
{
public async Task<ReadOnlyMemory<byte>> GetJsonBytesAsync(CancellationToken cancellationToken = default)
public async Task<ReadOnlyMemory<byte>> GetJsonBytesAsync(CT ct = default)
{
var bufferWriter = new ArrayBufferWriter<byte>();
await using var writer = new Utf8JsonWriter(bufferWriter, new JsonWriterOptions { Indented = false });
@ -23,7 +23,7 @@ internal class DiagnosticDataService(DateTime serverStartTime, IEnumerable<IDiag
writer.WriteEndObject();
await writer.FlushAsync(cancellationToken);
await writer.FlushAsync(ct);
return bufferWriter.WrittenMemory;
}

View file

@ -14,7 +14,7 @@ internal class DiagnosticHostedService(
ILogger<DiagnosticHostedService> 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);
}
}

View file

@ -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;

View file

@ -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;

View file

@ -21,7 +21,7 @@ internal class DefaultSilentLoginCallbackEndpoint(
{
/// <inheritdoc />
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)

View file

@ -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)

View file

@ -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;
/// <inheritdoc />
public async Task<string> StoreAsync(AuthenticationTicket ticket)

View file

@ -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();

View file

@ -143,7 +143,7 @@ public class BffRemoteApiTests : BffTestBase
public bool WasCalled = false;
public Task<TokenResult<UserToken>> 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]

View file

@ -47,7 +47,7 @@ public class BffScenarioTests : BffTestBase
TaskCompletionSource<string> contentReceived,
TaskCompletionSource workerIsAllowedToStart) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
protected override async Task ExecuteAsync(CT stoppingToken)
{
await workerIsAllowedToStart.Task;

View file

@ -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"));
}

View file

@ -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;

View file

@ -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<Scheme> GetSchemeAsync(UserTokenRequestParameters? parameters = null,
CancellationToken ct = new CancellationToken()) =>
CT ct = new CT()) =>
Task.FromResult(Scheme.Bearer);
}

View file

@ -10,19 +10,19 @@ internal class TestHybridCache : HybridCache
{
private ConcurrentDictionary<string, ValueTask<object>> _cache = new();
public override async ValueTask<T> GetOrCreateAsync<TState, T>(string key, TState state,
Func<TState, CancellationToken, ValueTask<T>> factory, HybridCacheEntryOptions? options = null,
IEnumerable<string>? tags = null, CancellationToken cancellationToken = new CancellationToken()) => (T)await _cache.GetOrAdd(key, async _ => (await factory(state, cancellationToken))!);
Func<TState, CT, ValueTask<T>> factory, HybridCacheEntryOptions? options = null,
IEnumerable<string>? tags = null, CT ct = new CT()) => (T)await _cache.GetOrAdd(key, async _ => (await factory(state, ct))!);
public override ValueTask SetAsync<T>(string key, T value, HybridCacheEntryOptions? options = null,
IEnumerable<string>? tags = null,
CancellationToken cancellationToken = new CancellationToken())
CT ct = new CT())
{
_cache[key] = new ValueTask<object>(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();

View file

@ -11,7 +11,7 @@ public class TestTokenRetriever : IAccessTokenRetriever
public AccessTokenRetrievalContext? UsedContext { get; set; }
public Task<AccessTokenResult> GetAccessTokenAsync(AccessTokenRetrievalContext context,
CancellationToken ct = default)
CT ct = default)
{
UsedContext = context;
return Task.FromResult<AccessTokenResult>(new NoAccessTokenResult());

View file

@ -41,7 +41,7 @@ internal sealed partial class ConformanceReportEndpoint
/// <summary>
/// Processes requests for the HTML conformance report.
/// </summary>
public async Task<IResult> GetHtmlReportAsync(HttpContext context, CancellationToken cancellationToken = default)
public async Task<IResult> 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();

View file

@ -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")

View file

@ -5,5 +5,5 @@ namespace Duende.ConformanceReport;
internal interface IConformanceReportClientStore
{
Task<IEnumerable<ConformanceReportClient>> GetAllClientsAsync(CancellationToken ct = default);
Task<IEnumerable<ConformanceReportClient>> GetAllClientsAsync(CT ct = default);
}

View file

@ -42,11 +42,11 @@ internal class ConformanceReportAssessmentService
/// <summary>
/// Generates a complete conformance assessment report.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="ct">The cancellation token.</param>
/// <returns>A conformance report containing the assessment results.</returns>
public async Task<ConformanceReportResult> GenerateReportAsync(CancellationToken cancellationToken = default)
public async Task<ConformanceReportResult> 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.
/// </summary>
/// <param name="profile">The profile to assess.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="ct">The cancellation token.</param>
/// <returns>A profile result containing the assessment findings.</returns>
public async Task<ProfileResult> 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

View file

@ -45,7 +45,7 @@ public class SystemBrowser : IBrowser
return port;
}
public async Task<BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
public async Task<BrowserResult> InvokeAsync(BrowserOptions options, CT ct = default)
{
using (var listener = new LoopbackHttpListener(Port, _path))
{

View file

@ -37,7 +37,7 @@ public class SystemBrowser : IBrowser
return port;
}
public async Task<BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
public async Task<BrowserResult> InvokeAsync(BrowserOptions options, CT ct = default)
{
using (var listener = new LoopbackHttpListener(Port, _path))
{

View file

@ -8,9 +8,9 @@ public class TestHandler : DelegatingHandler
private readonly ILogger<TestHandler> _logger;
public TestHandler(ILogger<TestHandler> logger) => _logger = logger;
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected override async Task<HttpResponseMessage> 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)

View file

@ -10,7 +10,7 @@ namespace MvcJarJwt;
public class ClientAssertionService(AssertionService assertionService) : IClientAssertionService
{
public Task<ClientAssertion> GetClientAssertionAsync(ClientCredentialsClientName? clientName = null, TokenRequestParameters parameters = null,
CancellationToken ct = new())
CT ct = new())
{
var assertion = new ClientAssertion
{

View file

@ -11,7 +11,7 @@ public class ClientAssertionService(AssertionService assertionService) : IClient
{
public Task<ClientAssertion> GetClientAssertionAsync(ClientCredentialsClientName? clientName = null,
TokenRequestParameters parameters = null,
CancellationToken ct = new())
CT ct = new())
{
var assertion = new ClientAssertion
{

View file

@ -10,7 +10,7 @@ namespace Web;
public class ClientAssertionService(AssertionService assertionService) : IClientAssertionService
{
public Task<ClientAssertion?> GetClientAssertionAsync(ClientCredentialsClientName? clientName = null, TokenRequestParameters? parameters = null,
CancellationToken ct = new CancellationToken())
CT ct = new CT())
{
var assertion = new ClientAssertion
{

View file

@ -26,9 +26,9 @@ internal class CallbackManager
}
}
public async Task<string> RunServer(CancellationToken? token = null)
public async Task<string> RunServer(CT? token = null)
{
token = CancellationToken.None;
token = CT.None;
await using var server = new NamedPipeServerStream(_name, PipeDirection.In);
await server.WaitForConnectionAsync(token.Value);

View file

@ -12,7 +12,7 @@ public class TestOperationalStoreNotification : IOperationalStoreNotification
{
public TestOperationalStoreNotification() => Console.WriteLine("ctor");
public Task PersistedGrantsRemovedAsync(IEnumerable<PersistedGrant> persistedGrants, CancellationToken cancellationToken = default)
public Task PersistedGrantsRemovedAsync(IEnumerable<PersistedGrant> 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<DeviceFlowCodes> deviceCodes, CancellationToken cancellationToken = default)
public Task DeviceCodesRemovedAsync(IEnumerable<DeviceFlowCodes> 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<ServerSideSession> userSessions, CancellationToken cancellationToken = default)
public Task ServerSideSessionsRemovedAsync(IEnumerable<ServerSideSession> userSessions, CT ct = default)
{
ArgumentNullException.ThrowIfNull(userSessions);
foreach (var session in userSessions)

View file

@ -18,7 +18,7 @@ public class DiscoveryHealthCheck : IHealthCheck
_httpContextAccessor = httpContextAccessor;
}
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CT ct = default)
{
ArgumentNullException.ThrowIfNull(context);
try
@ -55,7 +55,7 @@ public class DiscoveryKeysHealthCheck : IHealthCheck
_httpContextAccessor = httpContextAccessor;
}
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CT ct = default)
{
ArgumentNullException.ThrowIfNull(context);
try

View file

@ -18,7 +18,7 @@ public static class DbContextExtensions
/// <summary>
/// Saves changes and handles concurrency exceptions.
/// </summary>
public static async Task<ICollection<T>> SaveChangesWithConcurrencyCheckAsync<T>(this IPersistedGrantDbContext context, ILogger logger, CancellationToken cancellationToken = default)
public static async Task<ICollection<T>> SaveChangesWithConcurrencyCheckAsync<T>(this IPersistedGrantDbContext context, ILogger logger, CT ct = default)
where T : class
{
var list = new List<T>();
@ -29,7 +29,7 @@ public static class DbContextExtensions
{
try
{
await context.SaveChangesAsync(cancellationToken);
await context.SaveChangesAsync(ct);
return list;
}
catch (DbUpdateConcurrencyException ex)

View file

@ -67,7 +67,7 @@ public interface IConfigurationDbContext : IDisposable
/// Saves the changes.
/// </summary>
/// <returns></returns>
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
Task<int> 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.
/// </summary>
/// <returns></returns>
Task<int> SaveChangesAsync() => SaveChangesAsync(CancellationToken.None);
Task<int> SaveChangesAsync() => SaveChangesAsync(CT.None);
}

View file

@ -59,7 +59,7 @@ public interface IPersistedGrantDbContext : IDisposable
/// Saves the changes.
/// </summary>
/// <returns></returns>
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
Task<int> 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.
/// </summary>
/// <returns></returns>
Task<int> SaveChangesAsync() => SaveChangesAsync(CancellationToken.None);
Task<int> SaveChangesAsync() => SaveChangesAsync(CT.None);
}

View file

@ -50,11 +50,11 @@ public class ServerSideSessionStore : IServerSideSessionStore
/// <inheritdoc/>
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
}
/// <inheritdoc/>
public virtual async Task<ServerSideSession> GetSessionAsync(string key, CancellationToken cancellationToken = default)
public virtual async Task<ServerSideSession> 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
}
/// <inheritdoc/>
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
}
/// <inheritdoc/>
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
/// <inheritdoc/>
public virtual async Task<IReadOnlyCollection<ServerSideSession>> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default)
public virtual async Task<IReadOnlyCollection<ServerSideSession>> 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
}
/// <inheritdoc/>
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
/// <inheritdoc/>
public virtual async Task<IReadOnlyCollection<ServerSideSession>> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default)
public virtual async Task<IReadOnlyCollection<ServerSideSession>> 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<Entities.ServerSideSession>(Logger, cancellationToken);
var list = await Context.SaveChangesWithConcurrencyCheckAsync<Entities.ServerSideSession>(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
}
/// <inheritdoc/>
public virtual async Task<QueryResult<ServerSideSession>> QuerySessionsAsync(SessionQuery filter = null, CancellationToken cancellationToken = default)
public virtual async Task<QueryResult<ServerSideSession>> 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<Entities.ServerSideSession> query, int last, SessionPaginationContext pagination, CancellationToken cancellationToken)
private static async Task NextPage(IQueryable<Entities.ServerSideSession> 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<Entities.ServerSideSession> query, int first, SessionPaginationContext pagination, CancellationToken cancellationToken)
private static async Task PreviousPage(IQueryable<Entities.ServerSideSession> 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);
}

View file

@ -17,15 +17,15 @@ public interface IOperationalStoreNotification
/// Notification for persisted grants being removed.
/// </summary>
/// <param name="persistedGrants"></param>
/// <param name="cancellationToken"></param>
/// <param name="ct"></param>
/// <returns></returns>
Task PersistedGrantsRemovedAsync(IEnumerable<PersistedGrant> persistedGrants, CancellationToken cancellationToken = default);
Task PersistedGrantsRemovedAsync(IEnumerable<PersistedGrant> persistedGrants, CT ct = default);
/// <summary>
/// Notification for device codes being removed.
/// </summary>
/// <param name="deviceCodes"></param>
/// <param name="cancellationToken"></param>
/// <param name="ct"></param>
/// <returns></returns>
Task DeviceCodesRemovedAsync(IEnumerable<DeviceFlowCodes> deviceCodes, CancellationToken cancellationToken = default);
Task DeviceCodesRemovedAsync(IEnumerable<DeviceFlowCodes> deviceCodes, CT ct = default);
}

View file

@ -16,8 +16,8 @@ public interface ITokenCleanupService
/// Removes expired persisted grants, expired device codes, and optionally
/// consumed persisted grants from the stores.
/// </summary>
/// <param name="cancellationToken">A token that propagates notification
/// <param name="ct">A token that propagates notification
/// that the cleanup operation should be canceled.</param>
/// <returns></returns>
Task CleanupGrantsAsync(CancellationToken cancellationToken = default);
Task CleanupGrantsAsync(CT ct = default);
}

View file

@ -43,15 +43,15 @@ public class TokenCleanupService : ITokenCleanupService
}
/// <inheritdoc/>
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.
/// </summary>
/// <returns></returns>
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.
/// </summary>
/// <returns></returns>
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.
/// </summary>
/// <returns></returns>
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.
/// </summary>
/// <returns></returns>
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
/// <summary>
/// Removes stale pushed authorization requests.
/// </summary>
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)
{

View file

@ -38,7 +38,7 @@ public class TokenCleanupHost : IHostedService
/// <summary>
/// Starts the token cleanup polling.
/// </summary>
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
/// <summary>
/// Stops the token cleanup polling.
/// </summary>
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<IServiceScopeFactory>().CreateAsyncScope())
{
var tokenCleanupService = serviceScope.ServiceProvider.GetRequiredService<ITokenCleanupService>();
await tokenCleanupService.CleanupGrantsAsync(cancellationToken);
await tokenCleanupService.CleanupGrantsAsync(ct);
}
}
catch (Exception ex)

View file

@ -19,13 +19,13 @@ public class ServerSideSessionCleanupHost(
ILogger<ServerSideSessionCleanupHost> logger) : BackgroundService
{
/// <inheritdoc />
public override Task StartAsync(CancellationToken cancellationToken) =>
public override Task StartAsync(CT ct) =>
!options.ServerSideSessions.RemoveExpiredSessions
? Task.CompletedTask
: base.StartAsync(cancellationToken);
: base.StartAsync(ct);
/// <inheritdoc />
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)

View file

@ -10,7 +10,7 @@ namespace Duende.IdentityServer.Licensing.V2.Diagnostics;
internal class DiagnosticHostedService(DiagnosticSummary diagnosticSummary, IOptions<IdentityServerOptions> options, ILogger<DiagnosticHostedService> 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);
}
}

View file

@ -22,5 +22,5 @@ internal class DefaultCancellationTokenProvider : ICancellationTokenProvider
/// <summary>
/// Provides access to the cancellation token from the http context
/// </summary>
public CancellationToken CancellationToken => _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None;
public CT CancellationToken => _httpContextAccessor.HttpContext?.RequestAborted ?? CT.None;
}

View file

@ -33,11 +33,11 @@ public class DefaultSessionManagementService : ISessionManagementService
}
/// <inheritdoc/>
public Task<QueryResult<UserSession>> QuerySessionsAsync(SessionQuery filter = null, CancellationToken cancellationToken = default)
public Task<QueryResult<UserSession>> 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
};
/// <inheritdoc/>
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);
}
}
}

View file

@ -22,7 +22,7 @@ public class DiagnosticDataService
_entries = entries;
}
public async Task<ReadOnlyMemory<byte>> GetJsonBytesAsync(CancellationToken cancellationToken = default)
public async Task<ReadOnlyMemory<byte>> GetJsonBytesAsync(CT ct = default)
{
var bufferWriter = new ArrayBufferWriter<byte>();
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<string> GetJsonStringAsync(CancellationToken cancellationToken = default)
public async Task<string> GetJsonStringAsync(CT ct = default)
{
var bytes = await GetJsonBytesAsync(cancellationToken);
var bytes = await GetJsonBytesAsync(ct);
return Encoding.UTF8.GetString(bytes.Span);
}
}

View file

@ -17,12 +17,12 @@ public interface ISessionManagementService
/// <summary>
/// Queries all the session related data for a user.
/// </summary>
Task<QueryResult<UserSession>> QuerySessionsAsync(SessionQuery? filter = null, CancellationToken cancellationToken = default);
Task<QueryResult<UserSession>> QuerySessionsAsync(SessionQuery? filter = null, CT ct = default);
/// <summary>
/// Removes all the session related data for a user.
/// </summary>
Task RemoveSessionsAsync(RemoveSessionsContext context, CancellationToken cancellationToken = default);
Task RemoveSessionsAsync(RemoveSessionsContext context, CT ct = default);
}
/// <summary>

View file

@ -185,22 +185,22 @@ public class ServerSideTicketStore : IServerSideTicketStore
}
/// <inheritdoc/>
public async Task<IReadOnlyCollection<UserSession>> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default)
public async Task<IReadOnlyCollection<UserSession>> 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);
}
/// <inheritdoc />
public async Task<QueryResult<UserSession>> QuerySessionsAsync(SessionQuery filter = null, CancellationToken cancellationToken = default)
public async Task<QueryResult<UserSession>> 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
}
/// <inheritdoc/>
public async Task<IReadOnlyCollection<UserSession>> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default)
public async Task<IReadOnlyCollection<UserSession>> 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);
}

View file

@ -17,15 +17,15 @@ public interface IServerSideTicketStore : ITicketStore
/// <summary>
/// Gets sessions for a specific subject id and/or session id
/// </summary>
Task<IReadOnlyCollection<UserSession>> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default);
Task<IReadOnlyCollection<UserSession>> GetSessionsAsync(SessionFilter filter, CT ct = default);
/// <summary>
/// Queries user sessions based on filter
/// </summary>
Task<QueryResult<UserSession>> QuerySessionsAsync(SessionQuery filter, CancellationToken cancellationToken = default);
Task<QueryResult<UserSession>> QuerySessionsAsync(SessionQuery filter, CT ct = default);
/// <summary>
/// Removes and returns expired sessions
/// </summary>
Task<IReadOnlyCollection<UserSession>> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default);
Task<IReadOnlyCollection<UserSession>> GetAndRemoveExpiredSessionsAsync(int count, CT ct = default);
}

View file

@ -18,7 +18,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore
/// <inheritdoc />
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
}
/// <inheritdoc />
public Task<ServerSideSession> GetSessionAsync(string key, CancellationToken cancellationToken = default)
public Task<ServerSideSession> GetSessionAsync(string key, CT ct = default)
{
using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.GetSession");
@ -39,7 +39,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore
}
/// <inheritdoc />
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
}
/// <inheritdoc />
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
/// <inheritdoc />
public Task<IReadOnlyCollection<ServerSideSession>> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default)
public Task<IReadOnlyCollection<ServerSideSession>> GetSessionsAsync(SessionFilter filter, CT ct = default)
{
using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.GetSessions");
@ -80,7 +80,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore
}
/// <inheritdoc />
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
/// <inheritdoc/>
public Task<IReadOnlyCollection<ServerSideSession>> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default)
public Task<IReadOnlyCollection<ServerSideSession>> GetAndRemoveExpiredSessionsAsync(int count, CT ct = default)
{
using var activity = Tracing.StoreActivitySource.StartActivity("InMemoryServerSideSessionStore.GetAndRemoveExpiredSession");
@ -129,7 +129,7 @@ public class InMemoryServerSideSessionStore : IServerSideSessionStore
/// <inheritdoc/>
public Task<QueryResult<ServerSideSession>> QuerySessionsAsync(SessionQuery filter = null, CancellationToken cancellationToken = default)
public Task<QueryResult<ServerSideSession>> 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

View file

@ -14,5 +14,5 @@ public interface ICancellationTokenProvider
/// <summary>
/// Returns the current CancellationToken, or null if none present.
/// </summary>
CancellationToken CancellationToken { get; }
CT CancellationToken { get; }
}

View file

@ -10,5 +10,5 @@ namespace Duende.IdentityServer.Services;
public class NoneCancellationTokenProvider : ICancellationTokenProvider
{
/// <inheritdoc/>
public CancellationToken CancellationToken => CancellationToken.None;
public CT CancellationToken => CT.None;
}

View file

@ -16,43 +16,43 @@ public interface IServerSideSessionStore
/// <summary>
/// Retrieves a session
/// </summary>
Task<ServerSideSession?> GetSessionAsync(string key, CancellationToken cancellationToken = default);
Task<ServerSideSession?> GetSessionAsync(string key, CT ct = default);
/// <summary>
/// Creates a session
/// </summary>
Task CreateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default);
Task CreateSessionAsync(ServerSideSession session, CT ct = default);
/// <summary>
/// Updates a session
/// </summary>
Task UpdateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default);
Task UpdateSessionAsync(ServerSideSession session, CT ct = default);
/// <summary>
/// Deletes a session
/// </summary>
Task DeleteSessionAsync(string key, CancellationToken cancellationToken = default);
Task DeleteSessionAsync(string key, CT ct = default);
/// <summary>
/// Gets sessions for a specific subject id and/or session id
/// </summary>
Task<IReadOnlyCollection<ServerSideSession>> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default);
Task<IReadOnlyCollection<ServerSideSession>> GetSessionsAsync(SessionFilter filter, CT ct = default);
/// <summary>
/// Deletes sessions for a specific subject id and/or session id
/// </summary>
Task DeleteSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default);
Task DeleteSessionsAsync(SessionFilter filter, CT ct = default);
/// <summary>
/// Removes and returns expired sessions
/// </summary>
Task<IReadOnlyCollection<ServerSideSession>> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default);
Task<IReadOnlyCollection<ServerSideSession>> GetAndRemoveExpiredSessionsAsync(int count, CT ct = default);
/// <summary>
/// Queries sessions based on filter
/// </summary>
Task<QueryResult<ServerSideSession>> QuerySessionsAsync(SessionQuery? filter = null, CancellationToken cancellationToken = default);
Task<QueryResult<ServerSideSession>> QuerySessionsAsync(SessionQuery? filter = null, CT ct = default);
}

View file

@ -22,9 +22,9 @@ public class BrowserHandler : DelegatingHandler
{
}
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected async override Task<HttpResponseMessage> 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<HttpResponseMessage> SendCookiesAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected async Task<HttpResponseMessage> 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"))
{

View file

@ -602,7 +602,7 @@ public class MockMessageHandler : DelegatingHandler
public Func<HttpRequestMessage, Task> OnInvoke { get; set; }
public HttpResponseMessage Response { get; set; } = new HttpResponseMessage(HttpStatusCode.OK);
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CT ct)
{
InvokeWasCalled = true;

View file

@ -13,9 +13,9 @@ public class MessageHandlerWrapper : DelegatingHandler
{
}
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CT ct)
{
Response = await base.SendAsync(request, cancellationToken);
Response = await base.SendAsync(request, ct);
return Response;
}
}

View file

@ -16,7 +16,7 @@ public class MtlsMessageHandler : DelegatingHandler
public MtlsMessageHandler(HttpMessageHandler innerHandler, X509Certificate2 clientCertificate)
: base(innerHandler) => _clientCertificate = clientCertificate;
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected override async Task<HttpResponseMessage> 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);
}
}

View file

@ -71,6 +71,6 @@ public class TlsConnectionFeature : ITlsConnectionFeature
{
public X509Certificate2 ClientCertificate { get; set; }
public Task<X509Certificate2> GetClientCertificateAsync(CancellationToken cancellationToken)
public Task<X509Certificate2> GetClientCertificateAsync(CT ct)
=> Task.FromResult(ClientCertificate);
}

View file

@ -56,7 +56,7 @@ public class NetworkHandler : HttpMessageHandler
public NetworkHandler(Func<HttpRequestMessage, HttpResponseMessage> action) => _action = action;
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CT ct)
{
Request = request;
Body = await SafeReadContentFrom(request);

View file

@ -12,9 +12,9 @@ public class NetworkDelaySimulationInterceptor(TimeSpan delay) : DbCommandInterc
DbCommand command,
CommandEventData eventData,
InterceptionResult<DbDataReader> result,
CancellationToken cancellationToken = default)
CT ct = default)
{
await Task.Delay(delay, cancellationToken);
await Task.Delay(delay, ct);
return result;
}

View file

@ -15,14 +15,14 @@ public class MockOperationalStoreNotification : IOperationalStoreNotification
public Action<IEnumerable<PersistedGrant>> OnPersistedGrantsRemoved = _ => { };
public Action<IEnumerable<DeviceFlowCodes>> OnDeviceFlowCodesRemoved = _ => { };
public Task PersistedGrantsRemovedAsync(IEnumerable<PersistedGrant> persistedGrants, CancellationToken cancellationToken = default)
public Task PersistedGrantsRemovedAsync(IEnumerable<PersistedGrant> persistedGrants, CT ct = default)
{
OnPersistedGrantsRemoved(persistedGrants);
PersistedGrantNotifications.Add(persistedGrants);
return Task.CompletedTask;
}
public Task DeviceCodesRemovedAsync(IEnumerable<DeviceFlowCodes> deviceCodes, CancellationToken cancellationToken = default)
public Task DeviceCodesRemovedAsync(IEnumerable<DeviceFlowCodes> deviceCodes, CT ct = default)
{
OnDeviceFlowCodesRemoved(deviceCodes);
DeviceFlowCodeNotifications.Append(deviceCodes);

View file

@ -23,7 +23,7 @@ public class TestBrowserClient : HttpClient
{
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected override async Task<HttpResponseMessage> 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"))
{

View file

@ -56,7 +56,7 @@ public class NetworkHandler : HttpMessageHandler
public NetworkHandler(Func<HttpRequestMessage, HttpResponseMessage> action) => _action = action;
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CT ct)
{
Request = request;
Body = await SafeReadContentFrom(request);