From 9d2446764b52eb30e811e535558894acdd2f38e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Fri, 23 Aug 2019 17:16:10 +0200 Subject: [PATCH] Replace Task by ValueTask in OpenIddict.Server/OpenIddict.Server.AspNetCore/OpenIddict.Server.Owin --- ...penIddictServerAspNetCoreHandlerFilters.cs | 36 ++-- ...ServerAspNetCoreHandlers.Authentication.cs | 64 +++---- ...ddictServerAspNetCoreHandlers.Discovery.cs | 6 +- ...IddictServerAspNetCoreHandlers.Exchange.cs | 6 +- ...tServerAspNetCoreHandlers.Serialization.cs | 12 +- ...nIddictServerAspNetCoreHandlers.Session.cs | 60 +++---- .../OpenIddictServerAspNetCoreHandlers.cs | 60 +++---- ...ddictServerDataProtectionHandlerFilters.cs | 4 +- ...verDataProtectionHandlers.Serialization.cs | 52 +++--- .../OpenIddictServerOwinHandlerFilters.cs | 32 ++-- ...IddictServerOwinHandlers.Authentication.cs | 54 +++--- .../OpenIddictServerOwinHandlers.Discovery.cs | 6 +- .../OpenIddictServerOwinHandlers.Exchange.cs | 6 +- ...nIddictServerOwinHandlers.Serialization.cs | 12 +- .../OpenIddictServerOwinHandlers.Session.cs | 50 +++--- .../OpenIddictServerOwinHandlers.cs | 60 +++---- .../OpenIddictServerOwinMiddlewareFactory.cs | 2 +- .../IOpenIddictServerHandler.cs | 4 +- .../IOpenIddictServerHandlerFilter.cs | 2 +- .../IOpenIddictServerProvider.cs | 2 +- .../OpenIddictServerHandler.cs | 8 +- .../OpenIddictServerHandlerDescriptor.cs | 2 +- .../OpenIddictServerHandlerFilters.cs | 48 ++--- ...OpenIddictServerHandlers.Authentication.cs | 170 +++++++++--------- .../OpenIddictServerHandlers.Discovery.cs | 110 ++++++------ .../OpenIddictServerHandlers.Exchange.cs | 168 ++++++++--------- .../OpenIddictServerHandlers.Serialization.cs | 66 +++---- .../OpenIddictServerHandlers.Session.cs | 51 +++--- .../OpenIddictServerHandlers.cs | 46 ++--- .../OpenIddictServerProvider.cs | 4 +- 30 files changed, 601 insertions(+), 602 deletions(-) diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlerFilters.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlerFilters.cs index 8cda8b75..6eeaa7d2 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlerFilters.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlerFilters.cs @@ -31,14 +31,14 @@ namespace OpenIddict.Server.AspNetCore public RequireAuthorizationEndpointPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableAuthorizationEndpointPassthrough); + return new ValueTask(_options.CurrentValue.EnableAuthorizationEndpointPassthrough); } } @@ -52,14 +52,14 @@ namespace OpenIddict.Server.AspNetCore public RequireErrorPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableErrorPassthrough); + return new ValueTask(_options.CurrentValue.EnableErrorPassthrough); } } @@ -68,14 +68,14 @@ namespace OpenIddict.Server.AspNetCore /// public class RequireHttpRequest : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(context.Transaction.GetHttpRequest() != null); + return new ValueTask(context.Transaction.GetHttpRequest() != null); } } /// @@ -89,14 +89,14 @@ namespace OpenIddict.Server.AspNetCore public RequireLogoutEndpointPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableLogoutEndpointPassthrough); + return new ValueTask(_options.CurrentValue.EnableLogoutEndpointPassthrough); } } @@ -110,14 +110,14 @@ namespace OpenIddict.Server.AspNetCore public RequireTransportSecurityRequirementEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(!_options.CurrentValue.DisableTransportSecurityRequirement); + return new ValueTask(!_options.CurrentValue.DisableTransportSecurityRequirement); } } @@ -131,14 +131,14 @@ namespace OpenIddict.Server.AspNetCore public RequireRequestCachingEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableRequestCaching); + return new ValueTask(_options.CurrentValue.EnableRequestCaching); } } @@ -152,14 +152,14 @@ namespace OpenIddict.Server.AspNetCore public RequireStatusCodePagesIntegrationEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableStatusCodePagesIntegration); + return new ValueTask(_options.CurrentValue.EnableStatusCodePagesIntegration); } } @@ -174,14 +174,14 @@ namespace OpenIddict.Server.AspNetCore public RequireTokenEndpointPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableTokenEndpointPassthrough); + return new ValueTask(_options.CurrentValue.EnableTokenEndpointPassthrough); } } @@ -196,14 +196,14 @@ namespace OpenIddict.Server.AspNetCore public RequireUserinfoEndpointPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableUserinfoEndpointPassthrough); + return new ValueTask(_options.CurrentValue.EnableUserinfoEndpointPassthrough); } } } diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Authentication.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Authentication.cs index 53a60987..a1f2fc90 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Authentication.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Authentication.cs @@ -93,9 +93,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ExtractAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ExtractAuthorizationRequestContext context) { if (context == null) { @@ -180,9 +180,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ExtractAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ExtractAuthorizationRequestContext context) { if (context == null) { @@ -261,9 +261,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleAuthorizationRequestContext context) { if (context == null) { @@ -272,7 +272,7 @@ namespace OpenIddict.Server.AspNetCore context.SkipRequest(); - return Task.CompletedTask; + return default; } } @@ -310,9 +310,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -321,7 +321,7 @@ namespace OpenIddict.Server.AspNetCore if (string.IsNullOrEmpty(context.Request?.RequestId)) { - return Task.CompletedTask; + return default; } // Note: the ApplyAuthorizationResponse event is called for both successful @@ -330,7 +330,7 @@ namespace OpenIddict.Server.AspNetCore // Note: the cache key is always prefixed with a specific marker // to avoid collisions with the other types of cached payloads. - return _cache.RemoveAsync(Cache.AuthorizationRequest + context.Request.RequestId); + return new ValueTask(_cache.RemoveAsync(Cache.AuthorizationRequest + context.Request.RequestId)); } } @@ -360,9 +360,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public async ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -454,9 +454,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -474,7 +474,7 @@ namespace OpenIddict.Server.AspNetCore if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.Query, StringComparison.Ordinal)) { - return Task.CompletedTask; + return default; } context.Logger.LogInformation("The authorization response was successfully returned to " + @@ -494,7 +494,7 @@ namespace OpenIddict.Server.AspNetCore response.Redirect(location); context.HandleRequest(); - return Task.CompletedTask; + return default; } } @@ -519,9 +519,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -539,7 +539,7 @@ namespace OpenIddict.Server.AspNetCore if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.Fragment, StringComparison.Ordinal)) { - return Task.CompletedTask; + return default; } context.Logger.LogInformation("The authorization response was successfully returned to " + @@ -562,7 +562,7 @@ namespace OpenIddict.Server.AspNetCore response.Redirect(builder.ToString()); context.HandleRequest(); - return Task.CompletedTask; + return default; static bool Contains(StringBuilder builder, char delimiter) { @@ -603,9 +603,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -622,7 +622,7 @@ namespace OpenIddict.Server.AspNetCore if (string.IsNullOrEmpty(context.Response.Error) || !string.IsNullOrEmpty(context.RedirectUri)) { - return Task.CompletedTask; + return default; } // Apply a 400 status code by default. @@ -630,7 +630,7 @@ namespace OpenIddict.Server.AspNetCore context.SkipRequest(); - return Task.CompletedTask; + return default; } } @@ -656,9 +656,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -680,7 +680,7 @@ namespace OpenIddict.Server.AspNetCore if (string.IsNullOrEmpty(context.Error) || !string.IsNullOrEmpty(context.RedirectUri)) { - return Task.CompletedTask; + return default; } // Determine if the status code pages middleware has been enabled for this request. @@ -689,7 +689,7 @@ namespace OpenIddict.Server.AspNetCore var feature = response.HttpContext.Features.Get(); if (feature == null || !feature.Enabled) { - return Task.CompletedTask; + return default; } // Replace the default status code to return a 400 response. @@ -700,7 +700,7 @@ namespace OpenIddict.Server.AspNetCore // to rewrite the response using the logic defined by the developer when registering it. context.HandleRequest(); - return Task.CompletedTask; + return default; } } @@ -725,9 +725,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public async ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Discovery.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Discovery.cs index 98d53d7d..21e719ba 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Discovery.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Discovery.cs @@ -66,9 +66,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -100,7 +100,7 @@ namespace OpenIddict.Server.AspNetCore context.Issuer = issuer; } - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Exchange.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Exchange.cs index 14d312e8..693e962f 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Exchange.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Exchange.cs @@ -56,9 +56,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleTokenRequestContext context) + public ValueTask HandleAsync([NotNull] HandleTokenRequestContext context) { if (context == null) { @@ -75,7 +75,7 @@ namespace OpenIddict.Server.AspNetCore context.SkipRequest(); - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Serialization.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Serialization.cs index d72a1190..60f8a7e5 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Serialization.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Serialization.cs @@ -59,9 +59,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -93,7 +93,7 @@ namespace OpenIddict.Server.AspNetCore context.Issuer = issuer; } - return Task.CompletedTask; + return default; } } @@ -119,9 +119,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -153,7 +153,7 @@ namespace OpenIddict.Server.AspNetCore context.TokenValidationParameters.ValidIssuer = issuer.AbsoluteUri; } - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs index efcdf6a4..18913a36 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs @@ -91,9 +91,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ExtractLogoutRequestContext context) + public async ValueTask HandleAsync([NotNull] ExtractLogoutRequestContext context) { if (context == null) { @@ -178,9 +178,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ExtractLogoutRequestContext context) + public async ValueTask HandleAsync([NotNull] ExtractLogoutRequestContext context) { if (context == null) { @@ -259,9 +259,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleLogoutRequestContext context) + public ValueTask HandleAsync([NotNull] HandleLogoutRequestContext context) { if (context == null) { @@ -270,7 +270,7 @@ namespace OpenIddict.Server.AspNetCore context.SkipRequest(); - return Task.CompletedTask; + return default; } } @@ -308,9 +308,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -319,7 +319,7 @@ namespace OpenIddict.Server.AspNetCore if (string.IsNullOrEmpty(context.Request?.RequestId)) { - return Task.CompletedTask; + return default; } // Note: the ApplyLogoutResponse event is called for both successful @@ -328,7 +328,7 @@ namespace OpenIddict.Server.AspNetCore // Note: the cache key is always prefixed with a specific marker // to avoid collisions with the other types of cached payloads. - return _cache.RemoveAsync(Cache.LogoutRequest + context.Request.RequestId); + return new ValueTask(_cache.RemoveAsync(Cache.LogoutRequest + context.Request.RequestId)); } } @@ -353,9 +353,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -372,13 +372,13 @@ namespace OpenIddict.Server.AspNetCore if (!string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { - return Task.CompletedTask; + return default; } context.Logger.LogInformation("The logout response was successfully returned: {Response}.", response); context.HandleRequest(); - return Task.CompletedTask; + return default; } } @@ -403,9 +403,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -422,7 +422,7 @@ namespace OpenIddict.Server.AspNetCore if (string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { - return Task.CompletedTask; + return default; } context.Logger.LogInformation("The logout response was successfully returned to '{PostLogoutRedirectUri}': {Response}.", @@ -441,7 +441,7 @@ namespace OpenIddict.Server.AspNetCore response.Redirect(location); context.HandleRequest(); - return Task.CompletedTask; + return default; } } @@ -469,9 +469,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -488,7 +488,7 @@ namespace OpenIddict.Server.AspNetCore if (string.IsNullOrEmpty(context.Response.Error) || !string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { - return Task.CompletedTask; + return default; } // Apply a 400 status code by default. @@ -496,7 +496,7 @@ namespace OpenIddict.Server.AspNetCore context.SkipRequest(); - return Task.CompletedTask; + return default; } } @@ -522,9 +522,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -546,7 +546,7 @@ namespace OpenIddict.Server.AspNetCore if (string.IsNullOrEmpty(context.Error) || !string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { - return Task.CompletedTask; + return default; } // Determine if the status code pages middleware has been enabled for this request. @@ -555,7 +555,7 @@ namespace OpenIddict.Server.AspNetCore var feature = response.HttpContext.Features.Get(); if (feature == null || !feature.Enabled) { - return Task.CompletedTask; + return default; } // Replace the default status code to return a 400 response. @@ -566,7 +566,7 @@ namespace OpenIddict.Server.AspNetCore // to rewrite the response using the logic defined by the developer when registering it. context.HandleRequest(); - return Task.CompletedTask; + return default; } } @@ -591,9 +591,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public async ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs index 689154de..9e013b7b 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs @@ -61,9 +61,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessRequestContext context) + public ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -89,7 +89,7 @@ namespace OpenIddict.Server.AspNetCore Matches(context.Options.UserinfoEndpointUris) ? OpenIddictServerEndpointType.Userinfo : OpenIddictServerEndpointType.Unknown; - return Task.CompletedTask; + return default; bool Matches(IList addresses) { @@ -154,9 +154,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessRequestContext context) + public ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -174,7 +174,7 @@ namespace OpenIddict.Server.AspNetCore // Don't require that the host be present if the request is not handled by OpenIddict. if (context.EndpointType == OpenIddictServerEndpointType.Unknown) { - return Task.CompletedTask; + return default; } // Reject authorization requests sent without transport security. @@ -184,10 +184,10 @@ namespace OpenIddict.Server.AspNetCore error: Errors.InvalidRequest, description: "This server only accepts HTTPS requests."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -212,9 +212,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessRequestContext context) + public ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -233,7 +233,7 @@ namespace OpenIddict.Server.AspNetCore // by an OpenIddict endpoint or if an explicit issuer URL was set in the options. if (context.Options.Issuer != null || context.EndpointType == OpenIddictServerEndpointType.Unknown) { - return Task.CompletedTask; + return default; } if (!request.Host.HasValue) @@ -242,10 +242,10 @@ namespace OpenIddict.Server.AspNetCore error: Errors.InvalidRequest, description: "The mandatory 'Host' header is missing."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -270,9 +270,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -301,10 +301,10 @@ namespace OpenIddict.Server.AspNetCore error: Errors.InvalidRequest, description: "The specified HTTP method is not valid."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -329,9 +329,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -416,9 +416,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -499,9 +499,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -519,7 +519,7 @@ namespace OpenIddict.Server.AspNetCore string header = request.Headers[HeaderNames.Authorization]; if (string.IsNullOrEmpty(header) || !header.StartsWith("Basic ", StringComparison.OrdinalIgnoreCase)) { - return Task.CompletedTask; + return default; } // At this point, reject requests that use multiple client authentication methods. @@ -532,7 +532,7 @@ namespace OpenIddict.Server.AspNetCore error: Errors.InvalidRequest, description: "Multiple client credentials cannot be specified."); - return Task.CompletedTask; + return default; } try @@ -547,14 +547,14 @@ namespace OpenIddict.Server.AspNetCore error: Errors.InvalidRequest, description: "The specified client credentials are invalid."); - return Task.CompletedTask; + return default; } // Attach the basic authentication credentials to the request message. context.Request.ClientId = UnescapeDataString(data.Substring(0, index)); context.Request.ClientSecret = UnescapeDataString(data.Substring(index + 1)); - return Task.CompletedTask; + return default; } catch @@ -563,7 +563,7 @@ namespace OpenIddict.Server.AspNetCore error: Errors.InvalidRequest, description: "The specified client credentials are invalid."); - return Task.CompletedTask; + return default; } static string UnescapeDataString(string data) @@ -599,9 +599,9 @@ namespace OpenIddict.Server.AspNetCore /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlerFilters.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlerFilters.cs index 688e29b0..fcbfb278 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlerFilters.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlerFilters.cs @@ -29,14 +29,14 @@ namespace OpenIddict.Server.DataProtection public RequirePreferDataProtectionFormatEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.PreferDataProtectionFormat); + return new ValueTask(_options.CurrentValue.PreferDataProtectionFormat); } } } diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Serialization.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Serialization.cs index 11365ccc..8d5ea736 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Serialization.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Serialization.cs @@ -89,9 +89,9 @@ namespace OpenIddict.Server.DataProtection /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -145,7 +145,7 @@ namespace OpenIddict.Server.DataProtection context.Token = Base64UrlEncoder.Encode(protector.Protect(buffer.ToArray())); context.HandleSerialization(); - return Task.CompletedTask; + return default; // Note: the following local methods closely matches the logic used by ASP.NET Core's // authentication stack and MUST NOT be modified to ensure tokens encrypted using @@ -297,9 +297,9 @@ namespace OpenIddict.Server.DataProtection /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -323,7 +323,7 @@ namespace OpenIddict.Server.DataProtection var (principal, properties) = Read(reader, version: 5); if (principal == null) { - return Task.CompletedTask; + return default; } context.Principal = principal; @@ -349,14 +349,14 @@ namespace OpenIddict.Server.DataProtection context.HandleDeserialization(); - return Task.CompletedTask; + return default; } catch (Exception exception) { context.Logger.LogTrace(exception, "An exception occured while deserializing a token."); - return Task.CompletedTask; + return default; } static (ClaimsPrincipal principal, ImmutableDictionary properties) Read(BinaryReader reader, int version) @@ -508,9 +508,9 @@ namespace OpenIddict.Server.DataProtection /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] SerializeAccessTokenContext context) + public ValueTask HandleAsync([NotNull] SerializeAccessTokenContext context) { if (context == null) { @@ -534,7 +534,7 @@ namespace OpenIddict.Server.DataProtection var protector = _options.CurrentValue.DataProtectionProvider.CreateProtector(purposes); context.Properties[typeof(IDataProtector).FullName] = protector; - return Task.CompletedTask; + return default; } } @@ -562,9 +562,9 @@ namespace OpenIddict.Server.DataProtection /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] SerializeAuthorizationCodeContext context) + public ValueTask HandleAsync([NotNull] SerializeAuthorizationCodeContext context) { if (context == null) { @@ -588,7 +588,7 @@ namespace OpenIddict.Server.DataProtection var protector = _options.CurrentValue.DataProtectionProvider.CreateProtector(purposes); context.Properties[typeof(IDataProtector).FullName] = protector; - return Task.CompletedTask; + return default; } } @@ -616,9 +616,9 @@ namespace OpenIddict.Server.DataProtection /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] SerializeRefreshTokenContext context) + public ValueTask HandleAsync([NotNull] SerializeRefreshTokenContext context) { if (context == null) { @@ -642,7 +642,7 @@ namespace OpenIddict.Server.DataProtection var protector = _options.CurrentValue.DataProtectionProvider.CreateProtector(purposes); context.Properties[typeof(IDataProtector).FullName] = protector; - return Task.CompletedTask; + return default; } } @@ -670,9 +670,9 @@ namespace OpenIddict.Server.DataProtection /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] DeserializeAccessTokenContext context) + public ValueTask HandleAsync([NotNull] DeserializeAccessTokenContext context) { if (context == null) { @@ -696,7 +696,7 @@ namespace OpenIddict.Server.DataProtection var protector = _options.CurrentValue.DataProtectionProvider.CreateProtector(purposes); context.Properties[typeof(IDataProtector).FullName] = protector; - return Task.CompletedTask; + return default; } } @@ -724,9 +724,9 @@ namespace OpenIddict.Server.DataProtection /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] DeserializeAuthorizationCodeContext context) + public ValueTask HandleAsync([NotNull] DeserializeAuthorizationCodeContext context) { if (context == null) { @@ -750,7 +750,7 @@ namespace OpenIddict.Server.DataProtection var protector = _options.CurrentValue.DataProtectionProvider.CreateProtector(purposes); context.Properties[typeof(IDataProtector).FullName] = protector; - return Task.CompletedTask; + return default; } } @@ -778,9 +778,9 @@ namespace OpenIddict.Server.DataProtection /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] DeserializeRefreshTokenContext context) + public ValueTask HandleAsync([NotNull] DeserializeRefreshTokenContext context) { if (context == null) { @@ -804,7 +804,7 @@ namespace OpenIddict.Server.DataProtection var protector = _options.CurrentValue.DataProtectionProvider.CreateProtector(purposes); context.Properties[typeof(IDataProtector).FullName] = protector; - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlerFilters.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlerFilters.cs index efcbc96f..79844258 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlerFilters.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlerFilters.cs @@ -29,14 +29,14 @@ namespace OpenIddict.Server.Owin public RequireAuthorizationEndpointPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableAuthorizationEndpointPassthrough); + return new ValueTask(_options.CurrentValue.EnableAuthorizationEndpointPassthrough); } } @@ -50,14 +50,14 @@ namespace OpenIddict.Server.Owin public RequireErrorPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableErrorPassthrough); + return new ValueTask(_options.CurrentValue.EnableErrorPassthrough); } } @@ -72,14 +72,14 @@ namespace OpenIddict.Server.Owin public RequireLogoutEndpointPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableLogoutEndpointPassthrough); + return new ValueTask(_options.CurrentValue.EnableLogoutEndpointPassthrough); } } @@ -88,14 +88,14 @@ namespace OpenIddict.Server.Owin /// public class RequireOwinRequest : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(context.Transaction.GetOwinRequest() != null); + return new ValueTask(context.Transaction.GetOwinRequest() != null); } } @@ -109,14 +109,14 @@ namespace OpenIddict.Server.Owin public RequireTransportSecurityRequirementEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(!_options.CurrentValue.DisableTransportSecurityRequirement); + return new ValueTask(!_options.CurrentValue.DisableTransportSecurityRequirement); } } @@ -130,14 +130,14 @@ namespace OpenIddict.Server.Owin public RequireRequestCachingEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableRequestCaching); + return new ValueTask(_options.CurrentValue.EnableRequestCaching); } } @@ -152,14 +152,14 @@ namespace OpenIddict.Server.Owin public RequireTokenEndpointPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableTokenEndpointPassthrough); + return new ValueTask(_options.CurrentValue.EnableTokenEndpointPassthrough); } } @@ -174,14 +174,14 @@ namespace OpenIddict.Server.Owin public RequireUserinfoEndpointPassthroughEnabled([NotNull] IOptionsMonitor options) => _options = options; - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(_options.CurrentValue.EnableUserinfoEndpointPassthrough); + return new ValueTask(_options.CurrentValue.EnableUserinfoEndpointPassthrough); } } } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Authentication.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Authentication.cs index 2bff3200..8197f584 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Authentication.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Authentication.cs @@ -90,9 +90,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ExtractAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ExtractAuthorizationRequestContext context) { if (context == null) { @@ -177,9 +177,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ExtractAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ExtractAuthorizationRequestContext context) { if (context == null) { @@ -258,9 +258,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleAuthorizationRequestContext context) { if (context == null) { @@ -269,7 +269,7 @@ namespace OpenIddict.Server.Owin context.SkipRequest(); - return Task.CompletedTask; + return default; } } @@ -307,9 +307,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -318,7 +318,7 @@ namespace OpenIddict.Server.Owin if (string.IsNullOrEmpty(context.Request?.RequestId)) { - return Task.CompletedTask; + return default; } // Note: the ApplyAuthorizationResponse event is called for both successful @@ -327,7 +327,7 @@ namespace OpenIddict.Server.Owin // Note: the cache key is always prefixed with a specific marker // to avoid collisions with the other types of cached payloads. - return _cache.RemoveAsync(Cache.AuthorizationRequest + context.Request.RequestId); + return new ValueTask(_cache.RemoveAsync(Cache.AuthorizationRequest + context.Request.RequestId)); } } @@ -357,9 +357,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public async ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -452,9 +452,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -472,7 +472,7 @@ namespace OpenIddict.Server.Owin if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.Query, StringComparison.Ordinal)) { - return Task.CompletedTask; + return default; } context.Logger.LogInformation("The authorization response was successfully returned to " + @@ -492,7 +492,7 @@ namespace OpenIddict.Server.Owin response.Redirect(location); context.HandleRequest(); - return Task.CompletedTask; + return default; } } @@ -517,9 +517,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -537,7 +537,7 @@ namespace OpenIddict.Server.Owin if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.Fragment, StringComparison.Ordinal)) { - return Task.CompletedTask; + return default; } context.Logger.LogInformation("The authorization response was successfully returned to " + @@ -560,7 +560,7 @@ namespace OpenIddict.Server.Owin response.Redirect(builder.ToString()); context.HandleRequest(); - return Task.CompletedTask; + return default; static bool Contains(StringBuilder builder, char delimiter) { @@ -601,9 +601,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -620,7 +620,7 @@ namespace OpenIddict.Server.Owin if (string.IsNullOrEmpty(context.Response.Error) || !string.IsNullOrEmpty(context.RedirectUri)) { - return Task.CompletedTask; + return default; } // Don't return the state originally sent by the client application. @@ -631,7 +631,7 @@ namespace OpenIddict.Server.Owin context.SkipRequest(); - return Task.CompletedTask; + return default; } } @@ -656,9 +656,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public async ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Discovery.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Discovery.cs index 4d4ffd9a..2bc77a3e 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Discovery.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Discovery.cs @@ -66,9 +66,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -100,7 +100,7 @@ namespace OpenIddict.Server.Owin context.Issuer = issuer; } - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Exchange.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Exchange.cs index 90e68b35..701df971 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Exchange.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Exchange.cs @@ -55,9 +55,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleTokenRequestContext context) + public ValueTask HandleAsync([NotNull] HandleTokenRequestContext context) { if (context == null) { @@ -66,7 +66,7 @@ namespace OpenIddict.Server.Owin context.SkipRequest(); - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Serialization.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Serialization.cs index 2f055193..ca628f18 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Serialization.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Serialization.cs @@ -59,9 +59,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -93,7 +93,7 @@ namespace OpenIddict.Server.Owin context.Issuer = issuer; } - return Task.CompletedTask; + return default; } } @@ -119,9 +119,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -153,7 +153,7 @@ namespace OpenIddict.Server.Owin context.TokenValidationParameters.ValidIssuer = issuer.AbsoluteUri; } - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs index 7a6d1606..7a6e865e 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs @@ -88,9 +88,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ExtractLogoutRequestContext context) + public async ValueTask HandleAsync([NotNull] ExtractLogoutRequestContext context) { if (context == null) { @@ -175,9 +175,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ExtractLogoutRequestContext context) + public async ValueTask HandleAsync([NotNull] ExtractLogoutRequestContext context) { if (context == null) { @@ -257,9 +257,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleLogoutRequestContext context) + public ValueTask HandleAsync([NotNull] HandleLogoutRequestContext context) { if (context == null) { @@ -268,7 +268,7 @@ namespace OpenIddict.Server.Owin context.SkipRequest(); - return Task.CompletedTask; + return default; } } @@ -306,9 +306,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -317,7 +317,7 @@ namespace OpenIddict.Server.Owin if (string.IsNullOrEmpty(context.Request?.RequestId)) { - return Task.CompletedTask; + return default; } // Note: the ApplyLogoutResponse event is called for both successful @@ -326,7 +326,7 @@ namespace OpenIddict.Server.Owin // Note: the cache key is always prefixed with a specific marker // to avoid collisions with the other types of cached payloads. - return _cache.RemoveAsync(Cache.LogoutRequest + context.Request.RequestId); + return new ValueTask(_cache.RemoveAsync(Cache.LogoutRequest + context.Request.RequestId)); } } @@ -351,9 +351,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -370,13 +370,13 @@ namespace OpenIddict.Server.Owin if (!string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { - return Task.CompletedTask; + return default; } context.Logger.LogInformation("The logout response was successfully returned: {Response}.", response); context.HandleRequest(); - return Task.CompletedTask; + return default; } } @@ -401,9 +401,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -420,7 +420,7 @@ namespace OpenIddict.Server.Owin if (string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { - return Task.CompletedTask; + return default; } context.Logger.LogInformation("The logout response was successfully returned to '{PostLogoutRedirectUri}': {Response}.", @@ -439,7 +439,7 @@ namespace OpenIddict.Server.Owin response.Redirect(location); context.HandleRequest(); - return Task.CompletedTask; + return default; } } @@ -467,9 +467,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -486,7 +486,7 @@ namespace OpenIddict.Server.Owin if (string.IsNullOrEmpty(context.Response.Error) || !string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { - return Task.CompletedTask; + return default; } // Apply a 400 status code by default. @@ -494,7 +494,7 @@ namespace OpenIddict.Server.Owin context.SkipRequest(); - return Task.CompletedTask; + return default; } } @@ -519,9 +519,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public async ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs index dcbe2709..4dfd1390 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs @@ -62,9 +62,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessRequestContext context) + public ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -90,7 +90,7 @@ namespace OpenIddict.Server.Owin Matches(context.Options.UserinfoEndpointUris) ? OpenIddictServerEndpointType.Userinfo : OpenIddictServerEndpointType.Unknown; - return Task.CompletedTask; + return default; bool Matches(IList addresses) { @@ -155,9 +155,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessRequestContext context) + public ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -175,7 +175,7 @@ namespace OpenIddict.Server.Owin // Don't require that the host be present if the request is not handled by OpenIddict. if (context.EndpointType == OpenIddictServerEndpointType.Unknown) { - return Task.CompletedTask; + return default; } // Reject authorization requests sent without transport security. @@ -185,10 +185,10 @@ namespace OpenIddict.Server.Owin error: Errors.InvalidRequest, description: "This server only accepts HTTPS requests."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -213,9 +213,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessRequestContext context) + public ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -234,7 +234,7 @@ namespace OpenIddict.Server.Owin // by an OpenIddict endpoint or if an explicit issuer URL was set in the options. if (context.Options.Issuer != null || context.EndpointType == OpenIddictServerEndpointType.Unknown) { - return Task.CompletedTask; + return default; } if (string.IsNullOrEmpty(request.Host.Value)) @@ -243,10 +243,10 @@ namespace OpenIddict.Server.Owin error: Errors.InvalidRequest, description: "The mandatory 'Host' header is missing."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -271,9 +271,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -302,10 +302,10 @@ namespace OpenIddict.Server.Owin error: Errors.InvalidRequest, description: "The specified HTTP method is not valid."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -330,9 +330,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -417,9 +417,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -500,9 +500,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -520,7 +520,7 @@ namespace OpenIddict.Server.Owin var header = request.Headers["Authorization"]; if (string.IsNullOrEmpty(header) || !header.StartsWith("Basic ", StringComparison.OrdinalIgnoreCase)) { - return Task.CompletedTask; + return default; } // At this point, reject requests that use multiple client authentication methods. @@ -533,7 +533,7 @@ namespace OpenIddict.Server.Owin error: Errors.InvalidRequest, description: "Multiple client credentials cannot be specified."); - return Task.CompletedTask; + return default; } try @@ -548,14 +548,14 @@ namespace OpenIddict.Server.Owin error: Errors.InvalidRequest, description: "The specified client credentials are invalid."); - return Task.CompletedTask; + return default; } // Attach the basic authentication credentials to the request message. context.Request.ClientId = UnescapeDataString(data.Substring(0, index)); context.Request.ClientSecret = UnescapeDataString(data.Substring(index + 1)); - return Task.CompletedTask; + return default; } catch @@ -564,7 +564,7 @@ namespace OpenIddict.Server.Owin error: Errors.InvalidRequest, description: "The specified client credentials are invalid."); - return Task.CompletedTask; + return default; } static string UnescapeDataString(string data) @@ -600,9 +600,9 @@ namespace OpenIddict.Server.Owin /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs index 124bf2bc..4c7245e7 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs @@ -37,7 +37,7 @@ namespace OpenIddict.Server.Owin /// /// The . /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// public override Task Invoke([NotNull] IOwinContext context) { diff --git a/src/OpenIddict.Server/IOpenIddictServerHandler.cs b/src/OpenIddict.Server/IOpenIddictServerHandler.cs index af9caaab..fc12c5b4 100644 --- a/src/OpenIddict.Server/IOpenIddictServerHandler.cs +++ b/src/OpenIddict.Server/IOpenIddictServerHandler.cs @@ -21,8 +21,8 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - Task HandleAsync([NotNull] TContext context); + ValueTask HandleAsync([NotNull] TContext context); } } diff --git a/src/OpenIddict.Server/IOpenIddictServerHandlerFilter.cs b/src/OpenIddict.Server/IOpenIddictServerHandlerFilter.cs index 03958d31..4bc3be6a 100644 --- a/src/OpenIddict.Server/IOpenIddictServerHandlerFilter.cs +++ b/src/OpenIddict.Server/IOpenIddictServerHandlerFilter.cs @@ -12,6 +12,6 @@ namespace OpenIddict.Server { public interface IOpenIddictServerHandlerFilter where TContext : BaseContext { - Task IsActiveAsync([NotNull] TContext context); + ValueTask IsActiveAsync([NotNull] TContext context); } } diff --git a/src/OpenIddict.Server/IOpenIddictServerProvider.cs b/src/OpenIddict.Server/IOpenIddictServerProvider.cs index 1d5428e2..91051a8c 100644 --- a/src/OpenIddict.Server/IOpenIddictServerProvider.cs +++ b/src/OpenIddict.Server/IOpenIddictServerProvider.cs @@ -13,6 +13,6 @@ namespace OpenIddict.Server public interface IOpenIddictServerProvider { ValueTask CreateTransactionAsync(); - Task DispatchAsync([NotNull] TContext context) where TContext : BaseContext; + ValueTask DispatchAsync([NotNull] TContext context) where TContext : BaseContext; } } \ No newline at end of file diff --git a/src/OpenIddict.Server/OpenIddictServerHandler.cs b/src/OpenIddict.Server/OpenIddictServerHandler.cs index bdbf53a4..8f7cdc82 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandler.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandler.cs @@ -17,13 +17,13 @@ namespace OpenIddict.Server /// The type of the events handled by this instance. public class OpenIddictServerHandler : IOpenIddictServerHandler where TContext : BaseContext { - private readonly Func _handler; + private readonly Func _handler; /// /// Creates a new event using the specified handler delegate. /// /// The event handler delegate. - public OpenIddictServerHandler([NotNull] Func handler) + public OpenIddictServerHandler([NotNull] Func handler) => _handler = handler ?? throw new ArgumentNullException(nameof(handler)); /// @@ -31,9 +31,9 @@ namespace OpenIddict.Server /// /// The event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) => _handler(context ?? throw new ArgumentNullException(nameof(context))); } } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs b/src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs index 588aa4bd..a2bc58e7 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs @@ -136,7 +136,7 @@ namespace OpenIddict.Server /// /// The handler instance. /// The builder instance, so that calls can be easily chained. - public Builder UseInlineHandler([NotNull] Func handler) + public Builder UseInlineHandler([NotNull] Func handler) { if (handler == null) { diff --git a/src/OpenIddict.Server/OpenIddictServerHandlerFilters.cs b/src/OpenIddict.Server/OpenIddictServerHandlerFilters.cs index 0c759c28..bf97ea81 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlerFilters.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlerFilters.cs @@ -20,14 +20,14 @@ namespace OpenIddict.Server /// public class RequireAccessTokenIncluded : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] ProcessSigninResponseContext context) + public ValueTask IsActiveAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(context.IncludeAccessToken); + return new ValueTask(context.IncludeAccessToken); } } @@ -36,14 +36,14 @@ namespace OpenIddict.Server /// public class RequireAuthorizationCodeIncluded : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] ProcessSigninResponseContext context) + public ValueTask IsActiveAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(context.IncludeAuthorizationCode); + return new ValueTask(context.IncludeAuthorizationCode); } } @@ -52,14 +52,14 @@ namespace OpenIddict.Server /// public class RequireClientIdParameter : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(!string.IsNullOrEmpty(context.Request.ClientId)); + return new ValueTask(!string.IsNullOrEmpty(context.Request.ClientId)); } } @@ -68,14 +68,14 @@ namespace OpenIddict.Server /// public class RequireDegradedModeDisabled : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(!context.Options.EnableDegradedMode); + return new ValueTask(!context.Options.EnableDegradedMode); } } @@ -84,14 +84,14 @@ namespace OpenIddict.Server /// public class RequireDegradedModeEnabled : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(context.Options.EnableDegradedMode); + return new ValueTask(context.Options.EnableDegradedMode); } } @@ -100,14 +100,14 @@ namespace OpenIddict.Server /// public class RequireEndpointPermissionsEnabled : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(!context.Options.IgnoreEndpointPermissions); + return new ValueTask(!context.Options.IgnoreEndpointPermissions); } } @@ -116,14 +116,14 @@ namespace OpenIddict.Server /// public class RequireGrantTypePermissionsEnabled : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(!context.Options.IgnoreGrantTypePermissions); + return new ValueTask(!context.Options.IgnoreGrantTypePermissions); } } @@ -132,14 +132,14 @@ namespace OpenIddict.Server /// public class RequireIdentityTokenIncluded : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] ProcessSigninResponseContext context) + public ValueTask IsActiveAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(context.IncludeIdentityToken); + return new ValueTask(context.IncludeIdentityToken); } } @@ -148,14 +148,14 @@ namespace OpenIddict.Server /// public class RequirePostLogoutRedirectUriParameter : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(!string.IsNullOrEmpty(context.Request.PostLogoutRedirectUri)); + return new ValueTask(!string.IsNullOrEmpty(context.Request.PostLogoutRedirectUri)); } } @@ -164,14 +164,14 @@ namespace OpenIddict.Server /// public class RequireRefreshTokenIncluded : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] ProcessSigninResponseContext context) + public ValueTask IsActiveAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(context.IncludeRefreshToken); + return new ValueTask(context.IncludeRefreshToken); } } @@ -180,14 +180,14 @@ namespace OpenIddict.Server /// public class RequireScopePermissionsEnabled : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(!context.Options.IgnoreScopePermissions); + return new ValueTask(!context.Options.IgnoreScopePermissions); } } @@ -196,14 +196,14 @@ namespace OpenIddict.Server /// public class RequireScopeValidationEnabled : IOpenIddictServerHandlerFilter { - public Task IsActiveAsync([NotNull] BaseContext context) + public ValueTask IsActiveAsync([NotNull] BaseContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - return Task.FromResult(!context.Options.DisableScopeValidation); + return new ValueTask(!context.Options.DisableScopeValidation); } } } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs index de1d067c..19b77319 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs @@ -84,9 +84,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -159,9 +159,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -233,9 +233,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -327,9 +327,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -377,9 +377,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -396,10 +396,10 @@ namespace OpenIddict.Server error: Errors.RequestNotSupported, description: "The 'request' parameter is not supported."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -422,9 +422,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -441,10 +441,10 @@ namespace OpenIddict.Server error: Errors.RequestUriNotSupported, description: "The 'request_uri' parameter is not supported."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -467,9 +467,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -487,10 +487,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'client_id' parameter is missing."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -513,9 +513,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -538,10 +538,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'redirect_uri' parameter is missing."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } // Note: when specified, redirect_uri MUST be an absolute URI. @@ -561,7 +561,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The 'redirect_uri' parameter must be a valid absolute URL."); - return Task.CompletedTask; + return default; } // Note: when specified, redirect_uri MUST NOT include a fragment component. @@ -576,10 +576,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The 'redirect_uri' parameter must not include a fragment."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -602,9 +602,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -621,7 +621,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'response_type' parameter is missing."); - return Task.CompletedTask; + return default; } // Reject requests containing the id_token response_type if no openid scope has been received. @@ -633,7 +633,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'openid' scope is missing."); - return Task.CompletedTask; + return default; } // Reject requests containing the code response_type if the token endpoint has been disabled. @@ -645,7 +645,7 @@ namespace OpenIddict.Server error: Errors.UnsupportedResponseType, description: "The specified 'response_type' is not supported by this server."); - return Task.CompletedTask; + return default; } // Reject requests that specify an unsupported response_type. @@ -658,7 +658,7 @@ namespace OpenIddict.Server error: Errors.UnsupportedResponseType, description: "The specified 'response_type' parameter is not supported."); - return Task.CompletedTask; + return default; } // Reject code flow authorization requests if the authorization code flow is not enabled. @@ -671,7 +671,7 @@ namespace OpenIddict.Server error: Errors.UnsupportedResponseType, description: "The specified 'response_type' parameter is not allowed."); - return Task.CompletedTask; + return default; } // Reject implicit flow authorization requests if the implicit flow is not enabled. @@ -683,7 +683,7 @@ namespace OpenIddict.Server error: Errors.UnsupportedResponseType, description: "The specified 'response_type' parameter is not allowed."); - return Task.CompletedTask; + return default; } // Reject hybrid flow authorization requests if the authorization code or the implicit flows are not enabled. @@ -697,7 +697,7 @@ namespace OpenIddict.Server error: Errors.UnsupportedResponseType, description: "The specified 'response_type' parameter is not allowed."); - return Task.CompletedTask; + return default; } // Reject authorization requests that specify scope=offline_access if the refresh token flow is not enabled. @@ -707,10 +707,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The 'offline_access' scope is not allowed."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -733,9 +733,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -756,7 +756,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The specified 'response_type'/'response_mode' combination is invalid."); - return Task.CompletedTask; + return default; } // Reject requests that specify an unsupported response_mode. @@ -771,10 +771,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The specified 'response_mode' parameter is not supported."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -797,9 +797,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -813,7 +813,7 @@ namespace OpenIddict.Server if (!string.IsNullOrEmpty(context.Request.Nonce) || !context.Request.HasScope(Scopes.OpenId)) { - return Task.CompletedTask; + return default; } if (context.Request.IsImplicitFlow() || context.Request.IsHybridFlow()) @@ -824,10 +824,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'nonce' parameter is missing."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -850,9 +850,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -870,10 +870,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The specified 'prompt' parameter is invalid."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -896,9 +896,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -908,7 +908,7 @@ namespace OpenIddict.Server if (string.IsNullOrEmpty(context.Request.CodeChallenge) && string.IsNullOrEmpty(context.Request.CodeChallengeMethod)) { - return Task.CompletedTask; + return default; } // Ensure a code_challenge was specified if a code_challenge_method was used. @@ -920,7 +920,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The 'code_challenge_method' parameter cannot be used without 'code_challenge'."); - return Task.CompletedTask; + return default; } // When code_challenge or code_challenge_method is specified, ensure the response_type includes "code". @@ -934,7 +934,7 @@ namespace OpenIddict.Server description: "The 'code_challenge' and 'code_challenge_method' parameters " + "can only be used with a response type containing 'code'."); - return Task.CompletedTask; + return default; } // Reject authorization requests that contain response_type=token when a code_challenge is specified. @@ -947,7 +947,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The specified 'response_type' parameter is not allowed when using PKCE."); - return Task.CompletedTask; + return default; } // If a code_challenge_method was specified, ensure the algorithm is supported. @@ -962,10 +962,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The specified code_challenge_method is not supported'."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -1004,9 +1004,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -1072,9 +1072,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -1131,9 +1131,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -1198,9 +1198,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -1263,9 +1263,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -1328,9 +1328,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -1438,9 +1438,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateAuthorizationRequestContext context) { if (context == null) { @@ -1498,9 +1498,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -1509,7 +1509,7 @@ namespace OpenIddict.Server if (context.Request == null) { - return Task.CompletedTask; + return default; } // Note: at this stage, the validated redirect URI property may be null (e.g if an error @@ -1519,7 +1519,7 @@ namespace OpenIddict.Server context.RedirectUri = (string) property; } - return Task.CompletedTask; + return default; } } @@ -1543,9 +1543,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -1554,7 +1554,7 @@ namespace OpenIddict.Server if (context.Request == null) { - return Task.CompletedTask; + return default; } context.ResponseMode = context.Request.ResponseMode; @@ -1567,7 +1567,7 @@ namespace OpenIddict.Server context.Request.IsQueryResponseMode() ? ResponseModes.Query : null; } - return Task.CompletedTask; + return default; } } @@ -1590,9 +1590,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyAuthorizationResponseContext context) { if (context == null) { @@ -1605,7 +1605,7 @@ namespace OpenIddict.Server context.Response.State = context.Request?.State; } - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs index 5589bf08..b7254f25 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs @@ -91,9 +91,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -166,9 +166,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -232,9 +232,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -326,9 +326,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -376,9 +376,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -390,7 +390,7 @@ namespace OpenIddict.Server context.Issuer = context.Options.Issuer; } - return Task.CompletedTask; + return default; } } @@ -413,9 +413,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -505,7 +505,7 @@ namespace OpenIddict.Server context.UserinfoEndpoint = new Uri(context.Issuer, context.UserinfoEndpoint); } - return Task.CompletedTask; + return default; } } @@ -528,9 +528,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -543,7 +543,7 @@ namespace OpenIddict.Server context.GrantTypes.UnionWith(context.Options.GrantTypes); } - return Task.CompletedTask; + return default; } } @@ -566,9 +566,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -583,7 +583,7 @@ namespace OpenIddict.Server context.ResponseModes.Add(ResponseModes.Query); } - return Task.CompletedTask; + return default; } } @@ -606,9 +606,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -635,7 +635,7 @@ namespace OpenIddict.Server context.ResponseTypes.Add(ResponseTypes.Token); } - return Task.CompletedTask; + return default; } } @@ -659,9 +659,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -686,7 +686,7 @@ namespace OpenIddict.Server context.TokenEndpointAuthenticationMethods.Add(ClientAuthenticationMethods.ClientSecretPost); } - return Task.CompletedTask; + return default; } } @@ -710,9 +710,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -728,7 +728,7 @@ namespace OpenIddict.Server context.CodeChallengeMethods.Add(CodeChallengeMethods.Sha256); } - return Task.CompletedTask; + return default; } } @@ -751,9 +751,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -762,7 +762,7 @@ namespace OpenIddict.Server context.Scopes.UnionWith(context.Options.Scopes); - return Task.CompletedTask; + return default; } } @@ -785,9 +785,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -796,7 +796,7 @@ namespace OpenIddict.Server context.Claims.UnionWith(context.Options.Claims); - return Task.CompletedTask; + return default; } } @@ -819,9 +819,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -830,7 +830,7 @@ namespace OpenIddict.Server context.SubjectTypes.Add(SubjectTypes.Public); - return Task.CompletedTask; + return default; } } @@ -853,9 +853,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -914,7 +914,7 @@ namespace OpenIddict.Server context.IdTokenSigningAlgorithms.Add(algorithm); } - return Task.CompletedTask; + return default; } } @@ -937,9 +937,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleConfigurationRequestContext context) + public ValueTask HandleAsync([NotNull] HandleConfigurationRequestContext context) { if (context == null) { @@ -952,7 +952,7 @@ namespace OpenIddict.Server context.Metadata[Metadata.RequestParameterSupported] = false; context.Metadata[Metadata.RequestUriParameterSupported] = false; - return Task.CompletedTask; + return default; } } @@ -980,9 +980,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -1055,9 +1055,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -1121,9 +1121,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -1247,9 +1247,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -1297,9 +1297,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleCryptographyRequestContext context) + public ValueTask HandleAsync([NotNull] HandleCryptographyRequestContext context) { if (context == null) { @@ -1465,7 +1465,7 @@ namespace OpenIddict.Server context.Keys.Add(key); } - return Task.CompletedTask; + return default; static bool IsAlgorithmSupported(SecurityKey key, string algorithm) => key.CryptoProviderFactory.IsSupportedAlgorithm(algorithm, key); diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs index 10394f8a..1669d443 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs @@ -89,9 +89,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -164,9 +164,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -233,9 +233,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -327,9 +327,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -377,9 +377,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -395,7 +395,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'grant_type' parameter is missing."); - return Task.CompletedTask; + return default; } // Reject token requests that don't specify a supported grant type. @@ -408,7 +408,7 @@ namespace OpenIddict.Server error: Errors.UnsupportedGrantType, description: "The specified 'grant_type' parameter is not supported."); - return Task.CompletedTask; + return default; } // Reject token requests that specify scope=offline_access if the refresh token flow is not enabled. @@ -419,10 +419,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The 'offline_access' scope is not allowed."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -446,9 +446,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -457,7 +457,7 @@ namespace OpenIddict.Server if (!string.IsNullOrEmpty(context.ClientId)) { - return Task.CompletedTask; + return default; } // At this stage, reject the token request unless the client identification requirement was disabled. @@ -473,10 +473,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'client_id' parameter is missing."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -500,9 +500,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -519,10 +519,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'code' parameter is missing."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -546,9 +546,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -565,10 +565,10 @@ namespace OpenIddict.Server description: "The 'client_id' and 'client_secret' parameters are " + "required when using the client credentials grant."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -592,9 +592,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -611,10 +611,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'refresh_token' parameter is missing."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -638,9 +638,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -658,10 +658,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'username' and/or 'password' parameters are missing."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -700,9 +700,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -769,9 +769,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -831,9 +831,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -927,9 +927,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -995,9 +995,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -1062,9 +1062,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -1144,9 +1144,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -1212,9 +1212,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -1294,9 +1294,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -1372,9 +1372,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -1383,7 +1383,7 @@ namespace OpenIddict.Server if (!context.Request.IsAuthorizationCodeGrantType() && !context.Request.IsRefreshTokenGrantType()) { - return Task.CompletedTask; + return default; } var presenters = context.Principal.GetPresenters(); @@ -1396,7 +1396,7 @@ namespace OpenIddict.Server throw new InvalidOperationException("The presenters list cannot be extracted from the authorization code."); } - return Task.CompletedTask; + return default; } // If at least one presenter was associated to the authorization code/refresh token, @@ -1413,7 +1413,7 @@ namespace OpenIddict.Server "The specified authorization code cannot be used without specifying a client identifier." : "The specified refresh token cannot be used without specifying a client identifier."); - return Task.CompletedTask; + return default; } // Ensure the authorization code/refresh token was issued to the client application making the token request. @@ -1431,10 +1431,10 @@ namespace OpenIddict.Server "The specified authorization code cannot be used by this client application." : "The specified refresh token cannot be used by this client application."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -1457,9 +1457,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -1468,7 +1468,7 @@ namespace OpenIddict.Server if (!context.Request.IsAuthorizationCodeGrantType()) { - return Task.CompletedTask; + return default; } // Validate the redirect_uri sent by the client application as part of this token request. @@ -1481,7 +1481,7 @@ namespace OpenIddict.Server var address = context.Principal.GetClaim(Claims.Private.OriginalRedirectUri); if (string.IsNullOrEmpty(address)) { - return Task.CompletedTask; + return default; } if (string.IsNullOrEmpty(context.Request.RedirectUri)) @@ -1493,7 +1493,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'redirect_uri' parameter is missing."); - return Task.CompletedTask; + return default; } if (!string.Equals(address, context.Request.RedirectUri, StringComparison.Ordinal)) @@ -1506,10 +1506,10 @@ namespace OpenIddict.Server description: "The specified 'redirect_uri' parameter doesn't match the client " + "redirection endpoint the authorization code was initially sent to."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -1532,9 +1532,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -1543,7 +1543,7 @@ namespace OpenIddict.Server if (!context.Request.IsAuthorizationCodeGrantType()) { - return Task.CompletedTask; + return default; } // If a code challenge was initially sent in the authorization request and associated with the @@ -1551,7 +1551,7 @@ namespace OpenIddict.Server var challenge = context.Principal.GetClaim(Claims.Private.CodeChallenge); if (string.IsNullOrEmpty(challenge)) { - return Task.CompletedTask; + return default; } // Get the code verifier from the token request. @@ -1565,7 +1565,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The mandatory 'code_verifier' parameter is missing."); - return Task.CompletedTask; + return default; } // If no code challenge method was specified, default to S256. @@ -1597,7 +1597,7 @@ namespace OpenIddict.Server error: Errors.InvalidGrant, description: "The specified 'code_challenge_method' is invalid."); - return Task.CompletedTask; + return default; } // Compare the verifier and the code challenge: if the two don't match, return an error. @@ -1610,10 +1610,10 @@ namespace OpenIddict.Server error: Errors.InvalidGrant, description: "The specified 'code_verifier' parameter is invalid."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] @@ -1659,7 +1659,7 @@ namespace OpenIddict.Server .SetOrder(ValidateCodeVerifier.Descriptor.Order + 1_000) .Build(); - public Task HandleAsync([NotNull] ValidateTokenRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateTokenRequestContext context) { if (context == null) { @@ -1668,7 +1668,7 @@ namespace OpenIddict.Server if (!context.Request.IsAuthorizationCodeGrantType() || string.IsNullOrEmpty(context.Request.Scope)) { - return Task.CompletedTask; + return default; } // When an explicit scope parameter has been included in the token request @@ -1683,7 +1683,7 @@ namespace OpenIddict.Server error: Errors.InvalidGrant, description: "The 'scope' parameter is not valid in this context."); - return Task.CompletedTask; + return default; } // When an explicit scope parameter has been included in the token request, @@ -1698,10 +1698,10 @@ namespace OpenIddict.Server error: Errors.InvalidGrant, description: "The specified 'scope' parameter is invalid."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -1725,9 +1725,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] HandleTokenRequestContext context) + public ValueTask HandleAsync([NotNull] HandleTokenRequestContext context) { if (context == null) { @@ -1736,7 +1736,7 @@ namespace OpenIddict.Server if (!context.Request.IsAuthorizationCodeGrantType() && !context.Request.IsRefreshTokenGrantType()) { - return Task.CompletedTask; + return default; } if (context.Transaction.Properties.TryGetValue(Properties.OriginalPrincipal, out var principal)) @@ -1744,7 +1744,7 @@ namespace OpenIddict.Server context.Principal ??= (ClaimsPrincipal) principal; } - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Serialization.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Serialization.cs index 9e263a27..547bea7f 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Serialization.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Serialization.cs @@ -95,9 +95,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -178,7 +178,7 @@ namespace OpenIddict.Server context.HandleSerialization(); - return Task.CompletedTask; + return default; } } @@ -201,9 +201,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] TContext context) + public ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -214,7 +214,7 @@ namespace OpenIddict.Server { context.Logger.LogTrace("The token '{Token}' was not compatible with the JWT format.", context.Token); - return Task.CompletedTask; + return default; } try @@ -241,7 +241,7 @@ namespace OpenIddict.Server context.Logger.LogDebug("The token usage associated to the token {Token} does not match the expected type."); context.HandleDeserialization(); - return Task.CompletedTask; + return default; } context.Principal = new ClaimsPrincipal(result.ClaimsIdentity); @@ -260,7 +260,7 @@ namespace OpenIddict.Server context.HandleDeserialization(); - return Task.CompletedTask; + return default; } catch (Exception exception) @@ -268,7 +268,7 @@ namespace OpenIddict.Server context.Logger.LogDebug(exception, "An exception occured while deserializing a token."); context.HandleDeserialization(); - return Task.CompletedTask; + return default; } } } @@ -292,9 +292,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] SerializeAccessTokenContext context) + public ValueTask HandleAsync([NotNull] SerializeAccessTokenContext context) { if (context == null) { @@ -313,7 +313,7 @@ namespace OpenIddict.Server context.SigningCredentials = context.Options.SigningCredentials.FirstOrDefault( credentials => credentials.Key is SymmetricSecurityKey) ?? context.Options.SigningCredentials.First(); - return Task.CompletedTask; + return default; } } @@ -336,9 +336,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] SerializeAuthorizationCodeContext context) + public ValueTask HandleAsync([NotNull] SerializeAuthorizationCodeContext context) { if (context == null) { @@ -361,7 +361,7 @@ namespace OpenIddict.Server context.SigningCredentials = context.Options.SigningCredentials.FirstOrDefault( credentials => credentials.Key is SymmetricSecurityKey) ?? context.Options.SigningCredentials.First(); - return Task.CompletedTask; + return default; } } @@ -384,9 +384,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] SerializeIdentityTokenContext context) + public ValueTask HandleAsync([NotNull] SerializeIdentityTokenContext context) { if (context == null) { @@ -403,7 +403,7 @@ namespace OpenIddict.Server context.SigningCredentials = context.Options.SigningCredentials.First( credentials => credentials.Key is AsymmetricSecurityKey); - return Task.CompletedTask; + return default; } } @@ -426,9 +426,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] SerializeRefreshTokenContext context) + public ValueTask HandleAsync([NotNull] SerializeRefreshTokenContext context) { if (context == null) { @@ -451,7 +451,7 @@ namespace OpenIddict.Server context.SigningCredentials = context.Options.SigningCredentials.FirstOrDefault( credentials => credentials.Key is SymmetricSecurityKey) ?? context.Options.SigningCredentials.First(); - return Task.CompletedTask; + return default; } } @@ -474,9 +474,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] DeserializeAccessTokenContext context) + public ValueTask HandleAsync([NotNull] DeserializeAccessTokenContext context) { if (context == null) { @@ -496,7 +496,7 @@ namespace OpenIddict.Server context.TokenValidationParameters.ValidateAudience = false; context.TokenValidationParameters.ValidateLifetime = false; - return Task.CompletedTask; + return default; } } @@ -519,9 +519,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] DeserializeAuthorizationCodeContext context) + public ValueTask HandleAsync([NotNull] DeserializeAuthorizationCodeContext context) { if (context == null) { @@ -540,7 +540,7 @@ namespace OpenIddict.Server context.TokenValidationParameters.ValidateAudience = false; context.TokenValidationParameters.ValidateLifetime = false; - return Task.CompletedTask; + return default; } } @@ -563,9 +563,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] DeserializeIdentityTokenContext context) + public ValueTask HandleAsync([NotNull] DeserializeIdentityTokenContext context) { if (context == null) { @@ -583,7 +583,7 @@ namespace OpenIddict.Server context.TokenValidationParameters.ValidateAudience = false; context.TokenValidationParameters.ValidateLifetime = false; - return Task.CompletedTask; + return default; } } @@ -606,9 +606,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] DeserializeRefreshTokenContext context) + public ValueTask HandleAsync([NotNull] DeserializeRefreshTokenContext context) { if (context == null) { @@ -627,7 +627,7 @@ namespace OpenIddict.Server context.TokenValidationParameters.ValidateAudience = false; context.TokenValidationParameters.ValidateLifetime = false; - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs index 96408ce0..4a8a8b3e 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs @@ -68,9 +68,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -143,9 +143,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -215,9 +215,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessRequestContext context) + public async ValueTask HandleAsync([NotNull] ProcessRequestContext context) { if (context == null) { @@ -308,9 +308,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] TContext context) + public async ValueTask HandleAsync([NotNull] TContext context) { if (context == null) { @@ -358,9 +358,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ValidateLogoutRequestContext context) + public ValueTask HandleAsync([NotNull] ValidateLogoutRequestContext context) { if (context == null) { @@ -369,12 +369,11 @@ namespace OpenIddict.Server if (string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { - return Task.CompletedTask; + return default; } // If an optional post_logout_redirect_uri was provided, validate it. - if (!Uri.TryCreate(context.PostLogoutRedirectUri, UriKind.Absolute, out Uri uri) || - !uri.IsWellFormedOriginalString()) + if (!Uri.TryCreate(context.PostLogoutRedirectUri, UriKind.Absolute, out Uri uri) || !uri.IsWellFormedOriginalString()) { context.Logger.LogError("The logout request was rejected because the specified post_logout_redirect_uri " + "was not a valid absolute URL: {PostLogoutRedirectUri}.", context.PostLogoutRedirectUri); @@ -383,7 +382,7 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The 'post_logout_redirect_uri' parameter must be a valid absolute URL."); - return Task.CompletedTask; + return default; } if (!string.IsNullOrEmpty(uri.Fragment)) @@ -395,10 +394,10 @@ namespace OpenIddict.Server error: Errors.InvalidRequest, description: "The 'post_logout_redirect_uri' parameter must not include a fragment."); - return Task.CompletedTask; + return default; } - return Task.CompletedTask; + return default; } } @@ -437,9 +436,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ValidateLogoutRequestContext context) + public async ValueTask HandleAsync([NotNull] ValidateLogoutRequestContext context) { if (context == null) { @@ -458,7 +457,7 @@ namespace OpenIddict.Server return; } - async Task ValidatePostLogoutRedirectUriAsync(string address) + async ValueTask ValidatePostLogoutRedirectUriAsync(string address) { // To be considered valid, a post_logout_redirect_uri must correspond to an existing client application // that was granted the ept:logout permission, unless endpoint permissions checking was explicitly disabled. @@ -507,9 +506,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -518,7 +517,7 @@ namespace OpenIddict.Server if (context.Request == null) { - return Task.CompletedTask; + return default; } // Note: at this stage, the validated redirect URI property may be null (e.g if an error @@ -528,7 +527,7 @@ namespace OpenIddict.Server context.PostLogoutRedirectUri = (string) property; } - return Task.CompletedTask; + return default; } } @@ -551,9 +550,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ApplyLogoutResponseContext context) + public ValueTask HandleAsync([NotNull] ApplyLogoutResponseContext context) { if (context == null) { @@ -566,7 +565,7 @@ namespace OpenIddict.Server context.Response.State = context.Request?.State; } - return Task.CompletedTask; + return default; } } } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.cs index d421a619..afea9787 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.cs @@ -67,9 +67,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessChallengeResponseContext context) + public ValueTask HandleAsync([NotNull] ProcessChallengeResponseContext context) { if (context == null) { @@ -98,7 +98,7 @@ namespace OpenIddict.Server }; } - return Task.CompletedTask; + return default; } } @@ -122,9 +122,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessSigninResponseContext context) + public ValueTask HandleAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { @@ -156,7 +156,7 @@ namespace OpenIddict.Server .ToString()); } - return Task.CompletedTask; + return default; } } @@ -179,9 +179,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessSigninResponseContext context) + public ValueTask HandleAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { @@ -196,7 +196,7 @@ namespace OpenIddict.Server context.Principal.SetScopes(Scopes.OpenId); } - return Task.CompletedTask; + return default; } } @@ -219,9 +219,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessSigninResponseContext context) + public ValueTask HandleAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { @@ -235,7 +235,7 @@ namespace OpenIddict.Server context.Principal.SetPresenters(context.ClientId); } - return Task.CompletedTask; + return default; } } @@ -258,9 +258,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public Task HandleAsync([NotNull] ProcessSigninResponseContext context) + public ValueTask HandleAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { @@ -321,7 +321,7 @@ namespace OpenIddict.Server _ => false }; - return Task.CompletedTask; + return default; } } @@ -350,9 +350,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessSigninResponseContext context) + public async ValueTask HandleAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { @@ -476,9 +476,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessSigninResponseContext context) + public async ValueTask HandleAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { @@ -566,9 +566,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessSigninResponseContext context) + public async ValueTask HandleAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { @@ -630,9 +630,9 @@ namespace OpenIddict.Server /// /// The context associated with the event to process. /// - /// A that can be used to monitor the asynchronous operation. + /// A that can be used to monitor the asynchronous operation. /// - public async Task HandleAsync([NotNull] ProcessSigninResponseContext context) + public async ValueTask HandleAsync([NotNull] ProcessSigninResponseContext context) { if (context == null) { diff --git a/src/OpenIddict.Server/OpenIddictServerProvider.cs b/src/OpenIddict.Server/OpenIddictServerProvider.cs index af720c92..857c9a64 100644 --- a/src/OpenIddict.Server/OpenIddictServerProvider.cs +++ b/src/OpenIddict.Server/OpenIddictServerProvider.cs @@ -42,7 +42,7 @@ namespace OpenIddict.Server Options = _options.CurrentValue }); - public async Task DispatchAsync([NotNull] TContext context) where TContext : BaseContext + public async ValueTask DispatchAsync([NotNull] TContext context) where TContext : BaseContext { if (context == null) { @@ -116,7 +116,7 @@ namespace OpenIddict.Server } } - async Task IsActiveAsync(OpenIddictServerHandlerDescriptor descriptor) + async ValueTask IsActiveAsync(OpenIddictServerHandlerDescriptor descriptor) { for (var index = 0; index < descriptor.FilterTypes.Length; index++) {