diff --git a/identity-server/src/IdentityServer/Endpoints/BaseDiscoveryEndpoint.cs b/identity-server/src/IdentityServer/Endpoints/BaseDiscoveryEndpoint.cs index db79e5fe1..a2cb4469f 100644 --- a/identity-server/src/IdentityServer/Endpoints/BaseDiscoveryEndpoint.cs +++ b/identity-server/src/IdentityServer/Endpoints/BaseDiscoveryEndpoint.cs @@ -25,20 +25,20 @@ internal abstract class BaseDiscoveryEndpoint( var distributedCache = context.RequestServices.GetRequiredService(); if (distributedCache is not null) { - return await GetCachedDiscoveryDocument(distributedCache, baseUrl, issuerUri); + return await GetCachedDiscoveryDocument(distributedCache, baseUrl, issuerUri, context.RequestAborted); } // fall through to default implementation if there is no cache provider registered } - var response = await ResponseGenerator.CreateDiscoveryDocumentAsync(baseUrl, issuerUri); + var response = await ResponseGenerator.CreateDiscoveryDocumentAsync(baseUrl, issuerUri, context.RequestAborted); return new DiscoveryDocumentResult(response, Options.Discovery.ResponseCacheInterval); } private async Task GetCachedDiscoveryDocument(IDistributedCache cache, string baseUrl, - string issuerUri) + string issuerUri, CT ct) { var key = $"discoveryDocument/{baseUrl}/{issuerUri}"; - var json = await cache.GetStringAsync(key); + var json = await cache.GetStringAsync(key, ct); if (json is not null) { @@ -49,7 +49,7 @@ internal abstract class BaseDiscoveryEndpoint( } var entries = - await ResponseGenerator.CreateDiscoveryDocumentAsync(baseUrl, issuerUri); + await ResponseGenerator.CreateDiscoveryDocumentAsync(baseUrl, issuerUri, ct); var expirationFromNow = Options.Preview.DiscoveryDocumentCacheDuration; @@ -62,7 +62,7 @@ internal abstract class BaseDiscoveryEndpoint( await cache.SetStringAsync(key, result.Json, new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = expirationFromNow, - }); + }, ct); return result; } diff --git a/identity-server/src/IdentityServer/Endpoints/DiscoveryKeyEndpoint.cs b/identity-server/src/IdentityServer/Endpoints/DiscoveryKeyEndpoint.cs index 9a2cfc1be..143030e6d 100644 --- a/identity-server/src/IdentityServer/Endpoints/DiscoveryKeyEndpoint.cs +++ b/identity-server/src/IdentityServer/Endpoints/DiscoveryKeyEndpoint.cs @@ -53,7 +53,7 @@ internal class DiscoveryKeyEndpoint : IEndpointHandler // generate response _logger.LogTrace("Calling into discovery response generator: {type}", _responseGenerator.GetType().FullName); - var response = await _responseGenerator.CreateJwkDocumentAsync(); + var response = await _responseGenerator.CreateJwkDocumentAsync(context.RequestAborted); return new JsonWebKeysResult(response, _options.Discovery.ResponseCacheInterval); } diff --git a/identity-server/src/IdentityServer/Endpoints/IntrospectionEndpoint.cs b/identity-server/src/IdentityServer/Endpoints/IntrospectionEndpoint.cs index 69fbc02db..503be41fb 100644 --- a/identity-server/src/IdentityServer/Endpoints/IntrospectionEndpoint.cs +++ b/identity-server/src/IdentityServer/Endpoints/IntrospectionEndpoint.cs @@ -152,7 +152,7 @@ internal class IntrospectionEndpoint : IEndpointHandler // response generation _logger.LogTrace("Calling into introspection response generator: {type}", _responseGenerator.GetType().FullName); - var response = await _responseGenerator.ProcessAsync(validationResult); + var response = await _responseGenerator.ProcessAsync(validationResult, context.RequestAborted); // render result LogSuccess(validationResult.IsActive, callerName); diff --git a/identity-server/src/IdentityServer/Endpoints/Results/AuthorizeInteractionPageResult.cs b/identity-server/src/IdentityServer/Endpoints/Results/AuthorizeInteractionPageResult.cs index d3c4249cb..fd7cfcced 100644 --- a/identity-server/src/IdentityServer/Endpoints/Results/AuthorizeInteractionPageResult.cs +++ b/identity-server/src/IdentityServer/Endpoints/Results/AuthorizeInteractionPageResult.cs @@ -122,7 +122,7 @@ internal class AuthorizeInteractionPageHttpWriter : IHttpResponseWriter var uiLocalesService = context.RequestServices.GetService(); if (uiLocalesService != null) { - await uiLocalesService.StoreUiLocalesForRedirectAsync(response.Request?.UiLocales); + await uiLocalesService.StoreUiLocalesForRedirectAsync(response.Request?.UiLocales, context.RequestAborted); } var errorModel = await CreateErrorMessage(response, context); diff --git a/identity-server/src/IdentityServer/Endpoints/Results/EndSessionResult.cs b/identity-server/src/IdentityServer/Endpoints/Results/EndSessionResult.cs index 404df80bd..e05b65d69 100644 --- a/identity-server/src/IdentityServer/Endpoints/Results/EndSessionResult.cs +++ b/identity-server/src/IdentityServer/Endpoints/Results/EndSessionResult.cs @@ -75,7 +75,7 @@ internal class EndSessionHttpWriter : IHttpResponseWriter if (redirect.IsLocalUrl()) { redirect = _urls.GetIdentityServerRelativeUrl(redirect); - await _localesService.StoreUiLocalesForRedirectAsync(result.Result.ValidatedRequest?.UiLocales); + await _localesService.StoreUiLocalesForRedirectAsync(result.Result.ValidatedRequest?.UiLocales, context.RequestAborted); } if (id != null) diff --git a/identity-server/src/IdentityServer/ResponseHandling/Default/BackchannelAuthenticationResponseGenerator.cs b/identity-server/src/IdentityServer/ResponseHandling/Default/BackchannelAuthenticationResponseGenerator.cs index addbb4e88..913dd9b2a 100644 --- a/identity-server/src/IdentityServer/ResponseHandling/Default/BackchannelAuthenticationResponseGenerator.cs +++ b/identity-server/src/IdentityServer/ResponseHandling/Default/BackchannelAuthenticationResponseGenerator.cs @@ -118,7 +118,7 @@ public class BackchannelAuthenticationResponseGenerator : IBackchannelAuthentica Tenant = validationResult.ValidatedRequest.Tenant, IdP = validationResult.ValidatedRequest.IdP, Properties = validationResult.ValidatedRequest.Properties, - }); + }, ct); return response; } diff --git a/identity-server/src/IdentityServer/ResponseHandling/Default/DeviceAuthorizationResponseGenerator.cs b/identity-server/src/IdentityServer/ResponseHandling/Default/DeviceAuthorizationResponseGenerator.cs index 78d4ccfd6..daec9fc08 100644 --- a/identity-server/src/IdentityServer/ResponseHandling/Default/DeviceAuthorizationResponseGenerator.cs +++ b/identity-server/src/IdentityServer/ResponseHandling/Default/DeviceAuthorizationResponseGenerator.cs @@ -82,13 +82,13 @@ public class DeviceAuthorizationResponseGenerator : IDeviceAuthorizationResponse // generate user_code var userCodeGenerator = await UserCodeService.GetGenerator( validationResult.ValidatedRequest.Client.UserCodeType ?? - Options.DeviceFlow.DefaultUserCodeType); + Options.DeviceFlow.DefaultUserCodeType, ct); var retryCount = 0; while (retryCount < userCodeGenerator.RetryLimit) { - var userCode = await userCodeGenerator.GenerateAsync(); + var userCode = await userCodeGenerator.GenerateAsync(ct); var deviceCode = await DeviceFlowCodeService.FindByUserCodeAsync(userCode, ct); if (deviceCode == null) diff --git a/identity-server/src/IdentityServer/ResponseHandling/Default/DiscoveryResponseGenerator.cs b/identity-server/src/IdentityServer/ResponseHandling/Default/DiscoveryResponseGenerator.cs index 5b168da38..e030f72b2 100644 --- a/identity-server/src/IdentityServer/ResponseHandling/Default/DiscoveryResponseGenerator.cs +++ b/identity-server/src/IdentityServer/ResponseHandling/Default/DiscoveryResponseGenerator.cs @@ -92,7 +92,8 @@ public class DiscoveryResponseGenerator : IDiscoveryResponseGenerator /// /// The base URL. /// The issuer URI. - public virtual async Task> CreateDiscoveryDocumentAsync(string baseUrl, string issuerUri) + /// + public virtual async Task> CreateDiscoveryDocumentAsync(string baseUrl, string issuerUri, CT ct) { using var activity = Tracing.BasicActivitySource.StartActivity("DiscoveryResponseGenerator.CreateDiscoveryDocument"); @@ -106,7 +107,7 @@ public class DiscoveryResponseGenerator : IDiscoveryResponseGenerator // jwks if (Options.Discovery.ShowKeySet) { - if ((await Keys.GetValidationKeysAsync(default)).Any()) + if ((await Keys.GetValidationKeysAsync(ct)).Any()) { entries.Add(OidcConstants.Discovery.JwksUri, baseUrl + ProtocolRoutePaths.DiscoveryWebKeys); } @@ -236,7 +237,7 @@ public class DiscoveryResponseGenerator : IDiscoveryResponseGenerator Options.Discovery.ShowApiScopes || Options.Discovery.ShowClaims) { - var resources = await ResourceStore.GetAllEnabledResourcesAsync(default); + var resources = await ResourceStore.GetAllEnabledResourcesAsync(ct); var scopes = new List(); // scopes @@ -342,7 +343,7 @@ public class DiscoveryResponseGenerator : IDiscoveryResponseGenerator AddSigningAlgorithmsForEndpointIfNeeded(OidcConstants.Discovery.IntrospectionEndpointAuthSigningAlgorithmsSupported, entries, supportedAuthMethods); } - var signingCredentials = await Keys.GetAllSigningCredentialsAsync(default); + var signingCredentials = await Keys.GetAllSigningCredentialsAsync(ct); if (signingCredentials.Any()) { var signingAlgorithms = signingCredentials.Select(c => c.Algorithm).Distinct(); @@ -458,13 +459,14 @@ public class DiscoveryResponseGenerator : IDiscoveryResponseGenerator /// /// Creates the JWK document. /// - public virtual async Task> CreateJwkDocumentAsync() + /// + public virtual async Task> CreateJwkDocumentAsync(CT ct) { using var activity = Tracing.BasicActivitySource.StartActivity("DiscoveryResponseGenerator.CreateJwkDocument"); var webKeys = new List(); - foreach (var key in await Keys.GetValidationKeysAsync(default)) + foreach (var key in await Keys.GetValidationKeysAsync(ct)) { if (key.Key is X509SecurityKey x509Key) { diff --git a/identity-server/src/IdentityServer/ResponseHandling/Default/IntrospectionResponseGenerator.cs b/identity-server/src/IdentityServer/ResponseHandling/Default/IntrospectionResponseGenerator.cs index a8fb87904..1146ea3cd 100644 --- a/identity-server/src/IdentityServer/ResponseHandling/Default/IntrospectionResponseGenerator.cs +++ b/identity-server/src/IdentityServer/ResponseHandling/Default/IntrospectionResponseGenerator.cs @@ -45,8 +45,9 @@ public class IntrospectionResponseGenerator : IIntrospectionResponseGenerator /// Processes the response. /// /// The validation result. + /// /// - public virtual async Task> ProcessAsync(IntrospectionRequestValidationResult validationResult) + public virtual async Task> ProcessAsync(IntrospectionRequestValidationResult validationResult, CT ct) { using var activity = Tracing.BasicActivitySource.StartActivity("IntrospectionResponseGenerator.Process"); @@ -65,7 +66,7 @@ public class IntrospectionResponseGenerator : IIntrospectionResponseGenerator { Logger.LogDebug("Creating introspection response for inactive token."); Telemetry.Metrics.Introspection(callerName, false); - await Events.RaiseAsync(new TokenIntrospectionSuccessEvent(validationResult), default); + await Events.RaiseAsync(new TokenIntrospectionSuccessEvent(validationResult), ct); return response; } @@ -76,7 +77,7 @@ public class IntrospectionResponseGenerator : IIntrospectionResponseGenerator if (validationResult.Api != null) { // expected scope not present - if (await AreExpectedScopesPresentAsync(validationResult) == false) + if (await AreExpectedScopesPresentAsync(validationResult, ct) == false) { return response; } @@ -98,7 +99,7 @@ public class IntrospectionResponseGenerator : IIntrospectionResponseGenerator response.Add("scope", scopes.ToSpaceSeparatedString()); Telemetry.Metrics.Introspection(callerName, true); - await Events.RaiseAsync(new TokenIntrospectionSuccessEvent(validationResult), default); + await Events.RaiseAsync(new TokenIntrospectionSuccessEvent(validationResult), ct); return response; } @@ -106,8 +107,9 @@ public class IntrospectionResponseGenerator : IIntrospectionResponseGenerator /// Checks if the API resource is allowed to introspect the scopes. /// /// The validation result. + /// /// - protected virtual async Task AreExpectedScopesPresentAsync(IntrospectionRequestValidationResult validationResult) + protected virtual async Task AreExpectedScopesPresentAsync(IntrospectionRequestValidationResult validationResult, CT ct) { var apiScopes = validationResult.Api.Scopes; var tokenScopes = validationResult.Claims.Where(c => c.Type == JwtClaimTypes.Scope); @@ -129,7 +131,7 @@ public class IntrospectionResponseGenerator : IIntrospectionResponseGenerator const string errorMessage = "Expected scopes are missing"; var callerName = validationResult.Api?.Name ?? validationResult.Client.ClientId; Telemetry.Metrics.IntrospectionFailure(callerName, errorMessage); - await Events.RaiseAsync(new TokenIntrospectionFailureEvent(validationResult.Api.Name, errorMessage, validationResult.Token, apiScopes, tokenScopes.Select(s => s.Value)), default); + await Events.RaiseAsync(new TokenIntrospectionFailureEvent(validationResult.Api.Name, errorMessage, validationResult.Token, apiScopes, tokenScopes.Select(s => s.Value)), ct); } return result; diff --git a/identity-server/src/IdentityServer/ResponseHandling/IDiscoveryResponseGenerator.cs b/identity-server/src/IdentityServer/ResponseHandling/IDiscoveryResponseGenerator.cs index c24fb45c2..655ff87c2 100644 --- a/identity-server/src/IdentityServer/ResponseHandling/IDiscoveryResponseGenerator.cs +++ b/identity-server/src/IdentityServer/ResponseHandling/IDiscoveryResponseGenerator.cs @@ -16,10 +16,12 @@ public interface IDiscoveryResponseGenerator /// /// The base URL. /// The issuer URI. - Task> CreateDiscoveryDocumentAsync(string baseUrl, string issuerUri); + /// + Task> CreateDiscoveryDocumentAsync(string baseUrl, string issuerUri, CT ct); /// /// Creates the JWK document. /// - Task> CreateJwkDocumentAsync(); + /// + Task> CreateJwkDocumentAsync(CT ct); } diff --git a/identity-server/src/IdentityServer/ResponseHandling/IIntrospectionResponseGenerator.cs b/identity-server/src/IdentityServer/ResponseHandling/IIntrospectionResponseGenerator.cs index fc11b8651..5019caaef 100644 --- a/identity-server/src/IdentityServer/ResponseHandling/IIntrospectionResponseGenerator.cs +++ b/identity-server/src/IdentityServer/ResponseHandling/IIntrospectionResponseGenerator.cs @@ -15,6 +15,7 @@ public interface IIntrospectionResponseGenerator /// Processes the response. /// /// The validation result. + /// /// - Task> ProcessAsync(IntrospectionRequestValidationResult validationResult); + Task> ProcessAsync(IntrospectionRequestValidationResult validationResult, CT ct); } diff --git a/identity-server/src/IdentityServer/Services/Default/BackChannelLogoutHttpClient.cs b/identity-server/src/IdentityServer/Services/Default/BackChannelLogoutHttpClient.cs index b81e0394f..38de3163d 100644 --- a/identity-server/src/IdentityServer/Services/Default/BackChannelLogoutHttpClient.cs +++ b/identity-server/src/IdentityServer/Services/Default/BackChannelLogoutHttpClient.cs @@ -34,15 +34,16 @@ public class DefaultBackChannelLogoutHttpClient : IBackChannelLogoutHttpClient /// /// /// + /// /// - public async Task PostAsync(string url, Dictionary payload) + public async Task PostAsync(string url, Dictionary payload, CT ct) { using var activity = Tracing.ServiceActivitySource.StartActivity("DefaultBackChannelLogoutHttpClient.Post"); try { using var formEncodedContent = new FormUrlEncodedContent(payload); - var response = await _client.PostAsync(url, formEncodedContent, _cancellationTokenProvider.CancellationToken); + var response = await _client.PostAsync(url, formEncodedContent, ct); if (response.IsSuccessStatusCode) { _logger.LogDebug("Response from back-channel logout endpoint: {url} status code: {status}", url, (int)response.StatusCode); @@ -51,7 +52,7 @@ public class DefaultBackChannelLogoutHttpClient : IBackChannelLogoutHttpClient { BackChannelError err = null; - var errorjson = await response.Content.ReadAsStringAsync(); + var errorjson = await response.Content.ReadAsStringAsync(ct); try { err = JsonSerializer.Deserialize(errorjson); diff --git a/identity-server/src/IdentityServer/Services/Default/DefaultBackChannelLogoutService.cs b/identity-server/src/IdentityServer/Services/Default/DefaultBackChannelLogoutService.cs index b3531e979..510234721 100644 --- a/identity-server/src/IdentityServer/Services/Default/DefaultBackChannelLogoutService.cs +++ b/identity-server/src/IdentityServer/Services/Default/DefaultBackChannelLogoutService.cs @@ -82,7 +82,7 @@ public class DefaultBackChannelLogoutService : IBackChannelLogoutService var backChannelRequests = await LogoutNotificationService.GetBackChannelLogoutNotificationsAsync(context, ct); if (backChannelRequests.Any()) { - await SendLogoutNotificationsAsync(backChannelRequests); + await SendLogoutNotificationsAsync(backChannelRequests, ct); } } @@ -90,8 +90,9 @@ public class DefaultBackChannelLogoutService : IBackChannelLogoutService /// Sends the logout notifications for the collection of clients. /// /// + /// /// - protected virtual async Task SendLogoutNotificationsAsync(IEnumerable requests) + protected virtual async Task SendLogoutNotificationsAsync(IEnumerable requests, CT ct) { requests ??= []; var logoutRequestsWithPayload = new List<(BackChannelLogoutRequest, Dictionary)>(); @@ -106,7 +107,7 @@ public class DefaultBackChannelLogoutService : IBackChannelLogoutService logoutRequestsWithPayload.Add((backChannelLogoutRequest, payload)); } - var logoutRequests = logoutRequestsWithPayload.Select(request => PostLogoutJwt(request.Item1, request.Item2)).ToArray(); + var logoutRequests = logoutRequestsWithPayload.Select(request => PostLogoutJwt(request.Item1, request.Item2, ct)).ToArray(); await Task.WhenAll(logoutRequests); } @@ -115,8 +116,9 @@ public class DefaultBackChannelLogoutService : IBackChannelLogoutService /// /// /// + /// /// - protected virtual Task PostLogoutJwt(BackChannelLogoutRequest client, Dictionary data) => HttpClient.PostAsync(client.LogoutUri, data); + protected virtual Task PostLogoutJwt(BackChannelLogoutRequest client, Dictionary data, CT ct) => HttpClient.PostAsync(client.LogoutUri, data, ct); /// /// Creates the form-url-encoded payload (as a dictionary) to send to the client. diff --git a/identity-server/src/IdentityServer/Services/Default/DefaultJwtRequestUriHttpClient.cs b/identity-server/src/IdentityServer/Services/Default/DefaultJwtRequestUriHttpClient.cs index ffb07ba1a..5fe5b3874 100644 --- a/identity-server/src/IdentityServer/Services/Default/DefaultJwtRequestUriHttpClient.cs +++ b/identity-server/src/IdentityServer/Services/Default/DefaultJwtRequestUriHttpClient.cs @@ -38,14 +38,14 @@ public class DefaultJwtRequestUriHttpClient : IJwtRequestUriHttpClient /// - public async Task GetJwtAsync(string url, Client client) + public async Task GetJwtAsync(string url, Client client, CT ct) { using var activity = Tracing.ServiceActivitySource.StartActivity("DefaultJwtRequestUriHttpClient.GetJwt"); using var req = new HttpRequestMessage(HttpMethod.Get, url); req.Options.TryAdd(IdentityServerConstants.JwtRequestClientKey, client); - var response = await _client.SendAsync(req, _cancellationTokenProvider.CancellationToken); + var response = await _client.SendAsync(req, ct); if (response.StatusCode == System.Net.HttpStatusCode.OK) { if (_options.StrictJarValidation) @@ -61,7 +61,7 @@ public class DefaultJwtRequestUriHttpClient : IJwtRequestUriHttpClient _sanitizedLogger.LogDebug("Success http response from jwt url {url}", url); - var json = await response.Content.ReadAsStringAsync(); + var json = await response.Content.ReadAsStringAsync(ct); return json; } diff --git a/identity-server/src/IdentityServer/Services/Default/DefaultUiLocalesService.cs b/identity-server/src/IdentityServer/Services/Default/DefaultUiLocalesService.cs index d395bf97e..d10654053 100644 --- a/identity-server/src/IdentityServer/Services/Default/DefaultUiLocalesService.cs +++ b/identity-server/src/IdentityServer/Services/Default/DefaultUiLocalesService.cs @@ -13,7 +13,7 @@ namespace Duende.IdentityServer.Services.Default; public class DefaultUiLocalesService(IHttpContextAccessor httpContextAccessor, IOptions requestLocalizationOptions, ILogger logger) : IUiLocalesService { - public virtual Task StoreUiLocalesForRedirectAsync(string? uiLocales) + public virtual Task StoreUiLocalesForRedirectAsync(string? uiLocales, CT ct) { if (httpContextAccessor.HttpContext is null) { diff --git a/identity-server/src/IdentityServer/Services/Default/DefaultUserCodeService.cs b/identity-server/src/IdentityServer/Services/Default/DefaultUserCodeService.cs index 69ea36274..298e59266 100644 --- a/identity-server/src/IdentityServer/Services/Default/DefaultUserCodeService.cs +++ b/identity-server/src/IdentityServer/Services/Default/DefaultUserCodeService.cs @@ -23,7 +23,8 @@ public class DefaultUserCodeService : IUserCodeService /// Gets the user code generator. /// /// Type of user code. + /// /// - public Task GetGenerator(string userCodeType) => + public Task GetGenerator(string userCodeType, CT ct) => Task.FromResult(_generators.FirstOrDefault(x => x.UserCodeType == userCodeType)); } diff --git a/identity-server/src/IdentityServer/Services/Default/NopBackchannelAuthenticationUserNotificationService.cs b/identity-server/src/IdentityServer/Services/Default/NopBackchannelAuthenticationUserNotificationService.cs index 344d06d81..2f804645b 100644 --- a/identity-server/src/IdentityServer/Services/Default/NopBackchannelAuthenticationUserNotificationService.cs +++ b/identity-server/src/IdentityServer/Services/Default/NopBackchannelAuthenticationUserNotificationService.cs @@ -26,9 +26,9 @@ public class NopBackchannelAuthenticationUserNotificationService : IBackchannelA } /// - public async Task SendLoginRequestAsync(BackchannelUserLoginRequest request) + public async Task SendLoginRequestAsync(BackchannelUserLoginRequest request, CT ct) { - var url = await _issuerNameService.GetCurrentAsync(default); + var url = await _issuerNameService.GetCurrentAsync(ct); url += "/ciba?id=" + request.InternalId; _sanitizedLogger.LogWarning("IBackchannelAuthenticationUserNotificationService not implemented. But for testing, visit {url} to simulate what a user might need to do to complete the request.", url); } diff --git a/identity-server/src/IdentityServer/Services/Default/NumericUserCodeGenerator.cs b/identity-server/src/IdentityServer/Services/Default/NumericUserCodeGenerator.cs index a9dc8b835..a0e25c733 100644 --- a/identity-server/src/IdentityServer/Services/Default/NumericUserCodeGenerator.cs +++ b/identity-server/src/IdentityServer/Services/Default/NumericUserCodeGenerator.cs @@ -32,8 +32,9 @@ public class NumericUserCodeGenerator : IUserCodeGenerator /// /// Generates the user code. /// + /// /// - public Task GenerateAsync() + public Task GenerateAsync(CT ct) { var next = RandomNumberGenerator.GetInt32(100000000, 1000000000); return Task.FromResult(next.ToString(CultureInfo.InvariantCulture)); diff --git a/identity-server/src/IdentityServer/Services/IBackChannelLogoutHttpClient.cs b/identity-server/src/IdentityServer/Services/IBackChannelLogoutHttpClient.cs index 3cd09583f..1b3822cf0 100644 --- a/identity-server/src/IdentityServer/Services/IBackChannelLogoutHttpClient.cs +++ b/identity-server/src/IdentityServer/Services/IBackChannelLogoutHttpClient.cs @@ -16,6 +16,7 @@ public interface IBackChannelLogoutHttpClient /// /// /// + /// /// - Task PostAsync(string url, Dictionary payload); + Task PostAsync(string url, Dictionary payload, CT ct); } diff --git a/identity-server/src/IdentityServer/Services/IBackchannelAuthenticationUserNotificationService.cs b/identity-server/src/IdentityServer/Services/IBackchannelAuthenticationUserNotificationService.cs index 5d8ba7108..17fd5c1e6 100644 --- a/identity-server/src/IdentityServer/Services/IBackchannelAuthenticationUserNotificationService.cs +++ b/identity-server/src/IdentityServer/Services/IBackchannelAuthenticationUserNotificationService.cs @@ -16,5 +16,7 @@ public interface IBackchannelAuthenticationUserNotificationService /// /// Sends a notification for the user to login. /// - Task SendLoginRequestAsync(BackchannelUserLoginRequest request); + /// + /// + Task SendLoginRequestAsync(BackchannelUserLoginRequest request, CT ct); } diff --git a/identity-server/src/IdentityServer/Services/IJwtRequestUriHttpClient.cs b/identity-server/src/IdentityServer/Services/IJwtRequestUriHttpClient.cs index 16377cd4d..c9edff672 100644 --- a/identity-server/src/IdentityServer/Services/IJwtRequestUriHttpClient.cs +++ b/identity-server/src/IdentityServer/Services/IJwtRequestUriHttpClient.cs @@ -18,6 +18,7 @@ public interface IJwtRequestUriHttpClient /// /// /// + /// /// - Task GetJwtAsync(string url, Client client); + Task GetJwtAsync(string url, Client client, CT ct); } diff --git a/identity-server/src/IdentityServer/Services/IUiLocalesService.cs b/identity-server/src/IdentityServer/Services/IUiLocalesService.cs index bcba0d8a6..59e8d4755 100644 --- a/identity-server/src/IdentityServer/Services/IUiLocalesService.cs +++ b/identity-server/src/IdentityServer/Services/IUiLocalesService.cs @@ -6,5 +6,10 @@ namespace Duende.IdentityServer.Services; public interface IUiLocalesService { - Task StoreUiLocalesForRedirectAsync(string? uiLocales); + /// + /// Stores the UI locales for redirect. + /// + /// + /// + Task StoreUiLocalesForRedirectAsync(string? uiLocales, CT ct); } diff --git a/identity-server/src/IdentityServer/Services/IUserCodeGenerator.cs b/identity-server/src/IdentityServer/Services/IUserCodeGenerator.cs index 7d0f13144..56d01744d 100644 --- a/identity-server/src/IdentityServer/Services/IUserCodeGenerator.cs +++ b/identity-server/src/IdentityServer/Services/IUserCodeGenerator.cs @@ -30,6 +30,7 @@ public interface IUserCodeGenerator /// /// Generates the user code. /// + /// /// - Task GenerateAsync(); + Task GenerateAsync(CT ct); } diff --git a/identity-server/src/IdentityServer/Services/IUserCodeService.cs b/identity-server/src/IdentityServer/Services/IUserCodeService.cs index 91fba912e..d1bf75a6a 100644 --- a/identity-server/src/IdentityServer/Services/IUserCodeService.cs +++ b/identity-server/src/IdentityServer/Services/IUserCodeService.cs @@ -15,6 +15,7 @@ public interface IUserCodeService /// Gets the user code generator. /// /// Type of user code. + /// /// - Task GetGenerator(string userCodeType); + Task GetGenerator(string userCodeType, CT ct); } diff --git a/identity-server/src/IdentityServer/Validation/Default/RequestObjectValidator.cs b/identity-server/src/IdentityServer/Validation/Default/RequestObjectValidator.cs index 599bff8b7..2554d2b20 100644 --- a/identity-server/src/IdentityServer/Validation/Default/RequestObjectValidator.cs +++ b/identity-server/src/IdentityServer/Validation/Default/RequestObjectValidator.cs @@ -82,7 +82,7 @@ internal class RequestObjectValidator : IRequestObjectValidator return Invalid(request, error: OidcConstants.AuthorizeErrors.InvalidRequestUri, description: "request_uri is too long"); } - var jwt = await _jwtRequestUriHttpClient.GetJwtAsync(requestUri, request.Client); + var jwt = await _jwtRequestUriHttpClient.GetJwtAsync(requestUri, request.Client, ct); if (jwt.IsMissing()) { LogError("no value returned from request_uri", request); diff --git a/identity-server/test/IdentityServer.IntegrationTests/Common/MockCibaUserNotificationService.cs b/identity-server/test/IdentityServer.IntegrationTests/Common/MockCibaUserNotificationService.cs index 2c9851f66..63452c58f 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/Common/MockCibaUserNotificationService.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/Common/MockCibaUserNotificationService.cs @@ -11,7 +11,7 @@ internal class MockCibaUserNotificationService : IBackchannelAuthenticationUserN { public BackchannelUserLoginRequest LoginRequest { get; set; } - public Task SendLoginRequestAsync(BackchannelUserLoginRequest request) + public Task SendLoginRequestAsync(BackchannelUserLoginRequest request, CT ct) { LoginRequest = request; return Task.CompletedTask; diff --git a/identity-server/test/IdentityServer.UnitTests/Common/MockJwtRequestUriHttpClient.cs b/identity-server/test/IdentityServer.UnitTests/Common/MockJwtRequestUriHttpClient.cs index 8b6938eb4..217670c40 100644 --- a/identity-server/test/IdentityServer.UnitTests/Common/MockJwtRequestUriHttpClient.cs +++ b/identity-server/test/IdentityServer.UnitTests/Common/MockJwtRequestUriHttpClient.cs @@ -11,5 +11,5 @@ public class MockJwtRequestUriHttpClient : IJwtRequestUriHttpClient { public string Jwt { get; set; } - public Task GetJwtAsync(string url, Client client) => Task.FromResult(Jwt); + public Task GetJwtAsync(string url, Client client, CT ct) => Task.FromResult(Jwt); } diff --git a/identity-server/test/IdentityServer.UnitTests/Common/MockUiLocaleService.cs b/identity-server/test/IdentityServer.UnitTests/Common/MockUiLocaleService.cs index 7c7e2d978..ea5e2c3a7 100644 --- a/identity-server/test/IdentityServer.UnitTests/Common/MockUiLocaleService.cs +++ b/identity-server/test/IdentityServer.UnitTests/Common/MockUiLocaleService.cs @@ -8,5 +8,5 @@ namespace UnitTests.Common; public class MockUiLocaleService : IUiLocalesService { - public Task StoreUiLocalesForRedirectAsync(string? uiLocales) => Task.CompletedTask; + public Task StoreUiLocalesForRedirectAsync(string? uiLocales, CT ct) => Task.CompletedTask; } diff --git a/identity-server/test/IdentityServer.UnitTests/ResponseHandling/DeviceAuthorizationResponseGeneratorTests.cs b/identity-server/test/IdentityServer.UnitTests/ResponseHandling/DeviceAuthorizationResponseGeneratorTests.cs index 720add72a..9d89e32a9 100644 --- a/identity-server/test/IdentityServer.UnitTests/ResponseHandling/DeviceAuthorizationResponseGeneratorTests.cs +++ b/identity-server/test/IdentityServer.UnitTests/ResponseHandling/DeviceAuthorizationResponseGeneratorTests.cs @@ -193,7 +193,7 @@ internal class FakeUserCodeGenerator : IUserCodeGenerator set => retryLimit = value; } - public Task GenerateAsync() + public Task GenerateAsync(CT ct) { if (tryCount == 0) { diff --git a/identity-server/test/IdentityServer.UnitTests/Services/Default/DefaultUiLocalesServiceTests.cs b/identity-server/test/IdentityServer.UnitTests/Services/Default/DefaultUiLocalesServiceTests.cs index 9dfa43adf..eeae5d33f 100644 --- a/identity-server/test/IdentityServer.UnitTests/Services/Default/DefaultUiLocalesServiceTests.cs +++ b/identity-server/test/IdentityServer.UnitTests/Services/Default/DefaultUiLocalesServiceTests.cs @@ -15,6 +15,7 @@ namespace UnitTests.Services.Default; public class DefaultUiLocalesServiceTests { + private readonly CT _ct = TestContext.Current.CancellationToken; private readonly DefaultHttpContext _httpContext; private readonly HttpContextAccessor _httpContextAccessor; private readonly RequestLocalizationOptions _requestLocalizationOptions; @@ -34,7 +35,7 @@ public class DefaultUiLocalesServiceTests { _httpContextAccessor.HttpContext = null; - await _subject.StoreUiLocalesForRedirectAsync("en-US"); + await _subject.StoreUiLocalesForRedirectAsync("en-US", _ct); var setCookieHeader = _httpContext.Response.Headers.Where(x => x.Key == "Set-Cookie"); setCookieHeader.ShouldBeEmpty(); @@ -45,7 +46,7 @@ public class DefaultUiLocalesServiceTests { _requestLocalizationOptions.RequestCultureProviders.Clear(); - await _subject.StoreUiLocalesForRedirectAsync("en-US"); + await _subject.StoreUiLocalesForRedirectAsync("en-US", _ct); var setCookieHeader = _httpContext.Response.Headers.Where(x => x.Key == "Set-Cookie"); setCookieHeader.ShouldBeEmpty(); @@ -56,7 +57,7 @@ public class DefaultUiLocalesServiceTests { _requestLocalizationOptions.SupportedUICultures = new List { new("fr-FR") }; - await _subject.StoreUiLocalesForRedirectAsync("en-US"); + await _subject.StoreUiLocalesForRedirectAsync("en-US", _ct); var setCookieHeader = _httpContext.Response.Headers.Where(x => x.Key == "Set-Cookie"); setCookieHeader.ShouldBeEmpty(); @@ -67,7 +68,7 @@ public class DefaultUiLocalesServiceTests { _requestLocalizationOptions.SupportedUICultures = new List { new("fr-FR") }; - await _subject.StoreUiLocalesForRedirectAsync("en-US nb-NO"); + await _subject.StoreUiLocalesForRedirectAsync("en-US nb-NO", _ct); var setCookieHeader = _httpContext.Response.Headers.Where(x => x.Key == "Set-Cookie"); setCookieHeader.ShouldBeEmpty(); @@ -79,7 +80,7 @@ public class DefaultUiLocalesServiceTests [InlineData(" ")] public async Task StoreUiLocalesForRedirectAsync_NullOrWhitespaceUiLocales_DoesNothing(string? uiLocales) { - await _subject.StoreUiLocalesForRedirectAsync(uiLocales); + await _subject.StoreUiLocalesForRedirectAsync(uiLocales, _ct); var setCookieHeader = _httpContext.Response.Headers.Where(x => x.Key == "Set-Cookie"); setCookieHeader.ShouldBeEmpty(); @@ -90,7 +91,7 @@ public class DefaultUiLocalesServiceTests { _requestLocalizationOptions.SupportedUICultures = new List(); - await _subject.StoreUiLocalesForRedirectAsync("en-US"); + await _subject.StoreUiLocalesForRedirectAsync("en-US", _ct); var setCookieHeader = _httpContext.Response.Headers.Where(x => x.Key == "Set-Cookie"); setCookieHeader.ShouldBeEmpty(); @@ -102,7 +103,7 @@ public class DefaultUiLocalesServiceTests var expectedSetCookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(new CultureInfo("en-US"))); _requestLocalizationOptions.SupportedUICultures = new List { new("en-US") }; - await _subject.StoreUiLocalesForRedirectAsync("en-US"); + await _subject.StoreUiLocalesForRedirectAsync("en-US", _ct); var cookieContainer = new CookieContainer(); var cookies = _httpContext.HttpContext.Response.Headers.Where(x => x.Key.Equals("Set-Cookie", StringComparison.OrdinalIgnoreCase)).Select(x => x.Value); @@ -122,7 +123,7 @@ public class DefaultUiLocalesServiceTests new("de-DE") }; - await _subject.StoreUiLocalesForRedirectAsync("en-US fr-FR"); + await _subject.StoreUiLocalesForRedirectAsync("en-US fr-FR", _ct); var cookieContainer = new CookieContainer(); var cookies = _httpContext.HttpContext.Response.Headers.Where(x => x.Key.Equals("Set-Cookie", StringComparison.OrdinalIgnoreCase)).Select(x => x.Value); @@ -142,7 +143,7 @@ public class DefaultUiLocalesServiceTests new("de-DE") }; - await _subject.StoreUiLocalesForRedirectAsync("fr-FR en-US"); + await _subject.StoreUiLocalesForRedirectAsync("fr-FR en-US", _ct); var cookieContainer = new CookieContainer(); var cookies = _httpContext.HttpContext.Response.Headers.Where(x => x.Key.Equals("Set-Cookie", StringComparison.OrdinalIgnoreCase)).Select(x => x.Value); diff --git a/identity-server/test/IdentityServer.UnitTests/Services/Default/NumericUserCodeServiceTests.cs b/identity-server/test/IdentityServer.UnitTests/Services/Default/NumericUserCodeServiceTests.cs index 3971d327a..86d549cfc 100644 --- a/identity-server/test/IdentityServer.UnitTests/Services/Default/NumericUserCodeServiceTests.cs +++ b/identity-server/test/IdentityServer.UnitTests/Services/Default/NumericUserCodeServiceTests.cs @@ -8,12 +8,14 @@ namespace UnitTests.Services.Default; public class NumericUserCodeGeneratorTests { + private readonly CT _ct = TestContext.Current.CancellationToken; + [Fact] public async Task GenerateAsync_should_return_expected_code() { var sut = new NumericUserCodeGenerator(); - var userCode = await sut.GenerateAsync(); + var userCode = await sut.GenerateAsync(_ct); var userCodeInt = int.Parse(userCode); userCodeInt.ShouldBeGreaterThanOrEqualTo(100000000);