diff --git a/global.json b/global.json index b4907433..6a633705 100644 --- a/global.json +++ b/global.json @@ -1,16 +1,17 @@ { "sdk": { - "version": "6.0.100" + "version": "7.0.100-preview.2.22153.17" }, "tools": { - "dotnet": "6.0.100", + "dotnet": "7.0.100-preview.2.22153.17", "runtimes": { "aspnetcore": [ "2.1.28", "3.1.16", - "5.0.7" + "5.0.7", + "6.0.0" ] } }, diff --git a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Helpers/AsyncEnumerableExtensions.cs b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Helpers/AsyncEnumerableExtensions.cs index 946d35e7..ac379075 100644 --- a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Helpers/AsyncEnumerableExtensions.cs +++ b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Helpers/AsyncEnumerableExtensions.cs @@ -2,13 +2,8 @@ public static class AsyncEnumerableExtensions { - public static Task> ToListAsync(this IAsyncEnumerable source) + public static Task> ToListAsync(this IAsyncEnumerable source!!) { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - return ExecuteAsync(); async Task> ExecuteAsync() diff --git a/shared/OpenIddict.Extensions/Helpers/OpenIddictHelpers.cs b/shared/OpenIddict.Extensions/Helpers/OpenIddictHelpers.cs index d3aa75ab..45ea2888 100644 --- a/shared/OpenIddict.Extensions/Helpers/OpenIddictHelpers.cs +++ b/shared/OpenIddict.Extensions/Helpers/OpenIddictHelpers.cs @@ -20,18 +20,8 @@ internal static class OpenIddictHelpers /// The type to introspect. /// The generic type definition. /// A instance if the base type was found, null otherwise. - public static IEnumerable FindGenericBaseTypes(Type type, Type definition) + public static IEnumerable FindGenericBaseTypes(Type type!!, Type definition!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - - if (definition is null) - { - throw new ArgumentNullException(nameof(definition)); - } - if (!definition.IsGenericTypeDefinition) { throw new ArgumentException(SR.GetResourceString(SR.ID0263), nameof(definition)); diff --git a/src/OpenIddict.Abstractions/OpenIddictBuilder.cs b/src/OpenIddict.Abstractions/OpenIddictBuilder.cs index 2cb4ec12..e726618c 100644 --- a/src/OpenIddict.Abstractions/OpenIddictBuilder.cs +++ b/src/OpenIddict.Abstractions/OpenIddictBuilder.cs @@ -17,8 +17,8 @@ public class OpenIddictBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. diff --git a/src/OpenIddict.Abstractions/OpenIddictExtensions.cs b/src/OpenIddict.Abstractions/OpenIddictExtensions.cs index 1d30e8c3..25025c78 100644 --- a/src/OpenIddict.Abstractions/OpenIddictExtensions.cs +++ b/src/OpenIddict.Abstractions/OpenIddictExtensions.cs @@ -17,15 +17,8 @@ public static class OpenIddictExtensions /// The services collection. /// This extension can be safely called multiple times. /// The . - public static OpenIddictBuilder AddOpenIddict(this IServiceCollection services) - { - if (services is null) - { - throw new ArgumentNullException(nameof(services)); - } - - return new OpenIddictBuilder(services); - } + public static OpenIddictBuilder AddOpenIddict(this IServiceCollection services!!) + => new OpenIddictBuilder(services); /// /// Provides a common entry point for registering the OpenIddict services. @@ -34,18 +27,8 @@ public static class OpenIddictExtensions /// The configuration delegate used to register new services. /// This extension can be safely called multiple times. /// The . - public static IServiceCollection AddOpenIddict(this IServiceCollection services, Action configuration) + public static IServiceCollection AddOpenIddict(this IServiceCollection services!!, Action configuration!!) { - if (services is null) - { - throw new ArgumentNullException(nameof(services)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(services.AddOpenIddict()); return services; diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs index a89704b7..7a711d9f 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs +++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs @@ -19,13 +19,8 @@ public class OpenIddictConverter : JsonConverter /// /// The type to convert. /// true if the type is supported, false otherwise. - public override bool CanConvert(Type typeToConvert) + public override bool CanConvert(Type typeToConvert!!) { - if (typeToConvert is null) - { - throw new ArgumentNullException(nameof(typeToConvert)); - } - return typeToConvert == typeof(OpenIddictMessage) || typeToConvert == typeof(OpenIddictRequest) || typeToConvert == typeof(OpenIddictResponse); @@ -38,13 +33,8 @@ public class OpenIddictConverter : JsonConverter /// The type of the deserialized instance. /// The JSON serializer options. /// The deserialized instance. - public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type typeToConvert!!, JsonSerializerOptions options) { - if (typeToConvert is null) - { - throw new ArgumentNullException(nameof(typeToConvert)); - } - using var document = JsonDocument.ParseValue(ref reader); return typeToConvert == typeof(OpenIddictMessage) ? new OpenIddictMessage(document.RootElement.Clone()) : @@ -59,18 +49,8 @@ public class OpenIddictConverter : JsonConverter /// The JSON writer. /// The instance. /// The JSON serializer options. - public override void Write(Utf8JsonWriter writer, OpenIddictMessage value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer!!, OpenIddictMessage value!!, JsonSerializerOptions options) { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - - if (value is null) - { - throw new ArgumentNullException(nameof(value)); - } - value.WriteTo(writer); } } diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs index f4407188..d82b59a6 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs +++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs @@ -25,70 +25,37 @@ public static class OpenIddictExtensions /// Extracts the authentication context class values from an . /// /// The instance. - public static ImmutableArray GetAcrValues(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return GetValues(request.AcrValues, Separators.Space); - } + public static ImmutableArray GetAcrValues(this OpenIddictRequest request!!) + => GetValues(request.AcrValues, Separators.Space); /// /// Extracts the prompt values from an . /// /// The instance. - public static ImmutableArray GetPrompts(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return GetValues(request.Prompt, Separators.Space); - } + public static ImmutableArray GetPrompts(this OpenIddictRequest request!!) + => GetValues(request.Prompt, Separators.Space); /// /// Extracts the response types from an . /// /// The instance. - public static ImmutableArray GetResponseTypes(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return GetValues(request.ResponseType, Separators.Space); - } + public static ImmutableArray GetResponseTypes(this OpenIddictRequest request!!) + => GetValues(request.ResponseType, Separators.Space); /// /// Extracts the scopes from an . /// /// The instance. - public static ImmutableArray GetScopes(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return GetValues(request.Scope, Separators.Space); - } + public static ImmutableArray GetScopes(this OpenIddictRequest request!!) + => GetValues(request.Scope, Separators.Space); /// /// Determines whether the requested authentication context class values contain the specified item. /// /// The instance. /// The component to look for in the parameter. - public static bool HasAcrValue(this OpenIddictRequest request, string value) + public static bool HasAcrValue(this OpenIddictRequest request!!, string value) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(value)) { throw new ArgumentException(SR.GetResourceString(SR.ID0177), nameof(value)); @@ -102,13 +69,8 @@ public static class OpenIddictExtensions /// /// The instance. /// The component to look for in the parameter. - public static bool HasPrompt(this OpenIddictRequest request, string prompt) + public static bool HasPrompt(this OpenIddictRequest request!!, string prompt) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(prompt)) { throw new ArgumentException(SR.GetResourceString(SR.ID0178), nameof(prompt)); @@ -122,13 +84,8 @@ public static class OpenIddictExtensions /// /// The instance. /// The component to look for in the parameter. - public static bool HasResponseType(this OpenIddictRequest request, string type) + public static bool HasResponseType(this OpenIddictRequest request!!, string type) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0179), nameof(type)); @@ -142,13 +99,8 @@ public static class OpenIddictExtensions /// /// The instance. /// The component to look for in the parameter. - public static bool HasScope(this OpenIddictRequest request, string scope) + public static bool HasScope(this OpenIddictRequest request!!, string scope) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(scope)) { throw new ArgumentException(SR.GetResourceString(SR.ID0180), nameof(scope)); @@ -163,13 +115,8 @@ public static class OpenIddictExtensions /// /// The instance. /// true if the request is a response_type=none request, false otherwise. - public static bool IsNoneFlow(this OpenIddictRequest request) + public static bool IsNoneFlow(this OpenIddictRequest request!!) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(request.ResponseType)) { return false; @@ -190,13 +137,8 @@ public static class OpenIddictExtensions /// /// The instance. /// true if the request is a code flow request, false otherwise. - public static bool IsAuthorizationCodeFlow(this OpenIddictRequest request) + public static bool IsAuthorizationCodeFlow(this OpenIddictRequest request!!) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(request.ResponseType)) { return false; @@ -218,13 +160,8 @@ public static class OpenIddictExtensions /// /// The instance. /// true if the request is an implicit flow request, false otherwise. - public static bool IsImplicitFlow(this OpenIddictRequest request) + public static bool IsImplicitFlow(this OpenIddictRequest request!!) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(request.ResponseType)) { return false; @@ -272,13 +209,8 @@ public static class OpenIddictExtensions /// /// The instance. /// true if the request is an hybrid flow request, false otherwise. - public static bool IsHybridFlow(this OpenIddictRequest request) + public static bool IsHybridFlow(this OpenIddictRequest request!!) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(request.ResponseType)) { return false; @@ -339,13 +271,8 @@ public static class OpenIddictExtensions /// true if the request specified the fragment response mode or if /// it's the default value for the requested flow, false otherwise. /// - public static bool IsFragmentResponseMode(this OpenIddictRequest request) + public static bool IsFragmentResponseMode(this OpenIddictRequest request!!) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.Equals(request.ResponseMode, ResponseModes.Fragment, StringComparison.Ordinal)) { return true; @@ -372,13 +299,8 @@ public static class OpenIddictExtensions /// true if the request specified the query response mode or if /// it's the default value for the requested flow, false otherwise. /// - public static bool IsQueryResponseMode(this OpenIddictRequest request) + public static bool IsQueryResponseMode(this OpenIddictRequest request!!) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.Equals(request.ResponseMode, ResponseModes.Query, StringComparison.Ordinal)) { return true; @@ -404,15 +326,8 @@ public static class OpenIddictExtensions /// true if the request specified the form post response mode or if /// it's the default value for the requested flow, false otherwise. /// - public static bool IsFormPostResponseMode(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return string.Equals(request.ResponseMode, ResponseModes.FormPost, StringComparison.Ordinal); - } + public static bool IsFormPostResponseMode(this OpenIddictRequest request!!) + => string.Equals(request.ResponseMode, ResponseModes.FormPost, StringComparison.Ordinal); /// /// Determines whether the "grant_type" parameter corresponds to the authorization code grant. @@ -420,15 +335,8 @@ public static class OpenIddictExtensions /// /// The instance. /// true if the request is a code grant request, false otherwise. - public static bool IsAuthorizationCodeGrantType(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return string.Equals(request.GrantType, GrantTypes.AuthorizationCode, StringComparison.Ordinal); - } + public static bool IsAuthorizationCodeGrantType(this OpenIddictRequest request!!) + => string.Equals(request.GrantType, GrantTypes.AuthorizationCode, StringComparison.Ordinal); /// /// Determines whether the "grant_type" parameter corresponds to the client credentials grant. @@ -436,15 +344,8 @@ public static class OpenIddictExtensions /// /// The instance. /// true if the request is a client credentials grant request, false otherwise. - public static bool IsClientCredentialsGrantType(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return string.Equals(request.GrantType, GrantTypes.ClientCredentials, StringComparison.Ordinal); - } + public static bool IsClientCredentialsGrantType(this OpenIddictRequest request!!) + => string.Equals(request.GrantType, GrantTypes.ClientCredentials, StringComparison.Ordinal); /// /// Determines whether the "grant_type" parameter corresponds to the device code grant. @@ -452,15 +353,8 @@ public static class OpenIddictExtensions /// /// The instance. /// true if the request is a device code grant request, false otherwise. - public static bool IsDeviceCodeGrantType(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return string.Equals(request.GrantType, GrantTypes.DeviceCode, StringComparison.Ordinal); - } + public static bool IsDeviceCodeGrantType(this OpenIddictRequest request!!) + => string.Equals(request.GrantType, GrantTypes.DeviceCode, StringComparison.Ordinal); /// /// Determines whether the "grant_type" parameter corresponds to the password grant. @@ -468,15 +362,8 @@ public static class OpenIddictExtensions /// /// The instance. /// true if the request is a password grant request, false otherwise. - public static bool IsPasswordGrantType(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return string.Equals(request.GrantType, GrantTypes.Password, StringComparison.Ordinal); - } + public static bool IsPasswordGrantType(this OpenIddictRequest request!!) + => string.Equals(request.GrantType, GrantTypes.Password, StringComparison.Ordinal); /// /// Determines whether the "grant_type" parameter corresponds to the refresh token grant. @@ -484,28 +371,16 @@ public static class OpenIddictExtensions /// /// The instance. /// true if the request is a refresh token grant request, false otherwise. - public static bool IsRefreshTokenGrantType(this OpenIddictRequest request) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - return string.Equals(request.GrantType, GrantTypes.RefreshToken, StringComparison.Ordinal); - } + public static bool IsRefreshTokenGrantType(this OpenIddictRequest request!!) + => string.Equals(request.GrantType, GrantTypes.RefreshToken, StringComparison.Ordinal); /// /// Gets the destinations associated with a claim. /// /// The instance. /// The destinations associated with the claim. - public static ImmutableArray GetDestinations(this Claim claim) + public static ImmutableArray GetDestinations(this Claim claim!!) { - if (claim is null) - { - throw new ArgumentNullException(nameof(claim)); - } - claim.Properties.TryGetValue(Properties.Destinations, out string? destinations); if (string.IsNullOrEmpty(destinations)) @@ -535,13 +410,8 @@ public static class OpenIddictExtensions /// /// The instance. /// The required destination. - public static bool HasDestination(this Claim claim, string destination) + public static bool HasDestination(this Claim claim!!, string destination) { - if (claim is null) - { - throw new ArgumentNullException(nameof(claim)); - } - if (string.IsNullOrEmpty(destination)) { throw new ArgumentException(SR.GetResourceString(SR.ID0181), nameof(destination)); @@ -573,13 +443,8 @@ public static class OpenIddictExtensions /// /// The instance. /// The destinations. - public static Claim SetDestinations(this Claim claim, ImmutableArray destinations) + public static Claim SetDestinations(this Claim claim!!, ImmutableArray destinations) { - if (claim is null) - { - throw new ArgumentNullException(nameof(claim)); - } - if (destinations.IsDefaultOrEmpty) { claim.Properties.Remove(Properties.Destinations); @@ -587,7 +452,7 @@ public static class OpenIddictExtensions return claim; } - if (destinations.Any(destination => string.IsNullOrEmpty(destination))) + if (destinations.Any(string.IsNullOrEmpty)) { throw new ArgumentException(SR.GetResourceString(SR.ID0182), nameof(destinations)); } @@ -635,13 +500,8 @@ public static class OpenIddictExtensions /// /// The principal. /// The destinations, returned as a flattened dictionary. - public static ImmutableDictionary GetDestinations(this ClaimsPrincipal principal) + public static ImmutableDictionary GetDestinations(this ClaimsPrincipal principal!!) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - var builder = ImmutableDictionary.CreateBuilder(StringComparer.Ordinal); foreach (var group in principal.Claims.GroupBy(claim => claim.Type)) @@ -673,18 +533,8 @@ public static class OpenIddictExtensions /// The principal. /// The destinations, as a flattened dictionary. /// The principal. - public static ClaimsPrincipal SetDestinations(this ClaimsPrincipal principal, ImmutableDictionary destinations) + public static ClaimsPrincipal SetDestinations(this ClaimsPrincipal principal!!, ImmutableDictionary destinations!!) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - - if (destinations is null) - { - throw new ArgumentNullException(nameof(destinations)); - } - foreach (var destination in destinations) { foreach (var claim in principal.Claims.Where(claim => claim.Type == destination.Key)) @@ -704,18 +554,8 @@ public static class OpenIddictExtensions /// The delegate filtering the claims: return true /// to accept the claim, false to remove it. /// - public static ClaimsIdentity Clone(this ClaimsIdentity identity, Func filter) + public static ClaimsIdentity Clone(this ClaimsIdentity identity!!, Func filter!!) { - if (identity is null) - { - throw new ArgumentNullException(nameof(identity)); - } - - if (filter is null) - { - throw new ArgumentNullException(nameof(filter)); - } - var clone = identity.Clone(); // Note: make sure to call ToList() to avoid modifying @@ -744,18 +584,8 @@ public static class OpenIddictExtensions /// The delegate filtering the claims: return true /// to accept the claim, false to remove it. /// - public static ClaimsPrincipal Clone(this ClaimsPrincipal principal, Func filter) + public static ClaimsPrincipal Clone(this ClaimsPrincipal principal!!, Func filter!!) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - - if (filter is null) - { - throw new ArgumentNullException(nameof(filter)); - } - var clone = new ClaimsPrincipal(); foreach (var identity in principal.Identities) @@ -772,13 +602,8 @@ public static class OpenIddictExtensions /// The identity. /// The type associated with the claim. /// The value associated with the claim. - public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value) + public static ClaimsIdentity AddClaim(this ClaimsIdentity identity!!, string type, string value) { - if (identity is null) - { - throw new ArgumentNullException(nameof(identity)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -800,13 +625,8 @@ public static class OpenIddictExtensions /// The type associated with the claim. /// The value associated with the claim. /// The destinations associated with the claim. - public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value, ImmutableArray destinations) + public static ClaimsIdentity AddClaim(this ClaimsIdentity identity!!, string type, string value, ImmutableArray destinations) { - if (identity is null) - { - throw new ArgumentNullException(nameof(identity)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -837,13 +657,8 @@ public static class OpenIddictExtensions /// The identity. /// The type associated with the claim. /// The claim value. - public static string? GetClaim(this ClaimsIdentity identity, string type) + public static string? GetClaim(this ClaimsIdentity identity!!, string type) { - if (identity is null) - { - throw new ArgumentNullException(nameof(identity)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -858,13 +673,8 @@ public static class OpenIddictExtensions /// The principal. /// The type associated with the claim. /// The claim value. - public static string? GetClaim(this ClaimsPrincipal principal, string type) + public static string? GetClaim(this ClaimsPrincipal principal!!, string type) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -879,13 +689,8 @@ public static class OpenIddictExtensions /// The identity. /// The type associated with the claims. /// The claim values. - public static ImmutableArray GetClaims(this ClaimsIdentity identity, string type) + public static ImmutableArray GetClaims(this ClaimsIdentity identity!!, string type) { - if (identity is null) - { - throw new ArgumentNullException(nameof(identity)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -900,13 +705,8 @@ public static class OpenIddictExtensions /// The claims identity. /// The claim type. /// true if the identity contains at least one claim of the specified type. - public static bool HasClaim(this ClaimsIdentity identity, string type) + public static bool HasClaim(this ClaimsIdentity identity!!, string type) { - if (identity is null) - { - throw new ArgumentNullException(nameof(identity)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -921,13 +721,8 @@ public static class OpenIddictExtensions /// The principal. /// The type associated with the claims. /// The claim values. - public static ImmutableArray GetClaims(this ClaimsPrincipal principal, string type) + public static ImmutableArray GetClaims(this ClaimsPrincipal principal!!, string type) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -942,13 +737,8 @@ public static class OpenIddictExtensions /// The claims principal. /// The claim type. /// true if the principal contains at least one claim of the specified type. - public static bool HasClaim(this ClaimsPrincipal principal, string type) + public static bool HasClaim(this ClaimsPrincipal principal!!, string type) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -963,13 +753,8 @@ public static class OpenIddictExtensions /// The identity. /// The type associated with the claims. /// The claims identity. - public static ClaimsIdentity RemoveClaims(this ClaimsIdentity identity, string type) + public static ClaimsIdentity RemoveClaims(this ClaimsIdentity identity!!, string type) { - if (identity is null) - { - throw new ArgumentNullException(nameof(identity)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -989,13 +774,8 @@ public static class OpenIddictExtensions /// The principal. /// The type associated with the claims. /// The claims identity. - public static ClaimsPrincipal RemoveClaims(this ClaimsPrincipal principal, string type) + public static ClaimsPrincipal RemoveClaims(this ClaimsPrincipal principal!!, string type) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -1019,13 +799,8 @@ public static class OpenIddictExtensions /// The type associated with the claims. /// The claim value. /// The claims identity. - public static ClaimsIdentity SetClaims(this ClaimsIdentity identity, string type, string? value) + public static ClaimsIdentity SetClaims(this ClaimsIdentity identity!!, string type, string? value) { - if (identity is null) - { - throw new ArgumentNullException(nameof(identity)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -1048,13 +823,8 @@ public static class OpenIddictExtensions /// The type associated with the claims. /// The claim value. /// The claims identity. - public static ClaimsPrincipal SetClaim(this ClaimsPrincipal principal, string type, string? value) + public static ClaimsPrincipal SetClaim(this ClaimsPrincipal principal!!, string type, string? value) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (principal.Identity is not ClaimsIdentity identity) { throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal)); @@ -1082,13 +852,8 @@ public static class OpenIddictExtensions /// The type associated with the claims. /// The claim values. /// The claims identity. - public static ClaimsIdentity SetClaims(this ClaimsIdentity identity, string type, ImmutableArray values) + public static ClaimsIdentity SetClaims(this ClaimsIdentity identity!!, string type, ImmutableArray values) { - if (identity is null) - { - throw new ArgumentNullException(nameof(identity)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type)); @@ -1111,13 +876,8 @@ public static class OpenIddictExtensions /// The type associated with the claims. /// The claim values. /// The claims identity. - public static ClaimsPrincipal SetClaims(this ClaimsPrincipal principal, string type, ImmutableArray values) + public static ClaimsPrincipal SetClaims(this ClaimsPrincipal principal!!, string type, ImmutableArray values) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (principal.Identity is not ClaimsIdentity identity) { throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal)); @@ -1143,13 +903,8 @@ public static class OpenIddictExtensions /// /// The claims principal. /// The creation date or null if the claim cannot be found. - public static DateTimeOffset? GetCreationDate(this ClaimsPrincipal principal) + public static DateTimeOffset? GetCreationDate(this ClaimsPrincipal principal!!) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - var claim = principal.FindFirst(Claims.Private.CreationDate); if (claim is null) { @@ -1169,13 +924,8 @@ public static class OpenIddictExtensions /// /// The claims principal. /// The expiration date or null if the claim cannot be found. - public static DateTimeOffset? GetExpirationDate(this ClaimsPrincipal principal) + public static DateTimeOffset? GetExpirationDate(this ClaimsPrincipal principal!!) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - var claim = principal.FindFirst(Claims.Private.ExpirationDate); if (claim is null) { @@ -1308,13 +1058,8 @@ public static class OpenIddictExtensions /// The claims principal. /// The audience. /// true if the principal contains the given audience. - public static bool HasAudience(this ClaimsPrincipal principal, string audience) + public static bool HasAudience(this ClaimsPrincipal principal!!, string audience) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(audience)) { throw new ArgumentException(SR.GetResourceString(SR.ID0186), nameof(audience)); @@ -1329,13 +1074,8 @@ public static class OpenIddictExtensions /// The claims principal. /// The presenter. /// true if the principal contains the given presenter. - public static bool HasPresenter(this ClaimsPrincipal principal, string presenter) + public static bool HasPresenter(this ClaimsPrincipal principal!!, string presenter) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(presenter)) { throw new ArgumentException(SR.GetResourceString(SR.ID0187), nameof(presenter)); @@ -1350,13 +1090,8 @@ public static class OpenIddictExtensions /// The claims principal. /// The resource. /// true if the principal contains the given resource. - public static bool HasResource(this ClaimsPrincipal principal, string resource) + public static bool HasResource(this ClaimsPrincipal principal!!, string resource) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(resource)) { throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource)); @@ -1371,13 +1106,8 @@ public static class OpenIddictExtensions /// The claims principal. /// The scope. /// true if the principal contains the given scope. - public static bool HasScope(this ClaimsPrincipal principal, string scope) + public static bool HasScope(this ClaimsPrincipal principal!!, string scope) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(scope)) { throw new ArgumentException(SR.GetResourceString(SR.ID0180), nameof(scope)); @@ -1392,13 +1122,8 @@ public static class OpenIddictExtensions /// The claims principal. /// The token type. /// true if the token type matches the specified type. - public static bool HasTokenType(this ClaimsPrincipal principal, string type) + public static bool HasTokenType(this ClaimsPrincipal principal!!, string type) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0188), nameof(type)); @@ -1752,13 +1477,8 @@ public static class OpenIddictExtensions return false; } - private static TimeSpan? GetLifetime(ClaimsPrincipal principal, string type) + private static TimeSpan? GetLifetime(ClaimsPrincipal principal!!, string type) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - var value = principal.GetClaim(type); if (string.IsNullOrEmpty(value)) { diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs index 6a1f5573..6fb1f1e2 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs +++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs @@ -40,7 +40,7 @@ public class OpenIddictMessage /// Parameters with a null or empty key are always ignored. public OpenIddictMessage(JsonElement parameters) { - if (parameters.ValueKind != JsonValueKind.Object) + if (parameters.ValueKind is not JsonValueKind.Object) { throw new ArgumentException(SR.GetResourceString(SR.ID0189), nameof(parameters)); } @@ -69,13 +69,8 @@ public class OpenIddictMessage /// /// The message parameters. /// Parameters with a null or empty key are always ignored. - public OpenIddictMessage(IEnumerable> parameters) + public OpenIddictMessage(IEnumerable> parameters!!) { - if (parameters is null) - { - throw new ArgumentNullException(nameof(parameters)); - } - foreach (var parameter in parameters) { // Ignore parameters whose name is null or empty. @@ -93,13 +88,8 @@ public class OpenIddictMessage /// /// The message parameters. /// Parameters with a null or empty key are always ignored. - public OpenIddictMessage(IEnumerable> parameters) + public OpenIddictMessage(IEnumerable> parameters!!) { - if (parameters is null) - { - throw new ArgumentNullException(nameof(parameters)); - } - foreach (var parameter in parameters.GroupBy(parameter => parameter.Key)) { // Ignore parameters whose name is null or empty. @@ -128,13 +118,8 @@ public class OpenIddictMessage /// /// The message parameters. /// Parameters with a null or empty key are always ignored. - public OpenIddictMessage(IEnumerable> parameters) + public OpenIddictMessage(IEnumerable> parameters!!) { - if (parameters is null) - { - throw new ArgumentNullException(nameof(parameters)); - } - foreach (var parameter in parameters) { // Ignore parameters whose name is null or empty. @@ -161,13 +146,8 @@ public class OpenIddictMessage /// /// The message parameters. /// Parameters with a null or empty key are always ignored. - public OpenIddictMessage(IEnumerable> parameters) + public OpenIddictMessage(IEnumerable> parameters!!) { - if (parameters is null) - { - throw new ArgumentNullException(nameof(parameters)); - } - foreach (var parameter in parameters) { // Ignore parameters whose name is null or empty. @@ -387,13 +367,8 @@ public class OpenIddictMessage /// Writes the message to the specified JSON writer. /// /// The UTF-8 JSON writer. - public void WriteTo(Utf8JsonWriter writer) + public void WriteTo(Utf8JsonWriter writer!!) { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - writer.WriteStartObject(); foreach (var parameter in Parameters) diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs index 2f236f8a..b62c4e9b 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs +++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs @@ -151,24 +151,24 @@ public readonly struct OpenIddictParameter : IEquatable switch (left.ValueKind) { case JsonValueKind.Undefined: - return right.ValueKind == JsonValueKind.Undefined; + return right.ValueKind is JsonValueKind.Undefined; case JsonValueKind.Null: - return right.ValueKind == JsonValueKind.Null; + return right.ValueKind is JsonValueKind.Null; case JsonValueKind.False: - return right.ValueKind == JsonValueKind.False; + return right.ValueKind is JsonValueKind.False; case JsonValueKind.True: - return right.ValueKind == JsonValueKind.True; + return right.ValueKind is JsonValueKind.True; - case JsonValueKind.Number when right.ValueKind == JsonValueKind.Number: + case JsonValueKind.Number when right.ValueKind is JsonValueKind.Number: return left.GetInt64() == right.GetInt64(); - case JsonValueKind.String when right.ValueKind == JsonValueKind.String: + case JsonValueKind.String when right.ValueKind is JsonValueKind.String: return string.Equals(left.GetString(), right.GetString(), StringComparison.Ordinal); - case JsonValueKind.Array when right.ValueKind == JsonValueKind.Array: + case JsonValueKind.Array when right.ValueKind is JsonValueKind.Array: if (left.GetArrayLength() != right.GetArrayLength()) { return false; @@ -187,7 +187,7 @@ public readonly struct OpenIddictParameter : IEquatable return true; - case JsonValueKind.Object when right.ValueKind == JsonValueKind.Object: + case JsonValueKind.Object when right.ValueKind is JsonValueKind.Object: foreach (var property in left.EnumerateObject()) { if (!right.TryGetProperty(property.Name, out JsonElement element) || @@ -502,13 +502,8 @@ public readonly struct OpenIddictParameter : IEquatable /// Writes the parameter value to the specified JSON writer. /// /// The UTF-8 JSON writer. - public void WriteTo(Utf8JsonWriter writer) + public void WriteTo(Utf8JsonWriter writer!!) { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - switch (Value) { // Note: undefined JsonElement values are assimilated to null values. @@ -803,7 +798,7 @@ public readonly struct OpenIddictParameter : IEquatable for (var index = 0; enumerator.MoveNext(); index++) { var element = enumerator.Current; - if (element.ValueKind != JsonValueKind.String) + if (element.ValueKind is not JsonValueKind.String) { return null; } @@ -820,49 +815,49 @@ public readonly struct OpenIddictParameter : IEquatable /// /// The value to convert /// An instance. - public static implicit operator OpenIddictParameter(bool value) => new OpenIddictParameter(value); + public static implicit operator OpenIddictParameter(bool value) => new(value); /// /// Converts a nullable boolean to an instance. /// /// The value to convert /// An instance. - public static implicit operator OpenIddictParameter(bool? value) => new OpenIddictParameter(value); + public static implicit operator OpenIddictParameter(bool? value) => new(value); /// /// Converts a to an instance. /// /// The value to convert /// An instance. - public static implicit operator OpenIddictParameter(JsonElement value) => new OpenIddictParameter(value); + public static implicit operator OpenIddictParameter(JsonElement value) => new(value); /// /// Converts a long integer to an instance. /// /// The value to convert /// An instance. - public static implicit operator OpenIddictParameter(long value) => new OpenIddictParameter(value); + public static implicit operator OpenIddictParameter(long value) => new(value); /// /// Converts a nullable long integer to an instance. /// /// The value to convert /// An instance. - public static implicit operator OpenIddictParameter(long? value) => new OpenIddictParameter(value); + public static implicit operator OpenIddictParameter(long? value) => new(value); /// /// Converts a string to an instance. /// /// The value to convert /// An instance. - public static implicit operator OpenIddictParameter(string? value) => new OpenIddictParameter(value); + public static implicit operator OpenIddictParameter(string? value) => new(value); /// /// Converts an array of strings to an instance. /// /// The value to convert /// An instance. - public static implicit operator OpenIddictParameter(string?[]? value) => new OpenIddictParameter(value); + public static implicit operator OpenIddictParameter(string?[]? value) => new(value); /// /// Determines whether a parameter is null or empty. diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs index 552f6cc2..fd2c8879 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs @@ -20,8 +20,8 @@ public class OpenIddictClientAspNetCoreBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictClientAspNetCoreBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictClientAspNetCoreBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -35,13 +35,8 @@ public class OpenIddictClientAspNetCoreBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictClientAspNetCoreBuilder Configure(Action configuration) + public OpenIddictClientAspNetCoreBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs index 349ae54f..6eeea964 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs @@ -19,13 +19,8 @@ public class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions /// The options instance to initialize. - public void Configure(AuthenticationOptions options) + public void Configure(AuthenticationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // If a handler was already registered and the type doesn't correspond to the OpenIddict handler, throw an exception. if (options.SchemeMap.TryGetValue(OpenIddictClientAspNetCoreDefaults.AuthenticationScheme, out var builder) && builder.HandlerType != typeof(OpenIddictClientAspNetCoreHandler)) @@ -37,13 +32,8 @@ public class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions /// The authentication scheme associated with the handler instance. /// The options instance to initialize. - public void PostConfigure(string name, AuthenticationOptions options) + public void PostConfigure(string name, AuthenticationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - if (!TryValidate(options.SchemeMap, options.DefaultAuthenticateScheme) || !TryValidate(options.SchemeMap, options.DefaultScheme) || !TryValidate(options.SchemeMap, options.DefaultSignInScheme) || diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs index d9f7e705..b3df243b 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictClientAspNetCoreExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictClientAspNetCoreBuilder UseAspNetCore(this OpenIddictClientBuilder builder) + public static OpenIddictClientAspNetCoreBuilder UseAspNetCore(this OpenIddictClientBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddAuthentication(); builder.Services.TryAddScoped(); @@ -64,18 +59,8 @@ public static class OpenIddictClientAspNetCoreExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictClientBuilder UseAspNetCore( - this OpenIddictClientBuilder builder, Action configuration) + this OpenIddictClientBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseAspNetCore()); return builder; diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs index 81d80909..5b58a1e9 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs @@ -27,12 +27,12 @@ public class OpenIddictClientAspNetCoreHandler : AuthenticationHandler class. /// public OpenIddictClientAspNetCoreHandler( - IOpenIddictClientDispatcher dispatcher, - IOpenIddictClientFactory factory, - IOptionsMonitor options, - ILoggerFactory logger, - UrlEncoder encoder, - ISystemClock clock) + IOpenIddictClientDispatcher dispatcher!!, + IOpenIddictClientFactory factory!!, + IOptionsMonitor options!!, + ILoggerFactory logger!!, + UrlEncoder encoder!!, + ISystemClock clock!!) : base(options, logger, encoder, clock) { _dispatcher = dispatcher; diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs index 975ca33b..3d621dbd 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs @@ -24,18 +24,11 @@ public static class OpenIddictClientAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireRedirectionEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireRedirectionEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableRedirectionEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableRedirectionEndpointPassthrough); } /// @@ -45,18 +38,11 @@ public static class OpenIddictClientAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireErrorPassthroughEnabled(IOptionsMonitor options) + public RequireErrorPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableErrorPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableErrorPassthrough); } /// @@ -64,15 +50,8 @@ public static class OpenIddictClientAspNetCoreHandlerFilters /// public class RequireHttpRequest : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Transaction.GetHttpRequest() is not null); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Transaction.GetHttpRequest() is not null); } /// @@ -82,17 +61,10 @@ public static class OpenIddictClientAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireStatusCodePagesIntegrationEnabled(IOptionsMonitor options) + public RequireStatusCodePagesIntegrationEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableStatusCodePagesIntegration); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableStatusCodePagesIntegration); } } diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs index 0b826564..52dfeb61 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs @@ -57,20 +57,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationRequestContext context) + public ValueTask HandleAsync(ApplyAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Note: while initially not allowed by the core OAuth 2.0 specification, multiple parameters // with the same name are used by derived drafts like the OAuth 2.0 token exchange specification. diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs index 80930d3c..5e9c9992 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs @@ -57,20 +57,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessRequestContext context) + public ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } context.EndpointType = Matches(request, context.Options.RedirectionEndpointUris) ? OpenIddictClientEndpointType.Redirection : @@ -149,20 +141,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (HttpMethods.IsGet(request.Method)) { @@ -203,20 +187,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (HttpMethods.IsGet(request.Method)) { @@ -286,20 +262,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (HttpMethods.IsPost(request.Method)) { @@ -354,7 +322,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers { private readonly IOptionsMonitor _options; - public ValidateCorrelationCookie(IOptionsMonitor options) + public ValidateCorrelationCookie(IOptionsMonitor options!!) => _options = options; /// @@ -370,22 +338,14 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Resolve the request forgery protection from the state token principal. // If the claim cannot be found, this means the protection was disabled @@ -449,13 +409,8 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var properties = context.Transaction.GetProperty(typeof(AuthenticationProperties).FullName!); if (properties is null) { @@ -508,7 +463,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers { private readonly IOptionsMonitor _options; - public GenerateCorrelationCookie(IOptionsMonitor options) + public GenerateCorrelationCookie(IOptionsMonitor options!!) => _options = options; /// @@ -524,12 +479,8 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Note: using a correlation cookie serves as an antiforgery protection as the request will // always be rejected if a cookie corresponding to the request forgery protection claim @@ -548,11 +499,8 @@ public static partial class OpenIddictClientAspNetCoreHandlers // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } var options = _options.CurrentValue.CookieBuilder.Build(response.HttpContext); @@ -595,13 +543,8 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.SkipRequest(); return default; @@ -626,20 +569,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); @@ -672,20 +607,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Prevent the response from being cached. response.Headers[HeaderNames.CacheControl] = "no-store"; @@ -719,20 +646,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); @@ -767,20 +686,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); @@ -826,20 +737,12 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); @@ -903,13 +806,8 @@ public static partial class OpenIddictClientAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Logger.LogInformation(SR.GetResourceString(SR.ID6145)); context.HandleRequest(); diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs index c2188c59..72a617c4 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs @@ -19,13 +19,8 @@ public static class OpenIddictClientAspNetCoreHelpers /// /// The transaction instance. /// The instance or null if it couldn't be found. - public static HttpRequest? GetHttpRequest(this OpenIddictClientTransaction transaction) + public static HttpRequest? GetHttpRequest(this OpenIddictClientTransaction transaction!!) { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (!transaction.Properties.TryGetValue(typeof(HttpRequest).FullName!, out object? property)) { return null; @@ -44,13 +39,8 @@ public static class OpenIddictClientAspNetCoreHelpers /// /// The context instance. /// The . - public static OpenIddictClientEndpointType GetOpenIddictClientEndpointType(this HttpContext context) + public static OpenIddictClientEndpointType GetOpenIddictClientEndpointType(this HttpContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - return context.Features.Get()?.Transaction?.EndpointType ?? default; } @@ -59,13 +49,8 @@ public static class OpenIddictClientAspNetCoreHelpers /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictRequest? GetOpenIddictClientRequest(this HttpContext context) + public static OpenIddictRequest? GetOpenIddictClientRequest(this HttpContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - return context.Features.Get()?.Transaction?.Request; } @@ -74,13 +59,8 @@ public static class OpenIddictClientAspNetCoreHelpers /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictResponse? GetOpenIddictClientResponse(this HttpContext context) + public static OpenIddictResponse? GetOpenIddictClientResponse(this HttpContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - return context.Features.Get()?.Transaction?.Response; } } diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs index 84e937b5..55fb6756 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs @@ -19,8 +19,8 @@ public class OpenIddictClientSystemNetHttpBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictClientSystemNetHttpBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictClientSystemNetHttpBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -34,13 +34,8 @@ public class OpenIddictClientSystemNetHttpBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictClientSystemNetHttpBuilder Configure(Action configuration) + public OpenIddictClientSystemNetHttpBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs index 20976f44..6ea31f51 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs @@ -21,17 +21,12 @@ public class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptions _serviceProvider = serviceProvider; #endif - public void Configure(OpenIddictClientOptions options) + public void Configure(OpenIddictClientOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // Register the built-in event handlers used by the OpenIddict System.Net.Http client components. options.Handlers.AddRange(OpenIddictClientSystemNetHttpHandlers.DefaultHandlers); } @@ -39,13 +34,8 @@ public class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptions Debug.Fail("This infrastructure method shouldn't be called."); - public void Configure(string name, HttpClientFactoryOptions options) + public void Configure(string name, HttpClientFactoryOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName(); if (!string.Equals(name, assembly.Name, StringComparison.Ordinal)) diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs index cded095c..4171cfd0 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs @@ -23,13 +23,8 @@ public static class OpenIddictClientSystemNetHttpExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictClientSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictClientBuilder builder) + public static OpenIddictClientSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictClientBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddHttpClient(); // Register the built-in validation event handlers used by the OpenIddict System.Net.Http components. @@ -57,18 +52,8 @@ public static class OpenIddictClientSystemNetHttpExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictClientBuilder UseSystemNetHttp( - this OpenIddictClientBuilder builder, Action configuration) + this OpenIddictClientBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseSystemNetHttp()); return builder; diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs index af1afac4..8a4ba4ab 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs @@ -16,16 +16,8 @@ public static class OpenIddictClientSystemNetHttpHandlerFilters /// public class RequireHttpMetadataAddress : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(BaseExternalContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask( - string.Equals(context.Address?.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || - string.Equals(context.Address?.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)); - } + public ValueTask IsActiveAsync(BaseExternalContext context!!) + => new(string.Equals(context.Address?.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || + string.Equals(context.Address?.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)); } } diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Exchange.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Exchange.cs index c0d2e499..d3d3b9e9 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Exchange.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Exchange.cs @@ -48,22 +48,14 @@ public static partial class OpenIddictClientSystemNetHttpHandlers .Build(); /// - public async ValueTask HandleAsync(PrepareTokenRequestContext context) + public async ValueTask HandleAsync(PrepareTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } // If no client identifier was attached to the request, skip the following logic. if (string.IsNullOrEmpty(context.Request.ClientId)) diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs index 50e100ed..b352d0ac 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs @@ -48,22 +48,14 @@ public static partial class OpenIddictClientSystemNetHttpHandlers .Build(); /// - public ValueTask HandleAsync(PrepareUserinfoRequestContext context) + public ValueTask HandleAsync(PrepareUserinfoRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } // Attach the authorization header containing the access token to the HTTP request. request.Headers.Authorization = new AuthenticationHeaderValue(Schemes.Bearer, context.Request.AccessToken); @@ -92,20 +84,12 @@ public static partial class OpenIddictClientSystemNetHttpHandlers .Build(); /// - public async ValueTask HandleAsync(ExtractUserinfoResponseContext context) + public async ValueTask HandleAsync(ExtractUserinfoResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var response = context.Transaction.GetHttpResponseMessage(); - if (response is null) - { + var response = context.Transaction.GetHttpResponseMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } // The status code is deliberately not validated to ensure even errored responses // (typically in the 4xx range) can be deserialized and handled by the event handlers. diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs index 9699d65e..d45a718e 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs @@ -41,13 +41,8 @@ public static partial class OpenIddictClientSystemNetHttpHandlers /// [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The HTTP request message is disposed later by a dedicated handler.")] - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var request = new HttpRequestMessage(HttpMethod.Get, context.Address) { Headers = @@ -83,13 +78,8 @@ public static partial class OpenIddictClientSystemNetHttpHandlers /// [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The HTTP request message is disposed later by a dedicated handler.")] - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var request = new HttpRequestMessage(HttpMethod.Post, context.Address) { Headers = @@ -123,22 +113,14 @@ public static partial class OpenIddictClientSystemNetHttpHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } if (request.RequestUri is null || context.Transaction.Request.Count == 0) { @@ -189,22 +171,14 @@ public static partial class OpenIddictClientSystemNetHttpHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } request.Content = new FormUrlEncodedContent( from parameter in context.Transaction.Request.GetParameters() @@ -240,20 +214,12 @@ public static partial class OpenIddictClientSystemNetHttpHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName(); using var client = _factory.CreateClient(assembly.Name!); @@ -294,20 +260,12 @@ public static partial class OpenIddictClientSystemNetHttpHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } request.Dispose(); @@ -335,20 +293,12 @@ public static partial class OpenIddictClientSystemNetHttpHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var response = context.Transaction.GetHttpResponseMessage(); - if (response is null) - { + var response = context.Transaction.GetHttpResponseMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } // The status code is deliberately not validated to ensure even errored responses // (typically in the 4xx range) can be deserialized and handled by the event handlers. @@ -376,20 +326,12 @@ public static partial class OpenIddictClientSystemNetHttpHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var response = context.Transaction.GetHttpResponseMessage(); - if (response is null) - { + var response = context.Transaction.GetHttpResponseMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } response.Dispose(); diff --git a/src/OpenIddict.Client/OpenIddictClientBuilder.cs b/src/OpenIddict.Client/OpenIddictClientBuilder.cs index 5538c819..ea800754 100644 --- a/src/OpenIddict.Client/OpenIddictClientBuilder.cs +++ b/src/OpenIddict.Client/OpenIddictClientBuilder.cs @@ -25,8 +25,8 @@ public class OpenIddictClientBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictClientBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictClientBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -42,14 +42,9 @@ public class OpenIddictClientBuilder /// The . [EditorBrowsable(EditorBrowsableState.Advanced)] public OpenIddictClientBuilder AddEventHandler( - Action> configuration) + Action> configuration!!) where TContext : OpenIddictClientEvents.BaseContext { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - // Note: handlers registered using this API are assumed to be custom handlers by default. var builder = OpenIddictClientHandlerDescriptor.CreateBuilder() .SetType(OpenIddictClientHandlerType.Custom); @@ -65,13 +60,8 @@ public class OpenIddictClientBuilder /// The handler descriptor. /// The . [EditorBrowsable(EditorBrowsableState.Advanced)] - public OpenIddictClientBuilder AddEventHandler(OpenIddictClientHandlerDescriptor descriptor) + public OpenIddictClientBuilder AddEventHandler(OpenIddictClientHandlerDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - // Register the handler in the services collection. Services.Add(descriptor.ServiceDescriptor); @@ -84,13 +74,8 @@ public class OpenIddictClientBuilder /// The descriptor corresponding to the handler to remove. /// The . [EditorBrowsable(EditorBrowsableState.Advanced)] - public OpenIddictClientBuilder RemoveEventHandler(OpenIddictClientHandlerDescriptor descriptor) + public OpenIddictClientBuilder RemoveEventHandler(OpenIddictClientHandlerDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - Services.RemoveAll(descriptor.ServiceDescriptor.ServiceType); Services.PostConfigure(options => @@ -113,13 +98,8 @@ public class OpenIddictClientBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictClientBuilder Configure(Action configuration) + public OpenIddictClientBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -130,28 +110,16 @@ public class OpenIddictClientBuilder /// /// The encrypting credentials. /// The . - public OpenIddictClientBuilder AddEncryptionCredentials(EncryptingCredentials credentials) - { - if (credentials is null) - { - throw new ArgumentNullException(nameof(credentials)); - } - - return Configure(options => options.EncryptionCredentials.Add(credentials)); - } + public OpenIddictClientBuilder AddEncryptionCredentials(EncryptingCredentials credentials!!) + => Configure(options => options.EncryptionCredentials.Add(credentials)); /// /// Registers an encryption key. /// /// The security key. /// The . - public OpenIddictClientBuilder AddEncryptionKey(SecurityKey key) + public OpenIddictClientBuilder AddEncryptionKey(SecurityKey key!!) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - // If the encryption key is an asymmetric security key, ensure it has a private key. if (key is AsymmetricSecurityKey asymmetricSecurityKey && asymmetricSecurityKey.PrivateKeyStatus == PrivateKeyStatus.DoesNotExist) @@ -193,13 +161,8 @@ public class OpenIddictClientBuilder /// The . [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The X.509 certificate is attached to the client options.")] - public OpenIddictClientBuilder AddDevelopmentEncryptionCertificate(X500DistinguishedName subject) + public OpenIddictClientBuilder AddDevelopmentEncryptionCertificate(X500DistinguishedName subject!!) { - if (subject is null) - { - throw new ArgumentNullException(nameof(subject)); - } - using var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); @@ -354,13 +317,8 @@ public class OpenIddictClientBuilder /// /// The encryption certificate. /// The . - public OpenIddictClientBuilder AddEncryptionCertificate(X509Certificate2 certificate) + public OpenIddictClientBuilder AddEncryptionCertificate(X509Certificate2 certificate!!) { - if (certificate is null) - { - throw new ArgumentNullException(nameof(certificate)); - } - // If the certificate is a X.509v3 certificate that specifies at least one // key usage, ensure that the certificate key can be used for key encryption. if (certificate.Version >= 3) @@ -406,14 +364,9 @@ public class OpenIddictClientBuilder /// An enumeration of flags indicating how and where to store the private key of the certificate. /// The . public OpenIddictClientBuilder AddEncryptionCertificate( - Assembly assembly, string resource, + Assembly assembly!!, string resource, string? password, X509KeyStorageFlags flags) { - if (assembly is null) - { - throw new ArgumentNullException(nameof(assembly)); - } - if (string.IsNullOrEmpty(resource)) { throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource)); @@ -456,13 +409,8 @@ public class OpenIddictClientBuilder /// The . [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The X.509 certificate is attached to the client options.")] - public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream, string? password, X509KeyStorageFlags flags) + public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream!!, string? password, X509KeyStorageFlags flags) { - if (stream is null) - { - throw new ArgumentNullException(nameof(stream)); - } - using var buffer = new MemoryStream(); stream.CopyTo(buffer); @@ -534,28 +482,16 @@ public class OpenIddictClientBuilder /// /// The signing credentials. /// The . - public OpenIddictClientBuilder AddSigningCredentials(SigningCredentials credentials) - { - if (credentials is null) - { - throw new ArgumentNullException(nameof(credentials)); - } - - return Configure(options => options.SigningCredentials.Add(credentials)); - } + public OpenIddictClientBuilder AddSigningCredentials(SigningCredentials credentials!!) + => Configure(options => options.SigningCredentials.Add(credentials)); /// /// Registers a signing key. /// /// The security key. /// The . - public OpenIddictClientBuilder AddSigningKey(SecurityKey key) + public OpenIddictClientBuilder AddSigningKey(SecurityKey key!!) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - // If the signing key is an asymmetric security key, ensure it has a private key. if (key is AsymmetricSecurityKey asymmetricSecurityKey && asymmetricSecurityKey.PrivateKeyStatus == PrivateKeyStatus.DoesNotExist) @@ -615,13 +551,8 @@ public class OpenIddictClientBuilder /// The . [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The X.509 certificate is attached to the client options.")] - public OpenIddictClientBuilder AddDevelopmentSigningCertificate(X500DistinguishedName subject) + public OpenIddictClientBuilder AddDevelopmentSigningCertificate(X500DistinguishedName subject!!) { - if (subject is null) - { - throw new ArgumentNullException(nameof(subject)); - } - using var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); @@ -794,13 +725,8 @@ public class OpenIddictClientBuilder /// /// The signing certificate. /// The . - public OpenIddictClientBuilder AddSigningCertificate(X509Certificate2 certificate) + public OpenIddictClientBuilder AddSigningCertificate(X509Certificate2 certificate!!) { - if (certificate is null) - { - throw new ArgumentNullException(nameof(certificate)); - } - // If the certificate is a X.509v3 certificate that specifies at least // one key usage, ensure that the certificate key can be used for signing. if (certificate.Version >= 3) @@ -846,14 +772,9 @@ public class OpenIddictClientBuilder /// An enumeration of flags indicating how and where to store the private key of the certificate. /// The . public OpenIddictClientBuilder AddSigningCertificate( - Assembly assembly, string resource, + Assembly assembly!!, string resource, string? password, X509KeyStorageFlags flags) { - if (assembly is null) - { - throw new ArgumentNullException(nameof(assembly)); - } - if (string.IsNullOrEmpty(resource)) { throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource)); @@ -896,13 +817,8 @@ public class OpenIddictClientBuilder /// The . [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The X.509 certificate is attached to the client options.")] - public OpenIddictClientBuilder AddSigningCertificate(Stream stream, string? password, X509KeyStorageFlags flags) + public OpenIddictClientBuilder AddSigningCertificate(Stream stream!!, string? password, X509KeyStorageFlags flags) { - if (stream is null) - { - throw new ArgumentNullException(nameof(stream)); - } - using var buffer = new MemoryStream(); stream.CopyTo(buffer); @@ -974,15 +890,8 @@ public class OpenIddictClientBuilder /// /// The client registration. /// The . - public OpenIddictClientBuilder AddRegistration(OpenIddictClientRegistration registration) - { - if (registration is null) - { - throw new ArgumentNullException(nameof(registration)); - } - - return Configure(options => options.Registrations.Add(registration)); - } + public OpenIddictClientBuilder AddRegistration(OpenIddictClientRegistration registration!!) + => Configure(options => options.Registrations.Add(registration)); /// /// Sets the relative or absolute URLs associated to the redirection endpoint. @@ -991,15 +900,8 @@ public class OpenIddictClientBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictClientBuilder SetRedirectionEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetRedirectionEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictClientBuilder SetRedirectionEndpointUris(params string[] addresses!!) + => SetRedirectionEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the redirection endpoint. @@ -1008,13 +910,8 @@ public class OpenIddictClientBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictClientBuilder SetRedirectionEndpointUris(params Uri[] addresses) + public OpenIddictClientBuilder SetRedirectionEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); diff --git a/src/OpenIddict.Client/OpenIddictClientConfiguration.cs b/src/OpenIddict.Client/OpenIddictClientConfiguration.cs index 04de69ef..7c86dfa1 100644 --- a/src/OpenIddict.Client/OpenIddictClientConfiguration.cs +++ b/src/OpenIddict.Client/OpenIddictClientConfiguration.cs @@ -27,13 +27,8 @@ public class OpenIddictClientConfiguration : IPostConfigureOptions /// The authentication scheme associated with the handler instance. /// The options instance to initialize. - public void PostConfigure(string name, OpenIddictClientOptions options) + public void PostConfigure(string name, OpenIddictClientOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - if (options.JsonWebTokenHandler is null) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0075)); diff --git a/src/OpenIddict.Client/OpenIddictClientDispatcher.cs b/src/OpenIddict.Client/OpenIddictClientDispatcher.cs index 961df906..b32608a4 100644 --- a/src/OpenIddict.Client/OpenIddictClientDispatcher.cs +++ b/src/OpenIddict.Client/OpenIddictClientDispatcher.cs @@ -19,22 +19,17 @@ public class OpenIddictClientDispatcher : IOpenIddictClientDispatcher /// Creates a new instance of the class. /// public OpenIddictClientDispatcher( - ILogger logger, - IOptionsMonitor options, - IServiceProvider provider) + ILogger logger!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _logger = logger; _options = options; _provider = provider; } - public async ValueTask DispatchAsync(TContext context) where TContext : BaseContext + public async ValueTask DispatchAsync(TContext context!!) where TContext : BaseContext { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - await foreach (var handler in GetHandlersAsync()) { try diff --git a/src/OpenIddict.Client/OpenIddictClientEvents.cs b/src/OpenIddict.Client/OpenIddictClientEvents.cs index 0920e3a3..237e56a0 100644 --- a/src/OpenIddict.Client/OpenIddictClientEvents.cs +++ b/src/OpenIddict.Client/OpenIddictClientEvents.cs @@ -21,8 +21,8 @@ public static partial class OpenIddictClientEvents /// /// Creates a new instance of the class. /// - protected BaseContext(OpenIddictClientTransaction transaction) - => Transaction = transaction ?? throw new ArgumentNullException(nameof(transaction)); + protected BaseContext(OpenIddictClientTransaction transaction!!) + => Transaction = transaction; /// /// Gets the environment associated with the current request being processed. diff --git a/src/OpenIddict.Client/OpenIddictClientExtensions.cs b/src/OpenIddict.Client/OpenIddictClientExtensions.cs index c0a76d10..f9d8f0fd 100644 --- a/src/OpenIddict.Client/OpenIddictClientExtensions.cs +++ b/src/OpenIddict.Client/OpenIddictClientExtensions.cs @@ -21,13 +21,8 @@ public static class OpenIddictClientExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictClientBuilder AddClient(this OpenIddictBuilder builder) + public static OpenIddictClientBuilder AddClient(this OpenIddictBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddLogging(); builder.Services.AddOptions(); @@ -74,18 +69,8 @@ public static class OpenIddictClientExtensions /// The configuration delegate used to configure the client services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictBuilder AddClient(this OpenIddictBuilder builder, Action configuration) + public static OpenIddictBuilder AddClient(this OpenIddictBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.AddClient()); return builder; diff --git a/src/OpenIddict.Client/OpenIddictClientFactory.cs b/src/OpenIddict.Client/OpenIddictClientFactory.cs index 44d3bef9..3d90c3f0 100644 --- a/src/OpenIddict.Client/OpenIddictClientFactory.cs +++ b/src/OpenIddict.Client/OpenIddictClientFactory.cs @@ -18,15 +18,15 @@ public class OpenIddictClientFactory : IOpenIddictClientFactory /// Creates a new instance of the class. /// public OpenIddictClientFactory( - ILogger logger, - IOptionsMonitor options) + ILogger logger!!, + IOptionsMonitor options!!) { _logger = logger; _options = options; } public ValueTask CreateTransactionAsync() - => new ValueTask(new OpenIddictClientTransaction + => new(new OpenIddictClientTransaction { Logger = _logger, Options = _options.CurrentValue diff --git a/src/OpenIddict.Client/OpenIddictClientHandler.cs b/src/OpenIddict.Client/OpenIddictClientHandler.cs index 9abeaaf9..3c2eea85 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandler.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandler.cs @@ -18,8 +18,8 @@ public class OpenIddictClientHandler : IOpenIddictClientHandler /// The event handler delegate. - public OpenIddictClientHandler(Func handler) - => _handler = handler ?? throw new ArgumentNullException(nameof(handler)); + public OpenIddictClientHandler(Func handler!!) + => _handler = handler; /// /// Processes the event. @@ -28,6 +28,5 @@ public class OpenIddictClientHandler : IOpenIddictClientHandler /// A that can be used to monitor the asynchronous operation. /// - public ValueTask HandleAsync(TContext context) - => _handler(context ?? throw new ArgumentNullException(nameof(context))); + public ValueTask HandleAsync(TContext context!!) => _handler(context); } diff --git a/src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs b/src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs index 6c4abd8b..5f12141b 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs @@ -72,13 +72,8 @@ public class OpenIddictClientHandlerDescriptor /// /// The event handler filter type. /// The builder instance, so that calls can be easily chained. - public Builder AddFilter(Type type) + public Builder AddFilter(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (!typeof(IOpenIddictClientHandlerFilter<>).MakeGenericType(typeof(TContext)).IsAssignableFrom(type)) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0104)); @@ -104,13 +99,8 @@ public class OpenIddictClientHandlerDescriptor /// The existing descriptor properties are copied from. /// All the properties previously set on this instance are automatically replaced. /// The builder instance, so that calls can be easily chained. - public Builder Import(OpenIddictClientHandlerDescriptor descriptor) + public Builder Import(OpenIddictClientHandlerDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - if (descriptor.ContextType != typeof(TContext)) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0284)); @@ -130,13 +120,8 @@ public class OpenIddictClientHandlerDescriptor /// /// The service descriptor. /// The builder instance, so that calls can be easily chained. - public Builder SetServiceDescriptor(ServiceDescriptor descriptor) + public Builder SetServiceDescriptor(ServiceDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - var type = descriptor.ServiceType; if (!typeof(IOpenIddictClientHandler<>).MakeGenericType(typeof(TContext)).IsAssignableFrom(type)) { @@ -182,15 +167,8 @@ public class OpenIddictClientHandlerDescriptor /// /// The handler instance. /// The builder instance, so that calls can be easily chained. - public Builder UseInlineHandler(Func handler) - { - if (handler is null) - { - throw new ArgumentNullException(nameof(handler)); - } - - return UseSingletonHandler(new OpenIddictClientHandler(handler)); - } + public Builder UseInlineHandler(Func handler!!) + => UseSingletonHandler(new OpenIddictClientHandler(handler)); /// /// Configures the descriptor to use the specified scoped handler. @@ -208,17 +186,10 @@ public class OpenIddictClientHandlerDescriptor /// The handler type. /// The factory used to create the handler. /// The builder instance, so that calls can be easily chained. - public Builder UseScopedHandler(Func factory) + public Builder UseScopedHandler(Func factory!!) where THandler : IOpenIddictClientHandler - { - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - return SetServiceDescriptor(new ServiceDescriptor( + => SetServiceDescriptor(new ServiceDescriptor( typeof(THandler), factory, ServiceLifetime.Scoped)); - } /// /// Configures the descriptor to use the specified singleton handler. @@ -236,17 +207,10 @@ public class OpenIddictClientHandlerDescriptor /// The handler type. /// The factory used to create the handler. /// The builder instance, so that calls can be easily chained. - public Builder UseSingletonHandler(Func factory) + public Builder UseSingletonHandler(Func factory!!) where THandler : IOpenIddictClientHandler - { - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - return SetServiceDescriptor(new ServiceDescriptor( + => SetServiceDescriptor(new ServiceDescriptor( typeof(THandler), factory, ServiceLifetime.Singleton)); - } /// /// Configures the descriptor to use the specified singleton handler. @@ -254,16 +218,9 @@ public class OpenIddictClientHandlerDescriptor /// The handler type. /// The handler instance. /// The builder instance, so that calls can be easily chained. - public Builder UseSingletonHandler(THandler handler) + public Builder UseSingletonHandler(THandler handler!!) where THandler : IOpenIddictClientHandler - { - if (handler is null) - { - throw new ArgumentNullException(nameof(handler)); - } - - return SetServiceDescriptor(new ServiceDescriptor(typeof(THandler), handler)); - } + => SetServiceDescriptor(new ServiceDescriptor(typeof(THandler), handler)); /// /// Build a new descriptor instance, based on the parameters that were previously set. diff --git a/src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs b/src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs index cb8d8f4e..4a03e9f6 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs @@ -17,15 +17,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireAuthorizationCodeOrImplicitGrantType : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessChallengeContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.GrantType is GrantTypes.AuthorizationCode or GrantTypes.Implicit); - } + public ValueTask IsActiveAsync(ProcessChallengeContext context!!) + => new(context.GrantType is GrantTypes.AuthorizationCode or GrantTypes.Implicit); } /// @@ -33,15 +26,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireAuthorizationCodeValidated : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateAuthorizationCode); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateAuthorizationCode); } /// @@ -49,15 +35,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireBackchannelAccessTokenValidated : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateBackchannelAccessToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateBackchannelAccessToken); } /// @@ -65,15 +44,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireBackchannelIdentityTokenPrincipal : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.BackchannelIdentityTokenPrincipal is not null); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.BackchannelIdentityTokenPrincipal is not null); } /// @@ -81,15 +53,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireBackchannelIdentityTokenValidated : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateBackchannelIdentityToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateBackchannelIdentityToken); } /// @@ -97,15 +62,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireFrontchannelAccessTokenValidated : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateFrontchannelAccessToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateFrontchannelAccessToken); } /// @@ -113,15 +71,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireFrontchannelIdentityTokenPrincipal : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.FrontchannelIdentityTokenPrincipal is not null); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.FrontchannelIdentityTokenPrincipal is not null); } /// @@ -129,15 +80,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireFrontchannelIdentityTokenValidated : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateFrontchannelIdentityToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateFrontchannelIdentityToken); } /// @@ -145,15 +89,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireRedirectionRequest : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictClientEndpointType.Redirection); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictClientEndpointType.Redirection); } /// @@ -161,15 +98,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireRefreshTokenValidated : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateRefreshToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateRefreshToken); } /// @@ -177,15 +107,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireStateTokenGenerated : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessChallengeContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.GenerateStateToken); - } + public ValueTask IsActiveAsync(ProcessChallengeContext context!!) + => new(context.GenerateStateToken); } /// @@ -193,15 +116,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireStateTokenPrincipal : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.StateTokenPrincipal is not null); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.StateTokenPrincipal is not null); } /// @@ -209,15 +125,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireStateTokenValidated : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateStateToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateStateToken); } /// @@ -225,15 +134,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireTokenRequest : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.TokenRequest is not null); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.TokenRequest is not null); } /// @@ -241,15 +143,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireTokenResponse : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.TokenResponse is not null); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.TokenResponse is not null); } /// @@ -257,15 +152,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireUserinfoRequest : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.UserinfoRequest is not null); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.UserinfoRequest is not null); } /// @@ -273,15 +161,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireUserinfoResponse : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.UserinfoResponse is not null); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.UserinfoResponse is not null); } /// @@ -289,15 +170,8 @@ public static class OpenIddictClientHandlerFilters /// public class RequireUserinfoTokenExtracted : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ExtractUserinfoToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ExtractUserinfoToken); } /// @@ -305,14 +179,7 @@ public static class OpenIddictClientHandlerFilters /// public class RequireUserinfoTokenPrincipal : IOpenIddictClientHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.UserinfoTokenPrincipal is not null); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.UserinfoTokenPrincipal is not null); } } diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs index ba6eaed1..54630784 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs @@ -51,7 +51,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public PrepareAuthorizationRequest(IOpenIddictClientDispatcher dispatcher) + public PrepareAuthorizationRequest(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -65,13 +65,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new PrepareAuthorizationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -96,7 +91,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ApplyAuthorizationRequest(IOpenIddictClientDispatcher dispatcher) + public ApplyAuthorizationRequest(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -110,13 +105,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyAuthorizationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -149,13 +139,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context) + public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var configuration = await context.Registration.ConfigurationManager.GetConfigurationAsync(default) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0140)); @@ -183,7 +168,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ExtractRedirectionRequest(IOpenIddictClientDispatcher dispatcher) + public ExtractRedirectionRequest(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -197,13 +182,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractRedirectionRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -244,7 +224,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateRedirectionRequest(IOpenIddictClientDispatcher dispatcher) + public ValidateRedirectionRequest(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -259,13 +239,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateRedirectionRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -301,7 +276,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public HandleRedirectionRequest(IOpenIddictClientDispatcher dispatcher) + public HandleRedirectionRequest(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -315,13 +290,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleRedirectionRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -357,7 +327,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ApplyRedirectionResponse(IOpenIddictClientDispatcher dispatcher) + public ApplyRedirectionResponse(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -372,13 +342,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyRedirectionResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -414,12 +379,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(PrepareAuthorizationRequestContext context) + public ValueTask HandleAsync(PrepareAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // When the response mode corresponds to the default mode assigned to the selected // response type, the specification explicitly recommends omitting the response mode. @@ -451,7 +412,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateTokens(IOpenIddictClientDispatcher dispatcher) + public ValidateTokens(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -465,13 +426,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateRedirectionRequestContext context) + public async ValueTask HandleAsync(ValidateRedirectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ProcessAuthenticationContext(context.Transaction); await _dispatcher.DispatchAsync(notification); diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs index 433bbebb..230072ea 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs @@ -53,12 +53,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // The issuer returned in the discovery document must exactly match the URL used to access it. // See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationClient. @@ -105,13 +101,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Note: the authorization_endpoint node is required by the OpenID Connect discovery specification // but is optional in the OAuth 2.0 authorization server metadata specification. To make OpenIddict // compatible with the newer OAuth 2.0 specification, null/empty and missing values are allowed here. @@ -157,13 +148,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Note: the jwks_uri node is required by the OpenID Connect discovery specification. // See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationClient. var address = (string?) context.Response[Metadata.JwksUri]; @@ -209,13 +195,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var address = (string?) context.Response[Metadata.TokenEndpoint]; if (!string.IsNullOrEmpty(address)) { @@ -252,13 +233,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var address = (string?) context.Response[Metadata.UserinfoEndpoint]; if (!string.IsNullOrEmpty(address)) { @@ -295,12 +271,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Resolve the grant types supported by the authorization endpoint, if available. var types = context.Response[Metadata.GrantTypesSupported]?.GetUnnamedParameters(); @@ -337,12 +309,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Resolve the response modes supported by the authorization endpoint, if available. var modes = context.Response[Metadata.ResponseModesSupported]?.GetUnnamedParameters(); @@ -379,12 +347,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Resolve the response types supported by the authorization endpoint, if available. var types = context.Response[Metadata.ResponseTypesSupported]?.GetUnnamedParameters(); @@ -421,12 +385,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Resolve the code challenge methods supported by the authorization endpoint, if available. var methods = context.Response[Metadata.CodeChallengeMethodsSupported]?.GetUnnamedParameters(); @@ -463,12 +423,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Resolve the scopes supported by the remote server, if available. var scopes = context.Response[Metadata.ScopesSupported]?.GetUnnamedParameters(); @@ -506,13 +462,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Configuration.AuthorizationResponseIssParameterSupported = (bool?) context.Response[Metadata.AuthorizationResponseIssParameterSupported]; @@ -537,12 +488,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Resolve the client authentication methods supported by the token endpoint, if available. var methods = context.Response[Metadata.TokenEndpointAuthMethodsSupported]?.GetUnnamedParameters(); @@ -579,13 +526,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleCryptographyResponseContext context) + public ValueTask HandleAsync(HandleCryptographyResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var keys = context.Response[JsonWebKeySetParameterNames.Keys]?.GetUnnamedParameters(); if (keys is not { Count: > 0 }) { diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs index efc73eb1..a077013b 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs @@ -36,13 +36,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleTokenResponseContext context) + public ValueTask HandleAsync(HandleTokenResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - foreach (var parameter in context.Response.GetParameters()) { if (ValidateParameterType(parameter.Key, parameter.Value.Value)) diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs index ab14ccbe..6fdd07c2 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs @@ -50,12 +50,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // The OpenIddict client is expected to validate tokens it creates (e.g state tokens) and // tokens that are created by one or multiple authorization servers (e.g identity tokens). @@ -162,13 +158,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a principal was already attached, don't overwrite it. if (context.Principal is not null) { @@ -278,13 +269,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Note: only map the private claims from fully trusted tokens. if (context.Principal is null || !context.Principal.HasTokenType(TokenTypeHints.StateToken)) { @@ -335,13 +321,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Principal is null) { context.Reject( @@ -387,13 +368,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); var date = context.Principal.GetExpirationDate(); @@ -427,13 +403,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(GenerateTokenContext context) + public ValueTask HandleAsync(GenerateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.SecurityTokenHandler = context.Options.JsonWebTokenHandler; context.EncryptionCredentials = context.Options.EncryptionCredentials.First(); @@ -459,13 +430,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(GenerateTokenContext context) + public ValueTask HandleAsync(GenerateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a token was already attached by another handler, don't overwrite it. if (!string.IsNullOrEmpty(context.Token)) { diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs index a14aeeec..a9500ce7 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs @@ -40,13 +40,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(HandleUserinfoResponseContext context) + public ValueTask HandleAsync(HandleUserinfoResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Ignore the response instance if a userinfo token was extracted. if (!string.IsNullOrEmpty(context.UserinfoToken)) { @@ -97,13 +92,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(HandleUserinfoResponseContext context) + public async ValueTask HandleAsync(HandleUserinfoResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Ignore the response instance if a userinfo token was extracted. if (!string.IsNullOrEmpty(context.UserinfoToken)) { diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.cs index cef650c0..484e5d2c 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.cs @@ -124,12 +124,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Authentication demands can be triggered from the redirection endpoint // to handle authorization callbacks but also from unknown endpoints @@ -181,13 +177,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - (context.ExtractStateToken, context.RequireStateToken, context.ValidateStateToken) = context.EndpointType switch @@ -222,13 +213,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.StateToken = context.EndpointType switch { OpenIddictClientEndpointType.Redirection when context.ExtractStateToken @@ -257,13 +243,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.RequireStateToken && string.IsNullOrEmpty(context.StateToken)) { context.Reject( @@ -285,7 +266,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateStateToken(IOpenIddictClientDispatcher dispatcher) + public ValidateStateToken(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -300,13 +281,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.StateTokenPrincipal is not null || string.IsNullOrEmpty(context.StateToken)) { @@ -363,13 +339,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Retrieve the client definition using the authorization server stored in the state token. @@ -421,13 +392,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013)); var configuration = await context.Registration.ConfigurationManager.GetConfigurationAsync(default) ?? @@ -512,13 +478,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var (error, description, uri) = ( (string?) context.Request[Parameters.Error], (string?) context.Request[Parameters.ErrorDescription], @@ -556,13 +517,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Resolve the negotiated grant type from the state token. @@ -609,13 +565,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Resolve the negotiated response type from the state token. @@ -641,13 +592,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - (context.ExtractAuthorizationCode, context.RequireAuthorizationCode, context.ValidateAuthorizationCode) = context.GrantType switch @@ -723,13 +669,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.AuthorizationCode = context.EndpointType switch { OpenIddictClientEndpointType.Redirection when context.ExtractAuthorizationCode @@ -774,13 +715,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if ((context.RequireAuthorizationCode && string.IsNullOrEmpty(context.AuthorizationCode)) || (context.RequireFrontchannelAccessToken && string.IsNullOrEmpty(context.FrontchannelAccessToken)) || (context.RequireFrontchannelIdentityToken && string.IsNullOrEmpty(context.FrontchannelIdentityToken))) @@ -804,7 +740,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateFrontchannelIdentityToken(IOpenIddictClientDispatcher dispatcher) + public ValidateFrontchannelIdentityToken(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -819,13 +755,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.FrontchannelIdentityTokenPrincipal is not null || string.IsNullOrEmpty(context.FrontchannelIdentityToken)) { @@ -882,13 +813,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.FrontchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); foreach (var group in context.FrontchannelIdentityTokenPrincipal.Claims @@ -1018,13 +944,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.FrontchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Note: while an identity token typically contains a single audience represented @@ -1063,13 +984,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.FrontchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Note: the "azp" claim is optional, but if it's present, it MUST match the client identifier of the application. @@ -1107,13 +1023,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.FrontchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); @@ -1170,13 +1081,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.FrontchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Resolve the signing algorithm used to sign the identity token. If the private @@ -1299,7 +1205,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateFrontchannelAccessToken(IOpenIddictClientDispatcher dispatcher) + public ValidateFrontchannelAccessToken(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -1314,13 +1220,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.FrontchannelAccessTokenPrincipal is not null || string.IsNullOrEmpty(context.FrontchannelAccessToken)) { @@ -1369,7 +1270,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateAuthorizationCode(IOpenIddictClientDispatcher dispatcher) + public ValidateAuthorizationCode(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -1384,13 +1285,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.AuthorizationCodePrincipal is not null || string.IsNullOrEmpty(context.AuthorizationCode)) { @@ -1446,13 +1342,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - (context.ExtractBackchannelAccessToken, context.RequireBackchannelAccessToken, context.ValidateBackchannelAccessToken) = context.GrantType switch @@ -1537,13 +1428,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.ExtractBackchannelAccessToken && !context.ExtractBackchannelIdentityToken && !context.ExtractRefreshToken) @@ -1620,13 +1506,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008)); context.TokenResponse = await _service.SendTokenRequestAsync(context.Registration, context.TokenRequest); @@ -1649,13 +1530,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.TokenResponse is not null, SR.GetResourceString(SR.ID4007)); if (!string.IsNullOrEmpty(context.TokenResponse.Error)) @@ -1688,13 +1564,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.TokenResponse is not null, SR.GetResourceString(SR.ID4007)); context.BackchannelAccessToken = context.ExtractBackchannelAccessToken switch @@ -1735,13 +1606,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if ((context.RequireBackchannelAccessToken && string.IsNullOrEmpty(context.BackchannelAccessToken)) || (context.RequireBackchannelIdentityToken && string.IsNullOrEmpty(context.BackchannelIdentityToken)) || (context.RequireRefreshToken && string.IsNullOrEmpty(context.RefreshToken))) @@ -1765,7 +1631,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateBackchannelIdentityToken(IOpenIddictClientDispatcher dispatcher) + public ValidateBackchannelIdentityToken(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -1780,13 +1646,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.BackchannelIdentityTokenPrincipal is not null || string.IsNullOrEmpty(context.BackchannelIdentityToken)) { @@ -1843,13 +1704,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.BackchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); foreach (var group in context.BackchannelIdentityTokenPrincipal.Claims @@ -1979,13 +1835,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.BackchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Note: while an identity token typically contains a single audience represented @@ -2024,13 +1875,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.BackchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Note: the "azp" claim is optional, but if it's present, it MUST match the client identifier of the application. @@ -2068,13 +1914,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.BackchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); @@ -2131,13 +1972,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.BackchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(!string.IsNullOrEmpty(context.BackchannelAccessToken), SR.GetResourceString(SR.ID4010)); @@ -2233,7 +2069,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateBackchannelAccessToken(IOpenIddictClientDispatcher dispatcher) + public ValidateBackchannelAccessToken(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -2248,13 +2084,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.BackchannelAccessTokenPrincipal is not null || string.IsNullOrEmpty(context.BackchannelAccessToken)) { @@ -2303,7 +2134,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateRefreshToken(IOpenIddictClientDispatcher dispatcher) + public ValidateRefreshToken(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -2318,13 +2149,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.RefreshTokenPrincipal is not null || string.IsNullOrEmpty(context.RefreshToken)) { @@ -2380,13 +2206,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var configuration = await context.Registration.ConfigurationManager.GetConfigurationAsync(default) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0140)); @@ -2438,12 +2259,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Attach a new request instance if necessary. context.UserinfoRequest ??= new OpenIddictRequest(); @@ -2486,13 +2303,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.UserinfoRequest is not null, SR.GetResourceString(SR.ID4008)); // Note: userinfo responses can be of two types: @@ -2520,13 +2332,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.UserinfoResponse is not null, SR.GetResourceString(SR.ID4007)); if (!string.IsNullOrEmpty(context.UserinfoResponse.Error)) @@ -2559,13 +2366,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.RequireUserinfoToken && string.IsNullOrEmpty(context.UserinfoToken)) { context.Reject( @@ -2587,7 +2389,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public ValidateUserinfoToken(IOpenIddictClientDispatcher dispatcher) + public ValidateUserinfoToken(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -2602,13 +2404,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.UserinfoTokenPrincipal is not null || string.IsNullOrEmpty(context.UserinfoToken)) { return; @@ -2664,13 +2461,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.UserinfoTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); var configuration = await context.Registration.ConfigurationManager.GetConfigurationAsync(default) ?? @@ -2737,13 +2529,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.UserinfoTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); var configuration = await context.Registration.ConfigurationManager.GetConfigurationAsync(default) ?? @@ -2822,13 +2609,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If an explicit grant type was specified, ensure it is supported by OpenIddict. if (!string.IsNullOrEmpty(context.GrantType) && context.GrantType is not (GrantTypes.AuthorizationCode or GrantTypes.Implicit)) @@ -2866,12 +2648,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Note: if the static registration cannot be found in the options, this may indicate // the client was removed after the authorization dance started and thus, can no longer @@ -2901,13 +2679,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If an explicit grant type was specified, don't overwrite it. if (!string.IsNullOrEmpty(context.GrantType)) { @@ -2991,12 +2764,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // In OpenIddict, per-authorization demand values are stored in an encrypted and signed token // called "state token", that allows flowing per-authorization demand data like the issuer @@ -3035,13 +2804,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If an explicit response type was specified, don't overwrite it. if (!string.IsNullOrEmpty(context.ResponseType)) { @@ -3233,13 +2997,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If an explicit response type was specified, don't overwrite it. if (!string.IsNullOrEmpty(context.ResponseMode)) { @@ -3345,13 +3104,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.ClientId ??= context.Registration.ClientId; return default; @@ -3374,12 +3128,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Unlike OpenID Connect, OAuth 2.0 and 2.1 don't require specifying a redirect_uri. // To keep OpenIddict compatible with OAuth 2.0/2.1 deployments, the redirect_uri @@ -3407,13 +3157,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If an explicit set of scopes was specified, don't overwrite it. if (context.Scopes.Count > 0) { @@ -3459,12 +3204,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Generate a new crypto-secure random identifier that will // be used as the non-guessable part of the state token. @@ -3497,13 +3238,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var configuration = await context.Registration.ConfigurationManager.GetConfigurationAsync(default) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0140)); @@ -3547,12 +3283,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Don't attach a code challenge method if no authorization code is requested as some implementations // (like OpenIddict server) are known to eagerly block authorization requests that specify an invalid @@ -3654,13 +3386,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013)); Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); @@ -3751,7 +3478,7 @@ public static partial class OpenIddictClientHandlers { private readonly IOpenIddictClientDispatcher _dispatcher; - public GenerateStateToken(IOpenIddictClientDispatcher dispatcher) + public GenerateStateToken(IOpenIddictClientDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -3766,13 +3493,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new GenerateTokenContext(context.Transaction) { Principal = context.StateTokenPrincipal!, @@ -3823,12 +3545,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // While OAuth 2.0/2.1 allows sending an authorization request without a redirect_uri, // doing so is illegal in OpenID Connect and such requests will always be rejected. @@ -3858,12 +3576,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Note: while the exact order of the parameters has typically no effect on how requests // are handled by an authorization server, client_id and redirect_uri are deliberately @@ -3919,13 +3633,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!string.IsNullOrEmpty(context.Transaction.Response?.Error)) { context.Reject( @@ -3956,13 +3665,8 @@ public static partial class OpenIddictClientHandlers .Build(); /// - public ValueTask HandleAsync(ProcessErrorContext context) + public ValueTask HandleAsync(ProcessErrorContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Response.Error = context.Error; context.Response.ErrorDescription = context.ErrorDescription; context.Response.ErrorUri = context.ErrorUri; diff --git a/src/OpenIddict.Client/OpenIddictClientHelpers.cs b/src/OpenIddict.Client/OpenIddictClientHelpers.cs index 28fa91ee..574c13cb 100644 --- a/src/OpenIddict.Client/OpenIddictClientHelpers.cs +++ b/src/OpenIddict.Client/OpenIddictClientHelpers.cs @@ -19,13 +19,8 @@ public static class OpenIddictClientHelpers /// The property name. /// The property value or null if it couldn't be found. public static TProperty? GetProperty( - this OpenIddictClientTransaction transaction, string name) where TProperty : class + this OpenIddictClientTransaction transaction!!, string name) where TProperty : class { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (string.IsNullOrEmpty(name)) { throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name)); @@ -48,14 +43,9 @@ public static class OpenIddictClientHelpers /// The property value. /// The client transaction, so that calls can be easily chained. public static OpenIddictClientTransaction SetProperty( - this OpenIddictClientTransaction transaction, + this OpenIddictClientTransaction transaction!!, string name, TProperty? value) where TProperty : class { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (string.IsNullOrEmpty(name)) { throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name)); diff --git a/src/OpenIddict.Client/OpenIddictClientOptions.cs b/src/OpenIddict.Client/OpenIddictClientOptions.cs index 8398abbd..a312d943 100644 --- a/src/OpenIddict.Client/OpenIddictClientOptions.cs +++ b/src/OpenIddict.Client/OpenIddictClientOptions.cs @@ -19,7 +19,7 @@ public class OpenIddictClientOptions /// Note: the list is automatically sorted based on the order assigned to each handler descriptor. /// As such, it MUST NOT be mutated after options initialization to preserve the exact order. /// - public List Handlers { get; } = new(OpenIddictClientHandlers.DefaultHandlers); + public List Handlers { get; } = new(DefaultHandlers); /// /// Gets the list of encryption credentials used by the OpenIddict client services. diff --git a/src/OpenIddict.Client/OpenIddictClientRetriever.cs b/src/OpenIddict.Client/OpenIddictClientRetriever.cs index 5b9d6925..afdd8855 100644 --- a/src/OpenIddict.Client/OpenIddictClientRetriever.cs +++ b/src/OpenIddict.Client/OpenIddictClientRetriever.cs @@ -16,7 +16,7 @@ public class OpenIddictClientRetriever : IConfigurationRetriever class. /// /// The validation service. - public OpenIddictClientRetriever(OpenIddictClientService service) + public OpenIddictClientRetriever(OpenIddictClientService service!!) => _service = service; /// @@ -26,7 +26,8 @@ public class OpenIddictClientRetriever : IConfigurationRetrieverThe retriever used by IdentityModel. /// The that can be used to abort the operation. /// The OpenID Connect server configuration retrieved from the remote server. - async Task IConfigurationRetriever.GetConfigurationAsync(string address, IDocumentRetriever retriever, CancellationToken cancel) + async Task IConfigurationRetriever.GetConfigurationAsync( + string address, IDocumentRetriever retriever, CancellationToken cancel) { if (string.IsNullOrEmpty(address)) { diff --git a/src/OpenIddict.Client/OpenIddictClientService.cs b/src/OpenIddict.Client/OpenIddictClientService.cs index 433e8c5f..4d898e3b 100644 --- a/src/OpenIddict.Client/OpenIddictClientService.cs +++ b/src/OpenIddict.Client/OpenIddictClientService.cs @@ -19,7 +19,7 @@ public class OpenIddictClientService /// Creates a new instance of the class. /// /// The service provider. - public OpenIddictClientService(IServiceProvider provider) + public OpenIddictClientService(IServiceProvider provider!!) => _provider = provider; /// @@ -28,13 +28,8 @@ public class OpenIddictClientService /// The address of the remote metadata endpoint. /// The that can be used to abort the operation. /// The OpenID Connect server configuration retrieved from the remote server. - public async ValueTask GetConfigurationAsync(Uri address, CancellationToken cancellationToken = default) + public async ValueTask GetConfigurationAsync(Uri address!!, CancellationToken cancellationToken = default) { - if (address is null) - { - throw new ArgumentNullException(nameof(address)); - } - if (!address.IsAbsoluteUri) { throw new ArgumentException(SR.GetResourceString(SR.ID0144), nameof(address)); @@ -172,13 +167,8 @@ public class OpenIddictClientService /// The address of the remote metadata endpoint. /// The that can be used to abort the operation. /// The security keys retrieved from the remote server. - public async ValueTask GetSecurityKeysAsync(Uri address, CancellationToken cancellationToken = default) + public async ValueTask GetSecurityKeysAsync(Uri address!!, CancellationToken cancellationToken = default) { - if (address is null) - { - throw new ArgumentNullException(nameof(address)); - } - if (!address.IsAbsoluteUri) { throw new ArgumentException(SR.GetResourceString(SR.ID0144), nameof(address)); @@ -319,13 +309,8 @@ public class OpenIddictClientService /// The that can be used to abort the operation. /// The response and a merged principal containing the claims extracted from the tokens and userinfo response. public async ValueTask<(OpenIddictResponse Response, ClaimsPrincipal Principal)> RefreshTokensAsync( - OpenIddictClientRegistration registration, string token, CancellationToken cancellationToken = default) + OpenIddictClientRegistration registration!!, string token, CancellationToken cancellationToken = default) { - if (registration is null) - { - throw new ArgumentNullException(nameof(registration)); - } - if (string.IsNullOrEmpty(token)) { throw new ArgumentException(SR.GetResourceString(SR.ID0156), nameof(token)); @@ -442,13 +427,8 @@ public class OpenIddictClientService /// The that can be used to abort the operation. /// The token response. public async ValueTask SendTokenRequestAsync( - OpenIddictClientRegistration registration, OpenIddictRequest request, CancellationToken cancellationToken = default) + OpenIddictClientRegistration registration!!, OpenIddictRequest request, CancellationToken cancellationToken = default) { - if (registration is null) - { - throw new ArgumentNullException(nameof(registration)); - } - var configuration = await registration.ConfigurationManager.GetConfigurationAsync(default) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0140)); @@ -594,13 +574,8 @@ public class OpenIddictClientService /// The that can be used to abort the operation. /// The response and the principal extracted from the userinfo response or the userinfo token. public async ValueTask<(OpenIddictResponse Response, (ClaimsPrincipal? Principal, string? Token))> SendUserinfoRequestAsync( - OpenIddictClientRegistration registration, OpenIddictRequest request, CancellationToken cancellationToken = default) + OpenIddictClientRegistration registration!!, OpenIddictRequest request, CancellationToken cancellationToken = default) { - if (registration is null) - { - throw new ArgumentNullException(nameof(registration)); - } - var configuration = await registration.ConfigurationManager.GetConfigurationAsync(default) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0140)); diff --git a/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs b/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs index 2143e600..01e1af04 100644 --- a/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs +++ b/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs @@ -24,8 +24,8 @@ public class OpenIddictApplicationCache : IOpenIddictApplicationCa private readonly IOpenIddictApplicationStore _store; public OpenIddictApplicationCache( - IOptionsMonitor options, - IOpenIddictApplicationStoreResolver resolver) + IOptionsMonitor options!!, + IOpenIddictApplicationStoreResolver resolver!!) { _cache = new MemoryCache(new MemoryCacheOptions { @@ -37,13 +37,8 @@ public class OpenIddictApplicationCache : IOpenIddictApplicationCa } /// - public async ValueTask AddAsync(TApplication application, CancellationToken cancellationToken) + public async ValueTask AddAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - _cache.Remove(new { Method = nameof(FindByClientIdAsync), @@ -114,10 +109,10 @@ public class OpenIddictApplicationCache : IOpenIddictApplicationCa if (_cache.TryGetValue(parameters, out TApplication? application)) { - return new ValueTask(application); + return new(application); } - return new ValueTask(ExecuteAsync()); + return new(ExecuteAsync()); async Task ExecuteAsync() { @@ -148,10 +143,10 @@ public class OpenIddictApplicationCache : IOpenIddictApplicationCa if (_cache.TryGetValue(parameters, out TApplication? application)) { - return new ValueTask(application); + return new(application); } - return new ValueTask(ExecuteAsync()); + return new(ExecuteAsync()); async Task ExecuteAsync() { @@ -249,13 +244,8 @@ public class OpenIddictApplicationCache : IOpenIddictApplicationCa } /// - public async ValueTask RemoveAsync(TApplication application, CancellationToken cancellationToken) + public async ValueTask RemoveAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - var identifier = await _store.GetIdAsync(application, cancellationToken); if (string.IsNullOrEmpty(identifier)) { @@ -276,13 +266,8 @@ public class OpenIddictApplicationCache : IOpenIddictApplicationCa /// The application to store in the cache entry, if applicable. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - protected virtual async ValueTask CreateEntryAsync(object key, TApplication? application, CancellationToken cancellationToken) + protected virtual async ValueTask CreateEntryAsync(object key!!, TApplication? application, CancellationToken cancellationToken) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - using var entry = _cache.CreateEntry(key); if (application is not null) @@ -308,13 +293,8 @@ public class OpenIddictApplicationCache : IOpenIddictApplicationCa /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. protected virtual async ValueTask CreateEntryAsync( - object key, ImmutableArray applications, CancellationToken cancellationToken) + object key!!, ImmutableArray applications, CancellationToken cancellationToken) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - using var entry = _cache.CreateEntry(key); foreach (var application in applications) @@ -343,13 +323,8 @@ public class OpenIddictApplicationCache : IOpenIddictApplicationCa /// whose result returns an expiration signal for the specified application. /// protected virtual async ValueTask CreateExpirationSignalAsync( - TApplication application, CancellationToken cancellationToken) + TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - var identifier = await _store.GetIdAsync(application, cancellationToken); if (string.IsNullOrEmpty(identifier)) { diff --git a/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs b/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs index df9794aa..3cd30957 100644 --- a/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs +++ b/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs @@ -24,8 +24,8 @@ public class OpenIddictAuthorizationCache : IOpenIddictAuthoriza private readonly IOpenIddictAuthorizationStore _store; public OpenIddictAuthorizationCache( - IOptionsMonitor options, - IOpenIddictAuthorizationStoreResolver resolver) + IOptionsMonitor options!!, + IOpenIddictAuthorizationStoreResolver resolver!!) { _cache = new MemoryCache(new MemoryCacheOptions { @@ -37,13 +37,8 @@ public class OpenIddictAuthorizationCache : IOpenIddictAuthoriza } /// - public async ValueTask AddAsync(TAuthorization authorization, CancellationToken cancellationToken) + public async ValueTask AddAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - _cache.Remove(new { Method = nameof(FindAsync), @@ -365,10 +360,10 @@ public class OpenIddictAuthorizationCache : IOpenIddictAuthoriza if (_cache.TryGetValue(parameters, out TAuthorization? authorization)) { - return new ValueTask(authorization); + return new(authorization); } - return new ValueTask(ExecuteAsync()); + return new(ExecuteAsync()); async Task ExecuteAsync() { @@ -425,13 +420,8 @@ public class OpenIddictAuthorizationCache : IOpenIddictAuthoriza } /// - public async ValueTask RemoveAsync(TAuthorization authorization, CancellationToken cancellationToken) + public async ValueTask RemoveAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - var identifier = await _store.GetIdAsync(authorization, cancellationToken); if (string.IsNullOrEmpty(identifier)) { @@ -452,13 +442,8 @@ public class OpenIddictAuthorizationCache : IOpenIddictAuthoriza /// The authorization to store in the cache entry, if applicable. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - protected virtual async ValueTask CreateEntryAsync(object key, TAuthorization? authorization, CancellationToken cancellationToken) + protected virtual async ValueTask CreateEntryAsync(object key!!, TAuthorization? authorization, CancellationToken cancellationToken) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - using var entry = _cache.CreateEntry(key); if (authorization is not null) @@ -484,13 +469,8 @@ public class OpenIddictAuthorizationCache : IOpenIddictAuthoriza /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. protected virtual async ValueTask CreateEntryAsync( - object key, ImmutableArray authorizations, CancellationToken cancellationToken) + object key!!, ImmutableArray authorizations, CancellationToken cancellationToken) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - using var entry = _cache.CreateEntry(key); foreach (var authorization in authorizations) @@ -519,13 +499,8 @@ public class OpenIddictAuthorizationCache : IOpenIddictAuthoriza /// whose result returns an expiration signal for the specified authorization. /// protected virtual async ValueTask CreateExpirationSignalAsync( - TAuthorization authorization, CancellationToken cancellationToken) + TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - var identifier = await _store.GetIdAsync(authorization, cancellationToken); if (string.IsNullOrEmpty(identifier)) { diff --git a/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs b/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs index 48f507e4..882b89ac 100644 --- a/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs +++ b/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs @@ -24,8 +24,8 @@ public class OpenIddictScopeCache : IOpenIddictScopeCache, IDisp private readonly IOpenIddictScopeStore _store; public OpenIddictScopeCache( - IOptionsMonitor options, - IOpenIddictScopeStoreResolver resolver) + IOptionsMonitor options!!, + IOpenIddictScopeStoreResolver resolver!!) { _cache = new MemoryCache(new MemoryCacheOptions { @@ -37,13 +37,8 @@ public class OpenIddictScopeCache : IOpenIddictScopeCache, IDisp } /// - public async ValueTask AddAsync(TScope scope, CancellationToken cancellationToken) + public async ValueTask AddAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - _cache.Remove(new { Method = nameof(FindByIdAsync), @@ -105,10 +100,10 @@ public class OpenIddictScopeCache : IOpenIddictScopeCache, IDisp if (_cache.TryGetValue(parameters, out TScope? scope)) { - return new ValueTask(scope); + return new(scope); } - return new ValueTask(ExecuteAsync()); + return new(ExecuteAsync()); async Task ExecuteAsync() { @@ -139,7 +134,7 @@ public class OpenIddictScopeCache : IOpenIddictScopeCache, IDisp if (_cache.TryGetValue(parameters, out TScope? scope)) { - return new ValueTask(scope); + return new(scope); } async Task ExecuteAsync() @@ -154,13 +149,13 @@ public class OpenIddictScopeCache : IOpenIddictScopeCache, IDisp return scope; } - return new ValueTask(ExecuteAsync()); + return new(ExecuteAsync()); } /// public IAsyncEnumerable FindByNamesAsync(ImmutableArray names, CancellationToken cancellationToken) { - if (names.Any(name => string.IsNullOrEmpty(name))) + if (names.Any(string.IsNullOrEmpty)) { throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names)); } @@ -222,13 +217,8 @@ public class OpenIddictScopeCache : IOpenIddictScopeCache, IDisp } /// - public async ValueTask RemoveAsync(TScope scope, CancellationToken cancellationToken) + public async ValueTask RemoveAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - var identifier = await _store.GetIdAsync(scope, cancellationToken); if (string.IsNullOrEmpty(identifier)) { @@ -249,13 +239,8 @@ public class OpenIddictScopeCache : IOpenIddictScopeCache, IDisp /// The scope to store in the cache entry, if applicable. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - protected virtual async ValueTask CreateEntryAsync(object key, TScope? scope, CancellationToken cancellationToken) + protected virtual async ValueTask CreateEntryAsync(object key!!, TScope? scope, CancellationToken cancellationToken) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - using var entry = _cache.CreateEntry(key); if (scope is not null) @@ -281,13 +266,8 @@ public class OpenIddictScopeCache : IOpenIddictScopeCache, IDisp /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. protected virtual async ValueTask CreateEntryAsync( - object key, ImmutableArray scopes, CancellationToken cancellationToken) + object key!!, ImmutableArray scopes, CancellationToken cancellationToken) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - using var entry = _cache.CreateEntry(key); foreach (var scope in scopes) @@ -315,13 +295,8 @@ public class OpenIddictScopeCache : IOpenIddictScopeCache, IDisp /// A that can be used to monitor the asynchronous operation, /// whose result returns an expiration signal for the specified scope. /// - protected virtual async ValueTask CreateExpirationSignalAsync(TScope scope, CancellationToken cancellationToken) + protected virtual async ValueTask CreateExpirationSignalAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - var identifier = await _store.GetIdAsync(scope, cancellationToken); if (string.IsNullOrEmpty(identifier)) { diff --git a/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs b/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs index f9dbc056..9dfb0a17 100644 --- a/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs +++ b/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs @@ -24,8 +24,8 @@ public class OpenIddictTokenCache : IOpenIddictTokenCache, IDisp private readonly IOpenIddictTokenStore _store; public OpenIddictTokenCache( - IOptionsMonitor options, - IOpenIddictTokenStoreResolver resolver) + IOptionsMonitor options!!, + IOpenIddictTokenStoreResolver resolver!!) { _cache = new MemoryCache(new MemoryCacheOptions { @@ -37,13 +37,8 @@ public class OpenIddictTokenCache : IOpenIddictTokenCache, IDisp } /// - public async ValueTask AddAsync(TToken token, CancellationToken cancellationToken) + public async ValueTask AddAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - _cache.Remove(new { Method = nameof(FindAsync), @@ -383,10 +378,10 @@ public class OpenIddictTokenCache : IOpenIddictTokenCache, IDisp if (_cache.TryGetValue(parameters, out TToken? token)) { - return new ValueTask(token); + return new(token); } - return new ValueTask(ExecuteAsync()); + return new(ExecuteAsync()); async Task ExecuteAsync() { @@ -417,10 +412,10 @@ public class OpenIddictTokenCache : IOpenIddictTokenCache, IDisp if (_cache.TryGetValue(parameters, out TToken? token)) { - return new ValueTask(token); + return new(token); } - return new ValueTask(ExecuteAsync()); + return new(ExecuteAsync()); async Task ExecuteAsync() { @@ -477,13 +472,8 @@ public class OpenIddictTokenCache : IOpenIddictTokenCache, IDisp } /// - public async ValueTask RemoveAsync(TToken token, CancellationToken cancellationToken) + public async ValueTask RemoveAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - var identifier = await _store.GetIdAsync(token, cancellationToken); if (string.IsNullOrEmpty(identifier)) { @@ -504,13 +494,8 @@ public class OpenIddictTokenCache : IOpenIddictTokenCache, IDisp /// The token to store in the cache entry, if applicable. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - protected virtual async ValueTask CreateEntryAsync(object key, TToken? token, CancellationToken cancellationToken) + protected virtual async ValueTask CreateEntryAsync(object key!!, TToken? token, CancellationToken cancellationToken) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - using var entry = _cache.CreateEntry(key); if (token is not null) @@ -536,13 +521,8 @@ public class OpenIddictTokenCache : IOpenIddictTokenCache, IDisp /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. protected virtual async ValueTask CreateEntryAsync( - object key, ImmutableArray tokens, CancellationToken cancellationToken) + object key!!, ImmutableArray tokens, CancellationToken cancellationToken) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - using var entry = _cache.CreateEntry(key); foreach (var token in tokens) @@ -570,13 +550,8 @@ public class OpenIddictTokenCache : IOpenIddictTokenCache, IDisp /// A that can be used to monitor the asynchronous operation, /// whose result returns an expiration signal for the specified token. /// - protected virtual async ValueTask CreateExpirationSignalAsync(TToken token, CancellationToken cancellationToken) + protected virtual async ValueTask CreateExpirationSignalAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - var identifier = await _store.GetIdAsync(token, cancellationToken); if (string.IsNullOrEmpty(identifier)) { diff --git a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs index 9625b8af..98dc8390 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs @@ -41,10 +41,10 @@ namespace OpenIddict.Core; public class OpenIddictApplicationManager : IOpenIddictApplicationManager where TApplication : class { public OpenIddictApplicationManager( - IOpenIddictApplicationCache cache, - ILogger> logger, - IOptionsMonitor options, - IOpenIddictApplicationStoreResolver resolver) + IOpenIddictApplicationCache cache!!, + ILogger> logger!!, + IOptionsMonitor options!!, + IOpenIddictApplicationStoreResolver resolver!!) { Cache = cache; Logger = logger; @@ -94,15 +94,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns the number of applications that match the specified query. /// public virtual ValueTask CountAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.CountAsync(query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => Store.CountAsync(query, cancellationToken); /// /// Creates a new application. @@ -126,13 +119,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask CreateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default) + public virtual async ValueTask CreateAsync(TApplication application!!, string? secret, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (!string.IsNullOrEmpty(await Store.GetClientSecretAsync(application, cancellationToken))) { throw new ArgumentException(SR.GetResourceString(SR.ID0206), nameof(application)); @@ -201,13 +189,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns the unique identifier associated with the application. /// public virtual async ValueTask CreateAsync( - OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) + OpenIddictApplicationDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - var application = await Store.InstantiateAsync(cancellationToken); if (application is null) { @@ -238,13 +221,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken = default) + public virtual async ValueTask DeleteAsync(TApplication application!!, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (!Options.CurrentValue.DisableEntityCaching) { await Cache.RemoveAsync(application, cancellationToken); @@ -423,15 +401,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return GetAsync(static (applications, query) => query(applications), query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => GetAsync(static (applications, query) => query(applications), query, cancellationToken); /// /// Executes the specified query and returns the first element. @@ -446,16 +417,9 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.GetAsync(query, state, cancellationToken); - } + => Store.GetAsync(query, state, cancellationToken); /// /// Retrieves the client identifier associated with an application. @@ -467,15 +431,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns the client identifier associated with the application. /// public virtual ValueTask GetClientIdAsync( - TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return Store.GetClientIdAsync(application, cancellationToken); - } + TApplication application!!, CancellationToken cancellationToken = default) + => Store.GetClientIdAsync(application, cancellationToken); /// /// Retrieves the client type associated with an application. @@ -487,15 +444,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns the client type of the application (by default, "public"). /// public virtual ValueTask GetClientTypeAsync( - TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return Store.GetClientTypeAsync(application, cancellationToken); - } + TApplication application!!, CancellationToken cancellationToken = default) + => Store.GetClientTypeAsync(application, cancellationToken); /// /// Retrieves the consent type associated with an application. @@ -507,13 +457,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns the consent type of the application (by default, "explicit"). /// public virtual async ValueTask GetConsentTypeAsync( - TApplication application, CancellationToken cancellationToken = default) + TApplication application!!, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - var type = await Store.GetConsentTypeAsync(application, cancellationToken); if (string.IsNullOrEmpty(type)) { @@ -533,15 +478,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns the display name associated with the application. /// public virtual ValueTask GetDisplayNameAsync( - TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return Store.GetDisplayNameAsync(application, cancellationToken); - } + TApplication application!!, CancellationToken cancellationToken = default) + => Store.GetDisplayNameAsync(application, cancellationToken); /// /// Retrieves the localized display names associated with an application. @@ -553,21 +491,9 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns all the localized display names associated with the application. /// public virtual async ValueTask> GetDisplayNamesAsync( - TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - var names = await Store.GetDisplayNamesAsync(application, cancellationToken); - if (names is null || names.Count == 0) - { - return ImmutableDictionary.Create(); - } - - return names; - } + TApplication application!!, CancellationToken cancellationToken = default) + => await Store.GetDisplayNamesAsync(application, cancellationToken) is { Count: > 0 } names ? + names : ImmutableDictionary.Create(); /// /// Retrieves the unique identifier associated with an application. @@ -578,15 +504,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the application. /// - public virtual ValueTask GetIdAsync(TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return Store.GetIdAsync(application, cancellationToken); - } + public virtual ValueTask GetIdAsync(TApplication application!!, CancellationToken cancellationToken = default) + => Store.GetIdAsync(application, cancellationToken); /// /// Retrieves the localized display name associated with an application @@ -616,20 +535,10 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns the matching localized display name associated with the application. /// public virtual async ValueTask GetLocalizedDisplayNameAsync( - TApplication application, CultureInfo culture, CancellationToken cancellationToken = default) + TApplication application!!, CultureInfo culture!!, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (culture is null) - { - throw new ArgumentNullException(nameof(culture)); - } - var names = await Store.GetDisplayNamesAsync(application, cancellationToken); - if (names is null || names.IsEmpty) + if (names is not { IsEmpty: false }) { return await Store.GetDisplayNameAsync(application, cancellationToken); } @@ -659,15 +568,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns all the permissions associated with the application. /// public virtual ValueTask> GetPermissionsAsync( - TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return Store.GetPermissionsAsync(application, cancellationToken); - } + TApplication application!!, CancellationToken cancellationToken = default) + => Store.GetPermissionsAsync(application, cancellationToken); /// /// Retrieves the logout callback addresses associated with an application. @@ -679,15 +581,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns all the post_logout_redirect_uri associated with the application. /// public virtual ValueTask> GetPostLogoutRedirectUrisAsync( - TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken); - } + TApplication application!!, CancellationToken cancellationToken = default) + => Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken); /// /// Retrieves the additional properties associated with an application. @@ -699,15 +594,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns all the additional properties associated with the application. /// public virtual ValueTask> GetPropertiesAsync( - TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return Store.GetPropertiesAsync(application, cancellationToken); - } + TApplication application!!, CancellationToken cancellationToken = default) + => Store.GetPropertiesAsync(application, cancellationToken); /// /// Retrieves the callback addresses associated with an application. @@ -719,15 +607,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns all the redirect_uri associated with the application. /// public virtual ValueTask> GetRedirectUrisAsync( - TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return Store.GetRedirectUrisAsync(application, cancellationToken); - } + TApplication application!!, CancellationToken cancellationToken = default) + => Store.GetRedirectUrisAsync(application, cancellationToken); /// /// Retrieves the requirements associated with an application. @@ -739,15 +620,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns all the requirements associated with the application. /// public virtual ValueTask> GetRequirementsAsync( - TApplication application, CancellationToken cancellationToken = default) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return Store.GetRequirementsAsync(application, cancellationToken); - } + TApplication application!!, CancellationToken cancellationToken = default) + => Store.GetRequirementsAsync(application, cancellationToken); /// /// Determines whether a given application has the specified client type. @@ -757,13 +631,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// The that can be used to abort the operation. /// true if the application has the specified client type, false otherwise. public virtual async ValueTask HasClientTypeAsync( - TApplication application, string type, CancellationToken cancellationToken = default) + TApplication application!!, string type, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0209), nameof(type)); @@ -780,13 +649,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// The that can be used to abort the operation. /// true if the application has the specified consent type, false otherwise. public virtual async ValueTask HasConsentTypeAsync( - TApplication application, string type, CancellationToken cancellationToken = default) + TApplication application!!, string type, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0210), nameof(type)); @@ -803,13 +667,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// The that can be used to abort the operation. /// true if the application has been granted the specified permission, false otherwise. public virtual async ValueTask HasPermissionAsync( - TApplication application, string permission, CancellationToken cancellationToken = default) + TApplication application!!, string permission, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(permission)) { throw new ArgumentException(SR.GetResourceString(SR.ID0211), nameof(permission)); @@ -826,13 +685,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// The that can be used to abort the operation. /// true if the requirement has been enforced for the specified application, false otherwise. public virtual async ValueTask HasRequirementAsync( - TApplication application, string requirement, CancellationToken cancellationToken = default) + TApplication application!!, string requirement, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(requirement)) { throw new ArgumentException(SR.GetResourceString(SR.ID0212), nameof(requirement)); @@ -860,15 +714,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return ListAsync(static (applications, query) => query(applications), query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => ListAsync(static (applications, query) => query(applications), query, cancellationToken); /// /// Executes the specified query and returns all the corresponding elements. @@ -880,16 +727,9 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.ListAsync(query, state, cancellationToken); - } + => Store.ListAsync(query, state, cancellationToken); /// /// Populates the application using the specified descriptor. @@ -900,19 +740,9 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask PopulateAsync(TApplication application, - OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask PopulateAsync(TApplication application!!, + OpenIddictApplicationDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - await Store.SetClientIdAsync(application, descriptor.ClientId, cancellationToken); await Store.SetClientSecretAsync(application, descriptor.ClientSecret, cancellationToken); await Store.SetClientTypeAsync(application, descriptor.Type, cancellationToken); @@ -938,19 +768,9 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// A that can be used to monitor the asynchronous operation. /// public virtual async ValueTask PopulateAsync( - OpenIddictApplicationDescriptor descriptor, - TApplication application, CancellationToken cancellationToken = default) + OpenIddictApplicationDescriptor descriptor!!, + TApplication application!!, CancellationToken cancellationToken = default) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - descriptor.ClientId = await Store.GetClientIdAsync(application, cancellationToken); descriptor.ClientSecret = await Store.GetClientSecretAsync(application, cancellationToken); descriptor.ConsentType = await Store.GetConsentTypeAsync(application, cancellationToken); @@ -1018,13 +838,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync(TApplication application, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TApplication application!!, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - var results = await GetValidationResultsAsync(application, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { @@ -1073,13 +888,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TApplication application!!, string? secret, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(secret)) { await Store.SetClientSecretAsync(application, null, cancellationToken); @@ -1103,18 +913,9 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync(TApplication application, - OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TApplication application!!, + OpenIddictApplicationDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } // Store the original client secret for later comparison. var comparand = await Store.GetClientSecretAsync(application, cancellationToken); @@ -1139,12 +940,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// The that can be used to abort the operation. /// The validation error encountered when validating the application. public virtual async IAsyncEnumerable ValidateAsync( - TApplication application, [EnumeratorCancellation] CancellationToken cancellationToken = default) + TApplication application!!, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } // Ensure the client_id is not null or empty and is not already used for a different application. var identifier = await Store.GetClientIdAsync(application, cancellationToken); @@ -1254,12 +1051,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns a boolean indicating whether the client secret was valid. /// public virtual async ValueTask ValidateClientSecretAsync( - TApplication application, string secret, CancellationToken cancellationToken = default) + TApplication application!!, string secret, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } if (string.IsNullOrEmpty(secret)) { throw new ArgumentException(SR.GetResourceString(SR.ID0216), nameof(secret)); @@ -1301,13 +1094,8 @@ public class OpenIddictApplicationManager : IOpenIddictApplication /// whose result returns a boolean indicating whether the redirect_uri was valid. /// public virtual async ValueTask ValidateRedirectUriAsync( - TApplication application, string address, CancellationToken cancellationToken = default) + TApplication application!!, string address, CancellationToken cancellationToken = default) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(address)) { throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(address)); @@ -1358,7 +1146,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication var hash = HashSecret(secret, salt, HashAlgorithmName.SHA256, iterations: 10_000, length: 256 / 8); - return new ValueTask( + return new( #if SUPPORTS_BASE64_SPAN_CONVERSION Convert.ToBase64String(hash) #else @@ -1431,14 +1219,14 @@ public class OpenIddictApplicationManager : IOpenIddictApplication try { - return new ValueTask(VerifyHashedSecret(comparand, secret)); + return new(VerifyHashedSecret(comparand, secret)); } catch (Exception exception) { Logger.LogWarning(exception, SR.GetResourceString(SR.ID6163)); - return new ValueTask(false); + return new(false); } // Note: the following logic deliberately uses the same format as CryptoHelper (used in OpenIddict 1.x/2.x), diff --git a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs index d8544039..daa9e401 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs @@ -28,10 +28,10 @@ namespace OpenIddict.Core; public class OpenIddictAuthorizationManager : IOpenIddictAuthorizationManager where TAuthorization : class { public OpenIddictAuthorizationManager( - IOpenIddictAuthorizationCache cache, - ILogger> logger, - IOptionsMonitor options, - IOpenIddictAuthorizationStoreResolver resolver) + IOpenIddictAuthorizationCache cache!!, + ILogger> logger!!, + IOptionsMonitor options!!, + IOpenIddictAuthorizationStoreResolver resolver!!) { Cache = cache; Logger = logger; @@ -81,15 +81,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns the number of authorizations that match the specified query. /// public virtual ValueTask CountAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.CountAsync(query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => Store.CountAsync(query, cancellationToken); /// /// Creates a new authorization. @@ -99,13 +92,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask CreateAsync(TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual async ValueTask CreateAsync(TAuthorization authorization!!, CancellationToken cancellationToken = default) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - // If no status was explicitly specified, assume that the authorization is valid. if (string.IsNullOrEmpty(await Store.GetStatusAsync(authorization, cancellationToken))) { @@ -157,13 +145,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// A that can be used to monitor the asynchronous operation, whose result returns the authorization. /// public virtual async ValueTask CreateAsync( - OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) + OpenIddictAuthorizationDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - var authorization = await Store.InstantiateAsync(cancellationToken); if (authorization is null) { @@ -189,14 +172,9 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// A that can be used to monitor the asynchronous operation, whose result returns the authorization. /// public virtual ValueTask CreateAsync( - ClaimsPrincipal principal, string subject, string client, + ClaimsPrincipal principal!!, string subject, string client, string type, ImmutableArray scopes, CancellationToken cancellationToken = default) { - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (string.IsNullOrEmpty(subject)) { throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject)); @@ -235,13 +213,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask DeleteAsync(TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual async ValueTask DeleteAsync(TAuthorization authorization!!, CancellationToken cancellationToken = default) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (!Options.CurrentValue.DisableEntityCaching) { await Cache.RemoveAsync(authorization, cancellationToken); @@ -614,15 +587,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns the application identifier associated with the authorization. /// public virtual ValueTask GetApplicationIdAsync( - TAuthorization authorization, CancellationToken cancellationToken = default) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return Store.GetApplicationIdAsync(authorization, cancellationToken); - } + TAuthorization authorization!!, CancellationToken cancellationToken = default) + => Store.GetApplicationIdAsync(authorization, cancellationToken); /// /// Executes the specified query and returns the first element. @@ -635,15 +601,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return GetAsync(static (authorizations, query) => query(authorizations), query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => GetAsync(static (authorizations, query) => query(authorizations), query, cancellationToken); /// /// Executes the specified query and returns the first element. @@ -658,16 +617,9 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.GetAsync(query, state, cancellationToken); - } + => Store.GetAsync(query, state, cancellationToken); /// /// Retrieves the creation date associated with an authorization. @@ -679,15 +631,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns the creation date associated with the specified authorization. /// public virtual ValueTask GetCreationDateAsync( - TAuthorization authorization, CancellationToken cancellationToken = default) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return Store.GetCreationDateAsync(authorization, cancellationToken); - } + TAuthorization authorization!!, CancellationToken cancellationToken = default) + => Store.GetCreationDateAsync(authorization, cancellationToken); /// /// Retrieves the unique identifier associated with an authorization. @@ -698,15 +643,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the authorization. /// - public virtual ValueTask GetIdAsync(TAuthorization authorization, CancellationToken cancellationToken = default) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return Store.GetIdAsync(authorization, cancellationToken); - } + public virtual ValueTask GetIdAsync(TAuthorization authorization!!, CancellationToken cancellationToken = default) + => Store.GetIdAsync(authorization, cancellationToken); /// /// Retrieves the additional properties associated with an authorization. @@ -718,15 +656,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns all the additional properties associated with the authorization. /// public virtual ValueTask> GetPropertiesAsync( - TAuthorization authorization, CancellationToken cancellationToken = default) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return Store.GetPropertiesAsync(authorization, cancellationToken); - } + TAuthorization authorization!!, CancellationToken cancellationToken = default) + => Store.GetPropertiesAsync(authorization, cancellationToken); /// /// Retrieves the scopes associated with an authorization. @@ -738,15 +669,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns the scopes associated with the specified authorization. /// public virtual ValueTask> GetScopesAsync( - TAuthorization authorization, CancellationToken cancellationToken = default) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return Store.GetScopesAsync(authorization, cancellationToken); - } + TAuthorization authorization!!, CancellationToken cancellationToken = default) + => Store.GetScopesAsync(authorization, cancellationToken); /// /// Retrieves the status associated with an authorization. @@ -758,15 +682,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns the status associated with the specified authorization. /// public virtual ValueTask GetStatusAsync( - TAuthorization authorization, CancellationToken cancellationToken = default) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return Store.GetStatusAsync(authorization, cancellationToken); - } + TAuthorization authorization!!, CancellationToken cancellationToken = default) + => Store.GetStatusAsync(authorization, cancellationToken); /// /// Retrieves the subject associated with an authorization. @@ -778,15 +695,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns the subject associated with the specified authorization. /// public virtual ValueTask GetSubjectAsync( - TAuthorization authorization, CancellationToken cancellationToken = default) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return Store.GetSubjectAsync(authorization, cancellationToken); - } + TAuthorization authorization!!, CancellationToken cancellationToken = default) + => Store.GetSubjectAsync(authorization, cancellationToken); /// /// Retrieves the type associated with an authorization. @@ -798,15 +708,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// whose result returns the type associated with the specified authorization. /// public virtual ValueTask GetTypeAsync( - TAuthorization authorization, CancellationToken cancellationToken = default) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return Store.GetTypeAsync(authorization, cancellationToken); - } + TAuthorization authorization!!, CancellationToken cancellationToken = default) + => Store.GetTypeAsync(authorization, cancellationToken); /// /// Determines whether the specified scopes are included in the authorization. @@ -815,17 +718,10 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// The scopes. /// The that can be used to abort the operation. /// true if the scopes are included in the authorization, false otherwise. - public virtual async ValueTask HasScopesAsync(TAuthorization authorization, + public virtual async ValueTask HasScopesAsync(TAuthorization authorization!!, ImmutableArray scopes, CancellationToken cancellationToken = default) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new HashSet(await Store.GetScopesAsync( + => new HashSet(await Store.GetScopesAsync( authorization, cancellationToken), StringComparer.Ordinal).IsSupersetOf(scopes); - } /// /// Determines whether a given authorization has the specified status. @@ -834,14 +730,9 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// The expected status. /// The that can be used to abort the operation. /// true if the authorization has the specified status, false otherwise. - public virtual async ValueTask HasStatusAsync(TAuthorization authorization, + public virtual async ValueTask HasStatusAsync(TAuthorization authorization!!, string status, CancellationToken cancellationToken = default) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (string.IsNullOrEmpty(status)) { throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status)); @@ -858,13 +749,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// The that can be used to abort the operation. /// true if the authorization has the specified type, false otherwise. public virtual async ValueTask HasTypeAsync( - TAuthorization authorization, string type, CancellationToken cancellationToken = default) + TAuthorization authorization!!, string type, CancellationToken cancellationToken = default) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type)); @@ -892,15 +778,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return ListAsync(static (authorizations, query) => query(authorizations), query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => ListAsync(static (authorizations, query) => query(authorizations), query, cancellationToken); /// /// Executes the specified query and returns all the corresponding elements. @@ -912,16 +791,9 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.ListAsync(query, state, cancellationToken); - } + => Store.ListAsync(query, state, cancellationToken); /// /// Populates the authorization using the specified descriptor. @@ -932,19 +804,9 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask PopulateAsync(TAuthorization authorization, - OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask PopulateAsync(TAuthorization authorization!!, + OpenIddictAuthorizationDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - await Store.SetApplicationIdAsync(authorization, descriptor.ApplicationId, cancellationToken); await Store.SetCreationDateAsync(authorization, descriptor.CreationDate, cancellationToken); await Store.SetPropertiesAsync(authorization, descriptor.Properties.ToImmutableDictionary(), cancellationToken); @@ -964,19 +826,9 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// A that can be used to monitor the asynchronous operation. /// public virtual async ValueTask PopulateAsync( - OpenIddictAuthorizationDescriptor descriptor, - TAuthorization authorization, CancellationToken cancellationToken = default) + OpenIddictAuthorizationDescriptor descriptor!!, + TAuthorization authorization!!, CancellationToken cancellationToken = default) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - descriptor.ApplicationId = await Store.GetApplicationIdAsync(authorization, cancellationToken); descriptor.CreationDate = await Store.GetCreationDateAsync(authorization, cancellationToken); descriptor.Scopes.Clear(); @@ -1014,13 +866,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// The authorization to revoke. /// The that can be used to abort the operation. /// true if the authorization was successfully revoked, false otherwise. - public virtual async ValueTask TryRevokeAsync(TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual async ValueTask TryRevokeAsync(TAuthorization authorization!!, CancellationToken cancellationToken = default) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - var status = await Store.GetStatusAsync(authorization, cancellationToken); if (string.Equals(status, Statuses.Revoked, StringComparison.OrdinalIgnoreCase)) { @@ -1061,13 +908,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync(TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TAuthorization authorization!!, CancellationToken cancellationToken = default) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - var results = await GetValidationResultsAsync(authorization, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { @@ -1114,19 +956,9 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync(TAuthorization authorization, - OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TAuthorization authorization!!, + OpenIddictAuthorizationDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - await PopulateAsync(authorization, descriptor, cancellationToken); await UpdateAsync(authorization, cancellationToken); } @@ -1138,13 +970,8 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori /// The that can be used to abort the operation. /// The validation error encountered when validating the authorization. public virtual async IAsyncEnumerable ValidateAsync( - TAuthorization authorization, [EnumeratorCancellation] CancellationToken cancellationToken = default) + TAuthorization authorization!!, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - var type = await Store.GetTypeAsync(authorization, cancellationToken); if (string.IsNullOrEmpty(type)) { diff --git a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs index 6a26c8c5..b5f009be 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs @@ -27,10 +27,10 @@ namespace OpenIddict.Core; public class OpenIddictScopeManager : IOpenIddictScopeManager where TScope : class { public OpenIddictScopeManager( - IOpenIddictScopeCache cache, - ILogger> logger, - IOptionsMonitor options, - IOpenIddictScopeStoreResolver resolver) + IOpenIddictScopeCache cache!!, + ILogger> logger!!, + IOptionsMonitor options!!, + IOpenIddictScopeStoreResolver resolver!!) { Cache = cache; Logger = logger; @@ -80,15 +80,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// whose result returns the number of scopes that match the specified query. /// public virtual ValueTask CountAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.CountAsync(query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => Store.CountAsync(query, cancellationToken); /// /// Creates a new scope. @@ -98,13 +91,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cancellationToken = default) + public virtual async ValueTask CreateAsync(TScope scope!!, CancellationToken cancellationToken = default) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - var results = await GetValidationResultsAsync(scope, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { @@ -150,13 +138,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// A that can be used to monitor the asynchronous operation, whose result returns the scope. /// public virtual async ValueTask CreateAsync( - OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) + OpenIddictScopeDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - var scope = await Store.InstantiateAsync(cancellationToken); if (scope is null) { @@ -177,13 +160,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cancellationToken = default) + public virtual async ValueTask DeleteAsync(TScope scope!!, CancellationToken cancellationToken = default) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (!Options.CurrentValue.DisableEntityCaching) { await Cache.RemoveAsync(scope, cancellationToken); @@ -276,7 +254,7 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco public virtual IAsyncEnumerable FindByNamesAsync( ImmutableArray names, CancellationToken cancellationToken = default) { - if (names.Any(name => string.IsNullOrEmpty(name))) + if (names.Any(string.IsNullOrEmpty)) { throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names)); } @@ -361,15 +339,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return GetAsync(static (scopes, query) => query(scopes), query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => GetAsync(static (scopes, query) => query(scopes), query, cancellationToken); /// /// Executes the specified query and returns the first element. @@ -384,16 +355,9 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.GetAsync(query, state, cancellationToken); - } + => Store.GetAsync(query, state, cancellationToken); /// /// Retrieves the description associated with a scope. @@ -404,15 +368,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// A that can be used to monitor the asynchronous operation, /// whose result returns the description associated with the specified scope. /// - public virtual ValueTask GetDescriptionAsync(TScope scope, CancellationToken cancellationToken = default) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return Store.GetDescriptionAsync(scope, cancellationToken); - } + public virtual ValueTask GetDescriptionAsync(TScope scope!!, CancellationToken cancellationToken = default) + => Store.GetDescriptionAsync(scope, cancellationToken); /// /// Retrieves the localized descriptions associated with an scope. @@ -424,21 +381,9 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// whose result returns all the localized descriptions associated with the scope. /// public virtual async ValueTask> GetDescriptionsAsync( - TScope scope, CancellationToken cancellationToken = default) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - var descriptions = await Store.GetDescriptionsAsync(scope, cancellationToken); - if (descriptions is null || descriptions.Count == 0) - { - return ImmutableDictionary.Create(); - } - - return descriptions; - } + TScope scope!!, CancellationToken cancellationToken = default) + => await Store.GetDescriptionsAsync(scope, cancellationToken) is { Count: > 0 } descriptions ? + descriptions : ImmutableDictionary.Create(); /// /// Retrieves the display name associated with a scope. @@ -449,15 +394,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the scope. /// - public virtual ValueTask GetDisplayNameAsync(TScope scope, CancellationToken cancellationToken = default) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return Store.GetDisplayNameAsync(scope, cancellationToken); - } + public virtual ValueTask GetDisplayNameAsync(TScope scope!!, CancellationToken cancellationToken = default) + => Store.GetDisplayNameAsync(scope, cancellationToken); /// /// Retrieves the localized display names associated with an scope. @@ -469,21 +407,9 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// whose result returns all the localized display names associated with the scope. /// public virtual async ValueTask> GetDisplayNamesAsync( - TScope scope, CancellationToken cancellationToken = default) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - var names = await Store.GetDisplayNamesAsync(scope, cancellationToken); - if (names is null || names.Count == 0) - { - return ImmutableDictionary.Create(); - } - - return names; - } + TScope scope!!, CancellationToken cancellationToken = default) + => await Store.GetDisplayNamesAsync(scope, cancellationToken) is { Count: > 0 } names ? + names : ImmutableDictionary.Create(); /// /// Retrieves the unique identifier associated with a scope. @@ -494,15 +420,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the scope. /// - public virtual ValueTask GetIdAsync(TScope scope, CancellationToken cancellationToken = default) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return Store.GetIdAsync(scope, cancellationToken); - } + public virtual ValueTask GetIdAsync(TScope scope!!, CancellationToken cancellationToken = default) + => Store.GetIdAsync(scope, cancellationToken); /// /// Retrieves the localized display name associated with an scope @@ -531,20 +450,10 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// whose result returns the matching display name associated with the scope. /// public virtual async ValueTask GetLocalizedDisplayNameAsync( - TScope scope, CultureInfo culture, CancellationToken cancellationToken = default) + TScope scope!!, CultureInfo culture!!, CancellationToken cancellationToken = default) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (culture is null) - { - throw new ArgumentNullException(nameof(culture)); - } - var names = await Store.GetDisplayNamesAsync(scope, cancellationToken); - if (names is null || names.IsEmpty) + if (names is not { IsEmpty: false }) { return await Store.GetDisplayNameAsync(scope, cancellationToken); } @@ -591,20 +500,10 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// whose result returns the matching localized description associated with the scope. /// public virtual async ValueTask GetLocalizedDescriptionAsync( - TScope scope, CultureInfo culture, CancellationToken cancellationToken = default) + TScope scope!!, CultureInfo culture!!, CancellationToken cancellationToken = default) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (culture is null) - { - throw new ArgumentNullException(nameof(culture)); - } - var descriptions = await Store.GetDescriptionsAsync(scope, cancellationToken); - if (descriptions is null || descriptions.IsEmpty) + if (descriptions is not { IsEmpty: false }) { return await Store.GetDescriptionAsync(scope, cancellationToken); } @@ -633,15 +532,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// A that can be used to monitor the asynchronous operation, /// whose result returns the name associated with the specified scope. /// - public virtual ValueTask GetNameAsync(TScope scope, CancellationToken cancellationToken = default) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return Store.GetNameAsync(scope, cancellationToken); - } + public virtual ValueTask GetNameAsync(TScope scope!!, CancellationToken cancellationToken = default) + => Store.GetNameAsync(scope, cancellationToken); /// /// Retrieves the additional properties associated with a scope. @@ -653,15 +545,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// whose result returns all the additional properties associated with the scope. /// public virtual ValueTask> GetPropertiesAsync( - TScope scope, CancellationToken cancellationToken = default) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return Store.GetPropertiesAsync(scope, cancellationToken); - } + TScope scope!!, CancellationToken cancellationToken = default) + => Store.GetPropertiesAsync(scope, cancellationToken); /// /// Retrieves the resources associated with a scope. @@ -673,15 +558,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// whose result returns all the resources associated with the scope. /// public virtual ValueTask> GetResourcesAsync( - TScope scope, CancellationToken cancellationToken = default) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return Store.GetResourcesAsync(scope, cancellationToken); - } + TScope scope!!, CancellationToken cancellationToken = default) + => Store.GetResourcesAsync(scope, cancellationToken); /// /// Executes the specified query and returns all the corresponding elements. @@ -702,15 +580,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return ListAsync(static (scopes, query) => query(scopes), query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => ListAsync(static (scopes, query) => query(scopes), query, cancellationToken); /// /// Executes the specified query and returns all the corresponding elements. @@ -722,16 +593,9 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.ListAsync(query, state, cancellationToken); - } + => Store.ListAsync(query, state, cancellationToken); /// /// Lists all the resources associated with the specified scopes. @@ -764,19 +628,9 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask PopulateAsync(TScope scope, - OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask PopulateAsync(TScope scope!!, + OpenIddictScopeDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - await Store.SetDescriptionAsync(scope, descriptor.Description, cancellationToken); await Store.SetDescriptionsAsync(scope, descriptor.Descriptions.ToImmutableDictionary(), cancellationToken); await Store.SetDisplayNameAsync(scope, descriptor.DisplayName, cancellationToken); @@ -796,19 +650,9 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// A that can be used to monitor the asynchronous operation. /// public virtual async ValueTask PopulateAsync( - OpenIddictScopeDescriptor descriptor, - TScope scope, CancellationToken cancellationToken = default) + OpenIddictScopeDescriptor descriptor!!, + TScope scope!!, CancellationToken cancellationToken = default) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - descriptor.Description = await Store.GetDescriptionAsync(scope, cancellationToken); descriptor.DisplayName = await Store.GetDisplayNameAsync(scope, cancellationToken); descriptor.Name = await Store.GetNameAsync(scope, cancellationToken); @@ -842,13 +686,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TScope scope!!, CancellationToken cancellationToken = default) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - var results = await GetValidationResultsAsync(scope, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { @@ -895,19 +734,9 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync(TScope scope, - OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TScope scope!!, + OpenIddictScopeDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - await PopulateAsync(scope, descriptor, cancellationToken); await UpdateAsync(scope, cancellationToken); } @@ -919,12 +748,8 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco /// The that can be used to abort the operation. /// The validation error encountered when validating the scope. public virtual async IAsyncEnumerable ValidateAsync( - TScope scope, [EnumeratorCancellation] CancellationToken cancellationToken = default) + TScope scope!!, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } // Ensure the name is not null or empty, does not contain a // space and is not already used for a different scope entity. diff --git a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs index c7d8c334..1d3a73bb 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs @@ -28,10 +28,10 @@ namespace OpenIddict.Core; public class OpenIddictTokenManager : IOpenIddictTokenManager where TToken : class { public OpenIddictTokenManager( - IOpenIddictTokenCache cache, - ILogger> logger, - IOptionsMonitor options, - IOpenIddictTokenStoreResolver resolver) + IOpenIddictTokenCache cache!!, + ILogger> logger!!, + IOptionsMonitor options!!, + IOpenIddictTokenStoreResolver resolver!!) { Cache = cache; Logger = logger; @@ -81,15 +81,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// whose result returns the number of tokens that match the specified query. /// public virtual ValueTask CountAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.CountAsync(query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => Store.CountAsync(query, cancellationToken); /// /// Creates a new token. @@ -99,13 +92,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask CreateAsync(TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask CreateAsync(TToken token!!, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - // If no status was explicitly specified, assume that the token is valid. if (string.IsNullOrEmpty(await Store.GetStatusAsync(token, cancellationToken))) { @@ -165,13 +153,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, whose result returns the token. /// public virtual async ValueTask CreateAsync( - OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) + OpenIddictTokenDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - var token = await Store.InstantiateAsync(cancellationToken); if (token is null) { @@ -192,13 +175,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask DeleteAsync(TToken token!!, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (!Options.CurrentValue.DisableEntityCaching) { await Cache.RemoveAsync(token, cancellationToken); @@ -579,15 +557,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the token. /// - public virtual ValueTask GetApplicationIdAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetApplicationIdAsync(token, cancellationToken); - } + public virtual ValueTask GetApplicationIdAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetApplicationIdAsync(token, cancellationToken); /// /// Executes the specified query and returns the first element. @@ -600,15 +571,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return GetAsync(static (tokens, query) => query(tokens), query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => GetAsync(static (tokens, query) => query(tokens), query, cancellationToken); /// /// Executes the specified query and returns the first element. @@ -623,16 +587,9 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.GetAsync(query, state, cancellationToken); - } + => Store.GetAsync(query, state, cancellationToken); /// /// Retrieves the optional authorization identifier associated with a token. @@ -643,15 +600,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the authorization identifier associated with the token. /// - public virtual ValueTask GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetAuthorizationIdAsync(token, cancellationToken); - } + public virtual ValueTask GetAuthorizationIdAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetAuthorizationIdAsync(token, cancellationToken); /// /// Retrieves the creation date associated with a token. @@ -662,15 +612,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the creation date associated with the specified token. /// - public virtual ValueTask GetCreationDateAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetCreationDateAsync(token, cancellationToken); - } + public virtual ValueTask GetCreationDateAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetCreationDateAsync(token, cancellationToken); /// /// Retrieves the expiration date associated with a token. @@ -681,15 +624,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the expiration date associated with the specified token. /// - public virtual ValueTask GetExpirationDateAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetExpirationDateAsync(token, cancellationToken); - } + public virtual ValueTask GetExpirationDateAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetExpirationDateAsync(token, cancellationToken); /// /// Retrieves the unique identifier associated with a token. @@ -700,15 +636,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the token. /// - public virtual ValueTask GetIdAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetIdAsync(token, cancellationToken); - } + public virtual ValueTask GetIdAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetIdAsync(token, cancellationToken); /// /// Retrieves the payload associated with a token. @@ -719,15 +648,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the payload associated with the specified token. /// - public virtual ValueTask GetPayloadAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetPayloadAsync(token, cancellationToken); - } + public virtual ValueTask GetPayloadAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetPayloadAsync(token, cancellationToken); /// /// Retrieves the additional properties associated with a token. @@ -739,15 +661,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// whose result returns all the additional properties associated with the token. /// public virtual ValueTask> GetPropertiesAsync( - TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetPropertiesAsync(token, cancellationToken); - } + TToken token!!, CancellationToken cancellationToken = default) + => Store.GetPropertiesAsync(token, cancellationToken); /// /// Retrieves the redemption date associated with a token. @@ -758,15 +673,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the redemption date associated with the specified token. /// - public virtual ValueTask GetRedemptionDateAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetRedemptionDateAsync(token, cancellationToken); - } + public virtual ValueTask GetRedemptionDateAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetRedemptionDateAsync(token, cancellationToken); /// /// Retrieves the reference identifier associated with a token. @@ -779,15 +687,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the reference identifier associated with the specified token. /// - public virtual ValueTask GetReferenceIdAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetReferenceIdAsync(token, cancellationToken); - } + public virtual ValueTask GetReferenceIdAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetReferenceIdAsync(token, cancellationToken); /// /// Retrieves the status associated with a token. @@ -798,15 +699,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the status associated with the specified token. /// - public virtual ValueTask GetStatusAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetStatusAsync(token, cancellationToken); - } + public virtual ValueTask GetStatusAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetStatusAsync(token, cancellationToken); /// /// Retrieves the subject associated with a token. @@ -817,15 +711,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the subject associated with the specified token. /// - public virtual ValueTask GetSubjectAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetSubjectAsync(token, cancellationToken); - } + public virtual ValueTask GetSubjectAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetSubjectAsync(token, cancellationToken); /// /// Retrieves the token type associated with a token. @@ -836,15 +723,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation, /// whose result returns the token type associated with the specified token. /// - public virtual ValueTask GetTypeAsync(TToken token, CancellationToken cancellationToken = default) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return Store.GetTypeAsync(token, cancellationToken); - } + public virtual ValueTask GetTypeAsync(TToken token!!, CancellationToken cancellationToken = default) + => Store.GetTypeAsync(token, cancellationToken); /// /// Determines whether a given token has the specified status. @@ -853,13 +733,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// The expected status. /// The that can be used to abort the operation. /// true if the token has the specified status, false otherwise. - public virtual async ValueTask HasStatusAsync(TToken token, string status, CancellationToken cancellationToken = default) + public virtual async ValueTask HasStatusAsync(TToken token!!, string status, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (string.IsNullOrEmpty(status)) { throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status)); @@ -875,13 +750,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// The expected type. /// The that can be used to abort the operation. /// true if the token has the specified type, false otherwise. - public virtual async ValueTask HasTypeAsync(TToken token, string type, CancellationToken cancellationToken = default) + public virtual async ValueTask HasTypeAsync(TToken token!!, string type, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (string.IsNullOrEmpty(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type)); @@ -897,13 +767,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// The expected types. /// The that can be used to abort the operation. /// true if the token has any of the specified types, false otherwise. - public virtual async ValueTask HasTypeAsync(TToken token, ImmutableArray types, CancellationToken cancellationToken = default) + public virtual async ValueTask HasTypeAsync(TToken token!!, ImmutableArray types, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - var type = await Store.GetTypeAsync(token, cancellationToken); if (string.IsNullOrEmpty(type)) { @@ -940,15 +805,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - Func, IQueryable> query, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return ListAsync(static (tokens, query) => query(tokens), query, cancellationToken); - } + Func, IQueryable> query!!, CancellationToken cancellationToken = default) + => ListAsync(static (tokens, query) => query(tokens), query, cancellationToken); /// /// Executes the specified query and returns all the corresponding elements. @@ -960,16 +818,9 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken = default) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return Store.ListAsync(query, state, cancellationToken); - } + => Store.ListAsync(query, state, cancellationToken); /// /// Populates the token using the specified descriptor. @@ -980,19 +831,9 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask PopulateAsync(TToken token, - OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask PopulateAsync(TToken token!!, + OpenIddictTokenDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - await Store.SetApplicationIdAsync(token, descriptor.ApplicationId, cancellationToken); await Store.SetAuthorizationIdAsync(token, descriptor.AuthorizationId, cancellationToken); await Store.SetCreationDateAsync(token, descriptor.CreationDate, cancellationToken); @@ -1016,19 +857,9 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// A that can be used to monitor the asynchronous operation. /// public virtual async ValueTask PopulateAsync( - OpenIddictTokenDescriptor descriptor, - TToken token, CancellationToken cancellationToken = default) + OpenIddictTokenDescriptor descriptor!!, + TToken token!!, CancellationToken cancellationToken = default) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - descriptor.ApplicationId = await Store.GetApplicationIdAsync(token, cancellationToken); descriptor.AuthorizationId = await Store.GetAuthorizationIdAsync(token, cancellationToken); descriptor.CreationDate = await Store.GetCreationDateAsync(token, cancellationToken); @@ -1058,19 +889,15 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// public virtual ValueTask PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken = default) => Store.PruneAsync(threshold, cancellationToken); + /// /// Tries to redeem a token. /// /// The token to redeem. /// The that can be used to abort the operation. /// true if the token was successfully redemeed, false otherwise. - public virtual async ValueTask TryRedeemAsync(TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask TryRedeemAsync(TToken token!!, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - // If the token doesn't have a redemption date attached, this likely means it's // the first time the token is redeemed. In this case, attach the current date. if (await Store.GetRedemptionDateAsync(token, cancellationToken) is null) @@ -1110,13 +937,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// The token to reject. /// The that can be used to abort the operation. /// true if the token was successfully redemeed, false otherwise. - public virtual async ValueTask TryRejectAsync(TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask TryRejectAsync(TToken token!!, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - await Store.SetStatusAsync(token, Statuses.Rejected, cancellationToken); try @@ -1149,13 +971,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// The token to revoke. /// The that can be used to abort the operation. /// true if the token was successfully revoked, false otherwise. - public virtual async ValueTask TryRevokeAsync(TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask TryRevokeAsync(TToken token!!, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - await Store.SetStatusAsync(token, Statuses.Revoked, cancellationToken); try @@ -1190,13 +1007,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TToken token!!, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - var results = await GetValidationResultsAsync(token, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { @@ -1243,18 +1055,9 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync(TToken token, - OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TToken token!!, + OpenIddictTokenDescriptor descriptor!!, CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } // Store the original reference identifier for later comparison. var comparand = await Store.GetReferenceIdAsync(token, cancellationToken); @@ -1278,13 +1081,8 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok /// The that can be used to abort the operation. /// The validation error encountered when validating the token. public virtual async IAsyncEnumerable ValidateAsync( - TToken token, [EnumeratorCancellation] CancellationToken cancellationToken = default) + TToken token!!, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - // If a reference identifier was associated with the token, // ensure it's not already used for a different token. var identifier = await Store.GetReferenceIdAsync(token, cancellationToken); @@ -1334,7 +1132,7 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok // Compute the digest of the generated identifier and use it as the hashed identifier of the reference token. // Doing that prevents token identifiers stolen from the database from being used as valid reference tokens. using var algorithm = SHA256.Create(); - return new ValueTask(Convert.ToBase64String(algorithm.ComputeHash(Encoding.UTF8.GetBytes(identifier)))); + return new(Convert.ToBase64String(algorithm.ComputeHash(Encoding.UTF8.GetBytes(identifier)))); } /// diff --git a/src/OpenIddict.Core/OpenIddictCoreBuilder.cs b/src/OpenIddict.Core/OpenIddictCoreBuilder.cs index 30464030..b9504aee 100644 --- a/src/OpenIddict.Core/OpenIddictCoreBuilder.cs +++ b/src/OpenIddict.Core/OpenIddictCoreBuilder.cs @@ -20,8 +20,8 @@ public class OpenIddictCoreBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictCoreBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictCoreBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -35,13 +35,8 @@ public class OpenIddictCoreBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictCoreBuilder Configure(Action configuration) + public OpenIddictCoreBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -69,13 +64,8 @@ public class OpenIddictCoreBuilder /// The type of the custom store. /// The lifetime of the registered service. /// The . - public OpenIddictCoreBuilder AddApplicationStore(Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + public OpenIddictCoreBuilder AddApplicationStore(Type type!!, ServiceLifetime lifetime = ServiceLifetime.Scoped) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - var root = OpenIddictHelpers.FindGenericBaseType(type, typeof(IOpenIddictApplicationStore<>)); if (root is null) { @@ -125,13 +115,8 @@ public class OpenIddictCoreBuilder /// The type of the custom store. /// The lifetime of the registered service. /// The . - public OpenIddictCoreBuilder AddAuthorizationStore(Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + public OpenIddictCoreBuilder AddAuthorizationStore(Type type!!, ServiceLifetime lifetime = ServiceLifetime.Scoped) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - var root = OpenIddictHelpers.FindGenericBaseType(type, typeof(IOpenIddictAuthorizationStore<>)); if (root is null) { @@ -181,13 +166,8 @@ public class OpenIddictCoreBuilder /// The type of the custom store. /// The lifetime of the registered service. /// The . - public OpenIddictCoreBuilder AddScopeStore(Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + public OpenIddictCoreBuilder AddScopeStore(Type type!!, ServiceLifetime lifetime = ServiceLifetime.Scoped) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - var root = OpenIddictHelpers.FindGenericBaseType(type, typeof(IOpenIddictScopeStore<>)); if (root is null) { @@ -237,13 +217,8 @@ public class OpenIddictCoreBuilder /// The type of the custom store. /// The lifetime of the registered service. /// The . - public OpenIddictCoreBuilder AddTokenStore(Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + public OpenIddictCoreBuilder AddTokenStore(Type type!!, ServiceLifetime lifetime = ServiceLifetime.Scoped) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - var root = OpenIddictHelpers.FindGenericBaseType(type, typeof(IOpenIddictTokenStore<>)); if (root is null) { @@ -291,13 +266,8 @@ public class OpenIddictCoreBuilder /// /// The type of the custom manager. /// The . - public OpenIddictCoreBuilder ReplaceApplicationManager(Type type) + public OpenIddictCoreBuilder ReplaceApplicationManager(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - var root = OpenIddictHelpers.FindGenericBaseType(type, typeof(OpenIddictApplicationManager<>)); if (root is null) { @@ -348,13 +318,8 @@ public class OpenIddictCoreBuilder /// The lifetime of the registered service. /// The . public OpenIddictCoreBuilder ReplaceApplicationStoreResolver( - Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + Type type!!, ServiceLifetime lifetime = ServiceLifetime.Scoped) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (!typeof(IOpenIddictApplicationStoreResolver).IsAssignableFrom(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); @@ -385,13 +350,8 @@ public class OpenIddictCoreBuilder /// /// The type of the custom manager. /// The . - public OpenIddictCoreBuilder ReplaceAuthorizationManager(Type type) + public OpenIddictCoreBuilder ReplaceAuthorizationManager(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - var root = OpenIddictHelpers.FindGenericBaseType(type, typeof(OpenIddictAuthorizationManager<>)); if (root is null) { @@ -442,13 +402,8 @@ public class OpenIddictCoreBuilder /// The lifetime of the registered service. /// The . public OpenIddictCoreBuilder ReplaceAuthorizationStoreResolver( - Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + Type type!!, ServiceLifetime lifetime = ServiceLifetime.Scoped) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (!typeof(IOpenIddictAuthorizationStoreResolver).IsAssignableFrom(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); @@ -479,13 +434,8 @@ public class OpenIddictCoreBuilder /// /// The type of the custom manager. /// The . - public OpenIddictCoreBuilder ReplaceScopeManager(Type type) + public OpenIddictCoreBuilder ReplaceScopeManager(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - var root = OpenIddictHelpers.FindGenericBaseType(type, typeof(OpenIddictScopeManager<>)); if (root is null) { @@ -536,13 +486,8 @@ public class OpenIddictCoreBuilder /// The lifetime of the registered service. /// The . public OpenIddictCoreBuilder ReplaceScopeStoreResolver( - Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + Type type!!, ServiceLifetime lifetime = ServiceLifetime.Scoped) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (!typeof(IOpenIddictScopeStoreResolver).IsAssignableFrom(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); @@ -573,13 +518,8 @@ public class OpenIddictCoreBuilder /// /// The type of the custom manager. /// The . - public OpenIddictCoreBuilder ReplaceTokenManager(Type type) + public OpenIddictCoreBuilder ReplaceTokenManager(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - var root = OpenIddictHelpers.FindGenericBaseType(type, typeof(OpenIddictTokenManager<>)); if (root is null) { @@ -630,13 +570,8 @@ public class OpenIddictCoreBuilder /// The lifetime of the registered service. /// The . public OpenIddictCoreBuilder ReplaceTokenStoreResolver( - Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + Type type!!, ServiceLifetime lifetime = ServiceLifetime.Scoped) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (!typeof(IOpenIddictTokenStoreResolver).IsAssignableFrom(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); @@ -679,13 +614,8 @@ public class OpenIddictCoreBuilder /// /// The application entity type. /// The . - public OpenIddictCoreBuilder SetDefaultApplicationEntity(Type type) + public OpenIddictCoreBuilder SetDefaultApplicationEntity(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (type.IsValueType) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); @@ -706,13 +636,8 @@ public class OpenIddictCoreBuilder /// /// The authorization entity type. /// The . - public OpenIddictCoreBuilder SetDefaultAuthorizationEntity(Type type) + public OpenIddictCoreBuilder SetDefaultAuthorizationEntity(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (type.IsValueType) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); @@ -733,13 +658,8 @@ public class OpenIddictCoreBuilder /// /// The scope entity type. /// The . - public OpenIddictCoreBuilder SetDefaultScopeEntity(Type type) + public OpenIddictCoreBuilder SetDefaultScopeEntity(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (type.IsValueType) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); @@ -760,13 +680,8 @@ public class OpenIddictCoreBuilder /// /// The token entity type. /// The . - public OpenIddictCoreBuilder SetDefaultTokenEntity(Type type) + public OpenIddictCoreBuilder SetDefaultTokenEntity(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (type.IsValueType) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); diff --git a/src/OpenIddict.Core/OpenIddictCoreExtensions.cs b/src/OpenIddict.Core/OpenIddictCoreExtensions.cs index 6ff18082..bccdd52c 100644 --- a/src/OpenIddict.Core/OpenIddictCoreExtensions.cs +++ b/src/OpenIddict.Core/OpenIddictCoreExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictCoreExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictCoreBuilder AddCore(this OpenIddictBuilder builder) + public static OpenIddictCoreBuilder AddCore(this OpenIddictBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddLogging(); builder.Services.AddMemoryCache(); builder.Services.AddOptions(); @@ -106,18 +101,8 @@ public static class OpenIddictCoreExtensions /// The configuration delegate used to configure the core services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictBuilder AddCore(this OpenIddictBuilder builder, Action configuration) + public static OpenIddictBuilder AddCore(this OpenIddictBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.AddCore()); return builder; diff --git a/src/OpenIddict.Core/Resolvers/OpenIddictApplicationStoreResolver.cs b/src/OpenIddict.Core/Resolvers/OpenIddictApplicationStoreResolver.cs index 0d5ae13c..290d57cd 100644 --- a/src/OpenIddict.Core/Resolvers/OpenIddictApplicationStoreResolver.cs +++ b/src/OpenIddict.Core/Resolvers/OpenIddictApplicationStoreResolver.cs @@ -9,7 +9,7 @@ public class OpenIddictApplicationStoreResolver : IOpenIddictApplicationStoreRes { private readonly IServiceProvider _provider; - public OpenIddictApplicationStoreResolver(IServiceProvider provider) + public OpenIddictApplicationStoreResolver(IServiceProvider provider!!) => _provider = provider; /// diff --git a/src/OpenIddict.Core/Resolvers/OpenIddictAuthorizationStoreResolver.cs b/src/OpenIddict.Core/Resolvers/OpenIddictAuthorizationStoreResolver.cs index ae7f0193..e8c97b55 100644 --- a/src/OpenIddict.Core/Resolvers/OpenIddictAuthorizationStoreResolver.cs +++ b/src/OpenIddict.Core/Resolvers/OpenIddictAuthorizationStoreResolver.cs @@ -9,7 +9,7 @@ public class OpenIddictAuthorizationStoreResolver : IOpenIddictAuthorizationStor { private readonly IServiceProvider _provider; - public OpenIddictAuthorizationStoreResolver(IServiceProvider provider) + public OpenIddictAuthorizationStoreResolver(IServiceProvider provider!!) => _provider = provider; /// diff --git a/src/OpenIddict.Core/Resolvers/OpenIddictScopeStoreResolver.cs b/src/OpenIddict.Core/Resolvers/OpenIddictScopeStoreResolver.cs index 615d661d..9bd7bf23 100644 --- a/src/OpenIddict.Core/Resolvers/OpenIddictScopeStoreResolver.cs +++ b/src/OpenIddict.Core/Resolvers/OpenIddictScopeStoreResolver.cs @@ -9,7 +9,7 @@ public class OpenIddictScopeStoreResolver : IOpenIddictScopeStoreResolver { private readonly IServiceProvider _provider; - public OpenIddictScopeStoreResolver(IServiceProvider provider) + public OpenIddictScopeStoreResolver(IServiceProvider provider!!) => _provider = provider; /// diff --git a/src/OpenIddict.Core/Resolvers/OpenIddictTokenStoreResolver.cs b/src/OpenIddict.Core/Resolvers/OpenIddictTokenStoreResolver.cs index 0aa1ebfb..ab2e0e61 100644 --- a/src/OpenIddict.Core/Resolvers/OpenIddictTokenStoreResolver.cs +++ b/src/OpenIddict.Core/Resolvers/OpenIddictTokenStoreResolver.cs @@ -9,7 +9,7 @@ public class OpenIddictTokenStoreResolver : IOpenIddictTokenStoreResolver { private readonly IServiceProvider _provider; - public OpenIddictTokenStoreResolver(IServiceProvider provider) + public OpenIddictTokenStoreResolver(IServiceProvider provider!!) => _provider = provider; /// diff --git a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs index ea02d3a7..25920105 100644 --- a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs +++ b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs @@ -21,8 +21,8 @@ public class OpenIddictEntityFrameworkBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictEntityFrameworkBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictEntityFrameworkBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -36,13 +36,8 @@ public class OpenIddictEntityFrameworkBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictEntityFrameworkBuilder Configure(Action configuration) + public OpenIddictEntityFrameworkBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -94,13 +89,8 @@ public class OpenIddictEntityFrameworkBuilder /// /// The type of the used by OpenIddict. /// The . - public OpenIddictEntityFrameworkBuilder UseDbContext(Type type) + public OpenIddictEntityFrameworkBuilder UseDbContext(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (!typeof(DbContext).IsAssignableFrom(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); diff --git a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs index b77ca34a..c525f94f 100644 --- a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs +++ b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictEntityFrameworkExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictEntityFrameworkBuilder UseEntityFramework(this OpenIddictCoreBuilder builder) + public static OpenIddictEntityFrameworkBuilder UseEntityFramework(this OpenIddictCoreBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - // Since Entity Framework 6.x may be used with databases performing case-insensitive // or culture-sensitive comparisons, ensure the additional filtering logic is enforced // in case case-sensitive stores were registered before this extension was called. @@ -66,18 +61,8 @@ public static class OpenIddictEntityFrameworkExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictCoreBuilder UseEntityFramework( - this OpenIddictCoreBuilder builder, Action configuration) + this OpenIddictCoreBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseEntityFramework()); return builder; diff --git a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs index 92ea38ca..a0b669e5 100644 --- a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs +++ b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs @@ -38,18 +38,13 @@ public static class OpenIddictEntityFrameworkHelpers /// /// The builder used to configure the Entity Framework context. /// The Entity Framework context builder. - public static DbModelBuilder UseOpenIddict(this DbModelBuilder builder) + public static DbModelBuilder UseOpenIddict(this DbModelBuilder builder!!) where TApplication : OpenIddictEntityFrameworkApplication where TAuthorization : OpenIddictEntityFrameworkAuthorization where TScope : OpenIddictEntityFrameworkScope where TToken : OpenIddictEntityFrameworkToken where TKey : notnull, IEquatable { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Configurations .Add(new OpenIddictEntityFrameworkApplicationConfiguration()) .Add(new OpenIddictEntityFrameworkAuthorizationConfiguration()) @@ -66,13 +61,8 @@ public static class OpenIddictEntityFrameworkHelpers /// The query source. /// The that can be used to abort the operation. /// The non-streamed async enumeration containing the results. - internal static IAsyncEnumerable AsAsyncEnumerable(this IQueryable source, CancellationToken cancellationToken) + internal static IAsyncEnumerable AsAsyncEnumerable(this IQueryable source!!, CancellationToken cancellationToken) { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - return ExecuteAsync(source, cancellationToken); static async IAsyncEnumerable ExecuteAsync(IQueryable source, [EnumeratorCancellation] CancellationToken cancellationToken) diff --git a/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkApplicationStoreResolver.cs b/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkApplicationStoreResolver.cs index 59b49028..2c0aa2e4 100644 --- a/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkApplicationStoreResolver.cs +++ b/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkApplicationStoreResolver.cs @@ -22,9 +22,9 @@ public class OpenIddictEntityFrameworkApplicationStoreResolver : IOpenIddictAppl private readonly IServiceProvider _provider; public OpenIddictEntityFrameworkApplicationStoreResolver( - TypeResolutionCache cache, - IOptionsMonitor options, - IServiceProvider provider) + TypeResolutionCache cache!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _cache = cache; _options = options; diff --git a/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkAuthorizationStoreResolver.cs b/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkAuthorizationStoreResolver.cs index 8770eefe..8ae908ee 100644 --- a/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkAuthorizationStoreResolver.cs +++ b/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkAuthorizationStoreResolver.cs @@ -22,9 +22,9 @@ public class OpenIddictEntityFrameworkAuthorizationStoreResolver : IOpenIddictAu private readonly IServiceProvider _provider; public OpenIddictEntityFrameworkAuthorizationStoreResolver( - TypeResolutionCache cache, - IOptionsMonitor options, - IServiceProvider provider) + TypeResolutionCache cache!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _cache = cache; _options = options; diff --git a/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkScopeStoreResolver.cs b/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkScopeStoreResolver.cs index b640fc8f..c483f7ed 100644 --- a/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkScopeStoreResolver.cs +++ b/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkScopeStoreResolver.cs @@ -22,9 +22,9 @@ public class OpenIddictEntityFrameworkScopeStoreResolver : IOpenIddictScopeStore private readonly IServiceProvider _provider; public OpenIddictEntityFrameworkScopeStoreResolver( - TypeResolutionCache cache, - IOptionsMonitor options, - IServiceProvider provider) + TypeResolutionCache cache!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _cache = cache; _options = options; diff --git a/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkTokenStoreResolver.cs b/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkTokenStoreResolver.cs index e8857df1..3154c715 100644 --- a/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkTokenStoreResolver.cs +++ b/src/OpenIddict.EntityFramework/Resolvers/OpenIddictEntityFrameworkTokenStoreResolver.cs @@ -22,9 +22,9 @@ public class OpenIddictEntityFrameworkTokenStoreResolver : IOpenIddictTokenStore private readonly IServiceProvider _provider; public OpenIddictEntityFrameworkTokenStoreResolver( - TypeResolutionCache cache, - IOptionsMonitor options, - IServiceProvider provider) + TypeResolutionCache cache!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _cache = cache; _options = options; diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs index 9a9ae12a..15e27436 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs @@ -32,7 +32,7 @@ public class OpenIddictEntityFrameworkApplicationStore : public OpenIddictEntityFrameworkApplicationStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -54,9 +54,9 @@ public class OpenIddictEntityFrameworkApplicationStore { public OpenIddictEntityFrameworkApplicationStore( - IMemoryCache cache, - TContext context, - IOptionsMonitor options) + IMemoryCache cache!!, + TContext context!!, + IOptionsMonitor options!!) { Cache = cache; Context = context; @@ -98,37 +98,20 @@ public class OpenIddictEntityFrameworkApplicationStore await Applications.LongCountAsync(cancellationToken); /// - public virtual async ValueTask CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Applications).LongCountAsync(cancellationToken); - } + public virtual async ValueTask CountAsync(Func, IQueryable> query!!, CancellationToken cancellationToken) + => await query(Applications).LongCountAsync(cancellationToken); /// - public virtual async ValueTask CreateAsync(TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - Applications.Add(application); await Context.SaveChangesAsync(cancellationToken); } /// - public virtual async ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - DbContextTransaction? CreateTransaction() { try @@ -303,83 +286,36 @@ public class OpenIddictEntityFrameworkApplicationStore public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Applications, state).FirstOrDefaultAsync(cancellationToken); - } + => await query(Applications, state).FirstOrDefaultAsync(cancellationToken); /// - public virtual ValueTask GetClientIdAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.ClientId); - } + public virtual ValueTask GetClientIdAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.ClientId); /// - public virtual ValueTask GetClientSecretAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.ClientSecret); - } + public virtual ValueTask GetClientSecretAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.ClientSecret); /// - public virtual ValueTask GetClientTypeAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.Type); - } + public virtual ValueTask GetClientTypeAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.Type); /// - public virtual ValueTask GetConsentTypeAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.ConsentType); - } + public virtual ValueTask GetConsentTypeAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.ConsentType); /// - public virtual ValueTask GetDisplayNameAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.DisplayName); - } + public virtual ValueTask GetDisplayNameAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.DisplayName); /// - public virtual ValueTask> GetDisplayNamesAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetDisplayNamesAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.DisplayNames)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified display names is an expensive operation. @@ -407,31 +343,19 @@ public class OpenIddictEntityFrameworkApplicationStore>(names); + return new(names); } /// - public virtual ValueTask GetIdAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(ConvertIdentifierToString(application.Id)); - } + public virtual ValueTask GetIdAsync(TApplication application!!, CancellationToken cancellationToken) + => new(ConvertIdentifierToString(application.Id)); /// - public virtual ValueTask> GetPermissionsAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPermissionsAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.Permissions)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified permissions is an expensive operation. @@ -459,20 +383,15 @@ public class OpenIddictEntityFrameworkApplicationStore>(permissions); + return new(permissions); } /// - public virtual ValueTask> GetPostLogoutRedirectUrisAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPostLogoutRedirectUrisAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.PostLogoutRedirectUris)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified addresses is an expensive operation. @@ -500,20 +419,15 @@ public class OpenIddictEntityFrameworkApplicationStore>(addresses); + return new(addresses); } /// - public virtual ValueTask> GetPropertiesAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.Properties)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified properties is an expensive operation. @@ -535,20 +449,15 @@ public class OpenIddictEntityFrameworkApplicationStore>(properties); + return new(properties); } /// - public virtual ValueTask> GetRedirectUrisAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetRedirectUrisAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.RedirectUris)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified addresses is an expensive operation. @@ -576,20 +485,15 @@ public class OpenIddictEntityFrameworkApplicationStore>(addresses); + return new(addresses); } /// - public virtual ValueTask> GetRequirementsAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetRequirementsAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.Requirements)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified requirements is an expensive operation. @@ -617,7 +521,7 @@ public class OpenIddictEntityFrameworkApplicationStore>(requirements); + return new(requirements); } /// @@ -625,12 +529,12 @@ public class OpenIddictEntityFrameworkApplicationStore(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0240), exception))); } } @@ -656,91 +560,56 @@ public class OpenIddictEntityFrameworkApplicationStore public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - return query(Applications, state).AsAsyncEnumerable(cancellationToken); } /// - public virtual ValueTask SetClientIdAsync(TApplication application, string? identifier, CancellationToken cancellationToken) + public virtual ValueTask SetClientIdAsync(TApplication application!!, string? identifier, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.ClientId = identifier; return default; } /// - public virtual ValueTask SetClientSecretAsync(TApplication application, string? secret, CancellationToken cancellationToken) + public virtual ValueTask SetClientSecretAsync(TApplication application!!, string? secret, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.ClientSecret = secret; return default; } /// - public virtual ValueTask SetClientTypeAsync(TApplication application, string? type, CancellationToken cancellationToken) + public virtual ValueTask SetClientTypeAsync(TApplication application!!, string? type, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.Type = type; return default; } /// - public virtual ValueTask SetConsentTypeAsync(TApplication application, string? type, CancellationToken cancellationToken) + public virtual ValueTask SetConsentTypeAsync(TApplication application!!, string? type, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.ConsentType = type; return default; } /// - public virtual ValueTask SetDisplayNameAsync(TApplication application, string? name, CancellationToken cancellationToken) + public virtual ValueTask SetDisplayNameAsync(TApplication application!!, string? name, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.DisplayName = name; return default; } /// - public virtual ValueTask SetDisplayNamesAsync(TApplication application, + public virtual ValueTask SetDisplayNamesAsync(TApplication application!!, ImmutableDictionary names, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (names is null || names.IsEmpty) { application.DisplayNames = null; @@ -772,13 +641,8 @@ public class OpenIddictEntityFrameworkApplicationStore - public virtual ValueTask SetPermissionsAsync(TApplication application, ImmutableArray permissions, CancellationToken cancellationToken) + public virtual ValueTask SetPermissionsAsync(TApplication application!!, ImmutableArray permissions, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (permissions.IsDefaultOrEmpty) { application.Permissions = null; @@ -809,14 +673,9 @@ public class OpenIddictEntityFrameworkApplicationStore - public virtual ValueTask SetPostLogoutRedirectUrisAsync(TApplication application, + public virtual ValueTask SetPostLogoutRedirectUrisAsync(TApplication application!!, ImmutableArray addresses, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (addresses.IsDefaultOrEmpty) { application.PostLogoutRedirectUris = null; @@ -847,15 +706,10 @@ public class OpenIddictEntityFrameworkApplicationStore - public virtual ValueTask SetPropertiesAsync(TApplication application, + public virtual ValueTask SetPropertiesAsync(TApplication application!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { application.Properties = null; @@ -886,14 +740,9 @@ public class OpenIddictEntityFrameworkApplicationStore - public virtual ValueTask SetRedirectUrisAsync(TApplication application, + public virtual ValueTask SetRedirectUrisAsync(TApplication application!!, ImmutableArray addresses, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (addresses.IsDefaultOrEmpty) { application.RedirectUris = null; @@ -924,13 +773,8 @@ public class OpenIddictEntityFrameworkApplicationStore - public virtual ValueTask SetRequirementsAsync(TApplication application, ImmutableArray requirements, CancellationToken cancellationToken) + public virtual ValueTask SetRequirementsAsync(TApplication application!!, ImmutableArray requirements, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (requirements.IsDefaultOrEmpty) { application.Requirements = null; @@ -961,13 +805,8 @@ public class OpenIddictEntityFrameworkApplicationStore - public virtual async ValueTask UpdateAsync(TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - Applications.Attach(application); // Generate a new concurrency token and attach it diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs index c04612ff..b3fad305 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs @@ -31,7 +31,7 @@ public class OpenIddictEntityFrameworkAuthorizationStore : public OpenIddictEntityFrameworkAuthorizationStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -53,9 +53,9 @@ public class OpenIddictEntityFrameworkAuthorizationStore { public OpenIddictEntityFrameworkAuthorizationStore( - IMemoryCache cache, - TContext context, - IOptionsMonitor options) + IMemoryCache cache!!, + TContext context!!, + IOptionsMonitor options!!) { Cache = cache; Context = context; @@ -97,37 +97,20 @@ public class OpenIddictEntityFrameworkAuthorizationStore await Authorizations.LongCountAsync(cancellationToken); /// - public virtual async ValueTask CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Authorizations).LongCountAsync(cancellationToken); - } + public virtual async ValueTask CountAsync(Func, IQueryable> query!!, CancellationToken cancellationToken) + => await query(Authorizations).LongCountAsync(cancellationToken); /// - public virtual async ValueTask CreateAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - Authorizations.Add(authorization); await Context.SaveChangesAsync(cancellationToken); } /// - public virtual async ValueTask DeleteAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - DbContextTransaction? CreateTransaction() { try @@ -361,13 +344,8 @@ public class OpenIddictEntityFrameworkAuthorizationStore - public virtual async ValueTask GetApplicationIdAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask GetApplicationIdAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - // If the application is not attached to the authorization, try to load it manually. if (authorization.Application is null) { @@ -390,56 +368,25 @@ public class OpenIddictEntityFrameworkAuthorizationStore public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query( + => await query( Authorizations.Include(authorization => authorization.Application), state).FirstOrDefaultAsync(cancellationToken); - } /// - public virtual ValueTask GetCreationDateAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (authorization.CreationDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(authorization.CreationDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetCreationDateAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.CreationDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetIdAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(ConvertIdentifierToString(authorization.Id)); - } + public virtual ValueTask GetIdAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(ConvertIdentifierToString(authorization.Id)); /// - public virtual ValueTask> GetPropertiesAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (string.IsNullOrEmpty(authorization.Properties)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified properties is an expensive operation. @@ -461,20 +408,15 @@ public class OpenIddictEntityFrameworkAuthorizationStore>(properties); + return new(properties); } /// - public virtual ValueTask> GetScopesAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> GetScopesAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (string.IsNullOrEmpty(authorization.Scopes)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified scopes is an expensive operation. @@ -502,53 +444,32 @@ public class OpenIddictEntityFrameworkAuthorizationStore>(scopes); + return new(scopes); } /// - public virtual ValueTask GetStatusAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Status); - } + public virtual ValueTask GetStatusAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Status); /// - public virtual ValueTask GetSubjectAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Subject); - } + public virtual ValueTask GetSubjectAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Subject); /// - public virtual ValueTask GetTypeAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Type); - } + public virtual ValueTask GetTypeAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Type); /// public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0242), exception))); } } @@ -575,16 +496,9 @@ public class OpenIddictEntityFrameworkAuthorizationStore public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return query(Authorizations.Include(authorization => authorization.Application), state).AsAsyncEnumerable(cancellationToken); - } + => query(Authorizations.Include(authorization => authorization.Application), state).AsAsyncEnumerable(cancellationToken); /// public virtual async ValueTask PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken) @@ -668,14 +582,9 @@ public class OpenIddictEntityFrameworkAuthorizationStore - public virtual async ValueTask SetApplicationIdAsync(TAuthorization authorization, + public virtual async ValueTask SetApplicationIdAsync(TAuthorization authorization!!, string? identifier, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (!string.IsNullOrEmpty(identifier)) { var application = await Applications.FindAsync(cancellationToken, ConvertIdentifierFromString(identifier)); @@ -706,29 +615,19 @@ public class OpenIddictEntityFrameworkAuthorizationStore - public virtual ValueTask SetCreationDateAsync(TAuthorization authorization, + public virtual ValueTask SetCreationDateAsync(TAuthorization authorization!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.CreationDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetPropertiesAsync(TAuthorization authorization, + public virtual ValueTask SetPropertiesAsync(TAuthorization authorization!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { authorization.Properties = null; @@ -759,14 +658,9 @@ public class OpenIddictEntityFrameworkAuthorizationStore - public virtual ValueTask SetScopesAsync(TAuthorization authorization, + public virtual ValueTask SetScopesAsync(TAuthorization authorization!!, ImmutableArray scopes, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (scopes.IsDefaultOrEmpty) { authorization.Scopes = null; @@ -797,52 +691,32 @@ public class OpenIddictEntityFrameworkAuthorizationStore - public virtual ValueTask SetStatusAsync(TAuthorization authorization, string? status, CancellationToken cancellationToken) + public virtual ValueTask SetStatusAsync(TAuthorization authorization!!, string? status, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.Status = status; return default; } /// - public virtual ValueTask SetSubjectAsync(TAuthorization authorization, string? subject, CancellationToken cancellationToken) + public virtual ValueTask SetSubjectAsync(TAuthorization authorization!!, string? subject, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.Subject = subject; return default; } /// - public virtual ValueTask SetTypeAsync(TAuthorization authorization, string? type, CancellationToken cancellationToken) + public virtual ValueTask SetTypeAsync(TAuthorization authorization!!, string? type, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.Type = type; return default; } /// - public virtual async ValueTask UpdateAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - Authorizations.Attach(authorization); // Generate a new concurrency token and attach it diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs index 4dba6b40..f510625e 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs @@ -29,7 +29,7 @@ public class OpenIddictEntityFrameworkScopeStore : public OpenIddictEntityFrameworkScopeStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -47,9 +47,9 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen where TKey : notnull, IEquatable { public OpenIddictEntityFrameworkScopeStore( - IMemoryCache cache, - TContext context, - IOptionsMonitor options) + IMemoryCache cache!!, + TContext context!!, + IOptionsMonitor options!!) { Cache = cache; Context = context; @@ -81,37 +81,20 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen => await Scopes.LongCountAsync(cancellationToken); /// - public virtual async ValueTask CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Scopes).LongCountAsync(cancellationToken); - } + public virtual async ValueTask CountAsync(Func, IQueryable> query!!, CancellationToken cancellationToken) + => await query(Scopes).LongCountAsync(cancellationToken); /// - public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - Scopes.Add(scope); await Context.SaveChangesAsync(cancellationToken); } /// - public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - Scopes.Remove(scope); try @@ -160,7 +143,7 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen public virtual IAsyncEnumerable FindByNamesAsync( ImmutableArray names, CancellationToken cancellationToken) { - if (names.Any(name => string.IsNullOrEmpty(name))) + if (names.Any(string.IsNullOrEmpty)) { throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names)); } @@ -208,39 +191,20 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen /// public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Scopes, state).FirstOrDefaultAsync(cancellationToken); - } + => await query(Scopes, state).FirstOrDefaultAsync(cancellationToken); /// - public virtual ValueTask GetDescriptionAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.Description); - } + public virtual ValueTask GetDescriptionAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.Description); /// - public virtual ValueTask> GetDescriptionsAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetDescriptionsAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (string.IsNullOrEmpty(scope.Descriptions)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified descriptions is an expensive operation. @@ -268,31 +232,21 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen return builder.ToImmutable(); }); - return new ValueTask>(descriptions); + return new(descriptions); } /// - public virtual ValueTask GetDisplayNameAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask GetDisplayNameAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.DisplayName); + return new(scope.DisplayName); } /// - public virtual ValueTask> GetDisplayNamesAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetDisplayNamesAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (string.IsNullOrEmpty(scope.DisplayNames)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified display names is an expensive operation. @@ -320,42 +274,23 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen return builder.ToImmutable(); }); - return new ValueTask>(names); + return new(names); } /// - public virtual ValueTask GetIdAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(ConvertIdentifierToString(scope.Id)); - } + public virtual ValueTask GetIdAsync(TScope scope!!, CancellationToken cancellationToken) + => new(ConvertIdentifierToString(scope.Id)); /// - public virtual ValueTask GetNameAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.Name); - } + public virtual ValueTask GetNameAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.Name); /// - public virtual ValueTask> GetPropertiesAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (string.IsNullOrEmpty(scope.Properties)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified properties is an expensive operation. @@ -377,20 +312,15 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen return builder.ToImmutable(); }); - return new ValueTask>(properties); + return new(properties); } /// - public virtual ValueTask> GetResourcesAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetResourcesAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (string.IsNullOrEmpty(scope.Resources)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified resources is an expensive operation. @@ -418,7 +348,7 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen return builder.ToImmutable(); }); - return new ValueTask>(resources); + return new(resources); } /// @@ -426,12 +356,12 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0246), exception))); } } @@ -456,39 +386,22 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen /// public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return query(Scopes, state).AsAsyncEnumerable(cancellationToken); - } + => query(Scopes, state).AsAsyncEnumerable(cancellationToken); /// - public virtual ValueTask SetDescriptionAsync(TScope scope, string? description, CancellationToken cancellationToken) + public virtual ValueTask SetDescriptionAsync(TScope scope!!, string? description, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.Description = description; return default; } /// - public virtual ValueTask SetDescriptionsAsync(TScope scope, + public virtual ValueTask SetDescriptionsAsync(TScope scope!!, ImmutableDictionary descriptions, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (descriptions is null || descriptions.IsEmpty) { scope.Descriptions = null; @@ -520,27 +433,17 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen } /// - public virtual ValueTask SetDisplayNameAsync(TScope scope, string? name, CancellationToken cancellationToken) + public virtual ValueTask SetDisplayNameAsync(TScope scope!!, string? name, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.DisplayName = name; return default; } /// - public virtual ValueTask SetDisplayNamesAsync(TScope scope, + public virtual ValueTask SetDisplayNamesAsync(TScope scope!!, ImmutableDictionary names, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (names is null || names.IsEmpty) { scope.DisplayNames = null; @@ -572,28 +475,18 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen } /// - public virtual ValueTask SetNameAsync(TScope scope, string? name, CancellationToken cancellationToken) + public virtual ValueTask SetNameAsync(TScope scope!!, string? name, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.Name = name; return default; } /// - public virtual ValueTask SetPropertiesAsync(TScope scope, + public virtual ValueTask SetPropertiesAsync(TScope scope!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { scope.Properties = null; @@ -624,13 +517,8 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen } /// - public virtual ValueTask SetResourcesAsync(TScope scope, ImmutableArray resources, CancellationToken cancellationToken) + public virtual ValueTask SetResourcesAsync(TScope scope!!, ImmutableArray resources, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (resources.IsDefaultOrEmpty) { scope.Resources = null; @@ -661,13 +549,8 @@ public class OpenIddictEntityFrameworkScopeStore : IOpen } /// - public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - Scopes.Attach(scope); // Generate a new concurrency token and attach it diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs index 0d55be05..4f35080d 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs @@ -30,7 +30,7 @@ public class OpenIddictEntityFrameworkTokenStore : public OpenIddictEntityFrameworkTokenStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -52,9 +52,9 @@ public class OpenIddictEntityFrameworkTokenStore { public OpenIddictEntityFrameworkTokenStore( - IMemoryCache cache, - TContext context, - IOptionsMonitor options) + IMemoryCache cache!!, + TContext context!!, + IOptionsMonitor options!!) { Cache = cache; Context = context; @@ -96,37 +96,20 @@ public class OpenIddictEntityFrameworkTokenStore await Tokens.LongCountAsync(cancellationToken); /// - public virtual async ValueTask CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Tokens).LongCountAsync(cancellationToken); - } + public virtual async ValueTask CountAsync(Func, IQueryable> query!!, CancellationToken cancellationToken) + => await query(Tokens).LongCountAsync(cancellationToken); /// - public virtual async ValueTask CreateAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - Tokens.Add(token); await Context.SaveChangesAsync(cancellationToken); } /// - public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - Tokens.Remove(token); try @@ -301,13 +284,8 @@ public class OpenIddictEntityFrameworkTokenStore - public virtual async ValueTask GetApplicationIdAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask GetApplicationIdAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - // If the application is not attached to the token, try to load it manually. if (token.Application is null) { @@ -330,27 +308,15 @@ public class OpenIddictEntityFrameworkTokenStore public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query( + => await query( Tokens.Include(token => token.Application) .Include(token => token.Authorization), state).FirstOrDefaultAsync(cancellationToken); - } /// - public virtual async ValueTask GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask GetAuthorizationIdAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - // If the authorization is not attached to the token, try to load it manually. if (token.Authorization is null) { @@ -372,70 +338,27 @@ public class OpenIddictEntityFrameworkTokenStore - public virtual ValueTask GetCreationDateAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (token.CreationDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(token.CreationDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetCreationDateAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.CreationDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetExpirationDateAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (token.ExpirationDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(token.ExpirationDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetExpirationDateAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.ExpirationDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetIdAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(ConvertIdentifierToString(token.Id)); - } + public virtual ValueTask GetIdAsync(TToken token!!, CancellationToken cancellationToken) + => new(ConvertIdentifierToString(token.Id)); /// - public virtual ValueTask GetPayloadAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Payload); - } + public virtual ValueTask GetPayloadAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Payload); /// - public virtual ValueTask> GetPropertiesAsync(TToken token, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (string.IsNullOrEmpty(token.Properties)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified properties is an expensive operation. @@ -457,80 +380,40 @@ public class OpenIddictEntityFrameworkTokenStore>(properties); + return new(properties); } /// - public virtual ValueTask GetRedemptionDateAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (token.RedemptionDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(token.RedemptionDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetRedemptionDateAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.RedemptionDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetReferenceIdAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.ReferenceId); - } + public virtual ValueTask GetReferenceIdAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.ReferenceId); /// - public virtual ValueTask GetStatusAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Status); - } + public virtual ValueTask GetStatusAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Status); /// - public virtual ValueTask GetSubjectAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Subject); - } + public virtual ValueTask GetSubjectAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Subject); /// - public virtual ValueTask GetTypeAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Type); - } + public virtual ValueTask GetTypeAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Type); /// public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0248), exception))); } } @@ -558,18 +441,11 @@ public class OpenIddictEntityFrameworkTokenStore public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return query( + => query( Tokens.Include(token => token.Application) .Include(token => token.Authorization), state).AsAsyncEnumerable(cancellationToken); - } /// public virtual async ValueTask PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken) @@ -650,13 +526,8 @@ public class OpenIddictEntityFrameworkTokenStore - public virtual async ValueTask SetApplicationIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) + public virtual async ValueTask SetApplicationIdAsync(TToken token!!, string? identifier, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (!string.IsNullOrEmpty(identifier)) { var application = await Applications.FindAsync(cancellationToken, ConvertIdentifierFromString(identifier)); @@ -687,13 +558,8 @@ public class OpenIddictEntityFrameworkTokenStore - public virtual async ValueTask SetAuthorizationIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) + public virtual async ValueTask SetAuthorizationIdAsync(TToken token!!, string? identifier, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (!string.IsNullOrEmpty(identifier)) { var authorization = await Authorizations.FindAsync(cancellationToken, ConvertIdentifierFromString(identifier)); @@ -724,54 +590,34 @@ public class OpenIddictEntityFrameworkTokenStore - public virtual ValueTask SetCreationDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken) + public virtual ValueTask SetCreationDateAsync(TToken token!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.CreationDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetExpirationDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken) + public virtual ValueTask SetExpirationDateAsync(TToken token!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.ExpirationDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetPayloadAsync(TToken token, string? payload, CancellationToken cancellationToken) + public virtual ValueTask SetPayloadAsync(TToken token!!, string? payload, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Payload = payload; return default; } /// - public virtual ValueTask SetPropertiesAsync(TToken token, + public virtual ValueTask SetPropertiesAsync(TToken token!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { token.Properties = null; @@ -802,78 +648,48 @@ public class OpenIddictEntityFrameworkTokenStore - public virtual ValueTask SetRedemptionDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken) + public virtual ValueTask SetRedemptionDateAsync(TToken token!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.RedemptionDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetReferenceIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) + public virtual ValueTask SetReferenceIdAsync(TToken token!!, string? identifier, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.ReferenceId = identifier; return default; } /// - public virtual ValueTask SetStatusAsync(TToken token, string? status, CancellationToken cancellationToken) + public virtual ValueTask SetStatusAsync(TToken token!!, string? status, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Status = status; return default; } /// - public virtual ValueTask SetSubjectAsync(TToken token, string? subject, CancellationToken cancellationToken) + public virtual ValueTask SetSubjectAsync(TToken token!!, string? subject, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Subject = subject; return default; } /// - public virtual ValueTask SetTypeAsync(TToken token, string? type, CancellationToken cancellationToken) + public virtual ValueTask SetTypeAsync(TToken token!!, string? type, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Type = type; return default; } /// - public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - Tokens.Attach(token); // Generate a new concurrency token and attach it diff --git a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreApplicationConfiguration.cs b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreApplicationConfiguration.cs index 140bb402..a07f5d20 100644 --- a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreApplicationConfiguration.cs +++ b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreApplicationConfiguration.cs @@ -24,13 +24,8 @@ public class OpenIddictEntityFrameworkCoreApplicationConfiguration where TKey : notnull, IEquatable { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - // Warning: optional foreign keys MUST NOT be added as CLR properties because // Entity Framework would throw an exception due to the TKey generic parameter // being non-nullable when using value types like short, int, long or Guid. diff --git a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreAuthorizationConfiguration.cs b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreAuthorizationConfiguration.cs index 2ce61897..4590271f 100644 --- a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreAuthorizationConfiguration.cs +++ b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreAuthorizationConfiguration.cs @@ -24,13 +24,8 @@ public class OpenIddictEntityFrameworkCoreAuthorizationConfiguration where TKey : notnull, IEquatable { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - // Warning: optional foreign keys MUST NOT be added as CLR properties because // Entity Framework would throw an exception due to the TKey generic parameter // being non-nullable when using value types like short, int, long or Guid. diff --git a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreScopeConfiguration.cs b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreScopeConfiguration.cs index 828623d3..aa7e2180 100644 --- a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreScopeConfiguration.cs +++ b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreScopeConfiguration.cs @@ -20,13 +20,8 @@ public class OpenIddictEntityFrameworkCoreScopeConfiguration : IEn where TScope : OpenIddictEntityFrameworkCoreScope where TKey : notnull, IEquatable { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - // Warning: optional foreign keys MUST NOT be added as CLR properties because // Entity Framework would throw an exception due to the TKey generic parameter // being non-nullable when using value types like short, int, long or Guid. diff --git a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreTokenConfiguration.cs b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreTokenConfiguration.cs index bafb2138..4935c363 100644 --- a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreTokenConfiguration.cs +++ b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictEntityFrameworkCoreTokenConfiguration.cs @@ -24,13 +24,8 @@ public class OpenIddictEntityFrameworkCoreTokenConfiguration where TKey : notnull, IEquatable { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - // Warning: optional foreign keys MUST NOT be added as CLR properties because // Entity Framework would throw an exception due to the TKey generic parameter // being non-nullable when using value types like short, int, long or Guid. diff --git a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs index e5f54c24..e3c88e6c 100644 --- a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs +++ b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs @@ -20,8 +20,8 @@ public class OpenIddictEntityFrameworkCoreBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictEntityFrameworkCoreBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictEntityFrameworkCoreBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -35,13 +35,8 @@ public class OpenIddictEntityFrameworkCoreBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictEntityFrameworkCoreBuilder Configure(Action configuration) + public OpenIddictEntityFrameworkCoreBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -96,13 +91,8 @@ public class OpenIddictEntityFrameworkCoreBuilder /// /// The type of the used by OpenIddict. /// The . - public OpenIddictEntityFrameworkCoreBuilder UseDbContext(Type type) + public OpenIddictEntityFrameworkCoreBuilder UseDbContext(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (!typeof(DbContext).IsAssignableFrom(type)) { throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type)); diff --git a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs index 7413d67f..586aba69 100644 --- a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs +++ b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs @@ -25,18 +25,8 @@ public class OpenIddictEntityFrameworkCoreCustomizer - public override void Customize(ModelBuilder modelBuilder, DbContext context) + public override void Customize(ModelBuilder modelBuilder!!, DbContext context!!) { - if (modelBuilder is null) - { - throw new ArgumentNullException(nameof(modelBuilder)); - } - - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Register the OpenIddict entity sets. modelBuilder.UseOpenIddict(); diff --git a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreExtensions.cs b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreExtensions.cs index d99b7113..d8a0066a 100644 --- a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreExtensions.cs +++ b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictEntityFrameworkCoreExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictEntityFrameworkCoreBuilder UseEntityFrameworkCore(this OpenIddictCoreBuilder builder) + public static OpenIddictEntityFrameworkCoreBuilder UseEntityFrameworkCore(this OpenIddictCoreBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - // Since Entity Framework Core may be used with databases performing case-insensitive // or culture-sensitive comparisons, ensure the additional filtering logic is enforced // in case case-sensitive stores were registered before this extension was called. @@ -66,18 +61,8 @@ public static class OpenIddictEntityFrameworkCoreExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictCoreBuilder UseEntityFrameworkCore( - this OpenIddictCoreBuilder builder, Action configuration) + this OpenIddictCoreBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseEntityFrameworkCore()); return builder; diff --git a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreHelpers.cs b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreHelpers.cs index fddd7dc6..770e6f66 100644 --- a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreHelpers.cs +++ b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreHelpers.cs @@ -56,21 +56,14 @@ public static class OpenIddictEntityFrameworkCoreHelpers /// The builder used to configure the Entity Framework context. /// The Entity Framework context builder. public static DbContextOptionsBuilder UseOpenIddict( - this DbContextOptionsBuilder builder) + this DbContextOptionsBuilder builder!!) where TApplication : OpenIddictEntityFrameworkCoreApplication where TAuthorization : OpenIddictEntityFrameworkCoreAuthorization where TScope : OpenIddictEntityFrameworkCoreScope where TToken : OpenIddictEntityFrameworkCoreToken where TKey : notnull, IEquatable - { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - return builder.ReplaceService builder.ReplaceService>(); - } /// /// Registers the OpenIddict entity sets in the Entity Framework Core context @@ -110,24 +103,17 @@ public static class OpenIddictEntityFrameworkCoreHelpers /// /// The builder used to configure the Entity Framework context. /// The Entity Framework context builder. - public static ModelBuilder UseOpenIddict(this ModelBuilder builder) + public static ModelBuilder UseOpenIddict(this ModelBuilder builder!!) where TApplication : OpenIddictEntityFrameworkCoreApplication where TAuthorization : OpenIddictEntityFrameworkCoreAuthorization where TScope : OpenIddictEntityFrameworkCoreScope where TToken : OpenIddictEntityFrameworkCoreToken where TKey : notnull, IEquatable - { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - return builder + => builder .ApplyConfiguration(new OpenIddictEntityFrameworkCoreApplicationConfiguration()) .ApplyConfiguration(new OpenIddictEntityFrameworkCoreAuthorizationConfiguration()) .ApplyConfiguration(new OpenIddictEntityFrameworkCoreScopeConfiguration()) .ApplyConfiguration(new OpenIddictEntityFrameworkCoreTokenConfiguration()); - } #if SUPPORTS_BCL_ASYNC_ENUMERABLE /// @@ -146,13 +132,8 @@ public static class OpenIddictEntityFrameworkCoreHelpers /// The that can be used to abort the operation. /// The non-streamed async enumeration containing the results. #endif - internal static IAsyncEnumerable AsAsyncEnumerable(this IQueryable source, CancellationToken cancellationToken) + internal static IAsyncEnumerable AsAsyncEnumerable(this IQueryable source!!, CancellationToken cancellationToken) { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - return ExecuteAsync(source, cancellationToken); static async IAsyncEnumerable ExecuteAsync(IQueryable source, [EnumeratorCancellation] CancellationToken cancellationToken) diff --git a/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreApplicationStoreResolver.cs b/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreApplicationStoreResolver.cs index 66ce051d..f2132356 100644 --- a/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreApplicationStoreResolver.cs +++ b/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreApplicationStoreResolver.cs @@ -22,9 +22,9 @@ public class OpenIddictEntityFrameworkCoreApplicationStoreResolver : IOpenIddict private readonly IServiceProvider _provider; public OpenIddictEntityFrameworkCoreApplicationStoreResolver( - TypeResolutionCache cache, - IOptionsMonitor options, - IServiceProvider provider) + TypeResolutionCache cache!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _cache = cache; _options = options; diff --git a/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreAuthorizationStoreResolver.cs b/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreAuthorizationStoreResolver.cs index 97be87bd..0b253f87 100644 --- a/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreAuthorizationStoreResolver.cs +++ b/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreAuthorizationStoreResolver.cs @@ -22,9 +22,9 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStoreResolver : IOpenIddi private readonly IServiceProvider _provider; public OpenIddictEntityFrameworkCoreAuthorizationStoreResolver( - TypeResolutionCache cache, - IOptionsMonitor options, - IServiceProvider provider) + TypeResolutionCache cache!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _cache = cache; _options = options; diff --git a/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreScopeStoreResolver.cs b/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreScopeStoreResolver.cs index 779e1805..691fbb72 100644 --- a/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreScopeStoreResolver.cs +++ b/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreScopeStoreResolver.cs @@ -22,9 +22,9 @@ public class OpenIddictEntityFrameworkCoreScopeStoreResolver : IOpenIddictScopeS private readonly IServiceProvider _provider; public OpenIddictEntityFrameworkCoreScopeStoreResolver( - TypeResolutionCache cache, - IOptionsMonitor options, - IServiceProvider provider) + TypeResolutionCache cache!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _cache = cache; _options = options; diff --git a/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreTokenStoreResolver.cs b/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreTokenStoreResolver.cs index 1ad6e4e4..91f13ba7 100644 --- a/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreTokenStoreResolver.cs +++ b/src/OpenIddict.EntityFrameworkCore/Resolvers/OpenIddictEntityFrameworkCoreTokenStoreResolver.cs @@ -22,9 +22,9 @@ public class OpenIddictEntityFrameworkCoreTokenStoreResolver : IOpenIddictTokenS private readonly IServiceProvider _provider; public OpenIddictEntityFrameworkCoreTokenStoreResolver( - TypeResolutionCache cache, - IOptionsMonitor options, - IServiceProvider provider) + TypeResolutionCache cache!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _cache = cache; _options = options; diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs index 1c961318..96a60152 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs @@ -31,7 +31,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore : public OpenIddictEntityFrameworkCoreApplicationStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -52,7 +52,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore : public OpenIddictEntityFrameworkCoreApplicationStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -74,9 +74,9 @@ public class OpenIddictEntityFrameworkCoreApplicationStore { public OpenIddictEntityFrameworkCoreApplicationStore( - IMemoryCache cache, - TContext context, - IOptionsMonitor options) + IMemoryCache cache!!, + TContext context!!, + IOptionsMonitor options!!) { Cache = cache; Context = context; @@ -118,37 +118,20 @@ public class OpenIddictEntityFrameworkCoreApplicationStore await Applications.AsQueryable().LongCountAsync(cancellationToken); /// - public virtual async ValueTask CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Applications).LongCountAsync(cancellationToken); - } + public virtual async ValueTask CountAsync(Func, IQueryable> query!!, CancellationToken cancellationToken) + => await query(Applications).LongCountAsync(cancellationToken); /// - public virtual async ValueTask CreateAsync(TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - Context.Add(application); await Context.SaveChangesAsync(cancellationToken); } /// - public virtual async ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - async ValueTask CreateTransactionAsync() { // Note: transactions that specify an explicit isolation level are only supported by @@ -345,83 +328,36 @@ public class OpenIddictEntityFrameworkCoreApplicationStore public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Applications.AsTracking(), state).FirstOrDefaultAsync(cancellationToken); - } + => await query(Applications.AsTracking(), state).FirstOrDefaultAsync(cancellationToken); /// - public virtual ValueTask GetClientIdAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.ClientId); - } + public virtual ValueTask GetClientIdAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.ClientId); /// - public virtual ValueTask GetClientSecretAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.ClientSecret); - } + public virtual ValueTask GetClientSecretAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.ClientSecret); /// - public virtual ValueTask GetClientTypeAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.Type); - } + public virtual ValueTask GetClientTypeAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.Type); /// - public virtual ValueTask GetConsentTypeAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.ConsentType); - } + public virtual ValueTask GetConsentTypeAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.ConsentType); /// - public virtual ValueTask GetDisplayNameAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.DisplayName); - } + public virtual ValueTask GetDisplayNameAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.DisplayName); /// - public virtual ValueTask> GetDisplayNamesAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetDisplayNamesAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.DisplayNames)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified display names is an expensive operation. @@ -449,31 +385,19 @@ public class OpenIddictEntityFrameworkCoreApplicationStore>(names); + return new(names); } /// - public virtual ValueTask GetIdAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(ConvertIdentifierToString(application.Id)); - } + public virtual ValueTask GetIdAsync(TApplication application!!, CancellationToken cancellationToken) + => new(ConvertIdentifierToString(application.Id)); /// - public virtual ValueTask> GetPermissionsAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPermissionsAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.Permissions)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified permissions is an expensive operation. @@ -501,20 +425,15 @@ public class OpenIddictEntityFrameworkCoreApplicationStore>(permissions); + return new(permissions); } /// - public virtual ValueTask> GetPostLogoutRedirectUrisAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPostLogoutRedirectUrisAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.PostLogoutRedirectUris)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified addresses is an expensive operation. @@ -542,20 +461,15 @@ public class OpenIddictEntityFrameworkCoreApplicationStore>(addresses); + return new(addresses); } /// - public virtual ValueTask> GetPropertiesAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.Properties)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified properties is an expensive operation. @@ -577,20 +491,15 @@ public class OpenIddictEntityFrameworkCoreApplicationStore>(properties); + return new(properties); } /// - public virtual ValueTask> GetRedirectUrisAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetRedirectUrisAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.RedirectUris)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified addresses is an expensive operation. @@ -618,20 +527,15 @@ public class OpenIddictEntityFrameworkCoreApplicationStore>(addresses); + return new(addresses); } /// - public virtual ValueTask> GetRequirementsAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetRequirementsAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (string.IsNullOrEmpty(application.Requirements)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified requirements is an expensive operation. @@ -659,7 +563,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore>(requirements); + return new(requirements); } /// @@ -667,12 +571,12 @@ public class OpenIddictEntityFrameworkCoreApplicationStore(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0240), exception))); } } @@ -697,91 +601,54 @@ public class OpenIddictEntityFrameworkCoreApplicationStore public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return query(Applications.AsTracking(), state).AsAsyncEnumerable(cancellationToken); - } + => query(Applications.AsTracking(), state).AsAsyncEnumerable(cancellationToken); /// - public virtual ValueTask SetClientIdAsync(TApplication application, string? identifier, CancellationToken cancellationToken) + public virtual ValueTask SetClientIdAsync(TApplication application!!, string? identifier, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.ClientId = identifier; return default; } /// - public virtual ValueTask SetClientSecretAsync(TApplication application, string? secret, CancellationToken cancellationToken) + public virtual ValueTask SetClientSecretAsync(TApplication application!!, string? secret, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.ClientSecret = secret; return default; } /// - public virtual ValueTask SetClientTypeAsync(TApplication application, string? type, CancellationToken cancellationToken) + public virtual ValueTask SetClientTypeAsync(TApplication application!!, string? type, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.Type = type; return default; } /// - public virtual ValueTask SetConsentTypeAsync(TApplication application, string? type, CancellationToken cancellationToken) + public virtual ValueTask SetConsentTypeAsync(TApplication application!!, string? type, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.ConsentType = type; return default; } /// - public virtual ValueTask SetDisplayNameAsync(TApplication application, string? name, CancellationToken cancellationToken) + public virtual ValueTask SetDisplayNameAsync(TApplication application!!, string? name, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.DisplayName = name; return default; } /// - public virtual ValueTask SetDisplayNamesAsync(TApplication application, + public virtual ValueTask SetDisplayNamesAsync(TApplication application!!, ImmutableDictionary names, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (names is null || names.IsEmpty) { application.DisplayNames = null; @@ -813,13 +680,8 @@ public class OpenIddictEntityFrameworkCoreApplicationStore - public virtual ValueTask SetPermissionsAsync(TApplication application, ImmutableArray permissions, CancellationToken cancellationToken) + public virtual ValueTask SetPermissionsAsync(TApplication application!!, ImmutableArray permissions, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (permissions.IsDefaultOrEmpty) { application.Permissions = null; @@ -850,14 +712,9 @@ public class OpenIddictEntityFrameworkCoreApplicationStore - public virtual ValueTask SetPostLogoutRedirectUrisAsync(TApplication application, + public virtual ValueTask SetPostLogoutRedirectUrisAsync(TApplication application!!, ImmutableArray addresses, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (addresses.IsDefaultOrEmpty) { application.PostLogoutRedirectUris = null; @@ -888,15 +745,10 @@ public class OpenIddictEntityFrameworkCoreApplicationStore - public virtual ValueTask SetPropertiesAsync(TApplication application, + public virtual ValueTask SetPropertiesAsync(TApplication application!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { application.Properties = null; @@ -927,14 +779,9 @@ public class OpenIddictEntityFrameworkCoreApplicationStore - public virtual ValueTask SetRedirectUrisAsync(TApplication application, + public virtual ValueTask SetRedirectUrisAsync(TApplication application!!, ImmutableArray addresses, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (addresses.IsDefaultOrEmpty) { application.RedirectUris = null; @@ -965,13 +812,8 @@ public class OpenIddictEntityFrameworkCoreApplicationStore - public virtual ValueTask SetRequirementsAsync(TApplication application, ImmutableArray requirements, CancellationToken cancellationToken) + public virtual ValueTask SetRequirementsAsync(TApplication application!!, ImmutableArray requirements, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (requirements.IsDefaultOrEmpty) { application.Requirements = null; @@ -1002,13 +844,8 @@ public class OpenIddictEntityFrameworkCoreApplicationStore - public virtual async ValueTask UpdateAsync(TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - Context.Attach(application); // Generate a new concurrency token and attach it diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs index 6b829832..c903a0d4 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs @@ -30,7 +30,7 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore : public OpenIddictEntityFrameworkCoreAuthorizationStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -51,7 +51,7 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore : public OpenIddictEntityFrameworkCoreAuthorizationStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -73,9 +73,9 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore { public OpenIddictEntityFrameworkCoreAuthorizationStore( - IMemoryCache cache, - TContext context, - IOptionsMonitor options) + IMemoryCache cache!!, + TContext context!!, + IOptionsMonitor options!!) { Cache = cache; Context = context; @@ -117,37 +117,20 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore await Authorizations.AsQueryable().LongCountAsync(cancellationToken); /// - public virtual async ValueTask CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Authorizations).LongCountAsync(cancellationToken); - } + public virtual async ValueTask CountAsync(Func, IQueryable> query!!, CancellationToken cancellationToken) + => await query(Authorizations).LongCountAsync(cancellationToken); /// - public virtual async ValueTask CreateAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - Context.Add(authorization); await Context.SaveChangesAsync(cancellationToken); } /// - public virtual async ValueTask DeleteAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - async ValueTask CreateTransactionAsync() { // Note: transactions that specify an explicit isolation level are only supported by @@ -426,13 +409,8 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore - public virtual async ValueTask GetApplicationIdAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask GetApplicationIdAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - // If the application is not attached to the authorization, try to load it manually. if (authorization.Application is null) { @@ -455,57 +433,26 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query( + => await query( Authorizations.Include(authorization => authorization.Application) .AsTracking(), state).FirstOrDefaultAsync(cancellationToken); - } /// - public virtual ValueTask GetCreationDateAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (authorization.CreationDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(authorization.CreationDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetCreationDateAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.CreationDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetIdAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(ConvertIdentifierToString(authorization.Id)); - } + public virtual ValueTask GetIdAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(ConvertIdentifierToString(authorization.Id)); /// - public virtual ValueTask> GetPropertiesAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (string.IsNullOrEmpty(authorization.Properties)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified properties is an expensive operation. @@ -527,20 +474,15 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore>(properties); + return new(properties); } /// - public virtual ValueTask> GetScopesAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> GetScopesAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (string.IsNullOrEmpty(authorization.Scopes)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified scopes is an expensive operation. @@ -568,53 +510,32 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore>(scopes); + return new(scopes); } /// - public virtual ValueTask GetStatusAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Status); - } + public virtual ValueTask GetStatusAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Status); /// - public virtual ValueTask GetSubjectAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Subject); - } + public virtual ValueTask GetSubjectAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Subject); /// - public virtual ValueTask GetTypeAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Type); - } + public virtual ValueTask GetTypeAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Type); /// public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0242), exception))); } } @@ -641,14 +562,9 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - return query( Authorizations.Include(authorization => authorization.Application) .AsTracking(), state).AsAsyncEnumerable(cancellationToken); @@ -746,14 +662,9 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore - public virtual async ValueTask SetApplicationIdAsync(TAuthorization authorization, + public virtual async ValueTask SetApplicationIdAsync(TAuthorization authorization!!, string? identifier, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (!string.IsNullOrEmpty(identifier)) { var key = ConvertIdentifierFromString(identifier); @@ -792,29 +703,19 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore - public virtual ValueTask SetCreationDateAsync(TAuthorization authorization, + public virtual ValueTask SetCreationDateAsync(TAuthorization authorization!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.CreationDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetPropertiesAsync(TAuthorization authorization, + public virtual ValueTask SetPropertiesAsync(TAuthorization authorization!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { authorization.Properties = null; @@ -845,14 +746,9 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore - public virtual ValueTask SetScopesAsync(TAuthorization authorization, + public virtual ValueTask SetScopesAsync(TAuthorization authorization!!, ImmutableArray scopes, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (scopes.IsDefaultOrEmpty) { authorization.Scopes = null; @@ -883,55 +779,35 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore - public virtual ValueTask SetStatusAsync(TAuthorization authorization, + public virtual ValueTask SetStatusAsync(TAuthorization authorization!!, string? status, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.Status = status; return default; } /// - public virtual ValueTask SetSubjectAsync(TAuthorization authorization, + public virtual ValueTask SetSubjectAsync(TAuthorization authorization!!, string? subject, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.Subject = subject; return default; } /// - public virtual ValueTask SetTypeAsync(TAuthorization authorization, + public virtual ValueTask SetTypeAsync(TAuthorization authorization!!, string? type, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.Type = type; return default; } /// - public virtual async ValueTask UpdateAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - Context.Attach(authorization); // Generate a new concurrency token and attach it diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs index 7a85aa8a..43b59e24 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs @@ -27,7 +27,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore : OpenIddictEntit public OpenIddictEntityFrameworkCoreScopeStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -45,7 +45,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore : OpenIddic public OpenIddictEntityFrameworkCoreScopeStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -63,9 +63,9 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I where TKey : notnull, IEquatable { public OpenIddictEntityFrameworkCoreScopeStore( - IMemoryCache cache, - TContext context, - IOptionsMonitor options) + IMemoryCache cache!!, + TContext context!!, + IOptionsMonitor options!!) { Cache = cache; Context = context; @@ -97,37 +97,20 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I => await Scopes.AsQueryable().LongCountAsync(cancellationToken); /// - public virtual async ValueTask CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Scopes).LongCountAsync(cancellationToken); - } + public virtual async ValueTask CountAsync(Func, IQueryable> query!!, CancellationToken cancellationToken) + => await query(Scopes).LongCountAsync(cancellationToken); /// - public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - Scopes.Add(scope); await Context.SaveChangesAsync(cancellationToken); } /// - public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - Context.Remove(scope); try @@ -176,7 +159,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I public virtual IAsyncEnumerable FindByNamesAsync( ImmutableArray names, CancellationToken cancellationToken) { - if (names.Any(name => string.IsNullOrEmpty(name))) + if (names.Any(string.IsNullOrEmpty)) { throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names)); } @@ -224,39 +207,20 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I /// public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Scopes.AsTracking(), state).FirstOrDefaultAsync(cancellationToken); - } + => await query(Scopes.AsTracking(), state).FirstOrDefaultAsync(cancellationToken); /// - public virtual ValueTask GetDescriptionAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.Description); - } + public virtual ValueTask GetDescriptionAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.Description); /// - public virtual ValueTask> GetDescriptionsAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetDescriptionsAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (string.IsNullOrEmpty(scope.Descriptions)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified descriptions is an expensive operation. @@ -284,31 +248,19 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I return builder.ToImmutable(); }); - return new ValueTask>(descriptions); + return new(descriptions); } /// - public virtual ValueTask GetDisplayNameAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.DisplayName); - } + public virtual ValueTask GetDisplayNameAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.DisplayName); /// - public virtual ValueTask> GetDisplayNamesAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetDisplayNamesAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (string.IsNullOrEmpty(scope.DisplayNames)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified display names is an expensive operation. @@ -336,42 +288,23 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I return builder.ToImmutable(); }); - return new ValueTask>(names); + return new(names); } /// - public virtual ValueTask GetIdAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(ConvertIdentifierToString(scope.Id)); - } + public virtual ValueTask GetIdAsync(TScope scope!!, CancellationToken cancellationToken) + => new(ConvertIdentifierToString(scope.Id)); /// - public virtual ValueTask GetNameAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.Name); - } + public virtual ValueTask GetNameAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.Name); /// - public virtual ValueTask> GetPropertiesAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (string.IsNullOrEmpty(scope.Properties)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified properties is an expensive operation. @@ -393,20 +326,15 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I return builder.ToImmutable(); }); - return new ValueTask>(properties); + return new(properties); } /// - public virtual ValueTask> GetResourcesAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetResourcesAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (string.IsNullOrEmpty(scope.Resources)) { - return new ValueTask>(ImmutableArray.Create()); + return new(ImmutableArray.Create()); } // Note: parsing the stringified resources is an expensive operation. @@ -434,7 +362,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I return builder.ToImmutable(); }); - return new ValueTask>(resources); + return new(resources); } /// @@ -442,12 +370,12 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0246), exception))); } } @@ -472,39 +400,22 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I /// public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return query(Scopes.AsTracking(), state).AsAsyncEnumerable(cancellationToken); - } + => query(Scopes.AsTracking(), state).AsAsyncEnumerable(cancellationToken); /// - public virtual ValueTask SetDescriptionAsync(TScope scope, string? description, CancellationToken cancellationToken) + public virtual ValueTask SetDescriptionAsync(TScope scope!!, string? description, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.Description = description; return default; } /// - public virtual ValueTask SetDescriptionsAsync(TScope scope, + public virtual ValueTask SetDescriptionsAsync(TScope scope!!, ImmutableDictionary descriptions, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (descriptions is null || descriptions.IsEmpty) { scope.Descriptions = null; @@ -536,27 +447,17 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I } /// - public virtual ValueTask SetDisplayNameAsync(TScope scope, string? name, CancellationToken cancellationToken) + public virtual ValueTask SetDisplayNameAsync(TScope scope!!, string? name, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.DisplayName = name; return default; } /// - public virtual ValueTask SetDisplayNamesAsync(TScope scope, + public virtual ValueTask SetDisplayNamesAsync(TScope scope!!, ImmutableDictionary names, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (names is null || names.IsEmpty) { scope.DisplayNames = null; @@ -588,28 +489,18 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I } /// - public virtual ValueTask SetNameAsync(TScope scope, string? name, CancellationToken cancellationToken) + public virtual ValueTask SetNameAsync(TScope scope!!, string? name, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.Name = name; return default; } /// - public virtual ValueTask SetPropertiesAsync(TScope scope, + public virtual ValueTask SetPropertiesAsync(TScope scope!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { scope.Properties = null; @@ -640,13 +531,8 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I } /// - public virtual ValueTask SetResourcesAsync(TScope scope, ImmutableArray resources, CancellationToken cancellationToken) + public virtual ValueTask SetResourcesAsync(TScope scope!!, ImmutableArray resources, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (resources.IsDefaultOrEmpty) { scope.Resources = null; @@ -677,13 +563,8 @@ public class OpenIddictEntityFrameworkCoreScopeStore : I } /// - public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - Context.Attach(scope); // Generate a new concurrency token and attach it diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs index 77c36401..8d23a2cc 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs @@ -29,7 +29,7 @@ public class OpenIddictEntityFrameworkCoreTokenStore : public OpenIddictEntityFrameworkCoreTokenStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -50,7 +50,7 @@ public class OpenIddictEntityFrameworkCoreTokenStore : public OpenIddictEntityFrameworkCoreTokenStore( IMemoryCache cache, TContext context, - IOptionsMonitor options) + IOptionsMonitor options!!) : base(cache, context, options) { } @@ -72,9 +72,9 @@ public class OpenIddictEntityFrameworkCoreTokenStore { public OpenIddictEntityFrameworkCoreTokenStore( - IMemoryCache cache, - TContext context, - IOptionsMonitor options) + IMemoryCache cache!!, + TContext context!!, + IOptionsMonitor options!!) { Cache = cache; Context = context; @@ -116,37 +116,20 @@ public class OpenIddictEntityFrameworkCoreTokenStore await Tokens.AsQueryable().LongCountAsync(cancellationToken); /// - public virtual async ValueTask CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Tokens).LongCountAsync(cancellationToken); - } + public virtual async ValueTask CountAsync(Func, IQueryable> query!!, CancellationToken cancellationToken) + => await query(Tokens).LongCountAsync(cancellationToken); /// - public virtual async ValueTask CreateAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - Context.Add(token); await Context.SaveChangesAsync(cancellationToken); } /// - public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - Context.Remove(token); try @@ -350,13 +333,8 @@ public class OpenIddictEntityFrameworkCoreTokenStore - public virtual async ValueTask GetApplicationIdAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask GetApplicationIdAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - // If the application is not attached to the token, try to load it manually. if (token.Application is null) { @@ -379,27 +357,15 @@ public class OpenIddictEntityFrameworkCoreTokenStore public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return await query(Tokens.Include(token => token.Application) + => await query(Tokens.Include(token => token.Application) .Include(token => token.Authorization) .AsTracking(), state).FirstOrDefaultAsync(cancellationToken); - } /// - public virtual async ValueTask GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask GetAuthorizationIdAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - // If the authorization is not attached to the token, try to load it manually. if (token.Authorization is null) { @@ -421,70 +387,27 @@ public class OpenIddictEntityFrameworkCoreTokenStore - public virtual ValueTask GetCreationDateAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (token.CreationDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(token.CreationDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetCreationDateAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.CreationDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetExpirationDateAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (token.ExpirationDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(token.ExpirationDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetExpirationDateAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.ExpirationDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetIdAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(ConvertIdentifierToString(token.Id)); - } + public virtual ValueTask GetIdAsync(TToken token!!, CancellationToken cancellationToken) + => new(ConvertIdentifierToString(token.Id)); /// - public virtual ValueTask GetPayloadAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Payload); - } + public virtual ValueTask GetPayloadAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Payload); /// - public virtual ValueTask> GetPropertiesAsync(TToken token, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (string.IsNullOrEmpty(token.Properties)) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } // Note: parsing the stringified properties is an expensive operation. @@ -506,80 +429,40 @@ public class OpenIddictEntityFrameworkCoreTokenStore>(properties); + return new(properties); } /// - public virtual ValueTask GetRedemptionDateAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (token.RedemptionDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(token.RedemptionDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetRedemptionDateAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.RedemptionDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetReferenceIdAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.ReferenceId); - } + public virtual ValueTask GetReferenceIdAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.ReferenceId); /// - public virtual ValueTask GetStatusAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Status); - } + public virtual ValueTask GetStatusAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Status); /// - public virtual ValueTask GetSubjectAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Subject); - } + public virtual ValueTask GetSubjectAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Subject); /// - public virtual ValueTask GetTypeAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Type); - } + public virtual ValueTask GetTypeAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Type); /// public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0248), exception))); } } @@ -607,19 +490,12 @@ public class OpenIddictEntityFrameworkCoreTokenStore public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) - { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - - return query( + => query( Tokens.Include(token => token.Application) .Include(token => token.Authorization) .AsTracking(), state).AsAsyncEnumerable(cancellationToken); - } /// public virtual async ValueTask PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken) @@ -710,13 +586,8 @@ public class OpenIddictEntityFrameworkCoreTokenStore - public virtual async ValueTask SetApplicationIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) + public virtual async ValueTask SetApplicationIdAsync(TToken token!!, string? identifier, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (!string.IsNullOrEmpty(identifier)) { var key = ConvertIdentifierFromString(identifier); @@ -755,13 +626,8 @@ public class OpenIddictEntityFrameworkCoreTokenStore - public virtual async ValueTask SetAuthorizationIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) + public virtual async ValueTask SetAuthorizationIdAsync(TToken token!!, string? identifier, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (!string.IsNullOrEmpty(identifier)) { var key = ConvertIdentifierFromString(identifier); @@ -800,54 +666,34 @@ public class OpenIddictEntityFrameworkCoreTokenStore - public virtual ValueTask SetCreationDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken) + public virtual ValueTask SetCreationDateAsync(TToken token!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.CreationDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetExpirationDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken) + public virtual ValueTask SetExpirationDateAsync(TToken token!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.ExpirationDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetPayloadAsync(TToken token, string? payload, CancellationToken cancellationToken) + public virtual ValueTask SetPayloadAsync(TToken token!!, string? payload, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Payload = payload; return default; } /// - public virtual ValueTask SetPropertiesAsync(TToken token, + public virtual ValueTask SetPropertiesAsync(TToken token!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { token.Properties = null; @@ -878,78 +724,48 @@ public class OpenIddictEntityFrameworkCoreTokenStore - public virtual ValueTask SetRedemptionDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken) + public virtual ValueTask SetRedemptionDateAsync(TToken token!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.RedemptionDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetReferenceIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) + public virtual ValueTask SetReferenceIdAsync(TToken token!!, string? identifier, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.ReferenceId = identifier; return default; } /// - public virtual ValueTask SetStatusAsync(TToken token, string? status, CancellationToken cancellationToken) + public virtual ValueTask SetStatusAsync(TToken token!!, string? status, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Status = status; return default; } /// - public virtual ValueTask SetSubjectAsync(TToken token, string? subject, CancellationToken cancellationToken) + public virtual ValueTask SetSubjectAsync(TToken token!!, string? subject, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Subject = subject; return default; } /// - public virtual ValueTask SetTypeAsync(TToken token, string? type, CancellationToken cancellationToken) + public virtual ValueTask SetTypeAsync(TToken token!!, string? type, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Type = type; return default; } /// - public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - Context.Attach(token); // Generate a new concurrency token and attach it diff --git a/src/OpenIddict.MongoDb/OpenIddictMongoDbBuilder.cs b/src/OpenIddict.MongoDb/OpenIddictMongoDbBuilder.cs index f6fac7bd..185e7ad4 100644 --- a/src/OpenIddict.MongoDb/OpenIddictMongoDbBuilder.cs +++ b/src/OpenIddict.MongoDb/OpenIddictMongoDbBuilder.cs @@ -20,8 +20,8 @@ public class OpenIddictMongoDbBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictMongoDbBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictMongoDbBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -35,13 +35,8 @@ public class OpenIddictMongoDbBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictMongoDbBuilder Configure(Action configuration) + public OpenIddictMongoDbBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -161,13 +156,8 @@ public class OpenIddictMongoDbBuilder /// /// The . /// The . - public OpenIddictMongoDbBuilder UseDatabase(IMongoDatabase database) + public OpenIddictMongoDbBuilder UseDatabase(IMongoDatabase database!!) { - if (database is null) - { - throw new ArgumentNullException(nameof(database)); - } - return Configure(options => options.Database = database); } diff --git a/src/OpenIddict.MongoDb/OpenIddictMongoDbContext.cs b/src/OpenIddict.MongoDb/OpenIddictMongoDbContext.cs index f0450085..d589f56b 100644 --- a/src/OpenIddict.MongoDb/OpenIddictMongoDbContext.cs +++ b/src/OpenIddict.MongoDb/OpenIddictMongoDbContext.cs @@ -16,8 +16,8 @@ public class OpenIddictMongoDbContext : IOpenIddictMongoDbContext private readonly IServiceProvider _provider; public OpenIddictMongoDbContext( - IOptionsMonitor options, - IServiceProvider provider) + IOptionsMonitor options!!, + IServiceProvider provider!!) { _options = options; _provider = provider; @@ -28,7 +28,7 @@ public class OpenIddictMongoDbContext : IOpenIddictMongoDbContext { if (cancellationToken.IsCancellationRequested) { - return new ValueTask(Task.FromCanceled(cancellationToken)); + return new(Task.FromCanceled(cancellationToken)); } var database = _options.CurrentValue.Database; @@ -39,10 +39,10 @@ public class OpenIddictMongoDbContext : IOpenIddictMongoDbContext if (database is null) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0262)))); } - return new ValueTask(database); + return new(database); } } diff --git a/src/OpenIddict.MongoDb/OpenIddictMongoDbExtensions.cs b/src/OpenIddict.MongoDb/OpenIddictMongoDbExtensions.cs index 6e33434c..154b9a9e 100644 --- a/src/OpenIddict.MongoDb/OpenIddictMongoDbExtensions.cs +++ b/src/OpenIddict.MongoDb/OpenIddictMongoDbExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictMongoDbExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictMongoDbBuilder UseMongoDb(this OpenIddictCoreBuilder builder) + public static OpenIddictMongoDbBuilder UseMongoDb(this OpenIddictCoreBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - // Note: Mongo uses simple binary comparison checks by default so the additional // query filtering applied by the default OpenIddict managers can be safely disabled. builder.DisableAdditionalFiltering(); @@ -64,18 +59,8 @@ public static class OpenIddictMongoDbExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictCoreBuilder UseMongoDb( - this OpenIddictCoreBuilder builder, Action configuration) + this OpenIddictCoreBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseMongoDb()); return builder; diff --git a/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs b/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs index d0d38490..e2f29d81 100644 --- a/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs +++ b/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs @@ -20,13 +20,8 @@ internal static class OpenIddictMongoDbHelpers /// The query source. /// The that can be used to abort the operation. /// The streamed async enumeration containing the results. - internal static IAsyncEnumerable ToAsyncEnumerable(this IAsyncCursorSource source, CancellationToken cancellationToken) + internal static IAsyncEnumerable ToAsyncEnumerable(this IAsyncCursorSource source!!, CancellationToken cancellationToken) { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - return ExecuteAsync(source, cancellationToken); static async IAsyncEnumerable ExecuteAsync(IAsyncCursorSource source, [EnumeratorCancellation] CancellationToken cancellationToken) @@ -50,13 +45,6 @@ internal static class OpenIddictMongoDbHelpers /// The query source. /// The that can be used to abort the operation. /// The streamed async enumeration containing the results. - internal static IAsyncEnumerable ToAsyncEnumerable(this IQueryable source, CancellationToken cancellationToken) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return ((IAsyncCursorSource) source).ToAsyncEnumerable(cancellationToken); - } + internal static IAsyncEnumerable ToAsyncEnumerable(this IQueryable source!!, CancellationToken cancellationToken) + => ((IAsyncCursorSource) source).ToAsyncEnumerable(cancellationToken); } diff --git a/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbApplicationStoreResolver.cs b/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbApplicationStoreResolver.cs index fee2ca2e..9a1770a7 100644 --- a/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbApplicationStoreResolver.cs +++ b/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbApplicationStoreResolver.cs @@ -18,7 +18,7 @@ public class OpenIddictMongoDbApplicationStoreResolver : IOpenIddictApplicationS private readonly ConcurrentDictionary _cache = new ConcurrentDictionary(); private readonly IServiceProvider _provider; - public OpenIddictMongoDbApplicationStoreResolver(IServiceProvider provider) + public OpenIddictMongoDbApplicationStoreResolver(IServiceProvider provider!!) => _provider = provider; /// diff --git a/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbAuthorizationStoreResolver.cs b/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbAuthorizationStoreResolver.cs index b5ffdded..73e0788f 100644 --- a/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbAuthorizationStoreResolver.cs +++ b/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbAuthorizationStoreResolver.cs @@ -18,7 +18,7 @@ public class OpenIddictMongoDbAuthorizationStoreResolver : IOpenIddictAuthorizat private readonly ConcurrentDictionary _cache = new ConcurrentDictionary(); private readonly IServiceProvider _provider; - public OpenIddictMongoDbAuthorizationStoreResolver(IServiceProvider provider) + public OpenIddictMongoDbAuthorizationStoreResolver(IServiceProvider provider!!) => _provider = provider; /// diff --git a/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbScopeStoreResolver.cs b/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbScopeStoreResolver.cs index 86e78c14..c2b8edd1 100644 --- a/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbScopeStoreResolver.cs +++ b/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbScopeStoreResolver.cs @@ -18,7 +18,7 @@ public class OpenIddictMongoDbScopeStoreResolver : IOpenIddictScopeStoreResolver private readonly ConcurrentDictionary _cache = new ConcurrentDictionary(); private readonly IServiceProvider _provider; - public OpenIddictMongoDbScopeStoreResolver(IServiceProvider provider) + public OpenIddictMongoDbScopeStoreResolver(IServiceProvider provider!!) => _provider = provider; /// diff --git a/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbTokenStoreResolver.cs b/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbTokenStoreResolver.cs index 1c7d7711..60b1c23a 100644 --- a/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbTokenStoreResolver.cs +++ b/src/OpenIddict.MongoDb/Resolvers/OpenIddictMongoDbTokenStoreResolver.cs @@ -18,7 +18,7 @@ public class OpenIddictMongoDbTokenStoreResolver : IOpenIddictTokenStoreResolver private readonly ConcurrentDictionary _cache = new ConcurrentDictionary(); private readonly IServiceProvider _provider; - public OpenIddictMongoDbTokenStoreResolver(IServiceProvider provider) + public OpenIddictMongoDbTokenStoreResolver(IServiceProvider provider!!) => _provider = provider; /// diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs index 90c11d8b..5dc6d2ca 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs @@ -23,8 +23,8 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic where TApplication : OpenIddictMongoDbApplication { public OpenIddictMongoDbApplicationStore( - IOpenIddictMongoDbContext context, - IOptionsMonitor options) + IOpenIddictMongoDbContext context!!, + IOptionsMonitor options!!) { Context = context; Options = options; @@ -51,13 +51,8 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic /// public virtual async ValueTask CountAsync( - Func, IQueryable> query, CancellationToken cancellationToken) + Func, IQueryable> query!!, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName); @@ -65,13 +60,8 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual async ValueTask CreateAsync(TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName); @@ -79,13 +69,8 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual async ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName); @@ -135,8 +120,7 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual IAsyncEnumerable FindByPostLogoutRedirectUriAsync( - string address, CancellationToken cancellationToken) + public virtual IAsyncEnumerable FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(address)) { @@ -159,8 +143,7 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual IAsyncEnumerable FindByRedirectUriAsync( - string address, CancellationToken cancellationToken) + public virtual IAsyncEnumerable FindByRedirectUriAsync(string address, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(address)) { @@ -184,14 +167,9 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic /// public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName); @@ -199,132 +177,47 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual ValueTask GetClientIdAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.ClientId); - } + public virtual ValueTask GetClientIdAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.ClientId); /// - public virtual ValueTask GetClientSecretAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.ClientSecret); - } + public virtual ValueTask GetClientSecretAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.ClientSecret); /// - public virtual ValueTask GetClientTypeAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.Type); - } + public virtual ValueTask GetClientTypeAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.Type); /// - public virtual ValueTask GetConsentTypeAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.ConsentType); - } + public virtual ValueTask GetConsentTypeAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.ConsentType); /// - public virtual ValueTask GetDisplayNameAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.DisplayName); - } + public virtual ValueTask GetDisplayNameAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.DisplayName); /// - public virtual ValueTask> GetDisplayNamesAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (application.DisplayNames is null || application.DisplayNames.Count == 0) - { - return new ValueTask>(ImmutableDictionary.Create()); - } - - return new ValueTask>(application.DisplayNames.ToImmutableDictionary()); - } + public virtual ValueTask> GetDisplayNamesAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.DisplayNames is { Count: > 0 } names ? names.ToImmutableDictionary() : ImmutableDictionary.Create()); /// - public virtual ValueTask GetIdAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - return new ValueTask(application.Id.ToString()); - } + public virtual ValueTask GetIdAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.Id.ToString()); /// - public virtual ValueTask> GetPermissionsAsync( - TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (application.Permissions is null || application.Permissions.Count == 0) - { - return new ValueTask>(ImmutableArray.Create()); - } - - return new ValueTask>(application.Permissions.ToImmutableArray()); - } + public virtual ValueTask> GetPermissionsAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.Permissions is { Count: > 0 } permissions ? permissions.ToImmutableArray() : ImmutableArray.Create()); /// - public virtual ValueTask> GetPostLogoutRedirectUrisAsync( - TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (application.PostLogoutRedirectUris is null || application.PostLogoutRedirectUris.Count == 0) - { - return new ValueTask>(ImmutableArray.Create()); - } - - return new ValueTask>(application.PostLogoutRedirectUris.ToImmutableArray()); - } + public virtual ValueTask> GetPostLogoutRedirectUrisAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.PostLogoutRedirectUris is { Count: > 0 } addresses ? addresses.ToImmutableArray() : ImmutableArray.Create()); /// - public virtual ValueTask> GetPropertiesAsync(TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (application.Properties is null) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } using var document = JsonDocument.Parse(application.Properties.ToJson()); @@ -335,53 +228,28 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic builder[property.Name] = property.Value.Clone(); } - return new ValueTask>(builder.ToImmutable()); + return new(builder.ToImmutable()); } /// - public virtual ValueTask> GetRedirectUrisAsync( - TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (application.RedirectUris is null || application.RedirectUris.Count == 0) - { - return new ValueTask>(ImmutableArray.Create()); - } - - return new ValueTask>(application.RedirectUris.ToImmutableArray()); - } + public virtual ValueTask> GetRedirectUrisAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.RedirectUris is { Count: > 0 } addresses ? addresses.ToImmutableArray() : ImmutableArray.Create()); /// - public virtual ValueTask> GetRequirementsAsync(TApplication application, CancellationToken cancellationToken) - { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (application.Requirements is null || application.Requirements.Count == 0) - { - return new ValueTask>(ImmutableArray.Create()); - } - - return new ValueTask>(application.Requirements.ToImmutableArray()); - } + public virtual ValueTask> GetRequirementsAsync(TApplication application!!, CancellationToken cancellationToken) + => new(application.Requirements is { Count: > 0 } requirements ? requirements.ToImmutableArray() : ImmutableArray.Create()); /// public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0240), exception))); } } @@ -413,14 +281,9 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic /// public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - return ExecuteAsync(cancellationToken); async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) @@ -436,97 +299,62 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual ValueTask SetClientIdAsync(TApplication application, + public virtual ValueTask SetClientIdAsync(TApplication application!!, string? identifier, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.ClientId = identifier; return default; } /// - public virtual ValueTask SetClientSecretAsync(TApplication application, + public virtual ValueTask SetClientSecretAsync(TApplication application!!, string? secret, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.ClientSecret = secret; return default; } /// - public virtual ValueTask SetClientTypeAsync(TApplication application, + public virtual ValueTask SetClientTypeAsync(TApplication application!!, string? type, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.Type = type; return default; } /// - public virtual ValueTask SetConsentTypeAsync(TApplication application, + public virtual ValueTask SetConsentTypeAsync(TApplication application!!, string? type, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.ConsentType = type; return default; } /// - public virtual ValueTask SetDisplayNameAsync(TApplication application, + public virtual ValueTask SetDisplayNameAsync(TApplication application!!, string? name, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.DisplayName = name; return default; } /// - public virtual ValueTask SetDisplayNamesAsync(TApplication application, + public virtual ValueTask SetDisplayNamesAsync(TApplication application!!, ImmutableDictionary names, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - application.DisplayNames = names; return default; } /// - public virtual ValueTask SetPermissionsAsync(TApplication application, ImmutableArray permissions, CancellationToken cancellationToken) + public virtual ValueTask SetPermissionsAsync(TApplication application!!, ImmutableArray permissions, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (permissions.IsDefaultOrEmpty) { application.Permissions = ImmutableList.Create(); @@ -540,14 +368,9 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual ValueTask SetPostLogoutRedirectUrisAsync(TApplication application, + public virtual ValueTask SetPostLogoutRedirectUrisAsync(TApplication application!!, ImmutableArray addresses, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (addresses.IsDefaultOrEmpty) { application.PostLogoutRedirectUris = ImmutableList.Create(); @@ -561,15 +384,10 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual ValueTask SetPropertiesAsync(TApplication application, + public virtual ValueTask SetPropertiesAsync(TApplication application!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { application.Properties = null; @@ -600,14 +418,9 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual ValueTask SetRedirectUrisAsync(TApplication application, + public virtual ValueTask SetRedirectUrisAsync(TApplication application!!, ImmutableArray addresses, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (addresses.IsDefaultOrEmpty) { application.RedirectUris = ImmutableList.Create(); @@ -621,14 +434,9 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual ValueTask SetRequirementsAsync(TApplication application, + public virtual ValueTask SetRequirementsAsync(TApplication application!!, ImmutableArray requirements, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - if (requirements.IsDefaultOrEmpty) { application.Requirements = ImmutableList.Create(); @@ -642,13 +450,8 @@ public class OpenIddictMongoDbApplicationStore : IOpenIddictApplic } /// - public virtual async ValueTask UpdateAsync(TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TApplication application!!, CancellationToken cancellationToken) { - if (application is null) - { - throw new ArgumentNullException(nameof(application)); - } - // Generate a new concurrency token and attach it // to the application before persisting the changes. var timestamp = application.ConcurrencyToken; diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs index 6c5a27f3..d617d1e3 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs @@ -22,8 +22,8 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu where TAuthorization : OpenIddictMongoDbAuthorization { public OpenIddictMongoDbAuthorizationStore( - IOpenIddictMongoDbContext context, - IOptionsMonitor options) + IOpenIddictMongoDbContext context!!, + IOptionsMonitor options!!) { Context = context; Options = options; @@ -50,13 +50,8 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu /// public virtual async ValueTask CountAsync( - Func, IQueryable> query, CancellationToken cancellationToken) + Func, IQueryable> query!!, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName); @@ -64,13 +59,8 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu } /// - public virtual async ValueTask CreateAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName); @@ -78,13 +68,8 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu } /// - public virtual async ValueTask DeleteAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName); @@ -321,31 +306,21 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu } /// - public virtual ValueTask GetApplicationIdAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask GetApplicationIdAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (authorization.ApplicationId == ObjectId.Empty) { - return new ValueTask(result: null); + return new(result: null); } - return new ValueTask(authorization.ApplicationId.ToString()); + return new(authorization.ApplicationId.ToString()); } /// public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName); @@ -353,43 +328,19 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu } /// - public virtual ValueTask GetCreationDateAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (authorization.CreationDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(authorization.CreationDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetCreationDateAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.CreationDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetIdAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Id.ToString()); - } + public virtual ValueTask GetIdAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Id.ToString()); /// - public virtual ValueTask> GetPropertiesAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (authorization.Properties is null) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } using var document = JsonDocument.Parse(authorization.Properties.ToJson()); @@ -400,69 +351,36 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu builder[property.Name] = property.Value.Clone(); } - return new ValueTask>(builder.ToImmutable()); + return new(builder.ToImmutable()); } /// - public virtual ValueTask> GetScopesAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (authorization.Scopes is null || authorization.Scopes.Count == 0) - { - return new ValueTask>(ImmutableArray.Create()); - } - - return new ValueTask>(authorization.Scopes.ToImmutableArray()); - } + public virtual ValueTask> GetScopesAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Scopes is { Count: > 0 } scopes ? scopes.ToImmutableArray() : ImmutableArray.Create()); /// - public virtual ValueTask GetStatusAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Status); - } + public virtual ValueTask GetStatusAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Status); /// - public virtual ValueTask GetSubjectAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Subject); - } + public virtual ValueTask GetSubjectAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Subject); /// - public virtual ValueTask GetTypeAsync(TAuthorization authorization, CancellationToken cancellationToken) - { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - return new ValueTask(authorization.Type); - } + public virtual ValueTask GetTypeAsync(TAuthorization authorization!!, CancellationToken cancellationToken) + => new(authorization.Type); /// public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0242), exception))); } } @@ -494,14 +412,9 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu /// public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - return ExecuteAsync(cancellationToken); async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) @@ -567,14 +480,9 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu } /// - public virtual ValueTask SetApplicationIdAsync(TAuthorization authorization, + public virtual ValueTask SetApplicationIdAsync(TAuthorization authorization!!, string? identifier, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (!string.IsNullOrEmpty(identifier)) { authorization.ApplicationId = ObjectId.Parse(identifier); @@ -589,29 +497,19 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu } /// - public virtual ValueTask SetCreationDateAsync(TAuthorization authorization, + public virtual ValueTask SetCreationDateAsync(TAuthorization authorization!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.CreationDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetPropertiesAsync(TAuthorization authorization, + public virtual ValueTask SetPropertiesAsync(TAuthorization authorization!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { authorization.Properties = null; @@ -642,14 +540,9 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu } /// - public virtual ValueTask SetScopesAsync(TAuthorization authorization, + public virtual ValueTask SetScopesAsync(TAuthorization authorization!!, ImmutableArray scopes, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - if (scopes.IsDefaultOrEmpty) { authorization.Scopes = ImmutableList.Create(); @@ -663,52 +556,32 @@ public class OpenIddictMongoDbAuthorizationStore : IOpenIddictAu } /// - public virtual ValueTask SetStatusAsync(TAuthorization authorization, string? status, CancellationToken cancellationToken) + public virtual ValueTask SetStatusAsync(TAuthorization authorization!!, string? status, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.Status = status; return default; } /// - public virtual ValueTask SetSubjectAsync(TAuthorization authorization, string? subject, CancellationToken cancellationToken) + public virtual ValueTask SetSubjectAsync(TAuthorization authorization!!, string? subject, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.Subject = subject; return default; } /// - public virtual ValueTask SetTypeAsync(TAuthorization authorization, string? type, CancellationToken cancellationToken) + public virtual ValueTask SetTypeAsync(TAuthorization authorization!!, string? type, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - authorization.Type = type; return default; } /// - public virtual async ValueTask UpdateAsync(TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TAuthorization authorization!!, CancellationToken cancellationToken) { - if (authorization is null) - { - throw new ArgumentNullException(nameof(authorization)); - } - // Generate a new concurrency token and attach it // to the authorization before persisting the changes. var timestamp = authorization.ConcurrencyToken; diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs index 0e7b7496..ba2ee92e 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs @@ -23,8 +23,8 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore where TScope : OpenIddictMongoDbScope { public OpenIddictMongoDbScopeStore( - IOpenIddictMongoDbContext context, - IOptionsMonitor options) + IOpenIddictMongoDbContext context!!, + IOptionsMonitor options!!) { Context = context; Options = options; @@ -51,13 +51,8 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore /// public virtual async ValueTask CountAsync( - Func, IQueryable> query, CancellationToken cancellationToken) + Func, IQueryable> query!!, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); @@ -65,13 +60,8 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore } /// - public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); @@ -79,13 +69,8 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore } /// - public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); @@ -128,7 +113,7 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore /// public virtual IAsyncEnumerable FindByNamesAsync(ImmutableArray names, CancellationToken cancellationToken) { - if (names.Any(name => string.IsNullOrEmpty(name))) + if (names.Any(string.IsNullOrEmpty)) { throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names)); } @@ -173,14 +158,9 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore /// public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); @@ -188,92 +168,35 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore } /// - public virtual ValueTask GetDescriptionAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.Description); - } + public virtual ValueTask GetDescriptionAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.Description); /// - public virtual ValueTask> GetDescriptionsAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (scope.Descriptions is null || scope.Descriptions.Count == 0) - { - return new ValueTask>(ImmutableDictionary.Create()); - } - - return new ValueTask>(scope.Descriptions.ToImmutableDictionary()); - } + public virtual ValueTask> GetDescriptionsAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.Descriptions is { Count: > 0 } descriptions ? descriptions.ToImmutableDictionary() : ImmutableDictionary.Create()); /// - public virtual ValueTask GetDisplayNameAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.DisplayName); - } + public virtual ValueTask GetDisplayNameAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.DisplayName); /// - public virtual ValueTask> GetDisplayNamesAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (scope.DisplayNames is null || scope.DisplayNames.Count == 0) - { - return new ValueTask>(ImmutableDictionary.Create()); - } - - return new ValueTask>(scope.DisplayNames.ToImmutableDictionary()); - } + public virtual ValueTask> GetDisplayNamesAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.DisplayNames is { Count: > 0 } names ? names.ToImmutableDictionary() : ImmutableDictionary.Create()); /// - public virtual ValueTask GetIdAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.Id.ToString()); - } + public virtual ValueTask GetIdAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.Id.ToString()); /// - public virtual ValueTask GetNameAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - return new ValueTask(scope.Name); - } + public virtual ValueTask GetNameAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.Name); /// - public virtual ValueTask> GetPropertiesAsync(TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (scope.Properties is null) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } using var document = JsonDocument.Parse(scope.Properties.ToJson()); @@ -284,36 +207,24 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore builder[property.Name] = property.Value.Clone(); } - return new ValueTask>(builder.ToImmutable()); + return new(builder.ToImmutable()); } /// - public virtual ValueTask> GetResourcesAsync(TScope scope, CancellationToken cancellationToken) - { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (scope.Resources is null || scope.Resources.Count == 0) - { - return new ValueTask>(ImmutableArray.Create()); - } - - return new ValueTask>(scope.Resources.ToImmutableArray()); - } + public virtual ValueTask> GetResourcesAsync(TScope scope!!, CancellationToken cancellationToken) + => new(scope.Resources is { Count: > 0 } resources ? resources.ToImmutableArray() : ImmutableArray.Create()); /// public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0246), exception))); } } @@ -345,14 +256,9 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore /// public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - return ExecuteAsync(cancellationToken); async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) @@ -368,82 +274,52 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore } /// - public virtual ValueTask SetDescriptionAsync(TScope scope, string? description, CancellationToken cancellationToken) + public virtual ValueTask SetDescriptionAsync(TScope scope!!, string? description, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.Description = description; return default; } /// - public virtual ValueTask SetDescriptionsAsync(TScope scope, + public virtual ValueTask SetDescriptionsAsync(TScope scope!!, ImmutableDictionary descriptions, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.Descriptions = descriptions; return default; } /// - public virtual ValueTask SetDisplayNamesAsync(TScope scope, + public virtual ValueTask SetDisplayNamesAsync(TScope scope!!, ImmutableDictionary names, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.DisplayNames = names; return default; } /// - public virtual ValueTask SetDisplayNameAsync(TScope scope, string? name, CancellationToken cancellationToken) + public virtual ValueTask SetDisplayNameAsync(TScope scope!!, string? name, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.DisplayName = name; return default; } /// - public virtual ValueTask SetNameAsync(TScope scope, string? name, CancellationToken cancellationToken) + public virtual ValueTask SetNameAsync(TScope scope!!, string? name, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - scope.Name = name; return default; } /// - public virtual ValueTask SetPropertiesAsync(TScope scope, + public virtual ValueTask SetPropertiesAsync(TScope scope!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { scope.Properties = null; @@ -474,13 +350,8 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore } /// - public virtual ValueTask SetResourcesAsync(TScope scope, ImmutableArray resources, CancellationToken cancellationToken) + public virtual ValueTask SetResourcesAsync(TScope scope!!, ImmutableArray resources, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - if (resources.IsDefaultOrEmpty) { scope.Resources = ImmutableList.Create(); @@ -494,13 +365,8 @@ public class OpenIddictMongoDbScopeStore : IOpenIddictScopeStore } /// - public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TScope scope!!, CancellationToken cancellationToken) { - if (scope is null) - { - throw new ArgumentNullException(nameof(scope)); - } - // Generate a new concurrency token and attach it // to the scope before persisting the changes. var timestamp = scope.ConcurrencyToken; diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs index 60a859d2..00bf35d1 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs @@ -22,8 +22,8 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore where TToken : OpenIddictMongoDbToken { public OpenIddictMongoDbTokenStore( - IOpenIddictMongoDbContext context, - IOptionsMonitor options) + IOpenIddictMongoDbContext context!!, + IOptionsMonitor options!!) { Context = context; Options = options; @@ -50,13 +50,8 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore /// public virtual async ValueTask CountAsync( - Func, IQueryable> query, CancellationToken cancellationToken) + Func, IQueryable> query!!, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName); @@ -64,13 +59,8 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore } /// - public virtual async ValueTask CreateAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName); @@ -78,13 +68,8 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore } /// - public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask DeleteAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName); @@ -303,31 +288,21 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore } /// - public virtual ValueTask GetApplicationIdAsync(TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetApplicationIdAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (token.ApplicationId == ObjectId.Empty) { - return new ValueTask(result: null); + return new(result: null); } - return new ValueTask(token.ApplicationId.ToString()); + return new(token.ApplicationId.ToString()); } /// public virtual async ValueTask GetAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName); @@ -335,86 +310,38 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore } /// - public virtual ValueTask GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetAuthorizationIdAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (token.AuthorizationId == ObjectId.Empty) { - return new ValueTask(result: null); + return new(result: null); } - return new ValueTask(token.AuthorizationId.ToString()); + return new(token.AuthorizationId.ToString()); } /// - public virtual ValueTask GetCreationDateAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (token.CreationDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(token.CreationDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetCreationDateAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.CreationDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetExpirationDateAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (token.ExpirationDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(token.ExpirationDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetExpirationDateAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.ExpirationDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetIdAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Id.ToString()); - } + public virtual ValueTask GetIdAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Id.ToString()); /// - public virtual ValueTask GetPayloadAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Payload); - } + public virtual ValueTask GetPayloadAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Payload); /// - public virtual ValueTask> GetPropertiesAsync(TToken token, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (token.Properties is null) { - return new ValueTask>(ImmutableDictionary.Create()); + return new(ImmutableDictionary.Create()); } using var document = JsonDocument.Parse(token.Properties.ToJson()); @@ -425,80 +352,40 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore builder[property.Name] = property.Value.Clone(); } - return new ValueTask>(builder.ToImmutable()); + return new(builder.ToImmutable()); } /// - public virtual ValueTask GetRedemptionDateAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (token.RedemptionDate is null) - { - return new ValueTask(result: null); - } - - return new ValueTask(DateTime.SpecifyKind(token.RedemptionDate.Value, DateTimeKind.Utc)); - } + public virtual ValueTask GetRedemptionDateAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.RedemptionDate is DateTime date ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : null); /// - public virtual ValueTask GetReferenceIdAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.ReferenceId); - } + public virtual ValueTask GetReferenceIdAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.ReferenceId); /// - public virtual ValueTask GetStatusAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Status); - } + public virtual ValueTask GetStatusAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Status); /// - public virtual ValueTask GetSubjectAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Subject); - } + public virtual ValueTask GetSubjectAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Subject); /// - public virtual ValueTask GetTypeAsync(TToken token, CancellationToken cancellationToken) - { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - return new ValueTask(token.Type); - } + public virtual ValueTask GetTypeAsync(TToken token!!, CancellationToken cancellationToken) + => new(token.Type); /// public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) { try { - return new ValueTask(Activator.CreateInstance()); + return new(Activator.CreateInstance()); } catch (MemberAccessException exception) { - return new ValueTask(Task.FromException( + return new(Task.FromException( new InvalidOperationException(SR.GetResourceString(SR.ID0248), exception))); } } @@ -530,14 +417,9 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore /// public virtual IAsyncEnumerable ListAsync( - Func, TState, IQueryable> query, + Func, TState, IQueryable> query!!, TState state, CancellationToken cancellationToken) { - if (query is null) - { - throw new ArgumentNullException(nameof(query)); - } - return ExecuteAsync(cancellationToken); async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) @@ -604,13 +486,8 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore } /// - public virtual ValueTask SetApplicationIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) + public virtual ValueTask SetApplicationIdAsync(TToken token!!, string? identifier, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (!string.IsNullOrEmpty(identifier)) { token.ApplicationId = ObjectId.Parse(identifier); @@ -625,13 +502,8 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore } /// - public virtual ValueTask SetAuthorizationIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) + public virtual ValueTask SetAuthorizationIdAsync(TToken token!!, string? identifier, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - if (!string.IsNullOrEmpty(identifier)) { token.AuthorizationId = ObjectId.Parse(identifier); @@ -646,54 +518,34 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore } /// - public virtual ValueTask SetCreationDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken) + public virtual ValueTask SetCreationDateAsync(TToken token!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.CreationDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetExpirationDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken) + public virtual ValueTask SetExpirationDateAsync(TToken token!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.ExpirationDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetPayloadAsync(TToken token, string? payload, CancellationToken cancellationToken) + public virtual ValueTask SetPayloadAsync(TToken token!!, string? payload, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Payload = payload; return default; } /// - public virtual ValueTask SetPropertiesAsync(TToken token, + public virtual ValueTask SetPropertiesAsync(TToken token!!, ImmutableDictionary properties, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - - if (properties is null || properties.IsEmpty) + if (properties is not { IsEmpty: false }) { token.Properties = null; @@ -724,78 +576,48 @@ public class OpenIddictMongoDbTokenStore : IOpenIddictTokenStore } /// - public virtual ValueTask SetRedemptionDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken) + public virtual ValueTask SetRedemptionDateAsync(TToken token!!, DateTimeOffset? date, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.RedemptionDate = date?.UtcDateTime; return default; } /// - public virtual ValueTask SetReferenceIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) + public virtual ValueTask SetReferenceIdAsync(TToken token!!, string? identifier, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.ReferenceId = identifier; return default; } /// - public virtual ValueTask SetStatusAsync(TToken token, string? status, CancellationToken cancellationToken) + public virtual ValueTask SetStatusAsync(TToken token!!, string? status, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Status = status; return default; } /// - public virtual ValueTask SetSubjectAsync(TToken token, string? subject, CancellationToken cancellationToken) + public virtual ValueTask SetSubjectAsync(TToken token!!, string? subject, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Subject = subject; return default; } /// - public virtual ValueTask SetTypeAsync(TToken token, string? type, CancellationToken cancellationToken) + public virtual ValueTask SetTypeAsync(TToken token!!, string? type, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - token.Type = type; return default; } /// - public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken) + public virtual async ValueTask UpdateAsync(TToken token!!, CancellationToken cancellationToken) { - if (token is null) - { - throw new ArgumentNullException(nameof(token)); - } - // Generate a new concurrency token and attach it // to the token before persisting the changes. var timestamp = token.ConcurrencyToken; diff --git a/src/OpenIddict.Quartz/OpenIddictQuartzBuilder.cs b/src/OpenIddict.Quartz/OpenIddictQuartzBuilder.cs index 086db9d7..f6ea2245 100644 --- a/src/OpenIddict.Quartz/OpenIddictQuartzBuilder.cs +++ b/src/OpenIddict.Quartz/OpenIddictQuartzBuilder.cs @@ -18,8 +18,8 @@ public class OpenIddictQuartzBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictQuartzBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictQuartzBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -33,13 +33,8 @@ public class OpenIddictQuartzBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictQuartzBuilder Configure(Action configuration) + public OpenIddictQuartzBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; diff --git a/src/OpenIddict.Quartz/OpenIddictQuartzConfiguration.cs b/src/OpenIddict.Quartz/OpenIddictQuartzConfiguration.cs index f4bb8021..9a051257 100644 --- a/src/OpenIddict.Quartz/OpenIddictQuartzConfiguration.cs +++ b/src/OpenIddict.Quartz/OpenIddictQuartzConfiguration.cs @@ -14,13 +14,8 @@ namespace OpenIddict.Quartz; public class OpenIddictQuartzConfiguration : IConfigureOptions { /// - public void Configure(QuartzOptions options) + public void Configure(QuartzOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - options.AddJob(builder => { builder.StoreDurably() diff --git a/src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs b/src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs index d65f3f10..90be5848 100644 --- a/src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs +++ b/src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs @@ -21,13 +21,8 @@ public static class OpenIddictQuartzExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictQuartzBuilder UseQuartz(this OpenIddictCoreBuilder builder) + public static OpenIddictQuartzBuilder UseQuartz(this OpenIddictCoreBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddQuartz(); // The OpenIddict job is registered as a service to allow @@ -49,18 +44,8 @@ public static class OpenIddictQuartzExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictCoreBuilder UseQuartz( - this OpenIddictCoreBuilder builder, Action configuration) + this OpenIddictCoreBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseQuartz()); return builder; diff --git a/src/OpenIddict.Quartz/OpenIddictQuartzJob.cs b/src/OpenIddict.Quartz/OpenIddictQuartzJob.cs index c82f7d66..a8dc3499 100644 --- a/src/OpenIddict.Quartz/OpenIddictQuartzJob.cs +++ b/src/OpenIddict.Quartz/OpenIddictQuartzJob.cs @@ -28,7 +28,7 @@ public class OpenIddictQuartzJob : IJob /// /// The OpenIddict Quartz.NET options. /// The service provider. - public OpenIddictQuartzJob(IOptionsMonitor options, IServiceProvider provider) + public OpenIddictQuartzJob(IOptionsMonitor options!!, IServiceProvider provider!!) { _options = options; _provider = provider; @@ -42,13 +42,8 @@ public class OpenIddictQuartzJob : IJob group: typeof(OpenIddictQuartzJob).Assembly.GetName().Name!); /// - public async Task Execute(IJobExecutionContext context) + public async Task Execute(IJobExecutionContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - List? exceptions = null; // Note: this job is registered as a transient service. As such, it cannot directly depend on scoped services diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs index 68861785..b03706c7 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs @@ -21,8 +21,8 @@ public class OpenIddictServerAspNetCoreBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictServerAspNetCoreBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictServerAspNetCoreBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -36,13 +36,8 @@ public class OpenIddictServerAspNetCoreBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictServerAspNetCoreBuilder Configure(Action configuration) + public OpenIddictServerAspNetCoreBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -167,15 +162,8 @@ public class OpenIddictServerAspNetCoreBuilder /// /// The caching policy. /// The . - public OpenIddictServerAspNetCoreBuilder SetAuthorizationRequestCachingPolicy(DistributedCacheEntryOptions policy) - { - if (policy is null) - { - throw new ArgumentNullException(nameof(policy)); - } - - return Configure(options => options.AuthorizationRequestCachingPolicy = policy); - } + public OpenIddictServerAspNetCoreBuilder SetAuthorizationRequestCachingPolicy(DistributedCacheEntryOptions policy!!) + => Configure(options => options.AuthorizationRequestCachingPolicy = policy); /// /// Sets the caching policy used by the logout endpoint. @@ -183,15 +171,8 @@ public class OpenIddictServerAspNetCoreBuilder /// /// The caching policy. /// The . - public OpenIddictServerAspNetCoreBuilder SetLogoutRequestCachingPolicy(DistributedCacheEntryOptions policy) - { - if (policy is null) - { - throw new ArgumentNullException(nameof(policy)); - } - - return Configure(options => options.LogoutRequestCachingPolicy = policy); - } + public OpenIddictServerAspNetCoreBuilder SetLogoutRequestCachingPolicy(DistributedCacheEntryOptions policy!!) + => Configure(options => options.LogoutRequestCachingPolicy = policy); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreConfiguration.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreConfiguration.cs index 9545ab36..739510be 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreConfiguration.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreConfiguration.cs @@ -20,13 +20,8 @@ public class OpenIddictServerAspNetCoreConfiguration : IConfigureOptions /// The options instance to initialize. - public void Configure(AuthenticationOptions options) + public void Configure(AuthenticationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // If a handler was already registered and the type doesn't correspond to the OpenIddict handler, throw an exception. if (options.SchemeMap.TryGetValue(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, out var builder) && builder.HandlerType != typeof(OpenIddictServerAspNetCoreHandler)) @@ -38,13 +33,8 @@ public class OpenIddictServerAspNetCoreConfiguration : IConfigureOptions /// The name of the options instance to configure, if applicable. /// The options instance to initialize. - public void PostConfigure(string name, AuthenticationOptions options) + public void PostConfigure(string name, AuthenticationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - if (!TryValidate(options.SchemeMap, options.DefaultAuthenticateScheme) || !TryValidate(options.SchemeMap, options.DefaultChallengeScheme) || !TryValidate(options.SchemeMap, options.DefaultForbidScheme) || @@ -89,13 +74,8 @@ public class OpenIddictServerAspNetCoreConfiguration : IConfigureOptions /// The name of the options instance to configure, if applicable. /// The options instance to initialize. - public void PostConfigure(string name, OpenIddictServerAspNetCoreOptions options) + public void PostConfigure(string name, OpenIddictServerAspNetCoreOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - if (options.EnableErrorPassthrough && options.EnableStatusCodePagesIntegration) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0110)); diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreExtensions.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreExtensions.cs index 7a871d84..373fad2f 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreExtensions.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictServerAspNetCoreExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictServerAspNetCoreBuilder UseAspNetCore(this OpenIddictServerBuilder builder) + public static OpenIddictServerAspNetCoreBuilder UseAspNetCore(this OpenIddictServerBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddAuthentication(); builder.Services.TryAddScoped(); @@ -73,18 +68,8 @@ public static class OpenIddictServerAspNetCoreExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictServerBuilder UseAspNetCore( - this OpenIddictServerBuilder builder, Action configuration) + this OpenIddictServerBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseAspNetCore()); return builder; diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs index fcb59933..e9eece65 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs @@ -28,12 +28,12 @@ public class OpenIddictServerAspNetCoreHandler : AuthenticationHandler class. /// public OpenIddictServerAspNetCoreHandler( - IOpenIddictServerDispatcher dispatcher, - IOpenIddictServerFactory factory, - IOptionsMonitor options, - ILoggerFactory logger, - UrlEncoder encoder, - ISystemClock clock) + IOpenIddictServerDispatcher dispatcher!!, + IOpenIddictServerFactory factory!!, + IOptionsMonitor options!!, + ILoggerFactory logger!!, + UrlEncoder encoder!!, + ISystemClock clock!!) : base(options, logger, encoder, clock) { _dispatcher = dispatcher; @@ -338,13 +338,8 @@ public class OpenIddictServerAspNetCoreHandler : AuthenticationHandler HandleChallengeAsync(properties); /// - public async Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties? properties) + public async Task SignInAsync(ClaimsPrincipal user!!, AuthenticationProperties? properties) { - if (user is null) - { - throw new ArgumentNullException(nameof(user)); - } - var transaction = Context.Features.Get()?.Transaction ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0112)); diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlerFilters.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlerFilters.cs index 78bbfa6d..49dc2364 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlerFilters.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlerFilters.cs @@ -23,18 +23,11 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireAuthorizationRequestCachingEnabled(IOptionsMonitor options) + public RequireAuthorizationRequestCachingEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableAuthorizationRequestCaching); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableAuthorizationRequestCaching); } /// @@ -45,18 +38,11 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireAuthorizationEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireAuthorizationEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableAuthorizationEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableAuthorizationEndpointPassthrough); } /// @@ -66,18 +52,11 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireErrorPassthroughEnabled(IOptionsMonitor options) + public RequireErrorPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableErrorPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableErrorPassthrough); } /// @@ -85,15 +64,8 @@ public static class OpenIddictServerAspNetCoreHandlerFilters /// public class RequireHttpRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Transaction.GetHttpRequest() is not null); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Transaction.GetHttpRequest() is not null); } /// @@ -103,18 +75,11 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireLogoutRequestCachingEnabled(IOptionsMonitor options) + public RequireLogoutRequestCachingEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableLogoutRequestCaching); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableLogoutRequestCaching); } /// @@ -125,18 +90,11 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireLogoutEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireLogoutEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableLogoutEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableLogoutEndpointPassthrough); } /// @@ -146,18 +104,11 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireStatusCodePagesIntegrationEnabled(IOptionsMonitor options) + public RequireStatusCodePagesIntegrationEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableStatusCodePagesIntegration); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableStatusCodePagesIntegration); } /// @@ -167,18 +118,11 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireTransportSecurityRequirementEnabled(IOptionsMonitor options) + public RequireTransportSecurityRequirementEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!_options.CurrentValue.DisableTransportSecurityRequirement); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!_options.CurrentValue.DisableTransportSecurityRequirement); } /// @@ -189,18 +133,11 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireTokenEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireTokenEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableTokenEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableTokenEndpointPassthrough); } /// @@ -211,18 +148,11 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireUserinfoEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireUserinfoEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableUserinfoEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableUserinfoEndpointPassthrough); } /// @@ -233,17 +163,10 @@ public static class OpenIddictServerAspNetCoreHandlerFilters { private readonly IOptionsMonitor _options; - public RequireVerificationEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireVerificationEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableVerificationEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableVerificationEndpointPassthrough); } } diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Authentication.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Authentication.cs index b5da8da8..a50125ea 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Authentication.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Authentication.cs @@ -63,7 +63,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers public RestoreCachedRequestParameters() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0116)); - public RestoreCachedRequestParameters(IDistributedCache cache) + public RestoreCachedRequestParameters(IDistributedCache cache!!) => _cache = cache; /// @@ -79,13 +79,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(ExtractAuthorizationRequestContext context) + public async ValueTask HandleAsync(ExtractAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // If a request_id parameter can be found in the authorization request, @@ -131,7 +126,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers using var document = JsonDocument.Parse( Base64UrlEncoder.Decode(((JsonWebToken) result.SecurityToken).InnerToken.EncodedPayload)); - if (document.RootElement.ValueKind != JsonValueKind.Object) + if (document.RootElement.ValueKind is not JsonValueKind.Object) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0117)); } @@ -163,7 +158,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers public CacheRequestParameters( IDistributedCache cache, - IOptionsMonitor options) + IOptionsMonitor options!!) { _cache = cache; _options = options; @@ -182,22 +177,14 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(ExtractAuthorizationRequestContext context) + public async ValueTask HandleAsync(ExtractAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Don't cache the request if the request doesn't include any parameter. // If a request_id parameter can be found in the authorization request, @@ -261,7 +248,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers public RemoveCachedRequest() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0116)); - public RemoveCachedRequest(IDistributedCache cache) + public RemoveCachedRequest(IDistributedCache cache!!) => _cache = cache; /// @@ -277,13 +264,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (string.IsNullOrEmpty(context.Request?.RequestId)) { return default; @@ -295,7 +277,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers // Note: the cache key is always prefixed with a specific marker // to avoid collisions with the other types of cached payloads. - return new ValueTask(_cache.RemoveAsync(Cache.AuthorizationRequest + context.Request.RequestId)); + return new(_cache.RemoveAsync(Cache.AuthorizationRequest + context.Request.RequestId)); } } @@ -322,20 +304,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public async ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.FormPost, StringComparison.Ordinal)) @@ -412,20 +386,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.Query, StringComparison.Ordinal)) @@ -486,20 +452,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.Fragment, StringComparison.Ordinal)) diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs index 4f06a7aa..7fcf5a41 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Device.cs @@ -69,20 +69,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ApplyVerificationResponseContext context) + public ValueTask HandleAsync(ApplyVerificationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Note: this handler only redirects the user agent to the address specified in // the properties when there's no error or if the error is an access_denied error. diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs index 5e0c1f76..bb997d11 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.Session.cs @@ -61,7 +61,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers public RestoreCachedRequestParameters() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0116)); - public RestoreCachedRequestParameters(IDistributedCache cache) + public RestoreCachedRequestParameters(IDistributedCache cache!!) => _cache = cache; /// @@ -77,13 +77,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(ExtractLogoutRequestContext context) + public async ValueTask HandleAsync(ExtractLogoutRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // If a request_id parameter can be found in the logout request, @@ -129,7 +124,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers using var document = JsonDocument.Parse( Base64UrlEncoder.Decode(((JsonWebToken) result.SecurityToken).InnerToken.EncodedPayload)); - if (document.RootElement.ValueKind != JsonValueKind.Object) + if (document.RootElement.ValueKind is not JsonValueKind.Object) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0118)); } @@ -161,7 +156,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers public CacheRequestParameters( IDistributedCache cache, - IOptionsMonitor options) + IOptionsMonitor options!!) { _cache = cache; _options = options; @@ -180,22 +175,14 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(ExtractLogoutRequestContext context) + public async ValueTask HandleAsync(ExtractLogoutRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Don't cache the request if the request doesn't include any parameter. // If a request_id parameter can be found in the logout request, @@ -259,7 +246,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers public RemoveCachedRequest() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0116)); - public RemoveCachedRequest(IDistributedCache cache) + public RemoveCachedRequest(IDistributedCache cache!!) => _cache = cache; /// @@ -275,13 +262,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ApplyLogoutResponseContext context) + public ValueTask HandleAsync(ApplyLogoutResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (string.IsNullOrEmpty(context.Request?.RequestId)) { return default; @@ -293,7 +275,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers // Note: the cache key is always prefixed with a specific marker // to avoid collisions with the other types of cached payloads. - return new ValueTask(_cache.RemoveAsync(Cache.LogoutRequest + context.Request.RequestId)); + return new(_cache.RemoveAsync(Cache.LogoutRequest + context.Request.RequestId)); } } @@ -315,20 +297,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ApplyLogoutResponseContext context) + public ValueTask HandleAsync(ApplyLogoutResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { @@ -388,20 +362,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ApplyLogoutResponseContext context) + public ValueTask HandleAsync(ApplyLogoutResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Note: this handler only executes if no post_logout_redirect_uri was specified // and if the response doesn't correspond to an error, that must be handled locally. diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs index b054fd3e..158cde9d 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs @@ -71,20 +71,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessRequestContext context) + public ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } context.EndpointType = Matches(request, context.Options.AuthorizationEndpointUris) ? OpenIddictServerEndpointType.Authorization : @@ -177,24 +169,16 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessRequestContext context) + public ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Don't require that the request host be present if the request is not handled // by an OpenIddict endpoint or if an explicit issuer URL was already set. - if (context.Issuer is not null || context.EndpointType == OpenIddictServerEndpointType.Unknown) + if (context.Issuer is not null || context.EndpointType is OpenIddictServerEndpointType.Unknown) { return default; } @@ -245,23 +229,15 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessRequestContext context) + public ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Don't require that the host be present if the request is not handled by OpenIddict. - if (context.EndpointType == OpenIddictServerEndpointType.Unknown) + if (context.EndpointType is OpenIddictServerEndpointType.Unknown) { return default; } @@ -300,13 +276,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var properties = context.Transaction.GetProperty(typeof(AuthenticationProperties).FullName!); if (properties is null) { @@ -376,13 +347,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var properties = context.Transaction.GetProperty(typeof(AuthenticationProperties).FullName!); if (properties is null) { @@ -428,13 +394,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignOutContext context) + public ValueTask HandleAsync(ProcessSignOutContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var properties = context.Transaction.GetProperty(typeof(AuthenticationProperties).FullName!); if (properties is null) { @@ -479,20 +440,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (HttpMethods.IsGet(request.Method)) { @@ -533,20 +486,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (HttpMethods.IsGet(request.Method)) { @@ -616,20 +561,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (HttpMethods.IsPost(request.Method)) { @@ -695,22 +632,14 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } string header = request.Headers[HeaderNames.Authorization]; if (string.IsNullOrEmpty(header) || !header.StartsWith("Basic ", StringComparison.OrdinalIgnoreCase)) @@ -797,20 +726,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); @@ -848,13 +769,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.SkipRequest(); return default; @@ -879,20 +795,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); @@ -936,20 +844,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Prevent the response from being cached. response.Headers[HeaderNames.CacheControl] = "no-store"; @@ -968,7 +868,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers { private readonly IOptionsMonitor _options; - public AttachWwwAuthenticateHeader(IOptionsMonitor options) + public AttachWwwAuthenticateHeader(IOptionsMonitor options!!) => _options = options; /// @@ -983,20 +883,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); @@ -1097,20 +989,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // If the response doesn't contain a WWW-Authenticate header, don't return an empty response. if (!response.Headers.ContainsKey(HeaderNames.WWWAuthenticate)) @@ -1143,22 +1027,14 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } context.Logger.LogInformation(SR.GetResourceString(SR.ID6142), context.Transaction.Response); @@ -1205,20 +1081,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); @@ -1253,20 +1121,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); @@ -1312,20 +1172,12 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); @@ -1389,13 +1241,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Logger.LogInformation(SR.GetResourceString(SR.ID6145)); context.HandleRequest(); diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHelpers.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHelpers.cs index 326977b2..c9be806d 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHelpers.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHelpers.cs @@ -19,13 +19,8 @@ public static class OpenIddictServerAspNetCoreHelpers /// /// The transaction instance. /// The instance or null if it couldn't be found. - public static HttpRequest? GetHttpRequest(this OpenIddictServerTransaction transaction) + public static HttpRequest? GetHttpRequest(this OpenIddictServerTransaction transaction!!) { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (!transaction.Properties.TryGetValue(typeof(HttpRequest).FullName!, out object? property)) { return null; @@ -44,13 +39,8 @@ public static class OpenIddictServerAspNetCoreHelpers /// /// The context instance. /// The . - public static OpenIddictServerEndpointType GetOpenIddictServerEndpointType(this HttpContext context) + public static OpenIddictServerEndpointType GetOpenIddictServerEndpointType(this HttpContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - return context.Features.Get()?.Transaction?.EndpointType ?? default; } @@ -59,13 +49,8 @@ public static class OpenIddictServerAspNetCoreHelpers /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictRequest? GetOpenIddictServerRequest(this HttpContext context) + public static OpenIddictRequest? GetOpenIddictServerRequest(this HttpContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - return context.Features.Get()?.Transaction?.Request; } @@ -74,13 +59,8 @@ public static class OpenIddictServerAspNetCoreHelpers /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictResponse? GetOpenIddictServerResponse(this HttpContext context) + public static OpenIddictResponse? GetOpenIddictServerResponse(this HttpContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - return context.Features.Get()?.Transaction?.Response; } } diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionBuilder.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionBuilder.cs index 8a084c5b..a394574c 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionBuilder.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionBuilder.cs @@ -20,8 +20,8 @@ public class OpenIddictServerDataProtectionBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictServerDataProtectionBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictServerDataProtectionBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -35,13 +35,8 @@ public class OpenIddictServerDataProtectionBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictServerDataProtectionBuilder Configure(Action configuration) + public OpenIddictServerDataProtectionBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -53,30 +48,16 @@ public class OpenIddictServerDataProtectionBuilder /// /// The data protection provider used to create token protectors. /// The . - public OpenIddictServerDataProtectionBuilder UseDataProtectionProvider(IDataProtectionProvider provider) - { - if (provider is null) - { - throw new ArgumentNullException(nameof(provider)); - } - - return Configure(options => options.DataProtectionProvider = provider); - } + public OpenIddictServerDataProtectionBuilder UseDataProtectionProvider(IDataProtectionProvider provider!!) + => Configure(options => options.DataProtectionProvider = provider); /// /// Configures OpenIddict to use a specific formatter instead of relying on the default instance. /// /// The formatter used to read and write tokens. /// The . - public OpenIddictServerDataProtectionBuilder UseFormatter(IOpenIddictServerDataProtectionFormatter formatter) - { - if (formatter is null) - { - throw new ArgumentNullException(nameof(formatter)); - } - - return Configure(options => options.Formatter = formatter); - } + public OpenIddictServerDataProtectionBuilder UseFormatter(IOpenIddictServerDataProtectionFormatter formatter!!) + => Configure(options => options.Formatter = formatter); /// /// Configures OpenIddict to use the default token format (JWT) when issuing new access tokens. diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionConfiguration.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionConfiguration.cs index 27f05bd0..82247cb5 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionConfiguration.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionConfiguration.cs @@ -21,16 +21,11 @@ public class OpenIddictServerDataProtectionConfiguration : IConfigureOptions class. /// /// The ASP.NET Core Data Protection provider. - public OpenIddictServerDataProtectionConfiguration(IDataProtectionProvider dataProtectionProvider) + public OpenIddictServerDataProtectionConfiguration(IDataProtectionProvider dataProtectionProvider!!) => _dataProtectionProvider = dataProtectionProvider; - public void Configure(OpenIddictServerOptions options) + public void Configure(OpenIddictServerOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // Register the built-in event handlers used by the OpenIddict Data Protection server components. options.Handlers.AddRange(OpenIddictServerDataProtectionHandlers.DefaultHandlers); } @@ -41,13 +36,8 @@ public class OpenIddictServerDataProtectionConfiguration : IConfigureOptions /// The name of the options instance to configure, if applicable. /// The options instance to initialize. - public void PostConfigure(string name, OpenIddictServerDataProtectionOptions options) + public void PostConfigure(string name, OpenIddictServerDataProtectionOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - options.DataProtectionProvider ??= _dataProtectionProvider; } } diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionExtensions.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionExtensions.cs index df131355..35289e5f 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionExtensions.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionExtensions.cs @@ -23,13 +23,8 @@ public static class OpenIddictServerDataProtectionExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictServerDataProtectionBuilder UseDataProtection(this OpenIddictServerBuilder builder) + public static OpenIddictServerDataProtectionBuilder UseDataProtection(this OpenIddictServerBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddDataProtection(); // Register the built-in server event handlers used by the OpenIddict Data Protection components. @@ -55,18 +50,8 @@ public static class OpenIddictServerDataProtectionExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictServerBuilder UseDataProtection( - this OpenIddictServerBuilder builder, Action configuration) + this OpenIddictServerBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseDataProtection()); return builder; diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs index 2768c1e5..6e035820 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs @@ -15,13 +15,8 @@ namespace OpenIddict.Server.DataProtection; public class OpenIddictServerDataProtectionFormatter : IOpenIddictServerDataProtectionFormatter { - public ClaimsPrincipal ReadToken(BinaryReader reader) + public ClaimsPrincipal ReadToken(BinaryReader reader!!) { - if (reader is null) - { - throw new ArgumentNullException(nameof(reader)); - } - var (principal, properties) = Read(reader); // Tokens serialized using the ASP.NET Core Data Protection stack are compound @@ -191,18 +186,8 @@ public class OpenIddictServerDataProtectionFormatter : IOpenIddictServerDataProt } } - public void WriteToken(BinaryWriter writer, ClaimsPrincipal principal) + public void WriteToken(BinaryWriter writer!!, ClaimsPrincipal principal!!) { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - - if (principal is null) - { - throw new ArgumentNullException(nameof(principal)); - } - var properties = new Dictionary(); // Unlike ASP.NET Core Data Protection-based tokens, tokens serialized using the new format @@ -318,18 +303,8 @@ public class OpenIddictServerDataProtectionFormatter : IOpenIddictServerDataProt } } - static void WriteClaim(BinaryWriter writer, Claim claim) + static void WriteClaim(BinaryWriter writer!!, Claim claim!!) { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - - if (claim is null) - { - throw new ArgumentNullException(nameof(claim)); - } - WriteWithDefault(writer, claim.Type, claim.Subject?.NameClaimType ?? ClaimsIdentity.DefaultNameClaimType); writer.Write(claim.Value); WriteWithDefault(writer, claim.ValueType, ClaimValueTypes.String); diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Protection.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Protection.cs index 7ec54603..4ca1a965 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Protection.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.Protection.cs @@ -38,7 +38,7 @@ public static partial class OpenIddictServerDataProtectionHandlers { private readonly IOptionsMonitor _options; - public ValidateDataProtectionToken(IOptionsMonitor options) + public ValidateDataProtectionToken(IOptionsMonitor options!!) => _options = options; /// @@ -238,7 +238,7 @@ public static partial class OpenIddictServerDataProtectionHandlers { private readonly IOptionsMonitor _options; - public GenerateDataProtectionToken(IOptionsMonitor options) + public GenerateDataProtectionToken(IOptionsMonitor options!!) => _options = options; /// @@ -252,13 +252,8 @@ public static partial class OpenIddictServerDataProtectionHandlers .Build(); /// - public ValueTask HandleAsync(GenerateTokenContext context) + public ValueTask HandleAsync(GenerateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If an access token was already attached by another handler, don't overwrite it. if (!string.IsNullOrEmpty(context.Token)) { diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs index 77ca4e02..3612d1f7 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs @@ -21,8 +21,8 @@ public class OpenIddictServerOwinBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictServerOwinBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictServerOwinBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -36,13 +36,8 @@ public class OpenIddictServerOwinBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictServerOwinBuilder Configure(Action configuration) + public OpenIddictServerOwinBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -156,15 +151,8 @@ public class OpenIddictServerOwinBuilder /// /// The caching policy. /// The . - public OpenIddictServerOwinBuilder SetAuthorizationRequestCachingPolicy(DistributedCacheEntryOptions policy) - { - if (policy is null) - { - throw new ArgumentNullException(nameof(policy)); - } - - return Configure(options => options.AuthorizationRequestCachingPolicy = policy); - } + public OpenIddictServerOwinBuilder SetAuthorizationRequestCachingPolicy(DistributedCacheEntryOptions policy!!) + => Configure(options => options.AuthorizationRequestCachingPolicy = policy); /// /// Sets the caching policy used by the logout endpoint. @@ -172,15 +160,8 @@ public class OpenIddictServerOwinBuilder /// /// The caching policy. /// The . - public OpenIddictServerOwinBuilder SetLogoutRequestCachingPolicy(DistributedCacheEntryOptions policy) - { - if (policy is null) - { - throw new ArgumentNullException(nameof(policy)); - } - - return Configure(options => options.LogoutRequestCachingPolicy = policy); - } + public OpenIddictServerOwinBuilder SetLogoutRequestCachingPolicy(DistributedCacheEntryOptions policy!!) + => Configure(options => options.LogoutRequestCachingPolicy = policy); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinConfiguration.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinConfiguration.cs index cee6694f..7c80efba 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinConfiguration.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinConfiguration.cs @@ -14,25 +14,15 @@ namespace OpenIddict.Server.Owin; public class OpenIddictServerOwinConfiguration : IConfigureOptions, IPostConfigureOptions { - public void Configure(OpenIddictServerOptions options) + public void Configure(OpenIddictServerOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // Register the built-in event handlers used by the OpenIddict OWIN server components. options.Handlers.AddRange(OpenIddictServerOwinHandlers.DefaultHandlers); } - public void PostConfigure(string name, OpenIddictServerOwinOptions options) + public void PostConfigure(string name, OpenIddictServerOwinOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - - if (options.AuthenticationMode == AuthenticationMode.Active) + if (options.AuthenticationMode is AuthenticationMode.Active) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0119)); } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinExtensions.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinExtensions.cs index 608e3ad9..92f38d17 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinExtensions.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictServerOwinExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictServerOwinBuilder UseOwin(this OpenIddictServerBuilder builder) + public static OpenIddictServerOwinBuilder UseOwin(this OpenIddictServerBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddWebEncoders(); // Note: unlike regular OWIN middleware, the OpenIddict server middleware is registered @@ -71,18 +66,8 @@ public static class OpenIddictServerOwinExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictServerBuilder UseOwin( - this OpenIddictServerBuilder builder, Action configuration) + this OpenIddictServerBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseOwin()); return builder; diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs index f7952ac2..1e00b1a7 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs @@ -24,8 +24,8 @@ public class OpenIddictServerOwinHandler : AuthenticationHandlerThe OpenIddict server dispatcher used by this instance. /// The OpenIddict server factory used by this instance. public OpenIddictServerOwinHandler( - IOpenIddictServerDispatcher dispatcher, - IOpenIddictServerFactory factory) + IOpenIddictServerDispatcher dispatcher!!, + IOpenIddictServerFactory factory!!) { _dispatcher = dispatcher; _factory = factory; diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlerFilters.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlerFilters.cs index 1ae875a7..5a4536d0 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlerFilters.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlerFilters.cs @@ -21,18 +21,11 @@ public static class OpenIddictServerOwinHandlerFilters { private readonly IOptionsMonitor _options; - public RequireAuthorizationRequestCachingEnabled(IOptionsMonitor options) + public RequireAuthorizationRequestCachingEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableAuthorizationRequestCaching); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableAuthorizationRequestCaching); } /// @@ -43,18 +36,11 @@ public static class OpenIddictServerOwinHandlerFilters { private readonly IOptionsMonitor _options; - public RequireAuthorizationEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireAuthorizationEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableAuthorizationEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableAuthorizationEndpointPassthrough); } /// @@ -64,18 +50,11 @@ public static class OpenIddictServerOwinHandlerFilters { private readonly IOptionsMonitor _options; - public RequireErrorPassthroughEnabled(IOptionsMonitor options) + public RequireErrorPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableErrorPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableErrorPassthrough); } /// @@ -85,18 +64,11 @@ public static class OpenIddictServerOwinHandlerFilters { private readonly IOptionsMonitor _options; - public RequireLogoutRequestCachingEnabled(IOptionsMonitor options) + public RequireLogoutRequestCachingEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableLogoutRequestCaching); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableLogoutRequestCaching); } /// @@ -107,18 +79,11 @@ public static class OpenIddictServerOwinHandlerFilters { private readonly IOptionsMonitor _options; - public RequireLogoutEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireLogoutEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableLogoutEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableLogoutEndpointPassthrough); } /// @@ -126,15 +91,8 @@ public static class OpenIddictServerOwinHandlerFilters /// public class RequireOwinRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Transaction.GetOwinRequest() is not null); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Transaction.GetOwinRequest() is not null); } /// @@ -144,18 +102,11 @@ public static class OpenIddictServerOwinHandlerFilters { private readonly IOptionsMonitor _options; - public RequireTransportSecurityRequirementEnabled(IOptionsMonitor options) + public RequireTransportSecurityRequirementEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!_options.CurrentValue.DisableTransportSecurityRequirement); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!_options.CurrentValue.DisableTransportSecurityRequirement); } /// @@ -166,18 +117,11 @@ public static class OpenIddictServerOwinHandlerFilters { private readonly IOptionsMonitor _options; - public RequireTokenEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireTokenEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableTokenEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableTokenEndpointPassthrough); } /// @@ -188,18 +132,11 @@ public static class OpenIddictServerOwinHandlerFilters { private readonly IOptionsMonitor _options; - public RequireUserinfoEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireUserinfoEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableUserinfoEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableUserinfoEndpointPassthrough); } /// @@ -210,17 +147,10 @@ public static class OpenIddictServerOwinHandlerFilters { private readonly IOptionsMonitor _options; - public RequireVerificationEndpointPassthroughEnabled(IOptionsMonitor options) + public RequireVerificationEndpointPassthroughEnabled(IOptionsMonitor options!!) => _options = options; - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(_options.CurrentValue.EnableVerificationEndpointPassthrough); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(_options.CurrentValue.EnableVerificationEndpointPassthrough); } } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Authentication.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Authentication.cs index 31c37b24..53433098 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Authentication.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Authentication.cs @@ -61,7 +61,7 @@ public static partial class OpenIddictServerOwinHandlers public RestoreCachedRequestParameters() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0116)); - public RestoreCachedRequestParameters(IDistributedCache cache) + public RestoreCachedRequestParameters(IDistributedCache cache!!) => _cache = cache; /// @@ -77,13 +77,8 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public async ValueTask HandleAsync(ExtractAuthorizationRequestContext context) + public async ValueTask HandleAsync(ExtractAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // If a request_id parameter can be found in the authorization request, @@ -129,7 +124,7 @@ public static partial class OpenIddictServerOwinHandlers using var document = JsonDocument.Parse( Base64UrlEncoder.Decode(((JsonWebToken) result.SecurityToken).InnerToken.EncodedPayload)); - if (document.RootElement.ValueKind != JsonValueKind.Object) + if (document.RootElement.ValueKind is not JsonValueKind.Object) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0117)); } @@ -161,7 +156,7 @@ public static partial class OpenIddictServerOwinHandlers public CacheRequestParameters( IDistributedCache cache, - IOptionsMonitor options) + IOptionsMonitor options!!) { _cache = cache; _options = options; @@ -180,22 +175,14 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public async ValueTask HandleAsync(ExtractAuthorizationRequestContext context) + public async ValueTask HandleAsync(ExtractAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Don't cache the request if the request doesn't include any parameter. // If a request_id parameter can be found in the authorization request, @@ -254,7 +241,7 @@ public static partial class OpenIddictServerOwinHandlers public RemoveCachedRequest() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0116)); - public RemoveCachedRequest(IDistributedCache cache) + public RemoveCachedRequest(IDistributedCache cache!!) => _cache = cache; /// @@ -270,13 +257,8 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (string.IsNullOrEmpty(context.Request?.RequestId)) { return default; @@ -288,7 +270,7 @@ public static partial class OpenIddictServerOwinHandlers // Note: the cache key is always prefixed with a specific marker // to avoid collisions with the other types of cached payloads. - return new ValueTask(_cache.RemoveAsync(Cache.AuthorizationRequest + context.Request.RequestId)); + return new(_cache.RemoveAsync(Cache.AuthorizationRequest + context.Request.RequestId)); } } @@ -315,20 +297,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public async ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public async ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.FormPost, StringComparison.Ordinal)) @@ -406,20 +380,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.Query, StringComparison.Ordinal)) @@ -470,20 +436,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.IsNullOrEmpty(context.RedirectUri) || !string.Equals(context.ResponseMode, ResponseModes.Fragment, StringComparison.Ordinal)) diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs index 2da8b9f5..ba6b7960 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Device.cs @@ -68,20 +68,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ApplyVerificationResponseContext context) + public ValueTask HandleAsync(ApplyVerificationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Note: this handler only redirects the user agent to the address specified in // the properties when there's no error or if the error is an access_denied error. diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs index ee2d02b1..7c4cc8c6 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.Session.cs @@ -59,7 +59,7 @@ public static partial class OpenIddictServerOwinHandlers public RestoreCachedRequestParameters() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0116)); - public RestoreCachedRequestParameters(IDistributedCache cache) + public RestoreCachedRequestParameters(IDistributedCache cache!!) => _cache = cache; /// @@ -75,13 +75,8 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public async ValueTask HandleAsync(ExtractLogoutRequestContext context) + public async ValueTask HandleAsync(ExtractLogoutRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // If a request_id parameter can be found in the logout request, @@ -127,7 +122,7 @@ public static partial class OpenIddictServerOwinHandlers using var document = JsonDocument.Parse( Base64UrlEncoder.Decode(((JsonWebToken) result.SecurityToken).InnerToken.EncodedPayload)); - if (document.RootElement.ValueKind != JsonValueKind.Object) + if (document.RootElement.ValueKind is not JsonValueKind.Object) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0118)); } @@ -159,7 +154,7 @@ public static partial class OpenIddictServerOwinHandlers public CacheRequestParameters( IDistributedCache cache, - IOptionsMonitor options) + IOptionsMonitor options!!) { _cache = cache; _options = options; @@ -178,22 +173,14 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public async ValueTask HandleAsync(ExtractLogoutRequestContext context) + public async ValueTask HandleAsync(ExtractLogoutRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Don't cache the request if the request doesn't include any parameter. // If a request_id parameter can be found in the logout request, @@ -252,7 +239,7 @@ public static partial class OpenIddictServerOwinHandlers public RemoveCachedRequest() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0116)); - public RemoveCachedRequest(IDistributedCache cache) + public RemoveCachedRequest(IDistributedCache cache!!) => _cache = cache; /// @@ -268,13 +255,8 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ApplyLogoutResponseContext context) + public ValueTask HandleAsync(ApplyLogoutResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (string.IsNullOrEmpty(context.Request?.RequestId)) { return default; @@ -286,7 +268,7 @@ public static partial class OpenIddictServerOwinHandlers // Note: the cache key is always prefixed with a specific marker // to avoid collisions with the other types of cached payloads. - return new ValueTask(_cache.RemoveAsync(Cache.LogoutRequest + context.Request.RequestId)); + return new(_cache.RemoveAsync(Cache.LogoutRequest + context.Request.RequestId)); } } @@ -308,20 +290,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ApplyLogoutResponseContext context) + public ValueTask HandleAsync(ApplyLogoutResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { @@ -371,20 +345,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ApplyLogoutResponseContext context) + public ValueTask HandleAsync(ApplyLogoutResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Note: this handler only executes if no post_logout_redirect_uri was specified // and if the response doesn't correspond to an error, that must be handled locally. diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs index 5ab20b15..1310ed9c 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs @@ -62,20 +62,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ProcessRequestContext context) + public ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } context.EndpointType = Matches(request, context.Options.AuthorizationEndpointUris) ? OpenIddictServerEndpointType.Authorization : @@ -168,24 +160,16 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ProcessRequestContext context) + public ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Don't require that the request host be present if the request is not handled // by an OpenIddict endpoint or if an explicit issuer URL was already set. - if (context.Issuer is not null || context.EndpointType == OpenIddictServerEndpointType.Unknown) + if (context.Issuer is not null || context.EndpointType is OpenIddictServerEndpointType.Unknown) { return default; } @@ -236,23 +220,15 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ProcessRequestContext context) + public ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Don't require that the host be present if the request is not handled by OpenIddict. - if (context.EndpointType == OpenIddictServerEndpointType.Unknown) + if (context.EndpointType is OpenIddictServerEndpointType.Unknown) { return default; } @@ -291,13 +267,8 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var properties = context.Transaction.GetProperty(typeof(AuthenticationProperties).FullName!); if (properties is null) { @@ -350,20 +321,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.Equals(request.Method, "GET", StringComparison.OrdinalIgnoreCase)) { @@ -404,20 +367,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.Equals(request.Method, "GET", StringComparison.OrdinalIgnoreCase)) { @@ -487,20 +442,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.Equals(request.Method, "POST", StringComparison.OrdinalIgnoreCase)) { @@ -566,22 +513,14 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } var header = request.Headers[Headers.Authorization]; if (string.IsNullOrEmpty(header) || !header.StartsWith("Basic ", StringComparison.OrdinalIgnoreCase)) @@ -668,22 +607,14 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } var header = request.Headers[Headers.Authorization]; if (string.IsNullOrEmpty(header) || !header.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase)) @@ -719,13 +650,8 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.SkipRequest(); return default; @@ -750,22 +676,14 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // When client authentication is made using basic authentication, the authorization server MUST return // a 401 response with a valid WWW-Authenticate header containing the Basic scheme and a non-empty realm. @@ -807,20 +725,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Prevent the response from being cached. response.Headers[Headers.CacheControl] = "no-store"; @@ -839,7 +749,7 @@ public static partial class OpenIddictServerOwinHandlers { private readonly IOptionsMonitor _options; - public AttachWwwAuthenticateHeader(IOptionsMonitor options) + public AttachWwwAuthenticateHeader(IOptionsMonitor options!!) => _options = options; /// @@ -854,22 +764,14 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // When client authentication is made using basic authentication, the authorization server MUST return // a 401 response with a valid WWW-Authenticate header containing the HTTP Basic authentication scheme. @@ -968,20 +870,12 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // If the response doesn't contain a WWW-Authenticate header, don't return an empty response. if (!response.Headers.ContainsKey(Headers.WwwAuthenticate)) @@ -1014,22 +908,14 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } context.Logger.LogInformation(SR.GetResourceString(SR.ID6142), context.Transaction.Response); @@ -1076,22 +962,14 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.IsNullOrEmpty(context.Transaction.Response.Error)) { @@ -1126,22 +1004,14 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.IsNullOrEmpty(context.Transaction.Response.Error)) { @@ -1203,13 +1073,8 @@ public static partial class OpenIddictServerOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Logger.LogInformation(SR.GetResourceString(SR.ID6145)); context.HandleRequest(); diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHelpers.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHelpers.cs index 9df7d914..8d95cf54 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHelpers.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHelpers.cs @@ -21,28 +21,16 @@ public static class OpenIddictServerOwinHelpers /// /// The application builder used to register middleware instances. /// The . - public static IAppBuilder UseOpenIddictServer(this IAppBuilder app) - { - if (app is null) - { - throw new ArgumentNullException(nameof(app)); - } - - return app.Use(); - } + public static IAppBuilder UseOpenIddictServer(this IAppBuilder app!!) + => app.Use(); /// /// Retrieves the instance stored in the properties. /// /// The transaction instance. /// The instance or null if it couldn't be found. - public static IOwinRequest? GetOwinRequest(this OpenIddictServerTransaction transaction) + public static IOwinRequest? GetOwinRequest(this OpenIddictServerTransaction transaction!!) { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (!transaction.Properties.TryGetValue(typeof(IOwinRequest).FullName!, out object? property)) { return null; @@ -61,43 +49,22 @@ public static class OpenIddictServerOwinHelpers /// /// The context instance. /// The . - public static OpenIddictServerEndpointType GetOpenIddictServerEndpointType(this IOwinContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return context.Get(typeof(OpenIddictServerTransaction).FullName)?.EndpointType ?? default; - } + public static OpenIddictServerEndpointType GetOpenIddictServerEndpointType(this IOwinContext context!!) + => context.Get(typeof(OpenIddictServerTransaction).FullName)?.EndpointType ?? default; /// /// Retrieves the instance stored in . /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictRequest? GetOpenIddictServerRequest(this IOwinContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return context.Get(typeof(OpenIddictServerTransaction).FullName)?.Request; - } + public static OpenIddictRequest? GetOpenIddictServerRequest(this IOwinContext context!!) + => context.Get(typeof(OpenIddictServerTransaction).FullName)?.Request; /// /// Retrieves the instance stored in . /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictResponse? GetOpenIddictServerResponse(this IOwinContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return context.Get(typeof(OpenIddictServerTransaction).FullName)?.Response; - } + public static OpenIddictResponse? GetOpenIddictServerResponse(this IOwinContext context!!) + => context.Get(typeof(OpenIddictServerTransaction).FullName)?.Response; } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs index 2274663f..f6a3acc7 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs @@ -29,9 +29,9 @@ public class OpenIddictServerOwinMiddleware : AuthenticationMiddlewareThe OpenIddict server factory. public OpenIddictServerOwinMiddleware( OwinMiddleware? next, - IOptionsMonitor options, - IOpenIddictServerDispatcher dispatcher, - IOpenIddictServerFactory factory) + IOptionsMonitor options!!, + IOpenIddictServerDispatcher dispatcher!!, + IOpenIddictServerFactory factory!!) : base(next, options.CurrentValue) { _dispatcher = dispatcher; diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs index a1966639..bf08dd2a 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs @@ -33,13 +33,8 @@ public class OpenIddictServerOwinMiddlewareFactory : OwinMiddleware /// /// A that can be used to monitor the asynchronous operation. /// - public override Task Invoke(IOwinContext context) + public override Task Invoke(IOwinContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var provider = context.Get(typeof(IServiceProvider).FullName); if (provider is null) { diff --git a/src/OpenIddict.Server/OpenIddictServerBuilder.cs b/src/OpenIddict.Server/OpenIddictServerBuilder.cs index f611ab3b..a1da48d2 100644 --- a/src/OpenIddict.Server/OpenIddictServerBuilder.cs +++ b/src/OpenIddict.Server/OpenIddictServerBuilder.cs @@ -25,8 +25,8 @@ public class OpenIddictServerBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictServerBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictServerBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -42,14 +42,9 @@ public class OpenIddictServerBuilder /// The . [EditorBrowsable(EditorBrowsableState.Advanced)] public OpenIddictServerBuilder AddEventHandler( - Action> configuration) + Action> configuration!!) where TContext : OpenIddictServerEvents.BaseContext { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - // Note: handlers registered using this API are assumed to be custom handlers by default. var builder = OpenIddictServerHandlerDescriptor.CreateBuilder() .SetType(OpenIddictServerHandlerType.Custom); @@ -65,13 +60,8 @@ public class OpenIddictServerBuilder /// The handler descriptor. /// The . [EditorBrowsable(EditorBrowsableState.Advanced)] - public OpenIddictServerBuilder AddEventHandler(OpenIddictServerHandlerDescriptor descriptor) + public OpenIddictServerBuilder AddEventHandler(OpenIddictServerHandlerDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - // Register the handler in the services collection. Services.Add(descriptor.ServiceDescriptor); @@ -84,13 +74,8 @@ public class OpenIddictServerBuilder /// The descriptor corresponding to the handler to remove. /// The . [EditorBrowsable(EditorBrowsableState.Advanced)] - public OpenIddictServerBuilder RemoveEventHandler(OpenIddictServerHandlerDescriptor descriptor) + public OpenIddictServerBuilder RemoveEventHandler(OpenIddictServerHandlerDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - Services.RemoveAll(descriptor.ServiceDescriptor.ServiceType); Services.PostConfigure(options => @@ -113,13 +98,8 @@ public class OpenIddictServerBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictServerBuilder Configure(Action configuration) + public OpenIddictServerBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -139,28 +119,16 @@ public class OpenIddictServerBuilder /// /// The encrypting credentials. /// The . - public OpenIddictServerBuilder AddEncryptionCredentials(EncryptingCredentials credentials) - { - if (credentials is null) - { - throw new ArgumentNullException(nameof(credentials)); - } - - return Configure(options => options.EncryptionCredentials.Add(credentials)); - } + public OpenIddictServerBuilder AddEncryptionCredentials(EncryptingCredentials credentials!!) + => Configure(options => options.EncryptionCredentials.Add(credentials)); /// /// Registers an encryption key. /// /// The security key. /// The . - public OpenIddictServerBuilder AddEncryptionKey(SecurityKey key) + public OpenIddictServerBuilder AddEncryptionKey(SecurityKey key!!) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - // If the encryption key is an asymmetric security key, ensure it has a private key. if (key is AsymmetricSecurityKey asymmetricSecurityKey && asymmetricSecurityKey.PrivateKeyStatus == PrivateKeyStatus.DoesNotExist) @@ -202,13 +170,8 @@ public class OpenIddictServerBuilder /// The . [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The X.509 certificate is attached to the server options.")] - public OpenIddictServerBuilder AddDevelopmentEncryptionCertificate(X500DistinguishedName subject) + public OpenIddictServerBuilder AddDevelopmentEncryptionCertificate(X500DistinguishedName subject!!) { - if (subject is null) - { - throw new ArgumentNullException(nameof(subject)); - } - using var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); @@ -363,13 +326,8 @@ public class OpenIddictServerBuilder /// /// The encryption certificate. /// The . - public OpenIddictServerBuilder AddEncryptionCertificate(X509Certificate2 certificate) + public OpenIddictServerBuilder AddEncryptionCertificate(X509Certificate2 certificate!!) { - if (certificate is null) - { - throw new ArgumentNullException(nameof(certificate)); - } - // If the certificate is a X.509v3 certificate that specifies at least one // key usage, ensure that the certificate key can be used for key encryption. if (certificate.Version >= 3) @@ -415,14 +373,9 @@ public class OpenIddictServerBuilder /// An enumeration of flags indicating how and where to store the private key of the certificate. /// The . public OpenIddictServerBuilder AddEncryptionCertificate( - Assembly assembly, string resource, + Assembly assembly!!, string resource, string? password, X509KeyStorageFlags flags) { - if (assembly is null) - { - throw new ArgumentNullException(nameof(assembly)); - } - if (string.IsNullOrEmpty(resource)) { throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource)); @@ -465,13 +418,8 @@ public class OpenIddictServerBuilder /// The . [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The X.509 certificate is attached to the server options.")] - public OpenIddictServerBuilder AddEncryptionCertificate(Stream stream, string? password, X509KeyStorageFlags flags) + public OpenIddictServerBuilder AddEncryptionCertificate(Stream stream!!, string? password, X509KeyStorageFlags flags) { - if (stream is null) - { - throw new ArgumentNullException(nameof(stream)); - } - using var buffer = new MemoryStream(); stream.CopyTo(buffer); @@ -543,28 +491,16 @@ public class OpenIddictServerBuilder /// /// The signing credentials. /// The . - public OpenIddictServerBuilder AddSigningCredentials(SigningCredentials credentials) - { - if (credentials is null) - { - throw new ArgumentNullException(nameof(credentials)); - } - - return Configure(options => options.SigningCredentials.Add(credentials)); - } + public OpenIddictServerBuilder AddSigningCredentials(SigningCredentials credentials!!) + => Configure(options => options.SigningCredentials.Add(credentials)); /// /// Registers a signing key. /// /// The security key. /// The . - public OpenIddictServerBuilder AddSigningKey(SecurityKey key) + public OpenIddictServerBuilder AddSigningKey(SecurityKey key!!) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - // If the signing key is an asymmetric security key, ensure it has a private key. if (key is AsymmetricSecurityKey asymmetricSecurityKey && asymmetricSecurityKey.PrivateKeyStatus == PrivateKeyStatus.DoesNotExist) @@ -624,13 +560,8 @@ public class OpenIddictServerBuilder /// The . [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The X.509 certificate is attached to the server options.")] - public OpenIddictServerBuilder AddDevelopmentSigningCertificate(X500DistinguishedName subject) + public OpenIddictServerBuilder AddDevelopmentSigningCertificate(X500DistinguishedName subject!!) { - if (subject is null) - { - throw new ArgumentNullException(nameof(subject)); - } - using var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); @@ -803,13 +734,8 @@ public class OpenIddictServerBuilder /// /// The signing certificate. /// The . - public OpenIddictServerBuilder AddSigningCertificate(X509Certificate2 certificate) + public OpenIddictServerBuilder AddSigningCertificate(X509Certificate2 certificate!!) { - if (certificate is null) - { - throw new ArgumentNullException(nameof(certificate)); - } - // If the certificate is a X.509v3 certificate that specifies at least // one key usage, ensure that the certificate key can be used for signing. if (certificate.Version >= 3) @@ -855,14 +781,9 @@ public class OpenIddictServerBuilder /// An enumeration of flags indicating how and where to store the private key of the certificate. /// The . public OpenIddictServerBuilder AddSigningCertificate( - Assembly assembly, string resource, + Assembly assembly!!, string resource, string? password, X509KeyStorageFlags flags) { - if (assembly is null) - { - throw new ArgumentNullException(nameof(assembly)); - } - if (string.IsNullOrEmpty(resource)) { throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource)); @@ -905,13 +826,8 @@ public class OpenIddictServerBuilder /// The . [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The X.509 certificate is attached to the server options.")] - public OpenIddictServerBuilder AddSigningCertificate(Stream stream, string? password, X509KeyStorageFlags flags) + public OpenIddictServerBuilder AddSigningCertificate(Stream stream!!, string? password, X509KeyStorageFlags flags) { - if (stream is null) - { - throw new ArgumentNullException(nameof(stream)); - } - using var buffer = new MemoryStream(); stream.CopyTo(buffer); @@ -1117,15 +1033,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetAuthorizationEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetAuthorizationEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetAuthorizationEndpointUris(params string[] addresses!!) + => SetAuthorizationEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the authorization endpoint. @@ -1134,13 +1043,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetAuthorizationEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetAuthorizationEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1165,15 +1069,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetConfigurationEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetConfigurationEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetConfigurationEndpointUris(params string[] addresses!!) + => SetConfigurationEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the configuration endpoint. @@ -1182,13 +1079,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetConfigurationEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetConfigurationEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1213,15 +1105,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetCryptographyEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetCryptographyEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetCryptographyEndpointUris(params string[] addresses!!) + => SetCryptographyEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the cryptography endpoint. @@ -1230,13 +1115,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetCryptographyEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetCryptographyEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1261,15 +1141,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetDeviceEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetDeviceEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetDeviceEndpointUris(params string[] addresses!!) + => SetDeviceEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the device endpoint. @@ -1278,13 +1151,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetDeviceEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetDeviceEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1309,15 +1177,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetIntrospectionEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetIntrospectionEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetIntrospectionEndpointUris(params string[] addresses!!) + => SetIntrospectionEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the introspection endpoint. @@ -1326,13 +1187,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetIntrospectionEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetIntrospectionEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1357,15 +1213,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetLogoutEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetLogoutEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetLogoutEndpointUris(params string[] addresses!!) + => SetLogoutEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the logout endpoint. @@ -1374,13 +1223,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetLogoutEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetLogoutEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1405,15 +1249,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetRevocationEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetRevocationEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetRevocationEndpointUris(params string[] addresses!!) + => SetRevocationEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the revocation endpoint. @@ -1422,13 +1259,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetRevocationEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetRevocationEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1453,15 +1285,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetTokenEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetTokenEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetTokenEndpointUris(params string[] addresses!!) + => SetTokenEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the token endpoint. @@ -1470,13 +1295,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetTokenEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetTokenEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1501,15 +1321,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetUserinfoEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetUserinfoEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetUserinfoEndpointUris(params string[] addresses!!) + => SetUserinfoEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the userinfo endpoint. @@ -1518,13 +1331,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetUserinfoEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetUserinfoEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1549,15 +1357,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetVerificationEndpointUris(params string[] addresses) - { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - - return SetVerificationEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); - } + public OpenIddictServerBuilder SetVerificationEndpointUris(params string[] addresses!!) + => SetVerificationEndpointUris(addresses.Select(address => new Uri(address, UriKind.RelativeOrAbsolute)).ToArray()); /// /// Sets the relative or absolute URLs associated to the verification endpoint. @@ -1566,13 +1367,8 @@ public class OpenIddictServerBuilder /// /// The addresses associated to the endpoint. /// The . - public OpenIddictServerBuilder SetVerificationEndpointUris(params Uri[] addresses) + public OpenIddictServerBuilder SetVerificationEndpointUris(params Uri[] addresses!!) { - if (addresses is null) - { - throw new ArgumentNullException(nameof(addresses)); - } - if (addresses.Any(address => !address.IsWellFormedOriginalString())) { throw new ArgumentException(SR.GetResourceString(SR.ID0072), nameof(addresses)); @@ -1692,14 +1488,9 @@ public class OpenIddictServerBuilder /// /// The supported claims. /// The . - public OpenIddictServerBuilder RegisterClaims(params string[] claims) + public OpenIddictServerBuilder RegisterClaims(params string[] claims!!) { - if (claims is null) - { - throw new ArgumentNullException(nameof(claims)); - } - - if (claims.Any(claim => string.IsNullOrEmpty(claim))) + if (claims.Any(string.IsNullOrEmpty)) { throw new ArgumentException(SR.GetResourceString(SR.ID0073), nameof(claims)); } @@ -1713,14 +1504,9 @@ public class OpenIddictServerBuilder /// /// The supported scopes. /// The . - public OpenIddictServerBuilder RegisterScopes(params string[] scopes) + public OpenIddictServerBuilder RegisterScopes(params string[] scopes!!) { - if (scopes is null) - { - throw new ArgumentNullException(nameof(scopes)); - } - - if (scopes.Any(scope => string.IsNullOrEmpty(scope))) + if (scopes.Any(string.IsNullOrEmpty)) { throw new ArgumentException(SR.GetResourceString(SR.ID0074), nameof(scopes)); } @@ -1818,15 +1604,8 @@ public class OpenIddictServerBuilder /// /// The issuer address. /// The . - public OpenIddictServerBuilder SetIssuer(Uri address) - { - if (address is null) - { - throw new ArgumentNullException(nameof(address)); - } - - return Configure(options => options.Issuer = address); - } + public OpenIddictServerBuilder SetIssuer(Uri address!!) + => Configure(options => options.Issuer = address); /// /// Configures OpenIddict to use reference tokens, so that the access token payloads diff --git a/src/OpenIddict.Server/OpenIddictServerConfiguration.cs b/src/OpenIddict.Server/OpenIddictServerConfiguration.cs index d0f0a2fb..275458f4 100644 --- a/src/OpenIddict.Server/OpenIddictServerConfiguration.cs +++ b/src/OpenIddict.Server/OpenIddictServerConfiguration.cs @@ -21,12 +21,8 @@ public class OpenIddictServerConfiguration : IPostConfigureOptions /// The name of the options instance to configure, if applicable. /// The options instance to initialize. - public void PostConfigure(string name, OpenIddictServerOptions options) + public void PostConfigure(string name, OpenIddictServerOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } // Explicitly disable all the features that are implicitly excluded when the degraded mode is active. if (options.EnableDegradedMode) diff --git a/src/OpenIddict.Server/OpenIddictServerDispatcher.cs b/src/OpenIddict.Server/OpenIddictServerDispatcher.cs index 87ee208f..eee36712 100644 --- a/src/OpenIddict.Server/OpenIddictServerDispatcher.cs +++ b/src/OpenIddict.Server/OpenIddictServerDispatcher.cs @@ -19,22 +19,17 @@ public class OpenIddictServerDispatcher : IOpenIddictServerDispatcher /// Creates a new instance of the class. /// public OpenIddictServerDispatcher( - ILogger logger, - IOptionsMonitor options, - IServiceProvider provider) + ILogger logger!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _logger = logger; _options = options; _provider = provider; } - public async ValueTask DispatchAsync(TContext context) where TContext : BaseContext + public async ValueTask DispatchAsync(TContext context!!) where TContext : BaseContext { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - await foreach (var handler in GetHandlersAsync()) { try diff --git a/src/OpenIddict.Server/OpenIddictServerEvents.cs b/src/OpenIddict.Server/OpenIddictServerEvents.cs index af7440b2..d8fcacce 100644 --- a/src/OpenIddict.Server/OpenIddictServerEvents.cs +++ b/src/OpenIddict.Server/OpenIddictServerEvents.cs @@ -21,8 +21,8 @@ public static partial class OpenIddictServerEvents /// /// Creates a new instance of the class. /// - protected BaseContext(OpenIddictServerTransaction transaction) - => Transaction = transaction ?? throw new ArgumentNullException(nameof(transaction)); + protected BaseContext(OpenIddictServerTransaction transaction!!) + => Transaction = transaction; /// /// Gets the environment associated with the current request being processed. diff --git a/src/OpenIddict.Server/OpenIddictServerExtensions.cs b/src/OpenIddict.Server/OpenIddictServerExtensions.cs index d2f2cd24..6b26056e 100644 --- a/src/OpenIddict.Server/OpenIddictServerExtensions.cs +++ b/src/OpenIddict.Server/OpenIddictServerExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictServerExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictServerBuilder AddServer(this OpenIddictBuilder builder) + public static OpenIddictServerBuilder AddServer(this OpenIddictBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddLogging(); builder.Services.AddOptions(); @@ -94,18 +89,8 @@ public static class OpenIddictServerExtensions /// The configuration delegate used to configure the server services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictBuilder AddServer(this OpenIddictBuilder builder, Action configuration) + public static OpenIddictBuilder AddServer(this OpenIddictBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.AddServer()); return builder; diff --git a/src/OpenIddict.Server/OpenIddictServerFactory.cs b/src/OpenIddict.Server/OpenIddictServerFactory.cs index 90ad923d..2e2ee4e1 100644 --- a/src/OpenIddict.Server/OpenIddictServerFactory.cs +++ b/src/OpenIddict.Server/OpenIddictServerFactory.cs @@ -18,15 +18,15 @@ public class OpenIddictServerFactory : IOpenIddictServerFactory /// Creates a new instance of the class. /// public OpenIddictServerFactory( - ILogger logger, - IOptionsMonitor options) + ILogger logger!!, + IOptionsMonitor options!!) { _logger = logger; _options = options; } public ValueTask CreateTransactionAsync() - => new ValueTask(new OpenIddictServerTransaction + => new(new OpenIddictServerTransaction { Issuer = _options.CurrentValue.Issuer, Logger = _logger, diff --git a/src/OpenIddict.Server/OpenIddictServerHandler.cs b/src/OpenIddict.Server/OpenIddictServerHandler.cs index 90b59e9c..6232d198 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandler.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandler.cs @@ -18,8 +18,8 @@ public class OpenIddictServerHandler : IOpenIddictServerHandler /// The event handler delegate. - public OpenIddictServerHandler(Func handler) - => _handler = handler ?? throw new ArgumentNullException(nameof(handler)); + public OpenIddictServerHandler(Func handler!!) + => _handler = handler; /// /// Processes the event. @@ -28,6 +28,5 @@ public class OpenIddictServerHandler : IOpenIddictServerHandler /// A that can be used to monitor the asynchronous operation. /// - public ValueTask HandleAsync(TContext context) - => _handler(context ?? throw new ArgumentNullException(nameof(context))); + public ValueTask HandleAsync(TContext context!!) => _handler(context); } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs b/src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs index 500b16e8..c42ca463 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs @@ -72,13 +72,8 @@ public class OpenIddictServerHandlerDescriptor /// /// The event handler filter type. /// The builder instance, so that calls can be easily chained. - public Builder AddFilter(Type type) + public Builder AddFilter(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (!typeof(IOpenIddictServerHandlerFilter<>).MakeGenericType(typeof(TContext)).IsAssignableFrom(type)) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0104)); @@ -104,13 +99,8 @@ public class OpenIddictServerHandlerDescriptor /// The existing descriptor properties are copied from. /// All the properties previously set on this instance are automatically replaced. /// The builder instance, so that calls can be easily chained. - public Builder Import(OpenIddictServerHandlerDescriptor descriptor) + public Builder Import(OpenIddictServerHandlerDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - if (descriptor.ContextType != typeof(TContext)) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0284)); @@ -130,13 +120,8 @@ public class OpenIddictServerHandlerDescriptor /// /// The service descriptor. /// The builder instance, so that calls can be easily chained. - public Builder SetServiceDescriptor(ServiceDescriptor descriptor) + public Builder SetServiceDescriptor(ServiceDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - var type = descriptor.ServiceType; if (!typeof(IOpenIddictServerHandler<>).MakeGenericType(typeof(TContext)).IsAssignableFrom(type)) { @@ -182,15 +167,8 @@ public class OpenIddictServerHandlerDescriptor /// /// The handler instance. /// The builder instance, so that calls can be easily chained. - public Builder UseInlineHandler(Func handler) - { - if (handler is null) - { - throw new ArgumentNullException(nameof(handler)); - } - - return UseSingletonHandler(new OpenIddictServerHandler(handler)); - } + public Builder UseInlineHandler(Func handler!!) + => UseSingletonHandler(new OpenIddictServerHandler(handler)); /// /// Configures the descriptor to use the specified scoped handler. @@ -208,17 +186,10 @@ public class OpenIddictServerHandlerDescriptor /// The handler type. /// The factory used to create the handler. /// The builder instance, so that calls can be easily chained. - public Builder UseScopedHandler(Func factory) + public Builder UseScopedHandler(Func factory!!) where THandler : IOpenIddictServerHandler - { - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - return SetServiceDescriptor(new ServiceDescriptor( + => SetServiceDescriptor(new ServiceDescriptor( typeof(THandler), factory, ServiceLifetime.Scoped)); - } /// /// Configures the descriptor to use the specified singleton handler. @@ -236,17 +207,10 @@ public class OpenIddictServerHandlerDescriptor /// The handler type. /// The factory used to create the handler. /// The builder instance, so that calls can be easily chained. - public Builder UseSingletonHandler(Func factory) + public Builder UseSingletonHandler(Func factory!!) where THandler : IOpenIddictServerHandler - { - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - return SetServiceDescriptor(new ServiceDescriptor( + => SetServiceDescriptor(new ServiceDescriptor( typeof(THandler), factory, ServiceLifetime.Singleton)); - } /// /// Configures the descriptor to use the specified singleton handler. @@ -254,16 +218,9 @@ public class OpenIddictServerHandlerDescriptor /// The handler type. /// The handler instance. /// The builder instance, so that calls can be easily chained. - public Builder UseSingletonHandler(THandler handler) + public Builder UseSingletonHandler(THandler handler!!) where THandler : IOpenIddictServerHandler - { - if (handler is null) - { - throw new ArgumentNullException(nameof(handler)); - } - - return SetServiceDescriptor(new ServiceDescriptor(typeof(THandler), handler)); - } + => SetServiceDescriptor(new ServiceDescriptor(typeof(THandler), handler)); /// /// Build a new descriptor instance, based on the parameters that were previously set. diff --git a/src/OpenIddict.Server/OpenIddictServerHandlerFilters.cs b/src/OpenIddict.Server/OpenIddictServerHandlerFilters.cs index 57117c7b..ea15802f 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlerFilters.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlerFilters.cs @@ -16,15 +16,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireAccessTokenGenerated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessSignInContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.GenerateAccessToken); - } + public ValueTask IsActiveAsync(ProcessSignInContext context!!) + => new(context.GenerateAccessToken); } /// @@ -32,15 +25,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireAccessTokenValidated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateAccessToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateAccessToken); } /// @@ -48,15 +34,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireAuthorizationCodeGenerated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessSignInContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.GenerateAuthorizationCode); - } + public ValueTask IsActiveAsync(ProcessSignInContext context!!) + => new(context.GenerateAuthorizationCode); } /// @@ -64,15 +43,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireAuthorizationCodeValidated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateAuthorizationCode); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateAuthorizationCode); } /// @@ -80,15 +52,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireAuthorizationRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Authorization); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Authorization); } /// @@ -96,15 +61,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireAuthorizationStorageEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.Options.DisableAuthorizationStorage); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!context.Options.DisableAuthorizationStorage); } /// @@ -112,15 +70,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireClientIdParameter : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!string.IsNullOrEmpty(context.Transaction.Request?.ClientId)); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!string.IsNullOrEmpty(context.Transaction.Request?.ClientId)); } /// @@ -128,15 +79,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireConfigurationRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Configuration); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Configuration); } /// @@ -144,15 +88,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireCryptographyRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Cryptography); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Cryptography); } /// @@ -160,15 +97,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireDegradedModeDisabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.Options.EnableDegradedMode); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!context.Options.EnableDegradedMode); } /// @@ -176,15 +106,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireDeviceCodeGenerated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessSignInContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.GenerateDeviceCode); - } + public ValueTask IsActiveAsync(ProcessSignInContext context!!) + => new(context.GenerateDeviceCode); } /// @@ -192,15 +115,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireDeviceCodeValidated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateDeviceCode); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateDeviceCode); } /// @@ -208,15 +124,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireDeviceRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Device); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Device); } /// @@ -224,15 +133,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireEndpointPermissionsEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.Options.IgnoreEndpointPermissions); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!context.Options.IgnoreEndpointPermissions); } /// @@ -240,15 +142,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireGenericTokenValidated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateGenericToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateGenericToken); } /// @@ -256,15 +151,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireGrantTypePermissionsEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.Options.IgnoreGrantTypePermissions); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!context.Options.IgnoreGrantTypePermissions); } /// @@ -272,15 +160,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireIdentityTokenGenerated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessSignInContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.GenerateIdentityToken); - } + public ValueTask IsActiveAsync(ProcessSignInContext context!!) + => new(context.GenerateIdentityToken); } /// @@ -288,15 +169,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireIdentityTokenValidated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateIdentityToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateIdentityToken); } /// @@ -304,15 +178,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireIntrospectionRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Introspection); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Introspection); } /// @@ -320,15 +187,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireLogoutRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Logout); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Logout); } /// @@ -336,15 +196,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequirePostLogoutRedirectUriParameter : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!string.IsNullOrEmpty(context.Transaction.Request?.PostLogoutRedirectUri)); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!string.IsNullOrEmpty(context.Transaction.Request?.PostLogoutRedirectUri)); } /// @@ -352,15 +205,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireReferenceAccessTokensEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Options.UseReferenceAccessTokens); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Options.UseReferenceAccessTokens); } /// @@ -368,15 +214,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireReferenceRefreshTokensEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Options.UseReferenceRefreshTokens); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Options.UseReferenceRefreshTokens); } /// @@ -384,15 +223,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireRefreshTokenGenerated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessSignInContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.GenerateRefreshToken); - } + public ValueTask IsActiveAsync(ProcessSignInContext context!!) + => new(context.GenerateRefreshToken); } /// @@ -400,15 +232,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireRefreshTokenValidated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateRefreshToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateRefreshToken); } /// @@ -416,15 +241,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireResponseTypePermissionsEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.Options.IgnoreResponseTypePermissions); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!context.Options.IgnoreResponseTypePermissions); } /// @@ -432,15 +250,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireRevocationRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Revocation); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Revocation); } /// @@ -448,15 +259,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireScopePermissionsEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.Options.IgnoreScopePermissions); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!context.Options.IgnoreScopePermissions); } /// @@ -464,15 +268,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireScopeValidationEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.Options.DisableScopeValidation); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!context.Options.DisableScopeValidation); } /// @@ -480,15 +277,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireSlidingRefreshTokenExpirationEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.Options.DisableSlidingRefreshTokenExpiration); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!context.Options.DisableSlidingRefreshTokenExpiration); } /// @@ -496,15 +286,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireTokenEntryCreated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(GenerateTokenContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.CreateTokenEntry); - } + public ValueTask IsActiveAsync(GenerateTokenContext context!!) + => new(context.CreateTokenEntry); } /// @@ -512,15 +295,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireTokenLifetimeValidationEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ValidateTokenContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.DisableLifetimeValidation); - } + public ValueTask IsActiveAsync(ValidateTokenContext context!!) + => new(!context.DisableLifetimeValidation); } /// @@ -528,15 +304,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireTokenPayloadPersisted : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(GenerateTokenContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.PersistTokenPayload); - } + public ValueTask IsActiveAsync(GenerateTokenContext context!!) + => new(context.PersistTokenPayload); } /// @@ -544,15 +313,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireTokenRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Token); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Token); } /// @@ -560,15 +322,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireTokenStorageEnabled : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(!context.Options.DisableTokenStorage); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(!context.Options.DisableTokenStorage); } /// @@ -576,15 +331,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireUserCodeGenerated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessSignInContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.GenerateUserCode); - } + public ValueTask IsActiveAsync(ProcessSignInContext context!!) + => new(context.GenerateUserCode); } /// @@ -592,15 +340,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireUserCodeValidated : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateUserCode); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateUserCode); } /// @@ -608,15 +349,8 @@ public static class OpenIddictServerHandlerFilters /// public class RequireUserinfoRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Userinfo); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Userinfo); } /// @@ -624,14 +358,7 @@ public static class OpenIddictServerHandlerFilters /// public class RequireVerificationRequest : IOpenIddictServerHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.EndpointType == OpenIddictServerEndpointType.Verification); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.EndpointType is OpenIddictServerEndpointType.Verification); } } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs index ad2cad99..46dac199 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs @@ -66,7 +66,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractAuthorizationRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractAuthorizationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -81,13 +81,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractAuthorizationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -128,7 +123,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateAuthorizationRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateAuthorizationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -143,13 +138,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateAuthorizationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -194,7 +184,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleAuthorizationRequest(IOpenIddictServerDispatcher dispatcher) + public HandleAuthorizationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -209,13 +199,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleAuthorizationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -291,7 +276,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyAuthorizationResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyAuthorizationResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -306,13 +291,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyAuthorizationResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -348,12 +328,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject requests using the unsupported request parameter. if (!string.IsNullOrEmpty(context.Request.Request)) @@ -388,12 +364,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject requests using the unsupported request_uri parameter. if (!string.IsNullOrEmpty(context.Request.RequestUri)) @@ -428,12 +400,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // client_id is a required parameter and MUST cause an error when missing. // See http://openid.net/specs/openid-connect-core-1_0.html#AuthRequest. @@ -469,12 +437,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // While redirect_uri was not mandatory in OAuth 2.0, this parameter // is now declared as REQUIRED and MUST cause an error when missing. @@ -574,12 +538,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject requests missing the mandatory response_type parameter. if (string.IsNullOrEmpty(context.Request.ResponseType)) @@ -669,12 +629,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // response_mode=query (explicit or not) and a response_type containing id_token // or token are not considered as a safe combination and MUST be rejected. @@ -751,12 +707,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject authorization requests containing the id_token response_type if no openid scope has been received. if (context.Request.HasResponseType(ResponseTypes.IdToken) && !context.Request.HasScope(Scopes.OpenId)) @@ -802,12 +754,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject OpenID Connect implicit/hybrid requests missing the mandatory nonce parameter. // See http://openid.net/specs/openid-connect-core-1_0.html#AuthRequest, @@ -851,12 +799,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject requests specifying prompt=none with consent/login or select_account. if (context.Request.HasPrompt(Prompts.None) && (context.Request.HasPrompt(Prompts.Consent) || @@ -893,13 +837,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If OpenIddict was configured to require PKCE, reject the request if the code challenge // is missing and if an authorization code was requested by the client application. if (context.Options.RequireProofKeyForCodeExchange && @@ -1006,7 +945,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientId() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientId(IOpenIddictApplicationManager applicationManager) + public ValidateClientId(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1021,13 +960,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1057,7 +991,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientType() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientType(IOpenIddictApplicationManager applicationManager) + public ValidateClientType(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1072,13 +1006,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1122,7 +1051,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientRedirectUri() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientRedirectUri(IOpenIddictApplicationManager applicationManager) + public ValidateClientRedirectUri(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1137,13 +1066,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1222,13 +1146,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If all the specified scopes are registered in the options, avoid making a database lookup. var scopes = new HashSet(context.Request.GetScopes(), StringComparer.Ordinal); scopes.ExceptWith(context.Options.Scopes); @@ -1278,7 +1197,7 @@ public static partial class OpenIddictServerHandlers public ValidateEndpointPermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager) + public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1294,13 +1213,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1334,7 +1248,7 @@ public static partial class OpenIddictServerHandlers public ValidateGrantTypePermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateGrantTypePermissions(IOpenIddictApplicationManager applicationManager) + public ValidateGrantTypePermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1350,13 +1264,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1435,7 +1344,7 @@ public static partial class OpenIddictServerHandlers public ValidateResponseTypePermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateResponseTypePermissions(IOpenIddictApplicationManager applicationManager) + public ValidateResponseTypePermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1451,13 +1360,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1518,7 +1422,7 @@ public static partial class OpenIddictServerHandlers public ValidateScopePermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateScopePermissions(IOpenIddictApplicationManager applicationManager) + public ValidateScopePermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1534,13 +1438,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1585,7 +1484,7 @@ public static partial class OpenIddictServerHandlers public ValidateProofKeyForCodeExchangeRequirement() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateProofKeyForCodeExchangeRequirement(IOpenIddictApplicationManager applicationManager) + public ValidateProofKeyForCodeExchangeRequirement(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1600,13 +1499,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context) + public async ValueTask HandleAsync(ValidateAuthorizationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); // If a code_challenge was provided or if no authorization code is requested, the request is always @@ -1653,13 +1547,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Request is null) { return default; @@ -1696,13 +1585,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Request is null) { return default; @@ -1738,13 +1622,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If the user agent is expected to be redirected to the client application, attach the request // state to the authorization response to help the client mitigate CSRF/session fixation attacks. // @@ -1775,13 +1654,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ApplyAuthorizationResponseContext context) + public ValueTask HandleAsync(ApplyAuthorizationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If the user agent is expected to be redirected to the client application, attach the // issuer address to the authorization response to help the client detect mix-up attacks. // diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Device.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Device.cs index 041d5ab6..c07d6c78 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Device.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Device.cs @@ -65,7 +65,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractDeviceRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractDeviceRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -80,13 +80,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractDeviceRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -127,7 +122,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateDeviceRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateDeviceRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -142,13 +137,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateDeviceRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -184,7 +174,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleDeviceRequest(IOpenIddictServerDispatcher dispatcher) + public HandleDeviceRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -199,13 +189,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleDeviceRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -285,7 +270,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyDeviceResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyDeviceResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -300,13 +285,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyDeviceResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -342,12 +322,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateDeviceRequestContext context) + public ValueTask HandleAsync(ValidateDeviceRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // client_id is a required parameter and MUST cause an error when missing. // See https://tools.ietf.org/html/rfc8628#section-3.1 for more information. @@ -383,12 +359,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateDeviceRequestContext context) + public ValueTask HandleAsync(ValidateDeviceRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject device requests that specify scope=offline_access if the refresh token flow is not enabled. if (context.Request.HasScope(Scopes.OfflineAccess) && !context.Options.GrantTypes.Contains(GrantTypes.RefreshToken)) @@ -438,13 +410,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateDeviceRequestContext context) + public async ValueTask HandleAsync(ValidateDeviceRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If all the specified scopes are registered in the options, avoid making a database lookup. var scopes = new HashSet(context.Request.GetScopes(), StringComparer.Ordinal); scopes.ExceptWith(context.Options.Scopes); @@ -494,7 +461,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientId() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientId(IOpenIddictApplicationManager applicationManager) + public ValidateClientId(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -510,13 +477,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateDeviceRequestContext context) + public async ValueTask HandleAsync(ValidateDeviceRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); // Retrieve the application details corresponding to the requested client_id. @@ -547,7 +509,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientType() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientType(IOpenIddictApplicationManager applicationManager) + public ValidateClientType(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -563,13 +525,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateDeviceRequestContext context) + public async ValueTask HandleAsync(ValidateDeviceRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -621,7 +578,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientSecret() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientSecret(IOpenIddictApplicationManager applicationManager) + public ValidateClientSecret(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -637,13 +594,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateDeviceRequestContext context) + public async ValueTask HandleAsync(ValidateDeviceRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -685,7 +637,7 @@ public static partial class OpenIddictServerHandlers public ValidateEndpointPermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager) + public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -702,13 +654,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateDeviceRequestContext context) + public async ValueTask HandleAsync(ValidateDeviceRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -742,7 +689,7 @@ public static partial class OpenIddictServerHandlers public ValidateGrantTypePermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateGrantTypePermissions(IOpenIddictApplicationManager applicationManager) + public ValidateGrantTypePermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -758,13 +705,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateDeviceRequestContext context) + public async ValueTask HandleAsync(ValidateDeviceRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -814,7 +756,7 @@ public static partial class OpenIddictServerHandlers public ValidateScopePermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateScopePermissions(IOpenIddictApplicationManager applicationManager) + public ValidateScopePermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -831,13 +773,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateDeviceRequestContext context) + public async ValueTask HandleAsync(ValidateDeviceRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -878,7 +815,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractVerificationRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractVerificationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -893,13 +830,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractVerificationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -940,7 +872,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateVerificationRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateVerificationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -955,13 +887,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateVerificationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -997,7 +924,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleVerificationRequest(IOpenIddictServerDispatcher dispatcher) + public HandleVerificationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -1012,13 +939,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleVerificationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -1094,7 +1016,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyVerificationResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyVerificationResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -1109,13 +1031,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyVerificationResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -1142,7 +1059,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public AttachUserCodePrincipal(IOpenIddictServerDispatcher dispatcher) + public AttachUserCodePrincipal(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -1156,13 +1073,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(HandleVerificationRequestContext context) + public async ValueTask HandleAsync(HandleVerificationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Note: the user_code may not be present (e.g when the user typed // the verification_uri manually without the user code appended). // In this case, ignore the missing token so that a view can be diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs index 7f2eb59c..42632b1a 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs @@ -64,7 +64,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractConfigurationRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractConfigurationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -79,13 +79,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractConfigurationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -126,7 +121,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateConfigurationRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateConfigurationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -141,13 +136,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateConfigurationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -183,7 +173,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleConfigurationRequest(IOpenIddictServerDispatcher dispatcher) + public HandleConfigurationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -198,13 +188,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleConfigurationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -269,7 +254,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyConfigurationResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyConfigurationResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -284,13 +269,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyConfigurationResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -326,13 +306,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Note: while OpenIddict allows specifying multiple endpoint addresses, the OAuth 2.0 // and OpenID Connect discovery specifications only allow a single address per endpoint. @@ -417,13 +392,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.GrantTypes.UnionWith(context.Options.GrantTypes); return default; @@ -446,13 +416,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.ResponseModes.UnionWith(context.Options.ResponseModes); return default; @@ -475,13 +440,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.ResponseTypes.UnionWith(context.Options.ResponseTypes); return default; @@ -505,13 +465,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.IntrospectionEndpoint is not null) { context.IntrospectionEndpointAuthenticationMethods.Add(ClientAuthenticationMethods.ClientSecretBasic); @@ -551,13 +506,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.CodeChallengeMethods.UnionWith(context.Options.CodeChallengeMethods); return default; @@ -580,13 +530,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Scopes.UnionWith(context.Options.Scopes); return default; @@ -609,13 +554,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Claims.UnionWith(context.Options.Claims); return default; @@ -638,13 +578,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.SubjectTypes.Add(SubjectTypes.Public); return default; @@ -667,13 +602,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - foreach (var credentials in context.Options.SigningCredentials) { // Try to resolve the JWA algorithm short name. @@ -733,13 +663,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationRequestContext context) + public ValueTask HandleAsync(HandleConfigurationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Note: the optional claims/request/request_uri parameters are not yet supported // by OpenIddict, so "false" is returned to encourage clients not to use them. context.Metadata[Metadata.ClaimsParameterSupported] = false; @@ -762,7 +687,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractCryptographyRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractCryptographyRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -777,13 +702,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractCryptographyRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -824,7 +744,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateCryptographyRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateCryptographyRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -839,13 +759,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateCryptographyRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -881,7 +796,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleCryptographyRequest(IOpenIddictServerDispatcher dispatcher) + public HandleCryptographyRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -896,13 +811,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleCryptographyRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -1009,7 +919,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyCryptographyResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyCryptographyResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -1024,13 +934,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyCryptographyResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -1066,13 +971,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleCryptographyRequestContext context) + public ValueTask HandleAsync(HandleCryptographyRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - foreach (var credentials in context.Options.SigningCredentials) { #if SUPPORTS_ECDSA diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs index d83d267b..b7950f6a 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs @@ -78,7 +78,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractTokenRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractTokenRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -93,13 +93,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractTokenRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -140,7 +135,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateTokenRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateTokenRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -155,13 +150,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateTokenRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -201,7 +191,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleTokenRequest(IOpenIddictServerDispatcher dispatcher) + public HandleTokenRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -216,13 +206,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleTokenRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -298,7 +283,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyTokenResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyTokenResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -313,13 +298,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyTokenResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -355,12 +335,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject token requests missing the mandatory grant_type parameter. if (string.IsNullOrEmpty(context.Request.GrantType)) @@ -420,13 +396,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!string.IsNullOrEmpty(context.ClientId)) { return default; @@ -470,12 +441,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject grant_type=authorization_code requests missing the authorization code. // See https://tools.ietf.org/html/rfc6749#section-4.1.3 for more information. @@ -512,12 +479,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject grant_type=client_credentials requests missing the client credentials. // See https://tools.ietf.org/html/rfc6749#section-4.4.1 for more information. @@ -553,12 +516,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject grant_type=urn:ietf:params:oauth:grant-type:device_code requests missing the device code. // See https://tools.ietf.org/html/rfc8628#section-3.4 for more information. @@ -593,12 +552,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject grant_type=refresh_token requests missing the refresh token. // See https://tools.ietf.org/html/rfc6749#section-6 for more information. @@ -635,12 +590,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject grant_type=password requests missing username or password. // See https://tools.ietf.org/html/rfc6749#section-4.3.2 for more information. @@ -677,13 +628,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.Request.IsAuthorizationCodeGrantType()) { return default; @@ -742,13 +688,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenRequestContext context) + public async ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If all the specified scopes are registered in the options, avoid making a database lookup. var scopes = new HashSet(context.Request.GetScopes(), StringComparer.Ordinal); scopes.ExceptWith(context.Options.Scopes); @@ -798,7 +739,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientId() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientId(IOpenIddictApplicationManager applicationManager) + public ValidateClientId(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -814,13 +755,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenRequestContext context) + public async ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); // Retrieve the application details corresponding to the requested client_id. @@ -851,7 +787,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientType() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientType(IOpenIddictApplicationManager applicationManager) + public ValidateClientType(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -867,13 +803,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenRequestContext context) + public async ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -938,7 +869,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientSecret() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientSecret(IOpenIddictApplicationManager applicationManager) + public ValidateClientSecret(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -954,13 +885,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenRequestContext context) + public async ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1002,7 +928,7 @@ public static partial class OpenIddictServerHandlers public ValidateEndpointPermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager) + public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1019,13 +945,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenRequestContext context) + public async ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1060,7 +981,7 @@ public static partial class OpenIddictServerHandlers public ValidateGrantTypePermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateGrantTypePermissions(IOpenIddictApplicationManager applicationManager) + public ValidateGrantTypePermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1077,13 +998,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenRequestContext context) + public async ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1133,7 +1049,7 @@ public static partial class OpenIddictServerHandlers public ValidateScopePermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateScopePermissions(IOpenIddictApplicationManager applicationManager) + public ValidateScopePermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1150,13 +1066,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenRequestContext context) + public async ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -1201,7 +1112,7 @@ public static partial class OpenIddictServerHandlers public ValidateProofKeyForCodeExchangeRequirement() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateProofKeyForCodeExchangeRequirement(IOpenIddictApplicationManager applicationManager) + public ValidateProofKeyForCodeExchangeRequirement(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -1217,13 +1128,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenRequestContext context) + public async ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.Request.IsAuthorizationCodeGrantType()) { return; @@ -1266,7 +1172,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateToken(IOpenIddictServerDispatcher dispatcher) + public ValidateToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -1280,13 +1186,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenRequestContext context) + public async ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.Request.IsAuthorizationCodeGrantType() && !context.Request.IsDeviceCodeGrantType() && !context.Request.IsRefreshTokenGrantType()) @@ -1346,13 +1247,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.Request.IsAuthorizationCodeGrantType() && !context.Request.IsDeviceCodeGrantType() && !context.Request.IsRefreshTokenGrantType()) @@ -1438,13 +1334,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.Request.IsAuthorizationCodeGrantType()) { return default; @@ -1509,13 +1400,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.Request.IsAuthorizationCodeGrantType()) { return default; @@ -1628,13 +1514,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenRequestContext context) + public ValueTask HandleAsync(ValidateTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.Request.IsAuthorizationCodeGrantType() && !context.Request.IsRefreshTokenGrantType()) { return default; @@ -1700,13 +1581,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleTokenRequestContext context) + public ValueTask HandleAsync(HandleTokenRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.Request.IsAuthorizationCodeGrantType() && !context.Request.IsRefreshTokenGrantType()) { return default; @@ -1738,13 +1614,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ApplyTokenResponseContext context) + public ValueTask HandleAsync(ApplyTokenResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (string.IsNullOrEmpty(context.Error)) { return default; diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs index 6112fe6c..33237c84 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs @@ -63,7 +63,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractIntrospectionRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractIntrospectionRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -78,13 +78,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractIntrospectionRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -125,7 +120,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateIntrospectionRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateIntrospectionRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -140,13 +135,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateIntrospectionRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -186,7 +176,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleIntrospectionRequest(IOpenIddictServerDispatcher dispatcher) + public HandleIntrospectionRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -201,13 +191,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleIntrospectionRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -289,7 +274,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyIntrospectionResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyIntrospectionResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -304,13 +289,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyIntrospectionResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -346,12 +326,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateIntrospectionRequestContext context) + public ValueTask HandleAsync(ValidateIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject introspection requests missing the mandatory token parameter. if (string.IsNullOrEmpty(context.Request.Token)) @@ -386,12 +362,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateIntrospectionRequestContext context) + public ValueTask HandleAsync(ValidateIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // At this stage, reject the introspection request unless the client identification requirement was disabled. if (!context.Options.AcceptAnonymousClients && string.IsNullOrEmpty(context.ClientId)) @@ -420,7 +392,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientId() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientId(IOpenIddictApplicationManager applicationManager) + public ValidateClientId(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -436,13 +408,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context) + public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); // Retrieve the application details corresponding to the requested client_id. @@ -473,7 +440,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientType() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientType(IOpenIddictApplicationManager applicationManager) + public ValidateClientType(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -489,13 +456,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context) + public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -547,7 +509,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientSecret() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientSecret(IOpenIddictApplicationManager applicationManager) + public ValidateClientSecret(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -563,13 +525,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context) + public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -611,7 +568,7 @@ public static partial class OpenIddictServerHandlers public ValidateEndpointPermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager) + public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -628,13 +585,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context) + public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -665,7 +617,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateToken(IOpenIddictServerDispatcher dispatcher) + public ValidateToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -679,13 +631,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context) + public async ValueTask HandleAsync(ValidateIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ProcessAuthenticationContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -735,13 +682,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateIntrospectionRequestContext context) + public ValueTask HandleAsync(ValidateIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); if (!context.Principal.HasTokenType(TokenTypeHints.AccessToken) && @@ -782,13 +724,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateIntrospectionRequestContext context) + public ValueTask HandleAsync(ValidateIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); @@ -848,13 +785,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleIntrospectionRequestContext context) + public ValueTask HandleAsync(HandleIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = context.Transaction.GetProperty( typeof(ValidateIntrospectionRequestContext).FullName!) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0007)); @@ -883,13 +815,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleIntrospectionRequestContext context) + public ValueTask HandleAsync(HandleIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); context.TokenId = context.Principal.GetClaim(Claims.JwtId); @@ -926,7 +853,7 @@ public static partial class OpenIddictServerHandlers public AttachApplicationClaims() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public AttachApplicationClaims(IOpenIddictApplicationManager applicationManager) + public AttachApplicationClaims(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -942,13 +869,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(HandleIntrospectionRequestContext context) + public async ValueTask HandleAsync(HandleIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.Request.ClientId), SR.FormatID4000(Parameters.ClientId)); Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); @@ -1103,13 +1025,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ApplyIntrospectionResponseContext context) + public ValueTask HandleAsync(ApplyIntrospectionResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (string.IsNullOrEmpty(context.Error)) { return default; diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs index 8c035be0..61936172 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs @@ -60,13 +60,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var parameters = context.Options.TokenValidationParameters.Clone(); parameters.ValidIssuer ??= context.Issuer?.AbsoluteUri; parameters.ValidateIssuer = !string.IsNullOrEmpty(parameters.ValidIssuer); @@ -127,7 +122,7 @@ public static partial class OpenIddictServerHandlers public ValidateReferenceTokenIdentifier() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateReferenceTokenIdentifier(IOpenIddictTokenManager tokenManager) + public ValidateReferenceTokenIdentifier(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -142,13 +137,8 @@ public static partial class OpenIddictServerHandlers .SetType(OpenIddictServerHandlerType.BuiltIn) .Build(); - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var token = context.Token.Length switch { // 12 may correspond to a normalized user code and 43 to any @@ -255,13 +245,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a principal was already attached, don't overwrite it. if (context.Principal is not null) { @@ -406,13 +391,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Principal is null) { return default; @@ -451,13 +431,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Principal is null) { return default; @@ -548,7 +523,7 @@ public static partial class OpenIddictServerHandlers public RestoreReferenceTokenProperties() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public RestoreReferenceTokenProperties(IOpenIddictTokenManager tokenManager) + public RestoreReferenceTokenProperties(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -563,13 +538,8 @@ public static partial class OpenIddictServerHandlers .SetType(OpenIddictServerHandlerType.BuiltIn) .Build(); - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Principal is null || string.IsNullOrEmpty(context.TokenId)) { return; @@ -606,13 +576,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Principal is null) { context.Reject( @@ -684,13 +649,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); var date = context.Principal.GetExpirationDate(); @@ -737,7 +697,7 @@ public static partial class OpenIddictServerHandlers public ValidateTokenEntry() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateTokenEntry(IOpenIddictTokenManager tokenManager) + public ValidateTokenEntry(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -752,13 +712,8 @@ public static partial class OpenIddictServerHandlers .SetType(OpenIddictServerHandlerType.BuiltIn) .Build(); - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Extract the token identifier from the authentication principal. @@ -940,7 +895,7 @@ public static partial class OpenIddictServerHandlers public ValidateAuthorizationEntry() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateAuthorizationEntry(IOpenIddictAuthorizationManager authorizationManager) + public ValidateAuthorizationEntry(IOpenIddictAuthorizationManager authorizationManager!!) => _authorizationManager = authorizationManager; /// @@ -955,13 +910,8 @@ public static partial class OpenIddictServerHandlers .SetType(OpenIddictServerHandlerType.BuiltIn) .Build(); - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); var identifier = context.Principal.GetAuthorizationId(); @@ -1015,13 +965,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(GenerateTokenContext context) + public ValueTask HandleAsync(GenerateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.SecurityTokenHandler = context.Options.JsonWebTokenHandler; context.EncryptionCredentials = context.TokenType switch @@ -1080,13 +1025,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(GenerateTokenContext context) + public async ValueTask HandleAsync(GenerateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var descriptor = new OpenIddictTokenDescriptor { AuthorizationId = context.Principal.GetAuthorizationId(), @@ -1160,13 +1100,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(GenerateTokenContext context) + public ValueTask HandleAsync(GenerateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a token was already attached by another handler, don't overwrite it. if (!string.IsNullOrEmpty(context.Token)) { @@ -1277,7 +1212,7 @@ public static partial class OpenIddictServerHandlers public ConvertReferenceToken() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ConvertReferenceToken(IOpenIddictTokenManager tokenManager) + public ConvertReferenceToken(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -1294,13 +1229,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(GenerateTokenContext context) + public async ValueTask HandleAsync(GenerateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var identifier = context.Principal.GetTokenId(); if (string.IsNullOrEmpty(identifier)) { @@ -1395,12 +1325,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(GenerateTokenContext context) + public ValueTask HandleAsync(GenerateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // To make user codes easier to read and type by humans, a dash is automatically // appended before each new block of 4 integers. These dashes are expected to be diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs index 8169b611..f7c0fda9 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs @@ -56,7 +56,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractRevocationRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractRevocationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -71,13 +71,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractRevocationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -118,7 +113,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateRevocationRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateRevocationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -133,13 +128,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateRevocationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -179,7 +169,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleRevocationRequest(IOpenIddictServerDispatcher dispatcher) + public HandleRevocationRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -194,13 +184,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleRevocationRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -236,7 +221,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyRevocationResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyRevocationResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -251,13 +236,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyRevocationResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -293,12 +273,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateRevocationRequestContext context) + public ValueTask HandleAsync(ValidateRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reject revocation requests missing the mandatory token parameter. if (string.IsNullOrEmpty(context.Request.Token)) @@ -333,12 +309,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateRevocationRequestContext context) + public ValueTask HandleAsync(ValidateRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // At this stage, reject the revocation request unless the client identification requirement was disabled. if (!context.Options.AcceptAnonymousClients && string.IsNullOrEmpty(context.ClientId)) @@ -367,7 +339,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientId() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientId(IOpenIddictApplicationManager applicationManager) + public ValidateClientId(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -383,13 +355,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateRevocationRequestContext context) + public async ValueTask HandleAsync(ValidateRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); // Retrieve the application details corresponding to the requested client_id. @@ -420,7 +387,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientType() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientType(IOpenIddictApplicationManager applicationManager) + public ValidateClientType(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -436,13 +403,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateRevocationRequestContext context) + public async ValueTask HandleAsync(ValidateRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -494,7 +456,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientSecret() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientSecret(IOpenIddictApplicationManager applicationManager) + public ValidateClientSecret(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -510,13 +472,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateRevocationRequestContext context) + public async ValueTask HandleAsync(ValidateRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -558,7 +515,7 @@ public static partial class OpenIddictServerHandlers public ValidateEndpointPermissions() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager) + public ValidateEndpointPermissions(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -575,13 +532,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateRevocationRequestContext context) + public async ValueTask HandleAsync(ValidateRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); var application = await _applicationManager.FindByClientIdAsync(context.ClientId); @@ -612,7 +564,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateToken(IOpenIddictServerDispatcher dispatcher) + public ValidateToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -626,13 +578,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateRevocationRequestContext context) + public async ValueTask HandleAsync(ValidateRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ProcessAuthenticationContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -682,13 +629,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateRevocationRequestContext context) + public ValueTask HandleAsync(ValidateRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); if (!context.Principal.HasTokenType(TokenTypeHints.AccessToken) && @@ -729,13 +671,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateRevocationRequestContext context) + public ValueTask HandleAsync(ValidateRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.ClientId), SR.FormatID4000(Parameters.ClientId)); Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); @@ -795,13 +732,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleRevocationRequestContext context) + public ValueTask HandleAsync(HandleRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = context.Transaction.GetProperty( typeof(ValidateRevocationRequestContext).FullName!) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0007)); @@ -824,7 +756,7 @@ public static partial class OpenIddictServerHandlers public RevokeToken() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public RevokeToken(IOpenIddictTokenManager tokenManager) + public RevokeToken(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -839,13 +771,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(HandleRevocationRequestContext context) + public async ValueTask HandleAsync(HandleRevocationRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Extract the token identifier from the authentication principal. @@ -904,13 +831,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ApplyRevocationResponseContext context) + public ValueTask HandleAsync(ApplyRevocationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (string.IsNullOrEmpty(context.Error)) { return default; diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs index 11272efd..b089821f 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs @@ -44,7 +44,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractLogoutRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractLogoutRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -59,13 +59,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractLogoutRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -106,7 +101,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateLogoutRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateLogoutRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -121,13 +116,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateLogoutRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -167,7 +157,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleLogoutRequest(IOpenIddictServerDispatcher dispatcher) + public HandleLogoutRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -182,13 +172,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleLogoutRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -263,7 +248,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyLogoutResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyLogoutResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -278,13 +263,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyLogoutResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -320,13 +300,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateLogoutRequestContext context) + public ValueTask HandleAsync(ValidateLogoutRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (string.IsNullOrEmpty(context.PostLogoutRedirectUri)) { return default; @@ -371,7 +346,7 @@ public static partial class OpenIddictServerHandlers public ValidateClientPostLogoutRedirectUri() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public ValidateClientPostLogoutRedirectUri(IOpenIddictApplicationManager applicationManager) + public ValidateClientPostLogoutRedirectUri(IOpenIddictApplicationManager applicationManager!!) => _applicationManager = applicationManager; /// @@ -387,13 +362,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateLogoutRequestContext context) + public async ValueTask HandleAsync(ValidateLogoutRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(!string.IsNullOrEmpty(context.PostLogoutRedirectUri), SR.FormatID4000(Parameters.PostLogoutRedirectUri)); if (!await ValidatePostLogoutRedirectUriAsync(context.PostLogoutRedirectUri)) @@ -444,13 +414,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ApplyLogoutResponseContext context) + public ValueTask HandleAsync(ApplyLogoutResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Request is null) { return default; @@ -486,12 +451,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ApplyLogoutResponseContext context) + public ValueTask HandleAsync(ApplyLogoutResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Attach the request state to the logout response. if (string.IsNullOrEmpty(context.Response.State)) diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs index 41652727..b528a2c8 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs @@ -46,7 +46,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ExtractUserinfoRequest(IOpenIddictServerDispatcher dispatcher) + public ExtractUserinfoRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -61,13 +61,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ExtractUserinfoRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -108,7 +103,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateUserinfoRequest(IOpenIddictServerDispatcher dispatcher) + public ValidateUserinfoRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -123,13 +118,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ValidateUserinfoRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -169,7 +159,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public HandleUserinfoRequest(IOpenIddictServerDispatcher dispatcher) + public HandleUserinfoRequest(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -184,13 +174,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessRequestContext context) + public async ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new HandleUserinfoRequestContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -261,7 +246,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ApplyUserinfoResponse(IOpenIddictServerDispatcher dispatcher) + public ApplyUserinfoResponse(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -276,13 +261,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ApplyUserinfoResponseContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -318,13 +298,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ValidateUserinfoRequestContext context) + public ValueTask HandleAsync(ValidateUserinfoRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (string.IsNullOrEmpty(context.Request.AccessToken)) { context.Logger.LogInformation(SR.GetResourceString(SR.ID6131), Parameters.AccessToken); @@ -348,7 +323,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateToken(IOpenIddictServerDispatcher dispatcher) + public ValidateToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -362,13 +337,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateUserinfoRequestContext context) + public async ValueTask HandleAsync(ValidateUserinfoRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new ProcessAuthenticationContext(context.Transaction); await _dispatcher.DispatchAsync(notification); @@ -419,13 +389,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleUserinfoRequestContext context) + public ValueTask HandleAsync(HandleUserinfoRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = context.Transaction.GetProperty( typeof(ValidateUserinfoRequestContext).FullName!) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0007)); @@ -454,13 +419,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleUserinfoRequestContext context) + public ValueTask HandleAsync(HandleUserinfoRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Note: when receiving an access token, its audiences list cannot be used for the "aud" claim @@ -488,13 +448,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(HandleUserinfoRequestContext context) + public ValueTask HandleAsync(HandleUserinfoRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); context.Subject = context.Principal.GetClaim(Claims.Subject); diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.cs index bcdf9045..1a3a9cb3 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.cs @@ -114,13 +114,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - switch (context.EndpointType) { case OpenIddictServerEndpointType.Authorization: @@ -158,13 +153,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - (context.ExtractAccessToken, context.RequireAccessToken, context.ValidateAccessToken) = context.EndpointType switch @@ -258,13 +248,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.AccessToken = context.EndpointType switch { OpenIddictServerEndpointType.Userinfo when context.ExtractAccessToken @@ -343,13 +328,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if ((context.RequireAccessToken && string.IsNullOrEmpty(context.AccessToken)) || (context.RequireAuthorizationCode && string.IsNullOrEmpty(context.AuthorizationCode)) || (context.RequireDeviceCode && string.IsNullOrEmpty(context.DeviceCode)) || @@ -377,7 +357,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateAccessToken(IOpenIddictServerDispatcher dispatcher) + public ValidateAccessToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -392,13 +372,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.AccessTokenPrincipal is not null || string.IsNullOrEmpty(context.AccessToken)) { return; @@ -444,7 +419,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateAuthorizationCode(IOpenIddictServerDispatcher dispatcher) + public ValidateAuthorizationCode(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -459,13 +434,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.AuthorizationCodePrincipal is not null || string.IsNullOrEmpty(context.AuthorizationCode)) { return; @@ -511,7 +481,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateDeviceCode(IOpenIddictServerDispatcher dispatcher) + public ValidateDeviceCode(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -526,13 +496,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.DeviceCodePrincipal is not null || string.IsNullOrEmpty(context.DeviceCode)) { return; @@ -578,7 +543,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateGenericToken(IOpenIddictServerDispatcher dispatcher) + public ValidateGenericToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -593,13 +558,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.GenericTokenPrincipal is not null || string.IsNullOrEmpty(context.GenericToken)) { return; @@ -652,7 +612,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateIdentityToken(IOpenIddictServerDispatcher dispatcher) + public ValidateIdentityToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -667,13 +627,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.IdentityTokenPrincipal is not null || string.IsNullOrEmpty(context.IdentityToken)) { return; @@ -722,7 +677,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateRefreshToken(IOpenIddictServerDispatcher dispatcher) + public ValidateRefreshToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -737,13 +692,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.RefreshTokenPrincipal is not null || string.IsNullOrEmpty(context.RefreshToken)) { return; @@ -789,7 +739,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public ValidateUserCode(IOpenIddictServerDispatcher dispatcher) + public ValidateUserCode(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -804,13 +754,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.UserCodePrincipal is not null || string.IsNullOrEmpty(context.UserCode)) { return; @@ -865,13 +810,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.EndpointType is not (OpenIddictServerEndpointType.Authorization or OpenIddictServerEndpointType.Token or OpenIddictServerEndpointType.Userinfo or @@ -900,13 +840,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!context.Parameters.ContainsKey(Parameters.Error)) { context.Parameters[Parameters.Error] = context.EndpointType switch @@ -963,7 +898,7 @@ public static partial class OpenIddictServerHandlers public RejectDeviceCodeEntry() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public RejectDeviceCodeEntry(IOpenIddictTokenManager tokenManager) + public RejectDeviceCodeEntry(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -979,13 +914,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.EndpointType != OpenIddictServerEndpointType.Verification) { return; @@ -1022,7 +952,7 @@ public static partial class OpenIddictServerHandlers public RejectUserCodeEntry() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public RejectUserCodeEntry(IOpenIddictTokenManager tokenManager) + public RejectUserCodeEntry(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -1038,13 +968,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessChallengeContext context) + public async ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.EndpointType != OpenIddictServerEndpointType.Verification) { return; @@ -1087,13 +1012,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Parameters.Count > 0) { foreach (var parameter in context.Parameters) @@ -1123,13 +1043,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.EndpointType is not (OpenIddictServerEndpointType.Authorization or OpenIddictServerEndpointType.Device or OpenIddictServerEndpointType.Token or @@ -1146,7 +1061,7 @@ public static partial class OpenIddictServerHandlers // Note: sign-in operations triggered from the device endpoint can't be associated to specific users // as users' identity is not known until they reach the verification endpoint and validate the user code. // As such, the principal used in this case cannot contain an authenticated identity or a subject claim. - if (context.EndpointType == OpenIddictServerEndpointType.Device) + if (context.EndpointType is OpenIddictServerEndpointType.Device) { if (context.Principal.Identity.IsAuthenticated) { @@ -1192,13 +1107,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); switch (context.EndpointType) @@ -1251,7 +1161,7 @@ public static partial class OpenIddictServerHandlers } // When the request is a verification request, don't flow the scopes from the user code. - if (context.EndpointType == OpenIddictServerEndpointType.Verification && + if (context.EndpointType is OpenIddictServerEndpointType.Verification && string.Equals(claims.Key, Claims.Private.Scope, StringComparison.OrdinalIgnoreCase)) { continue; @@ -1280,13 +1190,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Always include the "openid" scope when the developer doesn't explicitly call SetScopes. @@ -1317,13 +1222,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Add the validated client_id to the list of authorized presenters, @@ -1353,13 +1253,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // When a "resources" property cannot be found in the ticket, infer it from the "audiences" property. @@ -1393,13 +1288,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); (context.GenerateAccessToken, context.IncludeAccessToken) = context.EndpointType switch @@ -1487,8 +1377,8 @@ public static partial class OpenIddictServerHandlers public AttachAuthorization() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); public AttachAuthorization( - IOpenIddictApplicationManager applicationManager, - IOpenIddictAuthorizationManager authorizationManager) + IOpenIddictApplicationManager applicationManager!!, + IOpenIddictAuthorizationManager authorizationManager!!) { _applicationManager = applicationManager; _authorizationManager = authorizationManager; @@ -1507,13 +1397,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessSignInContext context) + public async ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // If no authorization code, device code or refresh token is returned, don't create an authorization. @@ -1593,13 +1478,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Create a new principal containing only the filtered claims. @@ -1678,7 +1558,7 @@ public static partial class OpenIddictServerHandlers // When receiving a grant_type=refresh_token request, determine whether the client application // requests a limited set of scopes and immediately replace the scopes collection if necessary. - if (context.EndpointType == OpenIddictServerEndpointType.Token && + if (context.EndpointType is OpenIddictServerEndpointType.Token && context.Request.IsRefreshTokenGrantType() && !string.IsNullOrEmpty(context.Request.Scope)) { var scopes = context.Request.GetScopes(); @@ -1711,13 +1591,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Create a new principal containing only the filtered claims. @@ -1797,13 +1672,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Create a new principal containing only the filtered claims. @@ -1841,7 +1711,7 @@ public static partial class OpenIddictServerHandlers // Restore the device code internal token identifier from the principal // resolved from the user code used in the user code verification request. - if (context.EndpointType == OpenIddictServerEndpointType.Verification) + if (context.EndpointType is OpenIddictServerEndpointType.Verification) { principal.SetClaim(Claims.Private.TokenId, context.Principal.GetClaim(Claims.Private.DeviceCodeId)); } @@ -1870,13 +1740,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Create a new principal containing only the filtered claims. @@ -1908,7 +1773,7 @@ public static partial class OpenIddictServerHandlers // When sliding expiration is disabled, the expiration date of generated refresh tokens is fixed // and must exactly match the expiration date of the refresh token used in the token request. - if (context.EndpointType == OpenIddictServerEndpointType.Token && + if (context.EndpointType is OpenIddictServerEndpointType.Token && context.Request.IsRefreshTokenGrantType() && context.Options.DisableSlidingRefreshTokenExpiration) { @@ -1954,13 +1819,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Replace the principal by a new one containing only the filtered claims. @@ -2067,13 +1927,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // Create a new principal containing only the filtered claims. @@ -2129,7 +1984,7 @@ public static partial class OpenIddictServerHandlers public RedeemTokenEntry() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public RedeemTokenEntry(IOpenIddictTokenManager tokenManager) + public RedeemTokenEntry(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -2145,13 +2000,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessSignInContext context) + public async ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - switch (context.EndpointType) { case OpenIddictServerEndpointType.Token when context.Request.IsAuthorizationCodeGrantType(): @@ -2191,7 +2041,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public GenerateAccessToken(IOpenIddictServerDispatcher dispatcher) + public GenerateAccessToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -2206,13 +2056,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessSignInContext context) + public async ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new GenerateTokenContext(context.Transaction) { ClientId = context.ClientId, @@ -2258,7 +2103,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public GenerateAuthorizationCode(IOpenIddictServerDispatcher dispatcher) + public GenerateAuthorizationCode(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -2273,13 +2118,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessSignInContext context) + public async ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new GenerateTokenContext(context.Transaction) { ClientId = context.ClientId, @@ -2323,7 +2163,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public GenerateDeviceCode(IOpenIddictServerDispatcher dispatcher) + public GenerateDeviceCode(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -2338,13 +2178,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessSignInContext context) + public async ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new GenerateTokenContext(context.Transaction) { ClientId = context.ClientId, @@ -2395,7 +2230,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public GenerateRefreshToken(IOpenIddictServerDispatcher dispatcher) + public GenerateRefreshToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -2410,13 +2245,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessSignInContext context) + public async ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new GenerateTokenContext(context.Transaction) { ClientId = context.ClientId, @@ -2473,13 +2303,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.UserCodePrincipal is null) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0020)); @@ -2505,7 +2330,7 @@ public static partial class OpenIddictServerHandlers public UpdateReferenceDeviceCodeEntry() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); - public UpdateReferenceDeviceCodeEntry(IOpenIddictTokenManager tokenManager) + public UpdateReferenceDeviceCodeEntry(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -2522,13 +2347,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessSignInContext context) + public async ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.EndpointType != OpenIddictServerEndpointType.Verification || string.IsNullOrEmpty(context.DeviceCode)) { return; @@ -2590,13 +2410,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.IdentityTokenPrincipal is null) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0022)); @@ -2707,7 +2522,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public GenerateUserCode(IOpenIddictServerDispatcher dispatcher) + public GenerateUserCode(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -2722,13 +2537,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessSignInContext context) + public async ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new GenerateTokenContext(context.Transaction) { ClientId = context.ClientId, @@ -2772,7 +2582,7 @@ public static partial class OpenIddictServerHandlers { private readonly IOpenIddictServerDispatcher _dispatcher; - public GenerateIdentityToken(IOpenIddictServerDispatcher dispatcher) + public GenerateIdentityToken(IOpenIddictServerDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -2787,13 +2597,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessSignInContext context) + public async ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var notification = new GenerateTokenContext(context.Transaction) { ClientId = context.ClientId, @@ -2847,13 +2652,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignInContext context) + public ValueTask HandleAsync(ProcessSignInContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.IncludeAccessToken) { context.Response.AccessToken = context.AccessToken; @@ -2872,7 +2672,7 @@ public static partial class OpenIddictServerHandlers // If the granted access token scopes differ from the requested scopes, return the granted scopes // list as a parameter to inform the client application of the fact the scopes set will be reduced. var scopes = new HashSet(context.AccessTokenPrincipal.GetScopes(), StringComparer.Ordinal); - if ((context.EndpointType == OpenIddictServerEndpointType.Token && context.Request.IsAuthorizationCodeGrantType()) || + if ((context.EndpointType is OpenIddictServerEndpointType.Token && context.Request.IsAuthorizationCodeGrantType()) || !scopes.SetEquals(context.Request.GetScopes())) { context.Response.Scope = string.Join(" ", scopes); @@ -2994,13 +2794,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignOutContext context) + public ValueTask HandleAsync(ProcessSignOutContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.EndpointType != OpenIddictServerEndpointType.Logout) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0024)); @@ -3026,13 +2821,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessSignOutContext context) + public ValueTask HandleAsync(ProcessSignOutContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Parameters.Count > 0) { foreach (var parameter in context.Parameters) @@ -3061,13 +2851,8 @@ public static partial class OpenIddictServerHandlers .Build(); /// - public ValueTask HandleAsync(ProcessErrorContext context) + public ValueTask HandleAsync(ProcessErrorContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Response.Error = context.Error; context.Response.ErrorDescription = context.ErrorDescription; context.Response.ErrorUri = context.ErrorUri; diff --git a/src/OpenIddict.Server/OpenIddictServerHelpers.cs b/src/OpenIddict.Server/OpenIddictServerHelpers.cs index 5362a204..895ac102 100644 --- a/src/OpenIddict.Server/OpenIddictServerHelpers.cs +++ b/src/OpenIddict.Server/OpenIddictServerHelpers.cs @@ -19,13 +19,8 @@ public static class OpenIddictServerHelpers /// The property name. /// The property value or null if it couldn't be found. public static TProperty? GetProperty( - this OpenIddictServerTransaction transaction, string name) where TProperty : class + this OpenIddictServerTransaction transaction!!, string name) where TProperty : class { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (string.IsNullOrEmpty(name)) { throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name)); @@ -48,14 +43,9 @@ public static class OpenIddictServerHelpers /// The property value. /// The server transaction, so that calls can be easily chained. public static OpenIddictServerTransaction SetProperty( - this OpenIddictServerTransaction transaction, + this OpenIddictServerTransaction transaction!!, string name, TProperty? value) where TProperty : class { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (string.IsNullOrEmpty(name)) { throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name)); diff --git a/src/OpenIddict.Server/OpenIddictServerOptions.cs b/src/OpenIddict.Server/OpenIddictServerOptions.cs index 2399b57d..41ebf261 100644 --- a/src/OpenIddict.Server/OpenIddictServerOptions.cs +++ b/src/OpenIddict.Server/OpenIddictServerOptions.cs @@ -240,7 +240,7 @@ public class OpenIddictServerOptions /// Note: the list is automatically sorted based on the order assigned to each handler descriptor. /// As such, it MUST NOT be mutated after options initialization to preserve the exact order. /// - public List Handlers { get; } = new(OpenIddictServerHandlers.DefaultHandlers); + public List Handlers { get; } = new(DefaultHandlers); /// /// Gets or sets a boolean determining whether client identification is optional. diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreBuilder.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreBuilder.cs index ee0f1d49..c10b3023 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreBuilder.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreBuilder.cs @@ -19,8 +19,8 @@ public class OpenIddictValidationAspNetCoreBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictValidationAspNetCoreBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictValidationAspNetCoreBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -34,13 +34,8 @@ public class OpenIddictValidationAspNetCoreBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictValidationAspNetCoreBuilder Configure(Action configuration) + public OpenIddictValidationAspNetCoreBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreConfiguration.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreConfiguration.cs index 404515e5..366dba20 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreConfiguration.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreConfiguration.cs @@ -19,13 +19,8 @@ public class OpenIddictValidationAspNetCoreConfiguration : IConfigureOptions /// The options instance to initialize. - public void Configure(AuthenticationOptions options) + public void Configure(AuthenticationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // If a handler was already registered and the type doesn't correspond to the OpenIddict handler, throw an exception. if (options.SchemeMap.TryGetValue(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme, out var builder) && builder.HandlerType != typeof(OpenIddictValidationAspNetCoreHandler)) @@ -37,13 +32,8 @@ public class OpenIddictValidationAspNetCoreConfiguration : IConfigureOptions /// The name of the options instance to configure, if applicable. /// The options instance to initialize. - public void PostConfigure(string name, AuthenticationOptions options) + public void PostConfigure(string name, AuthenticationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - if (!TryValidate(options.SchemeMap, options.DefaultSignInScheme) || !TryValidate(options.SchemeMap, options.DefaultSignOutScheme)) { diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreExtensions.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreExtensions.cs index 29a56854..27d4e335 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreExtensions.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictValidationAspNetCoreExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictValidationAspNetCoreBuilder UseAspNetCore(this OpenIddictValidationBuilder builder) + public static OpenIddictValidationAspNetCoreBuilder UseAspNetCore(this OpenIddictValidationBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddAuthentication(); builder.Services.TryAddScoped(); @@ -61,18 +56,8 @@ public static class OpenIddictValidationAspNetCoreExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictValidationBuilder UseAspNetCore( - this OpenIddictValidationBuilder builder, Action configuration) + this OpenIddictValidationBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseAspNetCore()); return builder; diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs index 0713ab09..16bbab3a 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs @@ -25,12 +25,12 @@ public class OpenIddictValidationAspNetCoreHandler : AuthenticationHandler class. /// public OpenIddictValidationAspNetCoreHandler( - IOpenIddictValidationDispatcher dispatcher, - IOpenIddictValidationFactory factory, - IOptionsMonitor options, - ILoggerFactory logger, - UrlEncoder encoder, - ISystemClock clock) + IOpenIddictValidationDispatcher dispatcher!!, + IOpenIddictValidationFactory factory!!, + IOptionsMonitor options!!, + ILoggerFactory logger!!, + UrlEncoder encoder!!, + ISystemClock clock!!) : base(options, logger, encoder, clock) { _dispatcher = dispatcher; diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlerFilters.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlerFilters.cs index b2b877ba..a761a72b 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlerFilters.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlerFilters.cs @@ -20,14 +20,7 @@ public static class OpenIddictValidationAspNetCoreHandlerFilters /// public class RequireHttpRequest : IOpenIddictValidationHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Transaction.GetHttpRequest() is not null); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Transaction.GetHttpRequest() is not null); } } diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs index 563bfdf4..c0afeb21 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs @@ -73,20 +73,12 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessRequestContext context) + public ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Only use the current host as the issuer if the // issuer was not explicitly set in the options. @@ -141,13 +133,8 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a token was already resolved, don't overwrite it. if (!string.IsNullOrEmpty(context.AccessToken)) { @@ -156,11 +143,8 @@ public static partial class OpenIddictValidationAspNetCoreHandlers // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Resolve the access token from the standard Authorization header. // See https://tools.ietf.org/html/rfc6750#section-2.1 for more information. @@ -195,13 +179,8 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a token was already resolved, don't overwrite it. if (!string.IsNullOrEmpty(context.AccessToken)) { @@ -210,11 +189,8 @@ public static partial class OpenIddictValidationAspNetCoreHandlers // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } if (string.IsNullOrEmpty(request.ContentType) || !request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase)) @@ -253,13 +229,8 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a token was already resolved, don't overwrite it. if (!string.IsNullOrEmpty(context.AccessToken)) { @@ -268,11 +239,8 @@ public static partial class OpenIddictValidationAspNetCoreHandlers // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetHttpRequest(); - if (request is null) - { + var request = context.Transaction.GetHttpRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Resolve the access token from the standard access_token query parameter. // See https://tools.ietf.org/html/rfc6750#section-2.3 for more information. @@ -305,13 +273,8 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var properties = context.Transaction.GetProperty(typeof(AuthenticationProperties).FullName!); if (properties is null) { @@ -380,22 +343,14 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } response.StatusCode = context.Transaction.Response.Error switch { @@ -430,20 +385,12 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // Prevent the response from being cached. response.Headers[HeaderNames.CacheControl] = "no-store"; @@ -462,7 +409,7 @@ public static partial class OpenIddictValidationAspNetCoreHandlers { private readonly IOptionsMonitor _options; - public AttachWwwAuthenticateHeader(IOptionsMonitor options) + public AttachWwwAuthenticateHeader(IOptionsMonitor options!!) => _options = options; /// @@ -477,22 +424,14 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } var scheme = context.Transaction.Response.Error switch { @@ -582,20 +521,12 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } // If the response doesn't contain a WWW-Authenticate header, don't return an empty response. if (!response.Headers.ContainsKey(HeaderNames.WWWAuthenticate)) @@ -628,22 +559,14 @@ public static partial class OpenIddictValidationAspNetCoreHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetHttpRequest()?.HttpContext.Response; - if (response is null) - { + var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0114)); - } context.Logger.LogInformation(SR.GetResourceString(SR.ID6142), context.Transaction.Response); diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHelpers.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHelpers.cs index 27d43f17..ec3d0526 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHelpers.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHelpers.cs @@ -19,13 +19,8 @@ public static class OpenIddictValidationAspNetCoreHelpers /// /// The transaction instance. /// The instance or null if it couldn't be found. - public static HttpRequest? GetHttpRequest(this OpenIddictValidationTransaction transaction) + public static HttpRequest? GetHttpRequest(this OpenIddictValidationTransaction transaction!!) { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (!transaction.Properties.TryGetValue(typeof(HttpRequest).FullName!, out object? property)) { return null; @@ -44,13 +39,8 @@ public static class OpenIddictValidationAspNetCoreHelpers /// /// The context instance. /// The . - public static OpenIddictValidationEndpointType GetOpenIddictValidationEndpointType(this HttpContext context) + public static OpenIddictValidationEndpointType GetOpenIddictValidationEndpointType(this HttpContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - return context.Features.Get()?.Transaction?.EndpointType ?? default; } @@ -59,13 +49,8 @@ public static class OpenIddictValidationAspNetCoreHelpers /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictRequest? GetOpenIddictValidationRequest(this HttpContext context) + public static OpenIddictRequest? GetOpenIddictValidationRequest(this HttpContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - return context.Features.Get()?.Transaction?.Request; } @@ -74,13 +59,8 @@ public static class OpenIddictValidationAspNetCoreHelpers /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictResponse? GetOpenIddictValidationResponse(this HttpContext context) + public static OpenIddictResponse? GetOpenIddictValidationResponse(this HttpContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - return context.Features.Get()?.Transaction?.Response; } } diff --git a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionBuilder.cs b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionBuilder.cs index 4f7bc1db..698bba3e 100644 --- a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionBuilder.cs +++ b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionBuilder.cs @@ -20,8 +20,8 @@ public class OpenIddictValidationDataProtectionBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictValidationDataProtectionBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictValidationDataProtectionBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -35,13 +35,8 @@ public class OpenIddictValidationDataProtectionBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictValidationDataProtectionBuilder Configure(Action configuration) + public OpenIddictValidationDataProtectionBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -53,30 +48,16 @@ public class OpenIddictValidationDataProtectionBuilder /// /// The data protection provider used to create token protectors. /// The . - public OpenIddictValidationDataProtectionBuilder UseDataProtectionProvider(IDataProtectionProvider provider) - { - if (provider is null) - { - throw new ArgumentNullException(nameof(provider)); - } - - return Configure(options => options.DataProtectionProvider = provider); - } + public OpenIddictValidationDataProtectionBuilder UseDataProtectionProvider(IDataProtectionProvider provider!!) + => Configure(options => options.DataProtectionProvider = provider); /// /// Configures OpenIddict to use a specific formatter instead of relying on the default instance. /// /// The formatter used to read tokens. /// The . - public OpenIddictValidationDataProtectionBuilder UseFormatter(IOpenIddictValidationDataProtectionFormatter formatter) - { - if (formatter is null) - { - throw new ArgumentNullException(nameof(formatter)); - } - - return Configure(options => options.Formatter = formatter); - } + public OpenIddictValidationDataProtectionBuilder UseFormatter(IOpenIddictValidationDataProtectionFormatter formatter!!) + => Configure(options => options.Formatter = formatter); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionConfiguration.cs b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionConfiguration.cs index c8d4b5e1..ecdbe7b1 100644 --- a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionConfiguration.cs +++ b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionConfiguration.cs @@ -21,16 +21,11 @@ public class OpenIddictValidationDataProtectionConfiguration : IConfigureOptions /// Creates a new instance of the class. /// /// The ASP.NET Core Data Protection provider. - public OpenIddictValidationDataProtectionConfiguration(IDataProtectionProvider dataProtectionProvider) + public OpenIddictValidationDataProtectionConfiguration(IDataProtectionProvider dataProtectionProvider!!) => _dataProtectionProvider = dataProtectionProvider; - public void Configure(OpenIddictValidationOptions options) + public void Configure(OpenIddictValidationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // Register the built-in event handlers used by the OpenIddict Data Protection validation components. options.Handlers.AddRange(OpenIddictValidationDataProtectionHandlers.DefaultHandlers); } @@ -41,13 +36,6 @@ public class OpenIddictValidationDataProtectionConfiguration : IConfigureOptions /// /// The name of the options instance to configure, if applicable. /// The options instance to initialize. - public void PostConfigure(string name, OpenIddictValidationDataProtectionOptions options) - { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - - options.DataProtectionProvider ??= _dataProtectionProvider; - } + public void PostConfigure(string name, OpenIddictValidationDataProtectionOptions options!!) + => options.DataProtectionProvider ??= _dataProtectionProvider; } diff --git a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionExtensions.cs b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionExtensions.cs index 47abc50e..d062f8a9 100644 --- a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionExtensions.cs +++ b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictValidationDataProtectionExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictValidationDataProtectionBuilder UseDataProtection(this OpenIddictValidationBuilder builder) + public static OpenIddictValidationDataProtectionBuilder UseDataProtection(this OpenIddictValidationBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddDataProtection(); // Register the built-in validation event handlers used by the OpenIddict Data Protection components. @@ -53,18 +48,8 @@ public static class OpenIddictValidationDataProtectionExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictValidationBuilder UseDataProtection( - this OpenIddictValidationBuilder builder, Action configuration) + this OpenIddictValidationBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseDataProtection()); return builder; diff --git a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs index 360831f0..e423976e 100644 --- a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs +++ b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs @@ -13,13 +13,8 @@ namespace OpenIddict.Validation.DataProtection; public class OpenIddictValidationDataProtectionFormatter : IOpenIddictValidationDataProtectionFormatter { - public ClaimsPrincipal ReadToken(BinaryReader reader) + public ClaimsPrincipal ReadToken(BinaryReader reader!!) { - if (reader is null) - { - throw new ArgumentNullException(nameof(reader)); - } - var (principal, properties) = Read(reader); // Tokens serialized using the ASP.NET Core Data Protection stack are compound diff --git a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.Protection.cs b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.Protection.cs index bd5d48a1..14347b48 100644 --- a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.Protection.cs +++ b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.Protection.cs @@ -33,7 +33,7 @@ public static partial class OpenIddictValidationDataProtectionHandlers { private readonly IOptionsMonitor _options; - public ValidateDataProtectionToken(IOptionsMonitor options) + public ValidateDataProtectionToken(IOptionsMonitor options!!) => _options = options; /// diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinBuilder.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinBuilder.cs index 20af2ae5..0961d24d 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinBuilder.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinBuilder.cs @@ -19,8 +19,8 @@ public class OpenIddictValidationOwinBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictValidationOwinBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictValidationOwinBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -34,13 +34,8 @@ public class OpenIddictValidationOwinBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictValidationOwinBuilder Configure(Action configuration) + public OpenIddictValidationOwinBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinConfiguration.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinConfiguration.cs index fb033ae1..9c8d3a2c 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinConfiguration.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinConfiguration.cs @@ -13,13 +13,8 @@ namespace OpenIddict.Validation.Owin; /// public class OpenIddictValidationOwinConfiguration : IConfigureOptions { - public void Configure(OpenIddictValidationOptions options) + public void Configure(OpenIddictValidationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // Register the built-in event handlers used by the OpenIddict OWIN validation components. options.Handlers.AddRange(OpenIddictValidationOwinHandlers.DefaultHandlers); } diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinExtensions.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinExtensions.cs index fe5f6bfe..65235164 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinExtensions.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictValidationOwinExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictValidationOwinBuilder UseOwin(this OpenIddictValidationBuilder builder) + public static OpenIddictValidationOwinBuilder UseOwin(this OpenIddictValidationBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - // Note: unlike regular OWIN middleware, the OpenIddict validation middleware is registered // as a scoped service in the DI container. This allows containers that support middleware // resolution (like Autofac) to use it without requiring additional configuration. @@ -59,18 +54,8 @@ public static class OpenIddictValidationOwinExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictValidationBuilder UseOwin( - this OpenIddictValidationBuilder builder, Action configuration) + this OpenIddictValidationBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseOwin()); return builder; diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs index b9044eac..1d1dc478 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs @@ -24,8 +24,8 @@ public class OpenIddictValidationOwinHandler : AuthenticationHandlerThe OpenIddict validation provider used by this instance. /// The OpenIddict validation factory used by this instance. public OpenIddictValidationOwinHandler( - IOpenIddictValidationDispatcher dispatcher, - IOpenIddictValidationFactory factory) + IOpenIddictValidationDispatcher dispatcher!!, + IOpenIddictValidationFactory factory!!) { _dispatcher = dispatcher; _factory = factory; diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlerFilters.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlerFilters.cs index 00232746..47d3b355 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlerFilters.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlerFilters.cs @@ -18,14 +18,7 @@ public static class OpenIddictValidationOwinHandlerFilters /// public class RequireOwinRequest : IOpenIddictValidationHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Transaction.GetOwinRequest() is not null); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Transaction.GetOwinRequest() is not null); } } diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs index df320029..bfe38fec 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs @@ -72,20 +72,12 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public ValueTask HandleAsync(ProcessRequestContext context) + public ValueTask HandleAsync(ProcessRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Only use the current host as the issuer if the // issuer was not explicitly set in the options. @@ -140,13 +132,8 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a token was already resolved, don't overwrite it. if (!string.IsNullOrEmpty(context.AccessToken)) { @@ -155,11 +142,8 @@ public static partial class OpenIddictValidationOwinHandlers // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Resolve the access token from the standard Authorization header. // See https://tools.ietf.org/html/rfc6750#section-2.1 for more information. @@ -194,13 +178,8 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a token was already resolved, don't overwrite it. if (!string.IsNullOrEmpty(context.AccessToken)) { @@ -209,11 +188,8 @@ public static partial class OpenIddictValidationOwinHandlers // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.IsNullOrEmpty(request.ContentType) || !request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase)) @@ -253,13 +229,8 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a token was already resolved, don't overwrite it. if (!string.IsNullOrEmpty(context.AccessToken)) { @@ -268,11 +239,8 @@ public static partial class OpenIddictValidationOwinHandlers // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var request = context.Transaction.GetOwinRequest(); - if (request is null) - { + var request = context.Transaction.GetOwinRequest() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Resolve the access token from the standard access_token query parameter. // See https://tools.ietf.org/html/rfc6750#section-2.3 for more information. @@ -306,13 +274,8 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var properties = context.Transaction.GetProperty(typeof(AuthenticationProperties).FullName!); if (properties is null) { @@ -365,22 +328,14 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } response.StatusCode = context.Transaction.Response.Error switch { @@ -415,20 +370,12 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // Prevent the response from being cached. response.Headers[Headers.CacheControl] = "no-store"; @@ -447,7 +394,7 @@ public static partial class OpenIddictValidationOwinHandlers { private readonly IOptionsMonitor _options; - public AttachWwwAuthenticateHeader(IOptionsMonitor options) + public AttachWwwAuthenticateHeader(IOptionsMonitor options!!) => _options = options; /// @@ -462,22 +409,14 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } if (string.IsNullOrEmpty(context.Transaction.Response.Error)) { @@ -572,20 +511,12 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } // If the response doesn't contain a WWW-Authenticate header, don't return an empty response. if (!response.Headers.ContainsKey(Headers.WwwAuthenticate)) @@ -618,22 +549,14 @@ public static partial class OpenIddictValidationOwinHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); // This handler only applies to OWIN requests. If The OWIN request cannot be resolved, // this may indicate that the request was incorrectly processed by another server stack. - var response = context.Transaction.GetOwinRequest()?.Context.Response; - if (response is null) - { + var response = context.Transaction.GetOwinRequest()?.Context.Response ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0120)); - } context.Logger.LogInformation(SR.GetResourceString(SR.ID6142), context.Transaction.Response); diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHelpers.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHelpers.cs index e9aed395..c7c228ea 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHelpers.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHelpers.cs @@ -21,28 +21,16 @@ public static class OpenIddictValidationOwinHelpers /// /// The application builder used to register middleware instances. /// The . - public static IAppBuilder UseOpenIddictValidation(this IAppBuilder app) - { - if (app is null) - { - throw new ArgumentNullException(nameof(app)); - } - - return app.Use(); - } + public static IAppBuilder UseOpenIddictValidation(this IAppBuilder app!!) + => app.Use(); /// /// Retrieves the instance stored in the properties. /// /// The transaction instance. /// The instance or null if it couldn't be found. - public static IOwinRequest? GetOwinRequest(this OpenIddictValidationTransaction transaction) + public static IOwinRequest? GetOwinRequest(this OpenIddictValidationTransaction transaction!!) { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (!transaction.Properties.TryGetValue(typeof(IOwinRequest).FullName!, out object? property)) { return null; @@ -61,43 +49,22 @@ public static class OpenIddictValidationOwinHelpers /// /// The context instance. /// The . - public static OpenIddictValidationEndpointType GetOpenIddictValidationEndpointType(this IOwinContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return context.Get(typeof(OpenIddictValidationTransaction).FullName)?.EndpointType ?? default; - } + public static OpenIddictValidationEndpointType GetOpenIddictValidationEndpointType(this IOwinContext context!!) + => context.Get(typeof(OpenIddictValidationTransaction).FullName)?.EndpointType ?? default; /// /// Retrieves the instance stored in . /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictRequest? GetOpenIddictValidationRequest(this IOwinContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return context.Get(typeof(OpenIddictValidationTransaction).FullName)?.Request; - } + public static OpenIddictRequest? GetOpenIddictValidationRequest(this IOwinContext context!!) + => context.Get(typeof(OpenIddictValidationTransaction).FullName)?.Request; /// /// Retrieves the instance stored in . /// /// The context instance. /// The instance or null if it couldn't be found. - public static OpenIddictResponse? GetOpenIddictValidationResponse(this IOwinContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return context.Get(typeof(OpenIddictValidationTransaction).FullName)?.Response; - } + public static OpenIddictResponse? GetOpenIddictValidationResponse(this IOwinContext context!!) + => context.Get(typeof(OpenIddictValidationTransaction).FullName)?.Response; } diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddleware.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddleware.cs index 6ca27fa4..346a450d 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddleware.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddleware.cs @@ -29,9 +29,9 @@ public class OpenIddictValidationOwinMiddleware : AuthenticationMiddlewareThe OpenIddict validation factory. public OpenIddictValidationOwinMiddleware( OwinMiddleware? next, - IOptionsMonitor options, - IOpenIddictValidationDispatcher dispatcher, - IOpenIddictValidationFactory factory) + IOptionsMonitor options!!, + IOpenIddictValidationDispatcher dispatcher!!, + IOpenIddictValidationFactory factory!!) : base(next, options.CurrentValue) { _dispatcher = dispatcher; diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddlewareFactory.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddlewareFactory.cs index 96d426c8..cf230953 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddlewareFactory.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddlewareFactory.cs @@ -33,13 +33,8 @@ public class OpenIddictValidationOwinMiddlewareFactory : OwinMiddleware /// /// A that can be used to monitor the asynchronous operation. /// - public override Task Invoke(IOwinContext context) + public override Task Invoke(IOwinContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var provider = context.Get(typeof(IServiceProvider).FullName); if (provider is null) { diff --git a/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationBuilder.cs b/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationBuilder.cs index be160ea1..cfa21024 100644 --- a/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationBuilder.cs +++ b/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationBuilder.cs @@ -18,8 +18,8 @@ public class OpenIddictValidationServerIntegrationBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictValidationServerIntegrationBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictValidationServerIntegrationBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -33,13 +33,9 @@ public class OpenIddictValidationServerIntegrationBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictValidationServerIntegrationBuilder Configure(Action configuration) + public OpenIddictValidationServerIntegrationBuilder Configure( + Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; diff --git a/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationConfiguration.cs b/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationConfiguration.cs index 94c3f474..aebf87c3 100644 --- a/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationConfiguration.cs +++ b/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationConfiguration.cs @@ -21,7 +21,7 @@ public class OpenIddictValidationServerIntegrationConfiguration : IConfigureOpti /// Creates a new instance of the class. /// /// The OpenIddict server options. - public OpenIddictValidationServerIntegrationConfiguration(IOptionsMonitor options) + public OpenIddictValidationServerIntegrationConfiguration(IOptionsMonitor options!!) => _options = options; /// @@ -29,13 +29,8 @@ public class OpenIddictValidationServerIntegrationConfiguration : IConfigureOpti /// and ensures that the configuration is in a consistent and valid state. /// /// The options instance to initialize. - public void Configure(OpenIddictValidationOptions options) + public void Configure(OpenIddictValidationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // Note: the issuer may be null. In this case, it will be usually provided by // a validation handler registered by the host (e.g ASP.NET Core or OWIN/Katana). options.Configuration = new OpenIddictConfiguration @@ -62,13 +57,8 @@ public class OpenIddictValidationServerIntegrationConfiguration : IConfigureOpti /// /// The name of the options instance to configure, if applicable. /// The options instance to initialize. - public void PostConfigure(string name, OpenIddictValidationOptions options) + public void PostConfigure(string name, OpenIddictValidationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - if (options.ValidationType != OpenIddictValidationType.Direct) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0170)); diff --git a/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationExtensions.cs b/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationExtensions.cs index bd8b74be..ef8457b8 100644 --- a/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationExtensions.cs +++ b/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationExtensions.cs @@ -23,13 +23,8 @@ public static class OpenIddictValidationServerIntegrationExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictValidationServerIntegrationBuilder UseLocalServer(this OpenIddictValidationBuilder builder) + public static OpenIddictValidationServerIntegrationBuilder UseLocalServer(this OpenIddictValidationBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - // Note: TryAddEnumerable() is used here to ensure the initializers are registered only once. builder.Services.TryAddEnumerable(new[] { @@ -49,18 +44,8 @@ public static class OpenIddictValidationServerIntegrationExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictValidationBuilder UseLocalServer( - this OpenIddictValidationBuilder builder, Action configuration) + this OpenIddictValidationBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseLocalServer()); return builder; diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs index 6ce2d98c..e31175ab 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs @@ -19,8 +19,8 @@ public class OpenIddictValidationSystemNetHttpBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictValidationSystemNetHttpBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictValidationSystemNetHttpBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -34,13 +34,8 @@ public class OpenIddictValidationSystemNetHttpBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictValidationSystemNetHttpBuilder Configure(Action configuration) + public OpenIddictValidationSystemNetHttpBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpConfiguration.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpConfiguration.cs index 0cd6f197..30a0524d 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpConfiguration.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpConfiguration.cs @@ -21,17 +21,12 @@ public class OpenIddictValidationSystemNetHttpConfiguration : IConfigureOptions< #if !SUPPORTS_SERVICE_PROVIDER_IN_HTTP_MESSAGE_HANDLER_BUILDER private readonly IServiceProvider _provider; - public OpenIddictValidationSystemNetHttpConfiguration(IServiceProvider provider) + public OpenIddictValidationSystemNetHttpConfiguration(IServiceProvider provider!!) => _provider = provider; #endif - public void Configure(OpenIddictValidationOptions options) + public void Configure(OpenIddictValidationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - // Register the built-in event handlers used by the OpenIddict System.Net.Http validation components. options.Handlers.AddRange(OpenIddictValidationSystemNetHttpHandlers.DefaultHandlers); } @@ -39,13 +34,8 @@ public class OpenIddictValidationSystemNetHttpConfiguration : IConfigureOptions< public void Configure(HttpClientFactoryOptions options) => Debug.Fail("This infrastructure method shouldn't be called."); - public void Configure(string name, HttpClientFactoryOptions options) + public void Configure(string name, HttpClientFactoryOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - var assembly = typeof(OpenIddictValidationSystemNetHttpOptions).Assembly.GetName(); if (!string.Equals(name, assembly.Name, StringComparison.Ordinal)) diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpExtensions.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpExtensions.cs index 92398e04..305760a8 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpExtensions.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpExtensions.cs @@ -23,13 +23,8 @@ public static class OpenIddictValidationSystemNetHttpExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictValidationSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictValidationBuilder builder) + public static OpenIddictValidationSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictValidationBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddHttpClient(); // Register the built-in validation event handlers used by the OpenIddict System.Net.Http components. @@ -57,18 +52,8 @@ public static class OpenIddictValidationSystemNetHttpExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictValidationBuilder UseSystemNetHttp( - this OpenIddictValidationBuilder builder, Action configuration) + this OpenIddictValidationBuilder builder!!, Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.UseSystemNetHttp()); return builder; diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlerFilters.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlerFilters.cs index 0a35dd27..f301c92b 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlerFilters.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlerFilters.cs @@ -16,16 +16,8 @@ public static class OpenIddictValidationSystemNetHttpHandlerFilters /// public class RequireHttpMetadataAddress : IOpenIddictValidationHandlerFilter { - public ValueTask IsActiveAsync(BaseExternalContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask( - string.Equals(context.Address?.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || - string.Equals(context.Address?.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)); - } + public ValueTask IsActiveAsync(BaseExternalContext context!!) + => new(string.Equals(context.Address?.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || + string.Equals(context.Address?.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)); } } diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.Introspection.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.Introspection.cs index e0cf1ef1..55afb30b 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.Introspection.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.Introspection.cs @@ -48,22 +48,14 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers .Build(); /// - public async ValueTask HandleAsync(PrepareIntrospectionRequestContext context) + public async ValueTask HandleAsync(PrepareIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } // If no client identifier was attached to the request, skip the following logic. if (string.IsNullOrEmpty(context.Request.ClientId)) diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs index 2e7c539a..7fb2764c 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs @@ -40,13 +40,8 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers /// [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The HTTP request message is disposed later by a dedicated handler.")] - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var request = new HttpRequestMessage(HttpMethod.Get, context.Address) { Headers = @@ -82,13 +77,8 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers /// [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The HTTP request message is disposed later by a dedicated handler.")] - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var request = new HttpRequestMessage(HttpMethod.Post, context.Address) { Headers = @@ -122,22 +112,14 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } if (request.RequestUri is null || context.Transaction.Request.Count == 0) { @@ -188,22 +170,14 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } request.Content = new FormUrlEncodedContent( from parameter in context.Transaction.Request.GetParameters() @@ -239,20 +213,12 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } var assembly = typeof(OpenIddictValidationSystemNetHttpOptions).Assembly.GetName(); using var client = _factory.CreateClient(assembly.Name!); @@ -293,20 +259,12 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var request = context.Transaction.GetHttpRequestMessage(); - if (request is null) - { + var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } request.Dispose(); @@ -334,20 +292,12 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers .Build(); /// - public async ValueTask HandleAsync(TContext context) + public async ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var response = context.Transaction.GetHttpResponseMessage(); - if (response is null) - { + var response = context.Transaction.GetHttpResponseMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } // The status code is deliberately not validated to ensure even errored responses // (typically in the 4xx range) can be deserialized and handled by the event handlers. @@ -375,20 +325,12 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved, // this may indicate that the request was incorrectly processed by another client stack. - var response = context.Transaction.GetHttpResponseMessage(); - if (response is null) - { + var response = context.Transaction.GetHttpResponseMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); - } response.Dispose(); diff --git a/src/OpenIddict.Validation/OpenIddictValidationBuilder.cs b/src/OpenIddict.Validation/OpenIddictValidationBuilder.cs index 4935c3e3..0e2c7a8a 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationBuilder.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationBuilder.cs @@ -24,8 +24,8 @@ public class OpenIddictValidationBuilder /// Initializes a new instance of . /// /// The services collection. - public OpenIddictValidationBuilder(IServiceCollection services) - => Services = services ?? throw new ArgumentNullException(nameof(services)); + public OpenIddictValidationBuilder(IServiceCollection services!!) + => Services = services; /// /// Gets the services collection. @@ -41,14 +41,9 @@ public class OpenIddictValidationBuilder /// The . [EditorBrowsable(EditorBrowsableState.Advanced)] public OpenIddictValidationBuilder AddEventHandler( - Action> configuration) + Action> configuration!!) where TContext : OpenIddictValidationEvents.BaseContext { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - // Note: handlers registered using this API are assumed to be custom handlers by default. var builder = OpenIddictValidationHandlerDescriptor.CreateBuilder() .SetType(OpenIddictValidationHandlerType.Custom); @@ -64,13 +59,8 @@ public class OpenIddictValidationBuilder /// The handler descriptor. /// The . [EditorBrowsable(EditorBrowsableState.Advanced)] - public OpenIddictValidationBuilder AddEventHandler(OpenIddictValidationHandlerDescriptor descriptor) + public OpenIddictValidationBuilder AddEventHandler(OpenIddictValidationHandlerDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - // Register the handler in the services collection. Services.Add(descriptor.ServiceDescriptor); @@ -83,13 +73,8 @@ public class OpenIddictValidationBuilder /// The descriptor corresponding to the handler to remove. /// The . [EditorBrowsable(EditorBrowsableState.Advanced)] - public OpenIddictValidationBuilder RemoveEventHandler(OpenIddictValidationHandlerDescriptor descriptor) + public OpenIddictValidationBuilder RemoveEventHandler(OpenIddictValidationHandlerDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - Services.RemoveAll(descriptor.ServiceDescriptor.ServiceType); Services.PostConfigure(options => @@ -112,13 +97,8 @@ public class OpenIddictValidationBuilder /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictValidationBuilder Configure(Action configuration) + public OpenIddictValidationBuilder Configure(Action configuration!!) { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - Services.Configure(configuration); return this; @@ -129,28 +109,16 @@ public class OpenIddictValidationBuilder /// /// The encrypting credentials. /// The . - public OpenIddictValidationBuilder AddEncryptionCredentials(EncryptingCredentials credentials) - { - if (credentials is null) - { - throw new ArgumentNullException(nameof(credentials)); - } - - return Configure(options => options.EncryptionCredentials.Add(credentials)); - } + public OpenIddictValidationBuilder AddEncryptionCredentials(EncryptingCredentials credentials!!) + => Configure(options => options.EncryptionCredentials.Add(credentials)); /// /// Registers an encryption key. /// /// The security key. /// The . - public OpenIddictValidationBuilder AddEncryptionKey(SecurityKey key) + public OpenIddictValidationBuilder AddEncryptionKey(SecurityKey key!!) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - // If the encryption key is an asymmetric security key, ensure it has a private key. if (key is AsymmetricSecurityKey asymmetricSecurityKey && asymmetricSecurityKey.PrivateKeyStatus == PrivateKeyStatus.DoesNotExist) @@ -178,13 +146,8 @@ public class OpenIddictValidationBuilder /// /// The encryption certificate. /// The . - public OpenIddictValidationBuilder AddEncryptionCertificate(X509Certificate2 certificate) + public OpenIddictValidationBuilder AddEncryptionCertificate(X509Certificate2 certificate!!) { - if (certificate is null) - { - throw new ArgumentNullException(nameof(certificate)); - } - // If the certificate is a X.509v3 certificate that specifies at least one // key usage, ensure that the certificate key can be used for key encryption. if (certificate.Version >= 3) @@ -231,14 +194,9 @@ public class OpenIddictValidationBuilder /// An enumeration of flags indicating how and where to store the private key of the certificate. /// The . public OpenIddictValidationBuilder AddEncryptionCertificate( - Assembly assembly, string resource, + Assembly assembly!!, string resource, string? password, X509KeyStorageFlags flags) { - if (assembly is null) - { - throw new ArgumentNullException(nameof(assembly)); - } - if (string.IsNullOrEmpty(resource)) { throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource)); @@ -282,13 +240,8 @@ public class OpenIddictValidationBuilder [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The X.509 certificate is attached to the server options.")] public OpenIddictValidationBuilder AddEncryptionCertificate( - Stream stream, string? password, X509KeyStorageFlags flags) + Stream stream!!, string? password, X509KeyStorageFlags flags) { - if (stream is null) - { - throw new ArgumentNullException(nameof(stream)); - } - using var buffer = new MemoryStream(); stream.CopyTo(buffer); @@ -362,14 +315,9 @@ public class OpenIddictValidationBuilder /// /// The audiences valid for this resource server. /// The . - public OpenIddictValidationBuilder AddAudiences(params string[] audiences) + public OpenIddictValidationBuilder AddAudiences(params string[] audiences!!) { - if (audiences is null) - { - throw new ArgumentNullException(nameof(audiences)); - } - - if (audiences.Any(audience => string.IsNullOrEmpty(audience))) + if (audiences.Any(string.IsNullOrEmpty)) { throw new ArgumentException(SR.GetResourceString(SR.ID0123), nameof(audiences)); } @@ -403,15 +351,8 @@ public class OpenIddictValidationBuilder /// /// The server configuration. /// The . - public OpenIddictValidationBuilder SetConfiguration(OpenIddictConfiguration configuration) - { - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - - return Configure(options => options.Configuration = configuration); - } + public OpenIddictValidationBuilder SetConfiguration(OpenIddictConfiguration configuration!!) + => Configure(options => options.Configuration = configuration); /// /// Sets the client identifier client_id used when communicating @@ -451,15 +392,8 @@ public class OpenIddictValidationBuilder /// /// The issuer address. /// The . - public OpenIddictValidationBuilder SetIssuer(Uri address) - { - if (address is null) - { - throw new ArgumentNullException(nameof(address)); - } - - return Configure(options => options.Issuer = address); - } + public OpenIddictValidationBuilder SetIssuer(Uri address!!) + => Configure(options => options.Issuer = address); /// /// Sets the issuer address, which is used to determine the actual location of the diff --git a/src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs b/src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs index 8e8cb15d..a8b12b02 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs @@ -26,13 +26,8 @@ public class OpenIddictValidationConfiguration : IPostConfigureOptions /// The name of the options instance to configure, if applicable. /// The options instance to initialize. - public void PostConfigure(string name, OpenIddictValidationOptions options) + public void PostConfigure(string name, OpenIddictValidationOptions options!!) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } - if (options.JsonWebTokenHandler is null) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0075)); @@ -44,7 +39,7 @@ public class OpenIddictValidationConfiguration : IPostConfigureOptions descriptor.ContextType == typeof(ApplyIntrospectionRequestContext))) { diff --git a/src/OpenIddict.Validation/OpenIddictValidationDispatcher.cs b/src/OpenIddict.Validation/OpenIddictValidationDispatcher.cs index 97a7521f..0b718f14 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationDispatcher.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationDispatcher.cs @@ -19,22 +19,17 @@ public class OpenIddictValidationDispatcher : IOpenIddictValidationDispatcher /// Creates a new instance of the class. /// public OpenIddictValidationDispatcher( - ILogger logger, - IOptionsMonitor options, - IServiceProvider provider) + ILogger logger!!, + IOptionsMonitor options!!, + IServiceProvider provider!!) { _logger = logger; _options = options; _provider = provider; } - public async ValueTask DispatchAsync(TContext context) where TContext : BaseContext + public async ValueTask DispatchAsync(TContext context!!) where TContext : BaseContext { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - await foreach (var handler in GetHandlersAsync()) { try diff --git a/src/OpenIddict.Validation/OpenIddictValidationEvents.cs b/src/OpenIddict.Validation/OpenIddictValidationEvents.cs index 4f5c4ae8..67d7a52b 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationEvents.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationEvents.cs @@ -21,8 +21,8 @@ public static partial class OpenIddictValidationEvents /// /// Creates a new instance of the class. /// - protected BaseContext(OpenIddictValidationTransaction transaction) - => Transaction = transaction ?? throw new ArgumentNullException(nameof(transaction)); + protected BaseContext(OpenIddictValidationTransaction transaction!!) + => Transaction = transaction; /// /// Gets the environment associated with the current request being processed. diff --git a/src/OpenIddict.Validation/OpenIddictValidationExtensions.cs b/src/OpenIddict.Validation/OpenIddictValidationExtensions.cs index 769380fe..dad8538a 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationExtensions.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationExtensions.cs @@ -22,13 +22,8 @@ public static class OpenIddictValidationExtensions /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictValidationBuilder AddValidation(this OpenIddictBuilder builder) + public static OpenIddictValidationBuilder AddValidation(this OpenIddictBuilder builder!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - builder.Services.AddLogging(); builder.Services.AddOptions(); @@ -63,19 +58,9 @@ public static class OpenIddictValidationExtensions /// This extension can be safely called multiple times. /// The . public static OpenIddictBuilder AddValidation( - this OpenIddictBuilder builder, - Action configuration) + this OpenIddictBuilder builder!!, + Action configuration!!) { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (configuration is null) - { - throw new ArgumentNullException(nameof(configuration)); - } - configuration(builder.AddValidation()); return builder; diff --git a/src/OpenIddict.Validation/OpenIddictValidationFactory.cs b/src/OpenIddict.Validation/OpenIddictValidationFactory.cs index a51a5d94..68d6ccb9 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationFactory.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationFactory.cs @@ -18,15 +18,15 @@ public class OpenIddictValidationFactory : IOpenIddictValidationFactory /// Creates a new instance of the class. /// public OpenIddictValidationFactory( - ILogger logger, - IOptionsMonitor options) + ILogger logger!!, + IOptionsMonitor options!!) { _logger = logger; _options = options; } public ValueTask CreateTransactionAsync() - => new ValueTask(new OpenIddictValidationTransaction + => new(new OpenIddictValidationTransaction { Issuer = _options.CurrentValue.Issuer, Logger = _logger, diff --git a/src/OpenIddict.Validation/OpenIddictValidationHandler.cs b/src/OpenIddict.Validation/OpenIddictValidationHandler.cs index c193e1c5..356faa41 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHandler.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHandler.cs @@ -18,8 +18,8 @@ public class OpenIddictValidationHandler : IOpenIddictValidationHandle /// Creates a new event using the specified handler delegate. /// /// The event handler delegate. - public OpenIddictValidationHandler(Func handler) - => _handler = handler ?? throw new ArgumentNullException(nameof(handler)); + public OpenIddictValidationHandler(Func handler!!) + => _handler = handler; /// /// Processes the event. @@ -28,6 +28,5 @@ public class OpenIddictValidationHandler : IOpenIddictValidationHandle /// /// A that can be used to monitor the asynchronous operation. /// - public ValueTask HandleAsync(TContext context) - => _handler(context ?? throw new ArgumentNullException(nameof(context))); + public ValueTask HandleAsync(TContext context!!) => _handler(context); } diff --git a/src/OpenIddict.Validation/OpenIddictValidationHandlerDescriptor.cs b/src/OpenIddict.Validation/OpenIddictValidationHandlerDescriptor.cs index a6dc5347..b8838703 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHandlerDescriptor.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHandlerDescriptor.cs @@ -72,13 +72,8 @@ public class OpenIddictValidationHandlerDescriptor /// /// The event handler filter type. /// The builder instance, so that calls can be easily chained. - public Builder AddFilter(Type type) + public Builder AddFilter(Type type!!) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - if (!typeof(IOpenIddictValidationHandlerFilter<>).MakeGenericType(typeof(TContext)).IsAssignableFrom(type)) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0104)); @@ -104,13 +99,8 @@ public class OpenIddictValidationHandlerDescriptor /// The existing descriptor properties are copied from. /// All the properties previously set on this instance are automatically replaced. /// The builder instance, so that calls can be easily chained. - public Builder Import(OpenIddictValidationHandlerDescriptor descriptor) + public Builder Import(OpenIddictValidationHandlerDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - if (descriptor.ContextType != typeof(TContext)) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0284)); @@ -130,13 +120,8 @@ public class OpenIddictValidationHandlerDescriptor /// /// The service descriptor. /// The builder instance, so that calls can be easily chained. - public Builder SetServiceDescriptor(ServiceDescriptor descriptor) + public Builder SetServiceDescriptor(ServiceDescriptor descriptor!!) { - if (descriptor is null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - var type = descriptor.ServiceType; if (!typeof(IOpenIddictValidationHandler<>).MakeGenericType(typeof(TContext)).IsAssignableFrom(type)) { @@ -182,15 +167,8 @@ public class OpenIddictValidationHandlerDescriptor /// /// The handler instance. /// The builder instance, so that calls can be easily chained. - public Builder UseInlineHandler(Func handler) - { - if (handler is null) - { - throw new ArgumentNullException(nameof(handler)); - } - - return UseSingletonHandler(new OpenIddictValidationHandler(handler)); - } + public Builder UseInlineHandler(Func handler!!) + => UseSingletonHandler(new OpenIddictValidationHandler(handler)); /// /// Configures the descriptor to use the specified scoped handler. @@ -208,17 +186,10 @@ public class OpenIddictValidationHandlerDescriptor /// The handler type. /// The factory used to create the handler. /// The builder instance, so that calls can be easily chained. - public Builder UseScopedHandler(Func factory) + public Builder UseScopedHandler(Func factory!!) where THandler : IOpenIddictValidationHandler - { - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - return SetServiceDescriptor(new ServiceDescriptor( + => SetServiceDescriptor(new ServiceDescriptor( typeof(THandler), factory, ServiceLifetime.Scoped)); - } /// /// Configures the descriptor to use the specified singleton handler. @@ -236,17 +207,10 @@ public class OpenIddictValidationHandlerDescriptor /// The handler type. /// The factory used to create the handler. /// The builder instance, so that calls can be easily chained. - public Builder UseSingletonHandler(Func factory) + public Builder UseSingletonHandler(Func factory!!) where THandler : IOpenIddictValidationHandler - { - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - return SetServiceDescriptor(new ServiceDescriptor( + => SetServiceDescriptor(new ServiceDescriptor( typeof(THandler), factory, ServiceLifetime.Singleton)); - } /// /// Configures the descriptor to use the specified singleton handler. @@ -254,16 +218,9 @@ public class OpenIddictValidationHandlerDescriptor /// The handler type. /// The handler instance. /// The builder instance, so that calls can be easily chained. - public Builder UseSingletonHandler(THandler handler) + public Builder UseSingletonHandler(THandler handler!!) where THandler : IOpenIddictValidationHandler - { - if (handler is null) - { - throw new ArgumentNullException(nameof(handler)); - } - - return SetServiceDescriptor(new ServiceDescriptor(typeof(THandler), handler)); - } + => SetServiceDescriptor(new ServiceDescriptor(typeof(THandler), handler)); /// /// Build a new descriptor instance, based on the parameters that were previously set. diff --git a/src/OpenIddict.Validation/OpenIddictValidationHandlerFilters.cs b/src/OpenIddict.Validation/OpenIddictValidationHandlerFilters.cs index 92c16843..7de184f0 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHandlerFilters.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHandlerFilters.cs @@ -16,15 +16,8 @@ public static class OpenIddictValidationHandlerFilters /// public class RequireAccessTokenExtracted : IOpenIddictValidationHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ExtractAccessToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ExtractAccessToken); } /// @@ -32,15 +25,8 @@ public static class OpenIddictValidationHandlerFilters /// public class RequireAccessTokenValidated : IOpenIddictValidationHandlerFilter { - public ValueTask IsActiveAsync(ProcessAuthenticationContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.ValidateAccessToken); - } + public ValueTask IsActiveAsync(ProcessAuthenticationContext context!!) + => new(context.ValidateAccessToken); } /// @@ -48,15 +34,8 @@ public static class OpenIddictValidationHandlerFilters /// public class RequireAuthorizationEntryValidationEnabled : IOpenIddictValidationHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Options.EnableAuthorizationEntryValidation); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Options.EnableAuthorizationEntryValidation); } /// @@ -64,15 +43,8 @@ public static class OpenIddictValidationHandlerFilters /// public class RequireLocalValidation : IOpenIddictValidationHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Options.ValidationType == OpenIddictValidationType.Direct); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Options.ValidationType is OpenIddictValidationType.Direct); } /// @@ -80,15 +52,8 @@ public static class OpenIddictValidationHandlerFilters /// public class RequireIntrospectionValidation : IOpenIddictValidationHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Options.ValidationType == OpenIddictValidationType.Introspection); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Options.ValidationType is OpenIddictValidationType.Introspection); } /// @@ -96,14 +61,7 @@ public static class OpenIddictValidationHandlerFilters /// public class RequireTokenEntryValidationEnabled : IOpenIddictValidationHandlerFilter { - public ValueTask IsActiveAsync(BaseContext context) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - return new ValueTask(context.Options.EnableTokenEntryValidation); - } + public ValueTask IsActiveAsync(BaseContext context!!) + => new(context.Options.EnableTokenEntryValidation); } } diff --git a/src/OpenIddict.Validation/OpenIddictValidationHandlers.Discovery.cs b/src/OpenIddict.Validation/OpenIddictValidationHandlers.Discovery.cs index 04bbee75..89b31525 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHandlers.Discovery.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHandlers.Discovery.cs @@ -45,12 +45,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // The issuer returned in the discovery document must exactly match the URL used to access it. // See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationValidation. @@ -97,13 +93,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Note: the jwks_uri node is required by the OpenID Connect discovery specification. // See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationValidation. var address = (string?) context.Response[Metadata.JwksUri]; @@ -149,13 +140,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var address = (string?) context.Response[Metadata.IntrospectionEndpoint]; if (!string.IsNullOrEmpty(address)) { @@ -193,12 +179,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(HandleConfigurationResponseContext context) + public ValueTask HandleAsync(HandleConfigurationResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Resolve the client authentication methods supported by the introspection endpoint, if available. var methods = context.Response[Metadata.IntrospectionEndpointAuthMethodsSupported]?.GetUnnamedParameters(); @@ -235,13 +217,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(HandleCryptographyResponseContext context) + public ValueTask HandleAsync(HandleCryptographyResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var keys = context.Response[JsonWebKeySetParameterNames.Keys]?.GetUnnamedParameters(); if (keys is not { Count: > 0 }) { diff --git a/src/OpenIddict.Validation/OpenIddictValidationHandlers.Introspection.cs b/src/OpenIddict.Validation/OpenIddictValidationHandlers.Introspection.cs index bcc098ee..2b08fd42 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHandlers.Introspection.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHandlers.Introspection.cs @@ -49,13 +49,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(PrepareIntrospectionRequestContext context) + public ValueTask HandleAsync(PrepareIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Request.ClientId = context.Options.ClientId; context.Request.ClientSecret = context.Options.ClientSecret; @@ -79,13 +74,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(PrepareIntrospectionRequestContext context) + public ValueTask HandleAsync(PrepareIntrospectionRequestContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Request.Token = context.Token; context.Request.TokenTypeHint = context.TokenTypeHint; @@ -109,13 +99,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(HandleIntrospectionResponseContext context) + public ValueTask HandleAsync(HandleIntrospectionResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // Note: the introspection specification requires that server return "active: false" instead of a proper // OAuth 2.0 error when the token is invalid, expired, revoked or invalid for any other reason. // While OpenIddict's server can be tweaked to return a proper error (by removing NormalizeErrorResponse) @@ -163,13 +148,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(HandleIntrospectionResponseContext context) + public ValueTask HandleAsync(HandleIntrospectionResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - foreach (var parameter in context.Response.GetParameters()) { if (ValidateClaimType(parameter.Key, parameter.Value.Value)) @@ -239,12 +219,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(HandleIntrospectionResponseContext context) + public ValueTask HandleAsync(HandleIntrospectionResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // The issuer claim is optional. If it's not null or empty, validate it to // ensure it matches the issuer registered in the server configuration. @@ -292,12 +268,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(HandleIntrospectionResponseContext context) + public ValueTask HandleAsync(HandleIntrospectionResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // OpenIddict-based authorization servers always return the actual token type using // the special "token_usage" claim, that helps resource servers determine whether the @@ -351,13 +323,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public async ValueTask HandleAsync(HandleIntrospectionResponseContext context) + public async ValueTask HandleAsync(HandleIntrospectionResponseContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var configuration = await context.Options.ConfigurationManager.GetConfigurationAsync(default) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0140)); diff --git a/src/OpenIddict.Validation/OpenIddictValidationHandlers.Protection.cs b/src/OpenIddict.Validation/OpenIddictValidationHandlers.Protection.cs index cfcda469..9d00d580 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHandlers.Protection.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHandlers.Protection.cs @@ -51,13 +51,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - var configuration = await context.Options.ConfigurationManager.GetConfigurationAsync(default) ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0140)); @@ -129,7 +124,7 @@ public static partial class OpenIddictValidationHandlers public ValidateReferenceTokenIdentifier() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0139)); - public ValidateReferenceTokenIdentifier(IOpenIddictTokenManager tokenManager) + public ValidateReferenceTokenIdentifier(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -145,12 +140,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } // Reference tokens are base64url-encoded payloads of exactly 256 bits (generated using a // crypto-secure RNG). If the token length differs, the token cannot be a reference token. @@ -213,13 +204,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a principal was already attached, don't overwrite it. if (context.Principal is not null) { @@ -307,13 +293,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If a principal was already attached, don't overwrite it. if (context.Principal is not null) { @@ -410,13 +391,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Principal is null) { return default; @@ -455,13 +431,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Principal is null) { return default; @@ -552,7 +523,7 @@ public static partial class OpenIddictValidationHandlers public RestoreReferenceTokenProperties() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0139)); - public RestoreReferenceTokenProperties(IOpenIddictTokenManager tokenManager) + public RestoreReferenceTokenProperties(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -568,13 +539,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Principal is null || string.IsNullOrEmpty(context.TokenId)) { return; @@ -611,13 +577,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.Principal is null) { context.Reject( @@ -663,13 +624,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); var date = context.Principal.GetExpirationDate(); @@ -706,13 +662,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(ValidateTokenContext context) + public ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); // If no explicit audience has been configured, @@ -764,7 +715,7 @@ public static partial class OpenIddictValidationHandlers public ValidateTokenEntry() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0139)); - public ValidateTokenEntry(IOpenIddictTokenManager tokenManager) + public ValidateTokenEntry(IOpenIddictTokenManager tokenManager!!) => _tokenManager = tokenManager; /// @@ -780,13 +731,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); var identifier = context.Principal.GetTokenId(); @@ -828,7 +774,7 @@ public static partial class OpenIddictValidationHandlers public ValidateAuthorizationEntry() => throw new InvalidOperationException(SR.GetResourceString(SR.ID0142)); - public ValidateAuthorizationEntry(IOpenIddictAuthorizationManager authorizationManager) + public ValidateAuthorizationEntry(IOpenIddictAuthorizationManager authorizationManager!!) => _authorizationManager = authorizationManager; /// @@ -844,13 +790,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public async ValueTask HandleAsync(ValidateTokenContext context) + public async ValueTask HandleAsync(ValidateTokenContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); var identifier = context.Principal.GetAuthorizationId(); diff --git a/src/OpenIddict.Validation/OpenIddictValidationHandlers.cs b/src/OpenIddict.Validation/OpenIddictValidationHandlers.cs index b27abad6..2aa9404b 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHandlers.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHandlers.cs @@ -45,13 +45,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - (context.ExtractAccessToken, context.RequireAccessToken, context.ValidateAccessToken) = context.EndpointType switch { // The validation handler is responsible of validating access tokens for endpoints @@ -90,13 +85,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(ProcessAuthenticationContext context) + public ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.RequireAccessToken && string.IsNullOrEmpty(context.AccessToken)) { context.Reject( @@ -118,7 +108,7 @@ public static partial class OpenIddictValidationHandlers { private readonly IOpenIddictValidationDispatcher _dispatcher; - public ValidateAccessToken(IOpenIddictValidationDispatcher dispatcher) + public ValidateAccessToken(IOpenIddictValidationDispatcher dispatcher!!) => _dispatcher = dispatcher; /// @@ -133,13 +123,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public async ValueTask HandleAsync(ProcessAuthenticationContext context) + public async ValueTask HandleAsync(ProcessAuthenticationContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (context.AccessTokenPrincipal is not null || string.IsNullOrEmpty(context.AccessToken)) { return; @@ -194,13 +179,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(ProcessChallengeContext context) + public ValueTask HandleAsync(ProcessChallengeContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - // If an error was explicitly set by the application, don't override it. if (!string.IsNullOrEmpty(context.Response.Error) || !string.IsNullOrEmpty(context.Response.ErrorDescription) || @@ -253,13 +233,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(ProcessErrorContext context) + public ValueTask HandleAsync(ProcessErrorContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - context.Response.Error = context.Error; context.Response.ErrorDescription = context.ErrorDescription; context.Response.ErrorUri = context.ErrorUri; @@ -292,13 +267,8 @@ public static partial class OpenIddictValidationHandlers .Build(); /// - public ValueTask HandleAsync(TContext context) + public ValueTask HandleAsync(TContext context!!) { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - if (!string.IsNullOrEmpty(context.Transaction.Response?.Error)) { context.Reject( diff --git a/src/OpenIddict.Validation/OpenIddictValidationHelpers.cs b/src/OpenIddict.Validation/OpenIddictValidationHelpers.cs index c9c24533..6ebde856 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHelpers.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHelpers.cs @@ -19,13 +19,8 @@ public static class OpenIddictValidationHelpers /// The property name. /// The property value or null if it couldn't be found. public static TProperty? GetProperty( - this OpenIddictValidationTransaction transaction, string name) where TProperty : class + this OpenIddictValidationTransaction transaction!!, string name) where TProperty : class { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (string.IsNullOrEmpty(name)) { throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name)); @@ -48,14 +43,9 @@ public static class OpenIddictValidationHelpers /// The property value. /// The validation transaction, so that calls can be easily chained. public static OpenIddictValidationTransaction SetProperty( - this OpenIddictValidationTransaction transaction, + this OpenIddictValidationTransaction transaction!!, string name, TProperty? value) where TProperty : class { - if (transaction is null) - { - throw new ArgumentNullException(nameof(transaction)); - } - if (string.IsNullOrEmpty(name)) { throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name)); diff --git a/src/OpenIddict.Validation/OpenIddictValidationOptions.cs b/src/OpenIddict.Validation/OpenIddictValidationOptions.cs index b86e1992..f17a5f3b 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationOptions.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationOptions.cs @@ -44,7 +44,7 @@ public class OpenIddictValidationOptions /// Note: the list is automatically sorted based on the order assigned to each handler descriptor. /// As such, it MUST NOT be mutated after options initialization to preserve the exact order. /// - public List Handlers { get; } = new(OpenIddictValidationHandlers.DefaultHandlers); + public List Handlers { get; } = new(DefaultHandlers); /// /// Gets or sets the type of validation used by the OpenIddict validation services. diff --git a/src/OpenIddict.Validation/OpenIddictValidationRetriever.cs b/src/OpenIddict.Validation/OpenIddictValidationRetriever.cs index 4689b25d..be390cb4 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationRetriever.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationRetriever.cs @@ -16,7 +16,7 @@ public class OpenIddictValidationRetriever : IConfigurationRetriever class. /// /// The validation service. - public OpenIddictValidationRetriever(OpenIddictValidationService service) + public OpenIddictValidationRetriever(OpenIddictValidationService service!!) => _service = service; /// @@ -26,7 +26,8 @@ public class OpenIddictValidationRetriever : IConfigurationRetrieverThe retriever used by IdentityModel. /// The that can be used to abort the operation. /// The OpenID Connect server configuration retrieved from the remote server. - async Task IConfigurationRetriever.GetConfigurationAsync(string address, IDocumentRetriever retriever, CancellationToken cancel) + async Task IConfigurationRetriever.GetConfigurationAsync( + string address, IDocumentRetriever retriever, CancellationToken cancel) { if (string.IsNullOrEmpty(address)) { diff --git a/src/OpenIddict.Validation/OpenIddictValidationService.cs b/src/OpenIddict.Validation/OpenIddictValidationService.cs index 0fd61a3a..4160b935 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationService.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationService.cs @@ -19,7 +19,7 @@ public class OpenIddictValidationService /// Creates a new instance of the class. /// /// The service provider. - public OpenIddictValidationService(IServiceProvider provider) + public OpenIddictValidationService(IServiceProvider provider!!) => _provider = provider; /// @@ -28,13 +28,8 @@ public class OpenIddictValidationService /// The address of the remote metadata endpoint. /// The that can be used to abort the operation. /// The OpenID Connect server configuration retrieved from the remote server. - public async ValueTask GetConfigurationAsync(Uri address, CancellationToken cancellationToken = default) + public async ValueTask GetConfigurationAsync(Uri address!!, CancellationToken cancellationToken = default) { - if (address is null) - { - throw new ArgumentNullException(nameof(address)); - } - if (!address.IsAbsoluteUri) { throw new ArgumentException(SR.GetResourceString(SR.ID0144), nameof(address)); @@ -172,13 +167,8 @@ public class OpenIddictValidationService /// The address of the remote metadata endpoint. /// The that can be used to abort the operation. /// The security keys retrieved from the remote server. - public async ValueTask GetSecurityKeysAsync(Uri address, CancellationToken cancellationToken = default) + public async ValueTask GetSecurityKeysAsync(Uri address!!, CancellationToken cancellationToken = default) { - if (address is null) - { - throw new ArgumentNullException(nameof(address)); - } - if (!address.IsAbsoluteUri) { throw new ArgumentException(SR.GetResourceString(SR.ID0144), nameof(address)); @@ -329,13 +319,8 @@ public class OpenIddictValidationService /// The that can be used to abort the operation. /// The claims principal created from the claim retrieved from the remote server. public async ValueTask IntrospectTokenAsync( - Uri address, string token, string? hint, CancellationToken cancellationToken = default) + Uri address!!, string token, string? hint, CancellationToken cancellationToken = default) { - if (address is null) - { - throw new ArgumentNullException(nameof(address)); - } - if (!address.IsAbsoluteUri) { throw new ArgumentException(SR.GetResourceString(SR.ID0144), nameof(address)); diff --git a/test/OpenIddict.Abstractions.Tests/OpenIddictExtensionsTests.cs b/test/OpenIddict.Abstractions.Tests/OpenIddictExtensionsTests.cs index 432923f4..889c5ffd 100644 --- a/test/OpenIddict.Abstractions.Tests/OpenIddictExtensionsTests.cs +++ b/test/OpenIddict.Abstractions.Tests/OpenIddictExtensionsTests.cs @@ -18,7 +18,7 @@ public class OpenIddictExtensionsTests var services = (IServiceCollection) null!; // Act and assert - var exception = Assert.Throws(() => services.AddOpenIddict()); + var exception = Assert.Throws(services.AddOpenIddict); Assert.Equal("services", exception.ParamName); } diff --git a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictExtensionsTests.cs b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictExtensionsTests.cs index 169b1a12..0ca8b065 100644 --- a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictExtensionsTests.cs +++ b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictExtensionsTests.cs @@ -1078,7 +1078,7 @@ public class OpenIddictExtensionsTests var principal = (ClaimsPrincipal) null!; // Act and assert - var exception = Assert.Throws(() => principal.GetDestinations()); + var exception = Assert.Throws(principal.GetDestinations); Assert.Equal("principal", exception.ParamName); } @@ -1876,7 +1876,7 @@ public class OpenIddictExtensionsTests var principal = (ClaimsPrincipal) null!; // Act and assert - var exception = Assert.Throws(() => principal.GetAuthorizationId()); + var exception = Assert.Throws(principal.GetAuthorizationId); Assert.Equal("principal", exception.ParamName); } @@ -1903,7 +1903,7 @@ public class OpenIddictExtensionsTests var principal = (ClaimsPrincipal) null!; // Act and assert - var exception = Assert.Throws(() => principal.GetTokenId()); + var exception = Assert.Throws(principal.GetTokenId); Assert.Equal("principal", exception.ParamName); } @@ -1930,7 +1930,7 @@ public class OpenIddictExtensionsTests var principal = (ClaimsPrincipal) null!; // Act and assert - var exception = Assert.Throws(() => principal.GetTokenType()); + var exception = Assert.Throws(principal.GetTokenType); Assert.Equal("principal", exception.ParamName); } diff --git a/test/OpenIddict.Core.Tests/OpenIddictCoreExtensionsTests.cs b/test/OpenIddict.Core.Tests/OpenIddictCoreExtensionsTests.cs index 199a0bd2..f1687b48 100644 --- a/test/OpenIddict.Core.Tests/OpenIddictCoreExtensionsTests.cs +++ b/test/OpenIddict.Core.Tests/OpenIddictCoreExtensionsTests.cs @@ -21,7 +21,7 @@ public class OpenIddictCoreExtensionsTests var builder = (OpenIddictBuilder) null!; // Act and assert - var exception = Assert.Throws(() => builder.AddCore()); + var exception = Assert.Throws(builder.AddCore); Assert.Equal("builder", exception.ParamName); } @@ -135,10 +135,7 @@ public class OpenIddictCoreExtensionsTests // Assert var provider = services.BuildServiceProvider(); - var exception = Assert.Throws(delegate - { - return provider.GetRequiredService(); - }); + var exception = Assert.Throws(provider.GetRequiredService); Assert.Equal(SR.GetResourceString(SR.ID0273), exception.Message); } @@ -156,10 +153,7 @@ public class OpenIddictCoreExtensionsTests // Assert var provider = services.BuildServiceProvider(); - var exception = Assert.Throws(delegate - { - return provider.GetRequiredService(); - }); + var exception = Assert.Throws(provider.GetRequiredService); Assert.Equal(SR.GetResourceString(SR.ID0274), exception.Message); } @@ -177,10 +171,7 @@ public class OpenIddictCoreExtensionsTests // Assert var provider = services.BuildServiceProvider(); - var exception = Assert.Throws(delegate - { - return provider.GetRequiredService(); - }); + var exception = Assert.Throws(provider.GetRequiredService); Assert.Equal(SR.GetResourceString(SR.ID0275), exception.Message); } @@ -198,10 +189,7 @@ public class OpenIddictCoreExtensionsTests // Assert var provider = services.BuildServiceProvider(); - var exception = Assert.Throws(delegate - { - return provider.GetRequiredService(); - }); + var exception = Assert.Throws(provider.GetRequiredService); Assert.Equal(SR.GetResourceString(SR.ID0276), exception.Message); } diff --git a/test/OpenIddict.Core.Tests/Resolvers/OpenIddictApplicationStoreResolverTests.cs b/test/OpenIddict.Core.Tests/Resolvers/OpenIddictApplicationStoreResolverTests.cs index 849e1fcb..ddcd09ea 100644 --- a/test/OpenIddict.Core.Tests/Resolvers/OpenIddictApplicationStoreResolverTests.cs +++ b/test/OpenIddict.Core.Tests/Resolvers/OpenIddictApplicationStoreResolverTests.cs @@ -21,7 +21,7 @@ public class OpenIddictApplicationStoreResolverTests var resolver = new OpenIddictApplicationStoreResolver(provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0228), exception.Message); } diff --git a/test/OpenIddict.Core.Tests/Resolvers/OpenIddictAuthorizationStoreResolverTests.cs b/test/OpenIddict.Core.Tests/Resolvers/OpenIddictAuthorizationStoreResolverTests.cs index b8c5e133..bff3a2b1 100644 --- a/test/OpenIddict.Core.Tests/Resolvers/OpenIddictAuthorizationStoreResolverTests.cs +++ b/test/OpenIddict.Core.Tests/Resolvers/OpenIddictAuthorizationStoreResolverTests.cs @@ -21,7 +21,7 @@ public class OpenIddictAuthorizationStoreResolverTests var resolver = new OpenIddictAuthorizationStoreResolver(provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0229), exception.Message); } diff --git a/test/OpenIddict.Core.Tests/Resolvers/OpenIddictScopeStoreResolverTests.cs b/test/OpenIddict.Core.Tests/Resolvers/OpenIddictScopeStoreResolverTests.cs index b34c7352..28a13cc6 100644 --- a/test/OpenIddict.Core.Tests/Resolvers/OpenIddictScopeStoreResolverTests.cs +++ b/test/OpenIddict.Core.Tests/Resolvers/OpenIddictScopeStoreResolverTests.cs @@ -21,7 +21,7 @@ public class OpenIddictScopeStoreResolverTests var resolver = new OpenIddictScopeStoreResolver(provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0230), exception.Message); } diff --git a/test/OpenIddict.Core.Tests/Resolvers/OpenIddictTokenStoreResolverTests.cs b/test/OpenIddict.Core.Tests/Resolvers/OpenIddictTokenStoreResolverTests.cs index e7e273ab..4d22830b 100644 --- a/test/OpenIddict.Core.Tests/Resolvers/OpenIddictTokenStoreResolverTests.cs +++ b/test/OpenIddict.Core.Tests/Resolvers/OpenIddictTokenStoreResolverTests.cs @@ -21,7 +21,7 @@ public class OpenIddictTokenStoreResolverTests var resolver = new OpenIddictTokenStoreResolver(provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0231), exception.Message); } diff --git a/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkExtensionsTests.cs b/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkExtensionsTests.cs index fdbbb581..be26fde2 100644 --- a/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkExtensionsTests.cs +++ b/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkExtensionsTests.cs @@ -21,7 +21,7 @@ public class OpenIddictEntityFrameworkExtensionsTests var builder = (OpenIddictCoreBuilder) null!; // Act and assert - var exception = Assert.Throws(() => builder.UseEntityFramework()); + var exception = Assert.Throws(builder.UseEntityFramework); Assert.Equal("builder", exception.ParamName); } diff --git a/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkApplicationStoreResolverTests.cs b/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkApplicationStoreResolverTests.cs index c71c973f..49635ce5 100644 --- a/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkApplicationStoreResolverTests.cs +++ b/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkApplicationStoreResolverTests.cs @@ -43,7 +43,7 @@ public class OpenIddictEntityFrameworkApplicationStoreResolverTests var resolver = new OpenIddictEntityFrameworkApplicationStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0234), exception.Message); } @@ -64,7 +64,7 @@ public class OpenIddictEntityFrameworkApplicationStoreResolverTests var resolver = new OpenIddictEntityFrameworkApplicationStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0235), exception.Message); } diff --git a/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkAuthorizationStoreResolverTests.cs b/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkAuthorizationStoreResolverTests.cs index 2f6a1425..484e0ad9 100644 --- a/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkAuthorizationStoreResolverTests.cs +++ b/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkAuthorizationStoreResolverTests.cs @@ -43,7 +43,7 @@ public class OpenIddictEntityFrameworkAuthorizationStoreResolverTests var resolver = new OpenIddictEntityFrameworkAuthorizationStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0236), exception.Message); } @@ -64,7 +64,7 @@ public class OpenIddictEntityFrameworkAuthorizationStoreResolverTests var resolver = new OpenIddictEntityFrameworkAuthorizationStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0235), exception.Message); } diff --git a/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkScopeStoreResolverTests.cs b/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkScopeStoreResolverTests.cs index 44f8a1a4..71e6d4fd 100644 --- a/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkScopeStoreResolverTests.cs +++ b/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkScopeStoreResolverTests.cs @@ -43,7 +43,7 @@ public class OpenIddictEntityFrameworkScopeStoreResolverTests var resolver = new OpenIddictEntityFrameworkScopeStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0237), exception.Message); } @@ -64,7 +64,7 @@ public class OpenIddictEntityFrameworkScopeStoreResolverTests var resolver = new OpenIddictEntityFrameworkScopeStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0235), exception.Message); } diff --git a/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkTokenStoreResolverTests.cs b/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkTokenStoreResolverTests.cs index 4f1ef005..f1e59ef2 100644 --- a/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkTokenStoreResolverTests.cs +++ b/test/OpenIddict.EntityFramework.Tests/Resolvers/OpenIddictEntityFrameworkTokenStoreResolverTests.cs @@ -43,7 +43,7 @@ public class OpenIddictEntityFrameworkTokenStoreResolverTests var resolver = new OpenIddictEntityFrameworkTokenStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0238), exception.Message); } @@ -64,7 +64,7 @@ public class OpenIddictEntityFrameworkTokenStoreResolverTests var resolver = new OpenIddictEntityFrameworkTokenStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0235), exception.Message); } diff --git a/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs b/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs index 56cc3e6b..3e7c9e2f 100644 --- a/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs +++ b/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs @@ -21,7 +21,7 @@ public class OpenIddictEntityFrameworkCoreExtensionsTests var builder = (OpenIddictCoreBuilder) null!; // Act and assert - var exception = Assert.Throws(() => builder.UseEntityFrameworkCore()); + var exception = Assert.Throws(builder.UseEntityFrameworkCore); Assert.Equal("builder", exception.ParamName); } diff --git a/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreApplicationStoreResolverTests.cs b/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreApplicationStoreResolverTests.cs index 2f124fe9..60dfc790 100644 --- a/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreApplicationStoreResolverTests.cs +++ b/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreApplicationStoreResolverTests.cs @@ -43,7 +43,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStoreResolverTests var resolver = new OpenIddictEntityFrameworkCoreApplicationStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0252), exception.Message); } @@ -64,7 +64,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStoreResolverTests var resolver = new OpenIddictEntityFrameworkCoreApplicationStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0253), exception.Message); } diff --git a/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreAuthorizationStoreResolverTests.cs b/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreAuthorizationStoreResolverTests.cs index 08a728c9..c41250cf 100644 --- a/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreAuthorizationStoreResolverTests.cs +++ b/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreAuthorizationStoreResolverTests.cs @@ -43,7 +43,7 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStoreResolverTests var resolver = new OpenIddictEntityFrameworkCoreAuthorizationStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0254), exception.Message); } @@ -64,7 +64,7 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStoreResolverTests var resolver = new OpenIddictEntityFrameworkCoreAuthorizationStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0253), exception.Message); } diff --git a/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreScopeStoreResolverTests.cs b/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreScopeStoreResolverTests.cs index 9877c4c9..f54ae7ae 100644 --- a/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreScopeStoreResolverTests.cs +++ b/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreScopeStoreResolverTests.cs @@ -43,7 +43,7 @@ public class OpenIddictEntityFrameworkCoreScopeStoreResolverTests var resolver = new OpenIddictEntityFrameworkCoreScopeStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0255), exception.Message); } @@ -64,7 +64,7 @@ public class OpenIddictEntityFrameworkCoreScopeStoreResolverTests var resolver = new OpenIddictEntityFrameworkCoreScopeStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0253), exception.Message); } diff --git a/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreTokenStoreResolverTests.cs b/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreTokenStoreResolverTests.cs index d6b1d389..9bf6b9e0 100644 --- a/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreTokenStoreResolverTests.cs +++ b/test/OpenIddict.EntityFrameworkCore.Tests/Resolvers/OpenIddictEntityFrameworkCoreTokenStoreResolverTests.cs @@ -43,7 +43,7 @@ public class OpenIddictEntityFrameworkCoreTokenStoreResolverTests var resolver = new OpenIddictEntityFrameworkCoreTokenStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0256), exception.Message); } @@ -64,7 +64,7 @@ public class OpenIddictEntityFrameworkCoreTokenStoreResolverTests var resolver = new OpenIddictEntityFrameworkCoreTokenStoreResolver(new TypeResolutionCache(), options, provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0253), exception.Message); } diff --git a/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbExtensionsTests.cs b/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbExtensionsTests.cs index 7b089086..1a34e74d 100644 --- a/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbExtensionsTests.cs +++ b/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbExtensionsTests.cs @@ -21,7 +21,7 @@ public class OpenIddictMongoDbExtensionsTests var builder = (OpenIddictCoreBuilder) null!; // Act and assert - var exception = Assert.Throws(() => builder.UseMongoDb()); + var exception = Assert.Throws(builder.UseMongoDb); Assert.Equal("builder", exception.ParamName); } diff --git a/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbApplicationStoreResolverTests.cs b/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbApplicationStoreResolverTests.cs index 53deabfb..d9fcb422 100644 --- a/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbApplicationStoreResolverTests.cs +++ b/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbApplicationStoreResolverTests.cs @@ -38,7 +38,7 @@ public class OpenIddictMongoDbApplicationStoreResolverTests var resolver = new OpenIddictMongoDbApplicationStoreResolver(provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0257), exception.Message); } diff --git a/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbAuthorizationStoreResolverTests.cs b/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbAuthorizationStoreResolverTests.cs index ae9f5ba7..e3fd275c 100644 --- a/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbAuthorizationStoreResolverTests.cs +++ b/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbAuthorizationStoreResolverTests.cs @@ -38,7 +38,7 @@ public class OpenIddictMongoDbAuthorizationStoreResolverTests var resolver = new OpenIddictMongoDbAuthorizationStoreResolver(provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0258), exception.Message); } diff --git a/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbScopeStoreResolverTests.cs b/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbScopeStoreResolverTests.cs index ba4a4674..0ecf6dce 100644 --- a/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbScopeStoreResolverTests.cs +++ b/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbScopeStoreResolverTests.cs @@ -38,7 +38,7 @@ public class OpenIddictMongoDbScopeStoreResolverTests var resolver = new OpenIddictMongoDbScopeStoreResolver(provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0259), exception.Message); } diff --git a/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbTokenStoreResolverTests.cs b/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbTokenStoreResolverTests.cs index 2ff9911f..2625f3c6 100644 --- a/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbTokenStoreResolverTests.cs +++ b/test/OpenIddict.MongoDb.Tests/Resolvers/OpenIddictMongoDbTokenStoreResolverTests.cs @@ -38,7 +38,7 @@ public class OpenIddictMongoDbTokenStoreResolverTests var resolver = new OpenIddictMongoDbTokenStoreResolver(provider); // Act and assert - var exception = Assert.Throws(() => resolver.Get()); + var exception = Assert.Throws(resolver.Get); Assert.Equal(SR.GetResourceString(SR.ID0260), exception.Message); } diff --git a/test/OpenIddict.Quartz.Tests/OpenIddictQuartzExtensionsTests.cs b/test/OpenIddict.Quartz.Tests/OpenIddictQuartzExtensionsTests.cs index 0fbd4428..d72a54b3 100644 --- a/test/OpenIddict.Quartz.Tests/OpenIddictQuartzExtensionsTests.cs +++ b/test/OpenIddict.Quartz.Tests/OpenIddictQuartzExtensionsTests.cs @@ -14,7 +14,7 @@ public class OpenIddictQuartzExtensionsTests var builder = (OpenIddictCoreBuilder) null!; // Act and assert - var exception = Assert.Throws(() => builder.UseQuartz()); + var exception = Assert.Throws(builder.UseQuartz); Assert.Equal("builder", exception.ParamName); } diff --git a/test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTestServer.cs b/test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTestServer.cs index 81a12fd1..1d069866 100644 --- a/test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTestServer.cs +++ b/test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTestServer.cs @@ -6,9 +6,12 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.Hosting; using OpenIddict.Server.IntegrationTests; +#if SUPPORTS_GENERIC_HOST +using Microsoft.Extensions.Hosting; +#endif + namespace OpenIddict.Server.AspNetCore.IntegrationTests; /// @@ -40,8 +43,7 @@ public class OpenIddictServerAspNetCoreIntegrationTestServer : OpenIddictServerI [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The caller is responsible of disposing the test client.")] public override ValueTask CreateClientAsync() - => new ValueTask( - new OpenIddictServerIntegrationTestClient(Server.CreateClient())); + => new(new OpenIddictServerIntegrationTestClient(Server.CreateClient())); public override #if SUPPORTS_GENERIC_HOST diff --git a/test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTests.cs b/test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTests.cs index 86decc06..346fec6b 100644 --- a/test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTests.cs +++ b/test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTests.cs @@ -845,7 +845,7 @@ public partial class OpenIddictServerAspNetCoreIntegrationTests : OpenIddictServ #else var server = new TestServer(builder); - return new ValueTask(new OpenIddictServerAspNetCoreIntegrationTestServer(server)); + return new(new OpenIddictServerAspNetCoreIntegrationTestServer(server)); #endif void ConfigurePipeline(IApplicationBuilder app) diff --git a/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs b/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs index 4bc8460a..008491d6 100644 --- a/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs +++ b/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs @@ -40,18 +40,8 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable /// /// The HTTP client used to communicate with the OpenID Connect server. /// The HTML parser used to parse the responses returned by the OpenID Connect server. - public OpenIddictServerIntegrationTestClient(HttpClient client, HtmlParser parser) + public OpenIddictServerIntegrationTestClient(HttpClient client!!, HtmlParser parser!!) { - if (client is null) - { - throw new ArgumentNullException(nameof(client)); - } - - if (parser is null) - { - throw new ArgumentNullException(nameof(parser)); - } - HttpClient = client; HtmlParser = parser; } @@ -93,13 +83,8 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable /// The endpoint to which the request is sent. /// The OpenID Connect request to send. /// The OpenID Connect response returned by the server. - public Task GetAsync(string uri, OpenIddictRequest request) + public Task GetAsync(string uri, OpenIddictRequest request!!) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(uri)) { throw new ArgumentException("The URL cannot be null or empty.", nameof(uri)); @@ -125,13 +110,8 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable /// The endpoint to which the request is sent. /// The OpenID Connect request to send. /// The OpenID Connect response returned by the server. - public Task PostAsync(string uri, OpenIddictRequest request) + public Task PostAsync(string uri, OpenIddictRequest request!!) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(uri)) { throw new ArgumentException("The URL cannot be null or empty.", nameof(uri)); @@ -158,13 +138,8 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable /// The endpoint to which the request is sent. /// The OpenID Connect request to send. /// The OpenID Connect response returned by the server. - public Task SendAsync(string method, string uri, OpenIddictRequest request) + public Task SendAsync(string method, string uri, OpenIddictRequest request!!) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(method)) { throw new ArgumentException("The HTTP method cannot be null or empty.", nameof(method)); @@ -186,18 +161,8 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable /// The endpoint to which the request is sent. /// The OpenID Connect request to send. /// The OpenID Connect response returned by the server. - public Task SendAsync(HttpMethod method, string uri, OpenIddictRequest request) + public Task SendAsync(HttpMethod method!!, string uri, OpenIddictRequest request!!) { - if (method is null) - { - throw new ArgumentNullException(nameof(method)); - } - - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (string.IsNullOrEmpty(uri)) { throw new ArgumentException("The URL cannot be null or empty.", nameof(uri)); @@ -214,23 +179,8 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable /// The endpoint to which the request is sent. /// The OpenID Connect request to send. /// The OpenID Connect response returned by the server. - public virtual async Task SendAsync(HttpMethod method, Uri uri, OpenIddictRequest request) + public virtual async Task SendAsync(HttpMethod method!!, Uri uri!!, OpenIddictRequest request!!) { - if (method is null) - { - throw new ArgumentNullException(nameof(method)); - } - - if (uri is null) - { - throw new ArgumentNullException(nameof(uri)); - } - - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - if (HttpClient.BaseAddress is null && !uri.IsAbsoluteUri) { throw new ArgumentException("The address cannot be a relative URI when no base address " + diff --git a/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTests.Revocation.cs b/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTests.Revocation.cs index a0fbd511..90bbf8a4 100644 --- a/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTests.Revocation.cs +++ b/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTests.Revocation.cs @@ -717,7 +717,7 @@ public abstract partial class OpenIddictServerIntegrationTests .ReturnsAsync(token); mock.Setup(manager => manager.GetIdAsync(token, It.IsAny())) - .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); + .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); mock.Setup(manager => manager.HasStatusAsync(token, Statuses.Valid, It.IsAny())) .ReturnsAsync(false); @@ -778,7 +778,7 @@ public abstract partial class OpenIddictServerIntegrationTests .ReturnsAsync(token); mock.Setup(manager => manager.GetIdAsync(token, It.IsAny())) - .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); + .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); mock.Setup(manager => manager.HasStatusAsync(token, Statuses.Valid, It.IsAny())) .ReturnsAsync(true); diff --git a/test/OpenIddict.Server.Owin.IntegrationTests/OpenIddictServerOwinIntegrationTestServer.cs b/test/OpenIddict.Server.Owin.IntegrationTests/OpenIddictServerOwinIntegrationTestServer.cs index 2bd5c3b9..44b85313 100644 --- a/test/OpenIddict.Server.Owin.IntegrationTests/OpenIddictServerOwinIntegrationTestServer.cs +++ b/test/OpenIddict.Server.Owin.IntegrationTests/OpenIddictServerOwinIntegrationTestServer.cs @@ -26,8 +26,7 @@ public class OpenIddictServerOwinIntegrationTestServer : OpenIddictServerIntegra [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The caller is responsible of disposing the test client.")] public override ValueTask CreateClientAsync() - => new ValueTask( - new OpenIddictServerIntegrationTestClient(Server.HttpClient)); + => new(new OpenIddictServerIntegrationTestClient(Server.HttpClient)); public override ValueTask DisposeAsync() { diff --git a/test/OpenIddict.Server.Owin.IntegrationTests/OpenIddictServerOwinIntegrationTests.cs b/test/OpenIddict.Server.Owin.IntegrationTests/OpenIddictServerOwinIntegrationTests.cs index a0d14308..abf980d9 100644 --- a/test/OpenIddict.Server.Owin.IntegrationTests/OpenIddictServerOwinIntegrationTests.cs +++ b/test/OpenIddict.Server.Owin.IntegrationTests/OpenIddictServerOwinIntegrationTests.cs @@ -814,7 +814,6 @@ public partial class OpenIddictServerOwinIntegrationTests : OpenIddictServerInte }); }); - return new ValueTask( - new OpenIddictServerOwinIntegrationTestServer(server)); + return new(new OpenIddictServerOwinIntegrationTestServer(server)); } } diff --git a/test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs b/test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs index cc991de8..f7e45105 100644 --- a/test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs +++ b/test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs @@ -20,7 +20,7 @@ public class OpenIddictServerExtensionsTests var builder = (OpenIddictBuilder) null!; // Act and assert - var exception = Assert.Throws(() => builder.AddServer()); + var exception = Assert.Throws(builder.AddServer); Assert.Equal("builder", exception.ParamName); } @@ -169,7 +169,7 @@ public class OpenIddictServerExtensionsTests // Assert var provider = services.BuildServiceProvider(); - var exception = Assert.Throws(() => provider.GetRequiredService()); + var exception = Assert.Throws(provider.GetRequiredService); Assert.NotNull(exception); }