diff --git a/.editorconfig b/.editorconfig
index c487b3c4..1b59796a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -95,7 +95,7 @@ csharp_using_directive_placement = outside_namespace
[*.{cs,vb}]
dotnet_code_quality_unused_parameters = all
-dotnet_diagnostic.CA1510.severity = none
+dotnet_diagnostic.CA1510.severity = suggestion
dotnet_diagnostic.CA2254.severity = none
dotnet_diagnostic.IDE0002.severity = none
dotnet_diagnostic.IDE0305.severity = none
diff --git a/Directory.Build.props b/Directory.Build.props
index f727d266..25aef65d 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -16,12 +16,15 @@
portable
snupkg
true
+ true
false
true
true
false
false
true
+ true
+ true
@@ -207,10 +210,6 @@
true
-
- true
-
-
diff --git a/Directory.Build.targets b/Directory.Build.targets
index b543c1bc..dc320ece 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -55,30 +55,24 @@
$(DefineConstants);SUPPORTS_APPLICATION_CONFIGURATION_INITIALIZATION
$(DefineConstants);SUPPORTS_AUTHENTICATION_HANDLER_SELECTION_FALLBACK
+ $(DefineConstants);SUPPORTS_AUTHENTICATION_HANDLER_TIME_PROVIDER_ARGUMENT
$(DefineConstants);SUPPORTS_AUTHORIZATION_MIDDLEWARE
$(DefineConstants);SUPPORTS_BCL_ASYNC_ENUMERABLE
$(DefineConstants);SUPPORTS_BULK_DBSET_OPERATIONS
- $(DefineConstants);SUPPORTS_CHUNK_LINQ_EXTENSION
$(DefineConstants);SUPPORTS_DBSET_VALUETASK_FINDASYNC
$(DefineConstants);SUPPORTS_ENDPOINT_ROUTING
$(DefineConstants);SUPPORTS_ENVIRONMENT_PROCESS_PATH
- $(DefineConstants);SUPPORTS_HEXADECIMAL_STRING_CONVERSION
$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION
$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY
$(DefineConstants);SUPPORTS_HTTP_CLIENT_RESILIENCE
- $(DefineConstants);SUPPORTS_INT32_RANDOM_NUMBER_GENERATOR_METHODS
$(DefineConstants);SUPPORTS_MULTIPLE_VALUES_IN_QUERYHELPERS
$(DefineConstants);SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL
$(DefineConstants);SUPPORTS_ONE_SHOT_HASHING_METHODS
$(DefineConstants);SUPPORTS_ONE_SHOT_KEY_DERIVATION_METHODS
- $(DefineConstants);SUPPORTS_ONE_SHOT_RANDOM_NUMBER_GENERATOR_METHODS
$(DefineConstants);SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
$(DefineConstants);SUPPORTS_PEM_ENCODED_KEY_IMPORT
$(DefineConstants);SUPPORTS_REDIRECTION_ON_SIGN_IN
- $(DefineConstants);SUPPORTS_TASK_WAIT_ASYNC
$(DefineConstants);SUPPORTS_TEXT_ELEMENT_ENUMERATOR
- $(DefineConstants);SUPPORTS_TIME_PROVIDER
- $(DefineConstants);SUPPORTS_VALUETASK_COMPLETED_TASK
$(DefineConstants);SUPPORTS_WINFORMS_TASK_DIALOG
$(DefineConstants);SUPPORTS_ZLIB_COMPRESSION
@@ -98,7 +92,6 @@
$(DefineConstants);SUPPORTS_EPHEMERAL_KEY_SETS
$(DefineConstants);SUPPORTS_KEY_DERIVATION_WITH_SPECIFIED_HASH_ALGORITHM
$(DefineConstants);SUPPORTS_RSA_KEY_CREATION_WITH_SPECIFIED_SIZE
- $(DefineConstants);SUPPORTS_TOHASHSET_LINQ_EXTENSION
$(DefineConstants);SUPPORTS_BROTLI_COMPRESSION
$(DefineConstants);SUPPORTS_CURRENT_USER_ONLY_PIPE_OPTION
$(DefineConstants);SUPPORTS_SERVICE_PROVIDER_IN_HTTP_MESSAGE_HANDLER_BUILDER
- $(DefineConstants);SUPPORTS_STATIC_RANDOM_NUMBER_GENERATOR_METHODS
- $(DefineConstants);SUPPORTS_STREAM_MEMORY_METHODS
$(DefineConstants);SUPPORTS_TIME_CONSTANT_COMPARISONS
$(DefineConstants);SUPPORTS_WEB_INTEGRATION_IN_GENERIC_HOST
@@ -164,6 +155,19 @@
$(DefineConstants);SUPPORTS_WINDOWS_RUNTIME
+
+
+
+ $(DefineConstants);FeatureRuntimeInformation
+
+
+
+
+
+
+
+
+
diff --git a/Directory.Packages.props b/Directory.Packages.props
index c3147cfe..e0efa239 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -11,15 +11,117 @@
-->
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -96,10 +198,10 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs b/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs
index 469d3703..b3ad01df 100644
--- a/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs
+++ b/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs
@@ -241,10 +241,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetClaimsIssuer(string issuer)
{
- if (string.IsNullOrEmpty(issuer))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(issuer));
- }
+ ArgumentException.ThrowIfNullOrEmpty(issuer);
return Set(registration => registration.ClaimsIssuer = issuer);
}
@@ -256,10 +253,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetProviderName(string name)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
return Set(registration => registration.ProviderName = name);
}
@@ -271,10 +265,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetProviderDisplayName(string name)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
return Set(registration => registration.ProviderDisplayName = name);
}
@@ -286,10 +277,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetRegistrationId(string identifier)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
return Set(registration => registration.RegistrationId = identifier);
}
@@ -301,10 +289,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetClientId(string identifier)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
return Set(registration => registration.ClientId = identifier);
}
@@ -316,10 +301,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetClientSecret(string secret)
{
- if (string.IsNullOrEmpty(secret))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0125), nameof(secret));
- }
+ ArgumentException.ThrowIfNullOrEmpty(secret);
return Set(registration => registration.ClientSecret = secret);
}
@@ -335,10 +317,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetPostLogoutRedirectUri(Uri uri)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(uri);
return Set(registration => registration.PostLogoutRedirectUri = uri);
}
@@ -354,10 +333,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetPostLogoutRedirectUri([StringSyntax(StringSyntaxAttribute.Uri)] string uri)
{
- if (string.IsNullOrEmpty(uri))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
- }
+ ArgumentException.ThrowIfNullOrEmpty(uri);
return SetPostLogoutRedirectUri(new Uri(uri, UriKind.RelativeOrAbsolute));
}
@@ -373,10 +349,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetRedirectUri(Uri uri)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(uri);
return Set(registration => registration.RedirectUri = uri);
}
@@ -392,10 +365,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public {{ provider.name }} SetRedirectUri([StringSyntax(StringSyntaxAttribute.Uri)] string uri)
{
- if (string.IsNullOrEmpty(uri))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
- }
+ ArgumentException.ThrowIfNullOrEmpty(uri);
return SetRedirectUri(new Uri(uri, UriKind.RelativeOrAbsolute));
}
@@ -421,10 +391,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Add{{ setting.property_name }}(params {{ setting.clr_type }}[] {{ setting.parameter_name }})
{
- if ({{ setting.parameter_name }} is null)
- {
- throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
- }
+ ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
return Set(registration => registration.Get{{ provider.name }}Settings().{{ setting.property_name }}.UnionWith({{ setting.parameter_name }}));
}
@@ -439,10 +406,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(ECDsaSecurityKey {{ setting.parameter_name }})
{
- if ({{ setting.parameter_name }} is null)
- {
- throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
- }
+ ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
if ({{ setting.parameter_name }}.PrivateKeyStatus is PrivateKeyStatus.DoesNotExist)
{
@@ -524,10 +488,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(Uri {{ setting.parameter_name }})
{
- if ({{ setting.parameter_name }} is null)
- {
- throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
- }
+ ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
if (!{{ setting.parameter_name }}.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri({{ setting.parameter_name }}))
{
@@ -547,10 +508,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(string {{ setting.parameter_name }})
{
- if (string.IsNullOrEmpty({{ setting.parameter_name }}))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof({{ setting.parameter_name }}));
- }
+ ArgumentException.ThrowIfNullOrEmpty({{ setting.parameter_name }});
return Set{{ setting.property_name }}(new Uri({{ setting.parameter_name }}, UriKind.RelativeOrAbsolute));
}
@@ -565,10 +523,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(X509Certificate2 {{ setting.parameter_name }})
{
- if ({{ setting.parameter_name }} is null)
- {
- throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
- }
+ ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
if (!{{ setting.parameter_name }}.HasPrivateKey)
{
@@ -591,7 +546,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
public {{ provider.name }} Set{{ setting.property_name }}(Assembly assembly, string resource, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
- => Set{{ setting.property_name }}(assembly, resource, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
+ => Set{{ setting.property_name }}(assembly, resource, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@@ -613,15 +568,8 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
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));
- }
+ ArgumentNullException.ThrowIfNull(assembly);
+ ArgumentException.ThrowIfNullOrEmpty(resource);
using var stream = assembly.GetManifestResourceStream(resource) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0064));
@@ -641,7 +589,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
public {{ provider.name }} Set{{ setting.property_name }}(Stream stream, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
- => Set{{ setting.property_name }}(stream, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
+ => Set{{ setting.property_name }}(stream, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@@ -660,10 +608,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(Stream stream, string? password, X509KeyStorageFlags flags)
{
- if (stream is null)
- {
- throw new ArgumentNullException(nameof(stream));
- }
+ ArgumentNullException.ThrowIfNull(stream);
using var buffer = new MemoryStream();
stream.CopyTo(buffer);
@@ -691,10 +636,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(string thumbprint)
{
- if (string.IsNullOrEmpty(thumbprint))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
- }
+ ArgumentException.ThrowIfNullOrEmpty(thumbprint);
return Set{{ setting.property_name }}(
GetCertificate(StoreLocation.CurrentUser, thumbprint) ??
@@ -724,10 +666,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(string thumbprint, StoreName name, StoreLocation location)
{
- if (string.IsNullOrEmpty(thumbprint))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
- }
+ ArgumentException.ThrowIfNullOrEmpty(thumbprint);
using var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly);
@@ -759,10 +698,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}({{ setting.clr_type }} {{ setting.parameter_name }})
{
- if ({{ setting.parameter_name }} is null)
- {
- throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
- }
+ ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
return Set(registration => registration.Get{{ provider.name }}Settings().{{ setting.property_name }} = {{ setting.parameter_name }});
}
@@ -790,10 +726,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
private {{ provider.name }} Set(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
configuration(Registration);
@@ -973,6 +906,8 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration
{
public static partial void ConfigureProvider(OpenIddictClientRegistration registration)
{
+ ArgumentNullException.ThrowIfNull(registration);
+
{{~ for provider in providers ~}}
{{~ if for.index == 0 ~}}
if (registration.ProviderType is ProviderTypes.{{ provider.name }})
diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj b/sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj
index ff9daf7d..c8b52ada 100644
--- a/sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj
+++ b/sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj
@@ -7,7 +7,7 @@
false
disable
CA3147
- true
+ false
diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj b/sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj
index 28ae28f1..e0d2cc92 100644
--- a/sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj
+++ b/sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj
@@ -7,7 +7,7 @@
false
disable
CA3147
- true
+ false
diff --git a/sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs b/sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs
index 9fb74c50..856be8ab 100644
--- a/sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs
+++ b/sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs
@@ -436,7 +436,7 @@ public class InteractiveService : BackgroundService
select registration)
.UseConverter(registration => registration.ProviderDisplayName!)).ProviderName!;
- return WaitAsync(Task.Run(PromptAsync, cancellationToken), cancellationToken);
+ return Task.Run(PromptAsync, cancellationToken).WaitAsync(cancellationToken);
}
Task<(string? GrantType, string? ResponseType)> GetSelectedFlowAsync(
@@ -557,7 +557,7 @@ public class InteractiveService : BackgroundService
.UseConverter(choice => choice.DisplayName)).Item1;
}
- return WaitAsync(Task.Run(() => Prompt(registration, configuration), cancellationToken), cancellationToken);
+ return Task.Run(() => Prompt(registration, configuration), cancellationToken).WaitAsync(cancellationToken);
}
Task GetSelectedGrantTypeAsync(
@@ -608,7 +608,7 @@ public class InteractiveService : BackgroundService
.UseConverter(choice => choice.DisplayName)).GrantType;
}
- return WaitAsync(Task.Run(() => Prompt(registration, configuration), cancellationToken), cancellationToken);
+ return Task.Run(() => Prompt(registration, configuration), cancellationToken).WaitAsync(cancellationToken);
}
Task AuthenticateUserInteractivelyAsync(
@@ -632,7 +632,7 @@ public class InteractiveService : BackgroundService
registration.GrantTypes.Any(static type => type is not (
GrantTypes.AuthorizationCode or GrantTypes.Implicit or GrantTypes.RefreshToken))))
{
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
return Task.FromResult(true);
@@ -647,7 +647,7 @@ public class InteractiveService : BackgroundService
registration.GrantTypes.Any(static type => type is not (
GrantTypes.AuthorizationCode or GrantTypes.Implicit or GrantTypes.RefreshToken))))
{
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
return Task.FromResult(true);
@@ -664,7 +664,7 @@ public class InteractiveService : BackgroundService
IsSecret = false
});
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
Task GetPasswordAsync(CancellationToken cancellationToken)
@@ -675,7 +675,7 @@ public class InteractiveService : BackgroundService
IsSecret = true
});
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
static Task RefreshTokenAsync(CancellationToken cancellationToken)
@@ -688,7 +688,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true
});
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
Task GetRequestedTokenTypeAsync(CancellationToken cancellationToken)
@@ -704,7 +704,7 @@ public class InteractiveService : BackgroundService
])
.UseConverter(choice => choice.DisplayName)).TokenType;
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
Task<(string TokenType, string Token)> GetSubjectTokenAsync(CancellationToken cancellationToken)
@@ -730,7 +730,7 @@ public class InteractiveService : BackgroundService
return (type, token);
}
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
Task<(string? TokenType, string? Token)> GetActorTokenAsync(CancellationToken cancellationToken)
@@ -760,7 +760,7 @@ public class InteractiveService : BackgroundService
}));
}
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
static Task IntrospectAccessTokenAsync(CancellationToken cancellationToken)
@@ -773,7 +773,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true
});
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
static Task LogOutAsync(CancellationToken cancellationToken)
@@ -785,7 +785,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true
});
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
static Task RevokeAccessTokenAsync(CancellationToken cancellationToken)
@@ -798,26 +798,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true
});
- return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
- }
-
- static async Task WaitAsync(Task task, CancellationToken cancellationToken)
- {
-#if SUPPORTS_TASK_WAIT_ASYNC
- return await task.WaitAsync(cancellationToken);
-#else
- var source = new TaskCompletionSource(TaskCreationOptions.None);
-
- using (cancellationToken.Register(static state => ((TaskCompletionSource) state!).SetResult(true), source))
- {
- if (await Task.WhenAny(task, source.Task) == source.Task)
- {
- throw new OperationCanceledException(cancellationToken);
- }
-
- return await task;
- }
-#endif
+ return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
}
}
diff --git a/shared/OpenIddict.Extensions/OpenIddict.Extensions.csproj b/shared/OpenIddict.Extensions/OpenIddict.Extensions.csproj
index 72076a39..d1f609b1 100644
--- a/shared/OpenIddict.Extensions/OpenIddict.Extensions.csproj
+++ b/shared/OpenIddict.Extensions/OpenIddict.Extensions.csproj
@@ -3,6 +3,7 @@
netstandard2.0
false
+ $(DefineConstants);FeatureValueTuple
diff --git a/shared/OpenIddict.Extensions/OpenIddictHelpers.cs b/shared/OpenIddict.Extensions/OpenIddictHelpers.cs
index 0ebe8b84..42bf09c7 100644
--- a/shared/OpenIddict.Extensions/OpenIddictHelpers.cs
+++ b/shared/OpenIddict.Extensions/OpenIddictHelpers.cs
@@ -35,10 +35,7 @@ internal static class OpenIddictHelpers
///
public static bool IncludesAnyFromSet(IReadOnlyList array, ISet set)
{
- if (set is null)
- {
- throw new ArgumentNullException(nameof(set));
- }
+ ArgumentNullException.ThrowIfNull(set);
for (var index = 0; index < array.Count; index++)
{
@@ -150,15 +147,8 @@ internal static class OpenIddictHelpers
/// is not an absolute URI.
public static bool IsBaseOf(Uri left, Uri right)
{
- if (left is null)
- {
- throw new ArgumentNullException(nameof(left));
- }
-
- if (right is null)
- {
- throw new ArgumentNullException(nameof(right));
- }
+ ArgumentNullException.ThrowIfNull(left);
+ ArgumentNullException.ThrowIfNull(right);
if (left is not { IsAbsoluteUri: true })
{
@@ -188,10 +178,7 @@ internal static class OpenIddictHelpers
/// is .
public static bool IsImplicitFileUri(Uri uri)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(uri);
return uri.IsAbsoluteUri && uri.IsFile &&
!uri.OriginalString.StartsWith(uri.Scheme, StringComparison.OrdinalIgnoreCase);
@@ -206,10 +193,7 @@ internal static class OpenIddictHelpers
/// The final instance, with the specified parameter appended.
public static Uri AddQueryStringParameter(Uri uri, string name, string? value)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(uri);
var builder = new StringBuilder(uri.Query);
if (builder.Length > 0)
@@ -238,15 +222,8 @@ internal static class OpenIddictHelpers
/// is .
public static Uri AddQueryStringParameters(Uri uri, IReadOnlyDictionary parameters)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
-
- if (parameters is null)
- {
- throw new ArgumentNullException(nameof(parameters));
- }
+ ArgumentNullException.ThrowIfNull(uri);
+ ArgumentNullException.ThrowIfNull(parameters);
if (parameters.Count is 0)
{
@@ -302,10 +279,7 @@ internal static class OpenIddictHelpers
/// is .
public static IReadOnlyDictionary ParseQuery(string query)
{
- if (query is null)
- {
- throw new ArgumentNullException(nameof(query));
- }
+ ArgumentNullException.ThrowIfNull(query);
return query.TrimStart(Separators.QuestionMark[0])
.Split([Separators.Ampersand[0], Separators.Semicolon[0]], StringSplitOptions.RemoveEmptyEntries)
@@ -326,10 +300,7 @@ internal static class OpenIddictHelpers
/// is .
public static IReadOnlyDictionary ParseFragment(string fragment)
{
- if (fragment is null)
- {
- throw new ArgumentNullException(nameof(fragment));
- }
+ ArgumentNullException.ThrowIfNull(fragment);
return fragment.TrimStart(Separators.Hash[0])
.Split([Separators.Ampersand[0], Separators.Semicolon[0]], StringSplitOptions.RemoveEmptyEntries)
@@ -353,15 +324,8 @@ internal static class OpenIddictHelpers
public static async ValueTask> ParseFormAsync(
Stream stream, Encoding encoding, CancellationToken cancellationToken)
{
- if (stream is null)
- {
- throw new ArgumentNullException(nameof(stream));
- }
-
- if (encoding is null)
- {
- throw new ArgumentNullException(nameof(encoding));
- }
+ ArgumentNullException.ThrowIfNull(stream);
+ ArgumentNullException.ThrowIfNull(encoding);
var reader = new FormReader(stream, encoding);
return await reader.ReadFormAsync(cancellationToken);
@@ -692,7 +656,7 @@ internal static class OpenIddictHelpers
///
public static byte[] CreateRandomArray(int size)
{
- var algorithm = GetAlgorithmFromConfig() switch
+ using var algorithm = GetAlgorithmFromConfig() switch
{
RandomNumberGenerator result => result,
null => null,
@@ -701,32 +665,13 @@ internal static class OpenIddictHelpers
// If no custom random number generator was registered, use either the static GetBytes() or
// Fill() APIs on platforms that support them or create a default instance provided by the BCL.
-#if SUPPORTS_ONE_SHOT_RANDOM_NUMBER_GENERATOR_METHODS
if (algorithm is null)
{
return RandomNumberGenerator.GetBytes(size / 8);
}
-#endif
- var array = new byte[size / 8];
-
-#if SUPPORTS_STATIC_RANDOM_NUMBER_GENERATOR_METHODS
- if (algorithm is null)
- {
- RandomNumberGenerator.Fill(array);
- return array;
- }
-#else
- algorithm ??= RandomNumberGenerator.Create();
-#endif
- try
- {
- algorithm.GetBytes(array);
- }
- finally
- {
- algorithm.Dispose();
- }
+ var array = new byte[size / 8];
+ algorithm.GetBytes(array);
return array;
@@ -747,40 +692,30 @@ internal static class OpenIddictHelpers
///
public static string CreateRandomString(ReadOnlySpan charset, int count)
{
- var algorithm = GetAlgorithmFromConfig() switch
+ using var algorithm = GetAlgorithmFromConfig() switch
{
RandomNumberGenerator result => result,
null => null,
var result => throw new CryptographicException(SR.FormatID0351(result.GetType().FullName))
};
- try
- {
- var builder = new StringBuilder();
+ var builder = new StringBuilder();
- for (var index = 0; index < count; index++)
+ for (var index = 0; index < count; index++)
+ {
+ // Pick a character in the specified charset by generating a random index.
+ builder.Append(charset[index: algorithm switch
{
- // Pick a character in the specified charset by generating a random index.
- builder.Append(charset[index: algorithm switch
- {
-#if SUPPORTS_INT32_RANDOM_NUMBER_GENERATOR_METHODS
- // If no custom random number generator was registered, use
- // the static GetInt32() API on platforms that support it.
- null => RandomNumberGenerator.GetInt32(0, charset.Length),
-#endif
- // Otherwise, create a default implementation if necessary
- // and use the local function that achieves the same result.
- _ => GetInt32(algorithm ??= RandomNumberGenerator.Create(), 0..charset.Length)
- }]);
- }
+ // If no custom random number generator was registered, use the static GetInt32() API.
+ null => RandomNumberGenerator.GetInt32(0, charset.Length),
- return builder.ToString();
+ // Otherwise, create a default implementation if necessary
+ // and use the local function that achieves the same result.
+ _ => GetInt32(algorithm, 0..charset.Length)
+ }]);
}
- finally
- {
- algorithm?.Dispose();
- }
+ return builder.ToString();
static int GetInt32(RandomNumberGenerator algorithm, Range range)
{
@@ -867,32 +802,6 @@ internal static class OpenIddictHelpers
#endif
}
- ///
- /// Converts the specified hex-encoded to a byte array.
- ///
- /// The hexadecimal string.
- /// The byte array.
- public static byte[] ConvertFromHexadecimalString(string value)
- {
-#if SUPPORTS_HEXADECIMAL_STRING_CONVERSION
- return Convert.FromHexString(value);
-#else
- if ((uint) value.Length % 2 is not 0)
- {
- throw new FormatException(SR.GetResourceString(SR.ID0413));
- }
-
- var array = new byte[value.Length / 2];
-
- for (var index = 0; index < value.Length; index += 2)
- {
- array[index / 2] = Convert.ToByte(value.Substring(index, 2), 16);
- }
-
- return array;
-#endif
- }
-
///
/// Removes the characters that are not part of
/// from the specified string.
@@ -906,10 +815,7 @@ internal static class OpenIddictHelpers
/// is .
public static string? RemoveDisallowedCharacters(string? value, IReadOnlyCollection charset)
{
- if (charset is null)
- {
- throw new ArgumentNullException(nameof(charset));
- }
+ ArgumentNullException.ThrowIfNull(charset);
if (charset.Count is 0 || string.IsNullOrEmpty(value))
{
diff --git a/shared/OpenIddict.Extensions/OpenIddictPolyfills.cs b/shared/OpenIddict.Extensions/OpenIddictPolyfills.cs
deleted file mode 100644
index 6a5f50fd..00000000
--- a/shared/OpenIddict.Extensions/OpenIddictPolyfills.cs
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- * See https://github.com/openiddict/openiddict-core for more information concerning
- * the license and the contributors participating to this project.
- */
-
-using System.Diagnostics;
-
-namespace OpenIddict.Extensions;
-
-///
-/// Exposes common polyfills used by the OpenIddict assemblies.
-///
-internal static class OpenIddictPolyfills
-{
- extension(IEnumerable source)
- {
-#if !SUPPORTS_CHUNK_LINQ_EXTENSION
- ///
- /// Split the elements of a sequence into chunks of size at most .
- ///
- ///
- /// Every chunk except the last will be of size .
- /// The last chunk will contain the remaining elements and may be of a smaller size.
- ///
- /// Maximum size of each chunk.
- ///
- /// An that contains the elements of the input
- /// sequence split into chunks of size .
- ///
- public IEnumerable Chunk(int size)
- {
- // Note: this polyfill was directly copied from .NET's source code:
- // https://github.com/dotnet/runtime/blob/main/src/libraries/System.Linq/src/System/Linq/Chunk.cs.
-
- using IEnumerator enumerator = source.GetEnumerator();
-
- if (enumerator.MoveNext())
- {
- var count = Math.Min(size, 4);
- int index;
-
- do
- {
- var array = new TSource[count];
-
- array[0] = enumerator.Current;
- index = 1;
-
- if (size != array.Length)
- {
- for (; index < size && enumerator.MoveNext(); index++)
- {
- if (index >= array.Length)
- {
- count = (int) Math.Min((uint) size, 2 * (uint) array.Length);
- Array.Resize(ref array, count);
- }
-
- array[index] = enumerator.Current;
- }
- }
-
- else
- {
- var local = array;
- Debug.Assert(local.Length == size);
- for (; (uint) index < (uint) local.Length && enumerator.MoveNext(); index++)
- {
- local[index] = enumerator.Current;
- }
- }
-
- if (index != array.Length)
- {
- Array.Resize(ref array, index);
- }
-
- yield return array;
- }
-
- while (index >= size && enumerator.MoveNext());
- }
- }
-#endif
-
-#if !SUPPORTS_TOHASHSET_LINQ_EXTENSION
- ///
- /// Creates a new instance and imports the elements present in the specified source.
- ///
- /// The comparer to use.
- /// A new instance and imports the elements present in the specified source.
- public HashSet ToHashSet(IEqualityComparer? comparer) => new(source, comparer);
-#endif
- }
-
- extension(Task task)
- {
-#if !SUPPORTS_TASK_WAIT_ASYNC
- ///
- /// Waits until the specified task returns a result or the cancellation token is signaled.
- ///
- /// The that can be used to abort the operation.
- ///
- /// A that can be used to monitor the asynchronous operation.
- /// The specified is signaled.
- public async Task WaitAsync(CancellationToken cancellationToken)
- {
- var source = new TaskCompletionSource(TaskCreationOptions.None);
-
- using (cancellationToken.Register(static state => ((TaskCompletionSource) state!).SetResult(true), source))
- {
- if (await Task.WhenAny(task, source.Task) == source.Task)
- {
- throw new OperationCanceledException(cancellationToken);
- }
-
- await task;
- }
- }
-#endif
- }
-
- extension(Task task)
- {
-#if !SUPPORTS_TASK_WAIT_ASYNC
- ///
- /// Waits until the specified task returns a result or the cancellation token is signaled.
- ///
- /// The that can be used to abort the operation.
- ///
- /// A that can be used to monitor the asynchronous operation.
- /// The specified is signaled.
- public async Task WaitAsync(CancellationToken cancellationToken)
- {
- var source = new TaskCompletionSource(TaskCreationOptions.None);
-
- using (cancellationToken.Register(static state => ((TaskCompletionSource) state!).SetResult(true), source))
- {
- if (await Task.WhenAny(task, source.Task) == source.Task)
- {
- throw new OperationCanceledException(cancellationToken);
- }
-
- return await task;
- }
- }
-#endif
- }
-
- extension(ValueTask)
- {
-#if !SUPPORTS_VALUETASK_COMPLETED_TASK
- ///
- /// Gets a task that has already completed successfully.
- ///
- public static ValueTask CompletedTask => default;
-#endif
- }
-
- extension(ValueTask)
- {
-#if !SUPPORTS_VALUETASK_COMPLETED_TASK
- ///
- /// Gets a task that has already completed successfully.
- ///
- public static ValueTask CompletedTask => default;
-#endif
- }
-}
diff --git a/src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs b/src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
index 114b0878..3bf0c71f 100644
--- a/src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
+++ b/src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
@@ -89,10 +89,7 @@ public class OpenIddictApplicationDescriptor
/// is .
public OpenIddictApplicationDescriptor AddAudiencePermissions(params string[] audiences)
{
- if (audiences is null)
- {
- throw new ArgumentNullException(nameof(audiences));
- }
+ ArgumentNullException.ThrowIfNull(audiences);
foreach (var audience in audiences)
{
@@ -110,10 +107,7 @@ public class OpenIddictApplicationDescriptor
/// is .
public OpenIddictApplicationDescriptor AddGrantTypePermissions(params string[] types)
{
- if (types is null)
- {
- throw new ArgumentNullException(nameof(types));
- }
+ ArgumentNullException.ThrowIfNull(types);
foreach (var type in types)
{
@@ -131,10 +125,7 @@ public class OpenIddictApplicationDescriptor
/// is .
public OpenIddictApplicationDescriptor AddResourcePermissions(params string[] resources)
{
- if (resources is null)
- {
- throw new ArgumentNullException(nameof(resources));
- }
+ ArgumentNullException.ThrowIfNull(resources);
foreach (var resource in resources)
{
@@ -152,10 +143,7 @@ public class OpenIddictApplicationDescriptor
/// is .
public OpenIddictApplicationDescriptor AddScopePermissions(params string[] scopes)
{
- if (scopes is null)
- {
- throw new ArgumentNullException(nameof(scopes));
- }
+ ArgumentNullException.ThrowIfNull(scopes);
foreach (var scope in scopes)
{
@@ -341,10 +329,7 @@ public class OpenIddictApplicationDescriptor
/// is .
public OpenIddictApplicationDescriptor RemoveAudiencePermissions(params string[] audiences)
{
- if (audiences is null)
- {
- throw new ArgumentNullException(nameof(audiences));
- }
+ ArgumentNullException.ThrowIfNull(audiences);
foreach (var audience in audiences)
{
@@ -362,10 +347,7 @@ public class OpenIddictApplicationDescriptor
/// is .
public OpenIddictApplicationDescriptor RemoveGrantTypePermissions(params string[] types)
{
- if (types is null)
- {
- throw new ArgumentNullException(nameof(types));
- }
+ ArgumentNullException.ThrowIfNull(types);
foreach (var type in types)
{
@@ -383,10 +365,7 @@ public class OpenIddictApplicationDescriptor
/// is .
public OpenIddictApplicationDescriptor RemoveResourcePermissions(params string[] resources)
{
- if (resources is null)
- {
- throw new ArgumentNullException(nameof(resources));
- }
+ ArgumentNullException.ThrowIfNull(resources);
foreach (var resource in resources)
{
@@ -404,10 +383,7 @@ public class OpenIddictApplicationDescriptor
/// is .
public OpenIddictApplicationDescriptor RemoveScopePermissions(params string[] scopes)
{
- if (scopes is null)
- {
- throw new ArgumentNullException(nameof(scopes));
- }
+ ArgumentNullException.ThrowIfNull(scopes);
foreach (var scope in scopes)
{
diff --git a/src/OpenIddict.Abstractions/OpenIddictExtensions.cs b/src/OpenIddict.Abstractions/OpenIddictExtensions.cs
index d7731ae6..e93bfb73 100644
--- a/src/OpenIddict.Abstractions/OpenIddictExtensions.cs
+++ b/src/OpenIddict.Abstractions/OpenIddictExtensions.cs
@@ -19,10 +19,7 @@ public static class OpenIddictExtensions
/// The instance.
public static OpenIddictBuilder AddOpenIddict(this IServiceCollection services)
{
- if (services is null)
- {
- throw new ArgumentNullException(nameof(services));
- }
+ ArgumentNullException.ThrowIfNull(services);
return new OpenIddictBuilder(services);
}
@@ -36,15 +33,8 @@ public static class OpenIddictExtensions
/// The .
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));
- }
+ ArgumentNullException.ThrowIfNull(services);
+ ArgumentNullException.ThrowIfNull(configuration);
configuration(services.AddOpenIddict());
diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs
index 10326d2b..8a8f1bd1 100644
--- a/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs
+++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs
@@ -21,10 +21,7 @@ public sealed class OpenIddictConverter : JsonConverter
/// if the type is supported, otherwise.
public override bool CanConvert(Type typeToConvert)
{
- if (typeToConvert is null)
- {
- throw new ArgumentNullException(nameof(typeToConvert));
- }
+ ArgumentNullException.ThrowIfNull(typeToConvert);
return typeToConvert == typeof(OpenIddictMessage) ||
typeToConvert == typeof(OpenIddictRequest) ||
@@ -40,10 +37,7 @@ public sealed class OpenIddictConverter : JsonConverter
/// The deserialized instance.
public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
- if (typeToConvert is null)
- {
- throw new ArgumentNullException(nameof(typeToConvert));
- }
+ ArgumentNullException.ThrowIfNull(typeToConvert);
using var document = JsonDocument.ParseValue(ref reader);
@@ -61,15 +55,8 @@ public sealed class OpenIddictConverter : JsonConverter
/// The JSON serializer 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));
- }
+ ArgumentNullException.ThrowIfNull(writer);
+ ArgumentNullException.ThrowIfNull(value);
value.WriteTo(writer);
}
diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs
index 4391d4ff..42e3643e 100644
--- a/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs
+++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs
@@ -29,10 +29,7 @@ public static class OpenIddictExtensions
/// The instance.
public static ImmutableArray GetAcrValues(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return GetValues(request.AcrValues, Separators.Space);
}
@@ -43,10 +40,7 @@ public static class OpenIddictExtensions
/// The instance.
public static ImmutableArray GetAudiences(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
if (request.Audiences is not { IsDefaultOrEmpty: false } audiences)
{
@@ -72,10 +66,7 @@ public static class OpenIddictExtensions
/// The instance.
public static ImmutableArray GetPromptValues(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return GetValues(request.Prompt, Separators.Space);
}
@@ -86,10 +77,7 @@ public static class OpenIddictExtensions
/// The instance.
public static ImmutableArray GetResources(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
if (request.Resources is not { IsDefaultOrEmpty: false } resources)
{
@@ -115,10 +103,7 @@ public static class OpenIddictExtensions
/// The instance.
public static ImmutableArray GetResponseTypes(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return GetValues(request.ResponseType, Separators.Space);
}
@@ -129,10 +114,7 @@ public static class OpenIddictExtensions
/// The instance.
public static ImmutableArray GetScopes(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return GetValues(request.Scope, Separators.Space);
}
@@ -144,15 +126,8 @@ public static class OpenIddictExtensions
/// The component to look for in the parameter.
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.FormatID0366(nameof(value)), nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentException.ThrowIfNullOrEmpty(value);
return HasValue(request.AcrValues, value, Separators.Space);
}
@@ -164,15 +139,8 @@ public static class OpenIddictExtensions
/// The value to look for in the parameters.
public static bool HasAudience(this OpenIddictRequest request, string audience)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
-
- if (string.IsNullOrEmpty(audience))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(audience)), nameof(audience));
- }
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentException.ThrowIfNullOrEmpty(audience);
var audiences = request.Audiences;
if (audiences is null or [])
@@ -199,15 +167,8 @@ public static class OpenIddictExtensions
/// The component to look for in the parameter.
public static bool HasPromptValue(this OpenIddictRequest request, string value)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
-
- if (string.IsNullOrEmpty(value))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(value)), nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentException.ThrowIfNullOrEmpty(value);
return HasValue(request.Prompt, value, Separators.Space);
}
@@ -219,15 +180,8 @@ public static class OpenIddictExtensions
/// The value to look for in the parameters.
public static bool HasResource(this OpenIddictRequest request, string resource)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
-
- if (string.IsNullOrEmpty(resource))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(resource)), nameof(resource));
- }
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentException.ThrowIfNullOrEmpty(resource);
var resources = request.Resources;
if (resources is null or [])
@@ -254,15 +208,8 @@ public static class OpenIddictExtensions
/// The component to look for in the parameter.
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.FormatID0366(nameof(type)), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentException.ThrowIfNullOrEmpty(type);
return HasValue(request.ResponseType, type, Separators.Space);
}
@@ -274,15 +221,8 @@ public static class OpenIddictExtensions
/// The component to look for in the parameter.
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.FormatID0366(nameof(scope)), nameof(scope));
- }
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentException.ThrowIfNullOrEmpty(scope);
return HasValue(request.Scope, scope, Separators.Space);
}
@@ -295,10 +235,7 @@ public static class OpenIddictExtensions
/// if the request is a response_type=none request, otherwise.
public static bool IsNoneFlow(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
if (string.IsNullOrEmpty(request.ResponseType))
{
@@ -322,10 +259,7 @@ public static class OpenIddictExtensions
/// if the request is a code flow request, otherwise.
public static bool IsAuthorizationCodeFlow(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
if (string.IsNullOrEmpty(request.ResponseType))
{
@@ -350,10 +284,7 @@ public static class OpenIddictExtensions
/// if the request is an implicit flow request, otherwise.
public static bool IsImplicitFlow(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
if (string.IsNullOrEmpty(request.ResponseType))
{
@@ -404,10 +335,7 @@ public static class OpenIddictExtensions
/// if the request is an hybrid flow request, otherwise.
public static bool IsHybridFlow(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
if (string.IsNullOrEmpty(request.ResponseType))
{
@@ -471,10 +399,7 @@ public static class OpenIddictExtensions
///
public static bool IsFragmentResponseMode(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
if (string.Equals(request.ResponseMode, ResponseModes.Fragment, StringComparison.Ordinal))
{
@@ -504,10 +429,7 @@ public static class OpenIddictExtensions
///
public static bool IsQueryResponseMode(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
if (string.Equals(request.ResponseMode, ResponseModes.Query, StringComparison.Ordinal))
{
@@ -536,10 +458,7 @@ public static class OpenIddictExtensions
///
public static bool IsFormPostResponseMode(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return string.Equals(request.ResponseMode, ResponseModes.FormPost, StringComparison.Ordinal);
}
@@ -552,10 +471,7 @@ public static class OpenIddictExtensions
/// if the request is a code grant request, otherwise.
public static bool IsAuthorizationCodeGrantType(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return string.Equals(request.GrantType, GrantTypes.AuthorizationCode, StringComparison.Ordinal);
}
@@ -568,10 +484,7 @@ public static class OpenIddictExtensions
/// if the request is a client credentials grant request, otherwise.
public static bool IsClientCredentialsGrantType(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return string.Equals(request.GrantType, GrantTypes.ClientCredentials, StringComparison.Ordinal);
}
@@ -584,10 +497,7 @@ public static class OpenIddictExtensions
/// if the request is a device code grant request, otherwise.
public static bool IsDeviceCodeGrantType(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return string.Equals(request.GrantType, GrantTypes.DeviceCode, StringComparison.Ordinal);
}
@@ -600,10 +510,7 @@ public static class OpenIddictExtensions
/// if the request is a password grant request, otherwise.
public static bool IsPasswordGrantType(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return string.Equals(request.GrantType, GrantTypes.Password, StringComparison.Ordinal);
}
@@ -616,10 +523,7 @@ public static class OpenIddictExtensions
/// if the request is a refresh token grant request, otherwise.
public static bool IsRefreshTokenGrantType(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return string.Equals(request.GrantType, GrantTypes.RefreshToken, StringComparison.Ordinal);
}
@@ -632,10 +536,7 @@ public static class OpenIddictExtensions
/// if the request is a token exchange grant request, otherwise.
public static bool IsTokenExchangeGrantType(this OpenIddictRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
return string.Equals(request.GrantType, GrantTypes.TokenExchange, StringComparison.Ordinal);
}
@@ -647,10 +548,7 @@ public static class OpenIddictExtensions
/// The destinations associated with the claim.
public static ImmutableArray GetDestinations(this Claim claim)
{
- if (claim is null)
- {
- throw new ArgumentNullException(nameof(claim));
- }
+ ArgumentNullException.ThrowIfNull(claim);
claim.Properties.TryGetValue(Properties.Destinations, out string? destinations);
@@ -683,15 +581,8 @@ public static class OpenIddictExtensions
/// The required 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));
- }
+ ArgumentNullException.ThrowIfNull(claim);
+ ArgumentException.ThrowIfNullOrEmpty(destination);
claim.Properties.TryGetValue(Properties.Destinations, out string? destinations);
@@ -722,10 +613,7 @@ public static class OpenIddictExtensions
[OverloadResolutionPriority(0)]
public static Claim SetDestinations(this Claim claim, ImmutableArray destinations)
{
- if (claim is null)
- {
- throw new ArgumentNullException(nameof(claim));
- }
+ ArgumentNullException.ThrowIfNull(claim);
if (destinations.IsDefaultOrEmpty)
{
@@ -786,10 +674,7 @@ public static class OpenIddictExtensions
/// The destinations, returned as a flattened dictionary.
public static ImmutableDictionary> GetDestinations(this ClaimsIdentity identity)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
+ ArgumentNullException.ThrowIfNull(identity);
var builder = ImmutableDictionary.CreateBuilder>(StringComparer.Ordinal);
@@ -823,10 +708,7 @@ public static class OpenIddictExtensions
/// The destinations, returned as a flattened dictionary.
public static ImmutableDictionary> GetDestinations(this ClaimsPrincipal principal)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
var builder = ImmutableDictionary.CreateBuilder>(StringComparer.Ordinal);
@@ -862,15 +744,8 @@ public static class OpenIddictExtensions
public static ClaimsIdentity SetDestinations(this ClaimsIdentity identity,
ImmutableDictionary> destinations)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (destinations is null)
- {
- throw new ArgumentNullException(nameof(destinations));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentNullException.ThrowIfNull(destinations);
foreach (var destination in destinations)
{
@@ -892,15 +767,8 @@ public static class OpenIddictExtensions
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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentNullException.ThrowIfNull(destinations);
foreach (var destination in destinations)
{
@@ -921,15 +789,8 @@ public static class OpenIddictExtensions
/// The identity.
public static ClaimsIdentity SetDestinations(this ClaimsIdentity identity, Func> selector)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (selector is null)
- {
- throw new ArgumentNullException(nameof(selector));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentNullException.ThrowIfNull(selector);
foreach (var claim in identity.Claims)
{
@@ -947,15 +808,8 @@ public static class OpenIddictExtensions
/// The principal.
public static ClaimsPrincipal SetDestinations(this ClaimsPrincipal principal, Func> selector)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (selector is null)
- {
- throw new ArgumentNullException(nameof(selector));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentNullException.ThrowIfNull(selector);
foreach (var claim in principal.Claims)
{
@@ -975,15 +829,8 @@ public static class OpenIddictExtensions
///
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));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentNullException.ThrowIfNull(filter);
var clone = identity.Clone();
@@ -1015,15 +862,8 @@ public static class OpenIddictExtensions
///
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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentNullException.ThrowIfNull(filter);
var clone = new ClaimsPrincipal();
@@ -1062,20 +902,9 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (value is null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentNullException.ThrowIfNull(value);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.AddClaim(new Claim(type, value, ClaimValueTypes.String, issuer, issuer, identity));
return identity;
@@ -1090,21 +919,14 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsPrincipal AddClaim(this ClaimsPrincipal principal, string type, string value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (principal.Identity is not ClaimsIdentity identity)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal));
}
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
identity.AddClaim(type, value, issuer);
return principal;
}
@@ -1136,15 +958,8 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, bool value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.AddClaim(new Claim(type, value.ToString(), ClaimValueTypes.Boolean, issuer, issuer, identity));
return identity;
@@ -1159,10 +974,7 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsPrincipal AddClaim(this ClaimsPrincipal principal, string type, bool value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
if (principal.Identity is not ClaimsIdentity identity)
{
@@ -1200,15 +1012,8 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, long value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.AddClaim(new Claim(type, value.ToString(CultureInfo.InvariantCulture),
ClaimValueTypes.Integer64, issuer, issuer, identity));
@@ -1224,21 +1029,14 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsPrincipal AddClaim(this ClaimsPrincipal principal, string type, long value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (principal.Identity is not ClaimsIdentity identity)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal));
}
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
identity.AddClaim(type, value, issuer);
return principal;
}
@@ -1270,15 +1068,8 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, JsonElement value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (value.ValueKind is JsonValueKind.Array)
{
@@ -1305,21 +1096,14 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsPrincipal AddClaim(this ClaimsPrincipal principal, string type, JsonElement value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (principal.Identity is not ClaimsIdentity identity)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal));
}
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
identity.AddClaim(type, value, issuer);
return principal;
@@ -1352,20 +1136,10 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, JsonNode value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
- if (value is null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(value);
if (value is JsonArray)
{
@@ -1399,25 +1173,15 @@ public static class OpenIddictExtensions
/// The issuer associated with the claim.
public static ClaimsPrincipal AddClaim(this ClaimsPrincipal principal, string type, JsonNode value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (principal.Identity is not ClaimsIdentity identity)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal));
}
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
- if (value is null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(value);
identity.AddClaim(type, value, issuer);
@@ -1454,20 +1218,9 @@ public static class OpenIddictExtensions
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type,
IDictionary value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (value is null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentNullException.ThrowIfNull(value);
+ ArgumentException.ThrowIfNullOrEmpty(type);
using var stream = new MemoryStream();
using var writer = new Utf8JsonWriter(stream, new JsonWriterOptions
@@ -1508,21 +1261,14 @@ public static class OpenIddictExtensions
public static ClaimsPrincipal AddClaim(this ClaimsPrincipal principal, string type,
IDictionary value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (principal.Identity is not ClaimsIdentity identity)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal));
}
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
identity.AddClaim(type, value, issuer);
return principal;
@@ -1558,15 +1304,8 @@ public static class OpenIddictExtensions
[OverloadResolutionPriority(0)]
public static ClaimsIdentity AddClaims(this ClaimsIdentity identity, string type, ImmutableArray values, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
var set = new HashSet(StringComparer.Ordinal);
@@ -1599,21 +1338,14 @@ public static class OpenIddictExtensions
public static ClaimsPrincipal AddClaims(this ClaimsPrincipal principal,
string type, ImmutableArray values, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (principal.Identity is not ClaimsIdentity identity)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal));
}
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
identity.AddClaims(type, values, issuer);
return principal;
@@ -1646,15 +1378,8 @@ public static class OpenIddictExtensions
/// The issuer associated with the claims.
public static ClaimsIdentity AddClaims(this ClaimsIdentity identity, string type, JsonElement value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (value.ValueKind is not JsonValueKind.Array)
{
@@ -1690,21 +1415,14 @@ public static class OpenIddictExtensions
/// The issuer associated with the claims.
public static ClaimsPrincipal AddClaims(this ClaimsPrincipal principal, string type, JsonElement value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (principal.Identity is not ClaimsIdentity identity)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal));
}
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
if (value.ValueKind is not JsonValueKind.Array)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0185), nameof(value));
@@ -1745,20 +1463,9 @@ public static class OpenIddictExtensions
[OverloadResolutionPriority(-1)]
public static ClaimsIdentity AddClaims(this ClaimsIdentity identity, string type, JsonArray value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
- if (value is null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentNullException.ThrowIfNull(value);
+ ArgumentException.ThrowIfNullOrEmpty(type);
var set = new HashSet(StringComparer.Ordinal);
@@ -1801,21 +1508,14 @@ public static class OpenIddictExtensions
[OverloadResolutionPriority(-1)]
public static ClaimsPrincipal AddClaims(this ClaimsPrincipal principal, string type, JsonArray value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
if (principal.Identity is not ClaimsIdentity identity)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0286), nameof(principal));
}
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
identity.AddClaims(type, value, issuer);
return principal;
@@ -1832,15 +1532,8 @@ public static class OpenIddictExtensions
/// The claim value.
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));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
var claims = identity.FindAll(type);
if (claims is IList list)
@@ -1882,15 +1575,8 @@ public static class OpenIddictExtensions
/// The claim value.
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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
var claims = principal.FindAll(type);
if (claims is IList list)
@@ -1929,15 +1615,8 @@ public static class OpenIddictExtensions
/// The claim values.
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));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
var builder = ImmutableArray.CreateBuilder();
@@ -1981,15 +1660,8 @@ public static class OpenIddictExtensions
/// The claim values.
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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
var builder = ImmutableArray.CreateBuilder();
@@ -2033,15 +1705,8 @@ public static class OpenIddictExtensions
/// if the identity contains at least one claim of the specified 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));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
return identity.FindAll(type).Any();
}
@@ -2054,15 +1719,8 @@ public static class OpenIddictExtensions
/// if the principal contains at least one claim of the specified 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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
return principal.FindAll(type).Any();
}
@@ -2075,15 +1733,8 @@ public static class OpenIddictExtensions
/// The claims identity.
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));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
foreach (var claim in identity.FindAll(type).ToList())
{
@@ -2101,15 +1752,8 @@ public static class OpenIddictExtensions
/// The claims identity.
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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
foreach (var identity in principal.Identities)
{
@@ -2152,15 +1796,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsIdentity SetClaim(this ClaimsIdentity identity, string type, string? value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.RemoveClaims(type);
@@ -2182,15 +1819,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsPrincipal SetClaim(this ClaimsPrincipal principal, string type, string? value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
principal.RemoveClaims(type);
@@ -2232,15 +1862,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsIdentity SetClaim(this ClaimsIdentity identity, string type, bool? value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.RemoveClaims(type);
@@ -2262,15 +1885,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsPrincipal SetClaim(this ClaimsPrincipal principal, string type, bool? value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
principal.RemoveClaims(type);
@@ -2312,15 +1928,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsIdentity SetClaim(this ClaimsIdentity identity, string type, long? value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.RemoveClaims(type);
@@ -2342,15 +1951,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsPrincipal SetClaim(this ClaimsPrincipal principal, string type, long? value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
principal.RemoveClaims(type);
@@ -2392,15 +1994,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsIdentity SetClaim(this ClaimsIdentity identity, string type, JsonElement value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.RemoveClaims(type);
@@ -2422,15 +2017,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsPrincipal SetClaim(this ClaimsPrincipal principal, string type, JsonElement value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
principal.RemoveClaims(type);
@@ -2472,15 +2060,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsIdentity SetClaim(this ClaimsIdentity identity, string type, JsonNode? value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.RemoveClaims(type);
@@ -2502,15 +2083,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsPrincipal SetClaim(this ClaimsPrincipal principal, string type, JsonNode? value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
principal.RemoveClaims(type);
@@ -2555,15 +2129,8 @@ public static class OpenIddictExtensions
public static ClaimsIdentity SetClaim(this ClaimsIdentity identity, string type,
IDictionary? value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.RemoveClaims(type);
@@ -2586,15 +2153,8 @@ public static class OpenIddictExtensions
public static ClaimsPrincipal SetClaim(this ClaimsPrincipal principal, string type,
IDictionary? value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
principal.RemoveClaims(type);
@@ -2640,15 +2200,8 @@ public static class OpenIddictExtensions
public static ClaimsIdentity SetClaims(this ClaimsIdentity identity,
string type, ImmutableArray values, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.RemoveClaims(type);
@@ -2672,15 +2225,8 @@ public static class OpenIddictExtensions
public static ClaimsPrincipal SetClaims(this ClaimsPrincipal principal,
string type, ImmutableArray values, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
principal.RemoveClaims(type);
@@ -2722,15 +2268,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsIdentity SetClaims(this ClaimsIdentity identity, string type, JsonElement value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.RemoveClaims(type);
@@ -2752,15 +2291,8 @@ public static class OpenIddictExtensions
/// The claims identity.
public static ClaimsPrincipal SetClaims(this ClaimsPrincipal principal, string type, JsonElement value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
principal.RemoveClaims(type);
@@ -2805,20 +2337,9 @@ public static class OpenIddictExtensions
[OverloadResolutionPriority(-1)]
public static ClaimsIdentity SetClaims(this ClaimsIdentity identity, string type, JsonArray value, string issuer)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
- if (value is null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentNullException.ThrowIfNull(value);
+ ArgumentException.ThrowIfNullOrEmpty(type);
identity.RemoveClaims(type);
@@ -2841,20 +2362,9 @@ public static class OpenIddictExtensions
[OverloadResolutionPriority(-1)]
public static ClaimsPrincipal SetClaims(this ClaimsPrincipal principal, string type, JsonArray value, string issuer)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0184), nameof(type));
- }
-
- if (value is null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentNullException.ThrowIfNull(value);
+ ArgumentException.ThrowIfNullOrEmpty(type);
principal.RemoveClaims(type);
@@ -2873,10 +2383,7 @@ public static class OpenIddictExtensions
/// The creation date or if the claim cannot be found.
public static DateTimeOffset? GetCreationDate(this ClaimsIdentity identity)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
+ ArgumentNullException.ThrowIfNull(identity);
var claim = identity.FindFirst(Claims.Private.CreationDate);
if (claim is null)
@@ -2899,10 +2406,7 @@ public static class OpenIddictExtensions
/// The creation date or if the claim cannot be found.
public static DateTimeOffset? GetCreationDate(this ClaimsPrincipal principal)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
var claim = principal.FindFirst(Claims.Private.CreationDate);
if (claim is null)
@@ -2925,10 +2429,7 @@ public static class OpenIddictExtensions
/// The expiration date or if the claim cannot be found.
public static DateTimeOffset? GetExpirationDate(this ClaimsIdentity identity)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
+ ArgumentNullException.ThrowIfNull(identity);
var claim = identity.FindFirst(Claims.Private.ExpirationDate);
if (claim is null)
@@ -2951,10 +2452,7 @@ public static class OpenIddictExtensions
/// The expiration date or if the claim cannot be found.
public static DateTimeOffset? GetExpirationDate(this ClaimsPrincipal principal)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(principal);
var claim = principal.FindFirst(Claims.Private.ExpirationDate);
if (claim is null)
@@ -3234,15 +2732,8 @@ public static class OpenIddictExtensions
/// if the identity contains the given audience.
public static bool HasAudience(this ClaimsIdentity identity, string audience)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(audience))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0186), nameof(audience));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(audience);
return identity.HasClaim(Claims.Private.Audience, audience);
}
@@ -3255,15 +2746,8 @@ public static class OpenIddictExtensions
/// if the principal contains the given 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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(audience);
return principal.HasClaim(Claims.Private.Audience, audience);
}
@@ -3276,15 +2760,8 @@ public static class OpenIddictExtensions
/// if the identity contains the given presenter.
public static bool HasPresenter(this ClaimsIdentity identity, string presenter)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(presenter))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0187), nameof(presenter));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(presenter);
return identity.HasClaim(Claims.Private.Presenter, presenter);
}
@@ -3297,15 +2774,8 @@ public static class OpenIddictExtensions
/// if the principal contains the given 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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(presenter);
return principal.HasClaim(Claims.Private.Presenter, presenter);
}
@@ -3318,15 +2788,8 @@ public static class OpenIddictExtensions
/// if the identity contains the given resource.
public static bool HasResource(this ClaimsIdentity identity, string resource)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(resource))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(resource);
return identity.HasClaim(Claims.Private.Resource, resource);
}
@@ -3339,15 +2802,8 @@ public static class OpenIddictExtensions
/// if the principal contains the given 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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(resource);
return principal.HasClaim(Claims.Private.Resource, resource);
}
@@ -3360,15 +2816,8 @@ public static class OpenIddictExtensions
/// if the identity contains the given scope.
public static bool HasScope(this ClaimsIdentity identity, string scope)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(scope))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0180), nameof(scope));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(scope);
return identity.HasClaim(Claims.Private.Scope, scope);
}
@@ -3381,15 +2830,8 @@ public static class OpenIddictExtensions
/// if the principal contains the given 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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(scope);
return principal.HasClaim(Claims.Private.Scope, scope);
}
@@ -3402,15 +2844,8 @@ public static class OpenIddictExtensions
/// if the token type matches the specified type.
public static bool HasTokenType(this ClaimsIdentity identity, string type)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
-
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0188), nameof(type));
- }
+ ArgumentNullException.ThrowIfNull(identity);
+ ArgumentException.ThrowIfNullOrEmpty(type);
return string.Equals(identity.GetTokenType(), type, StringComparison.OrdinalIgnoreCase);
}
@@ -3423,15 +2858,8 @@ public static class OpenIddictExtensions
/// if the token type matches the specified 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));
- }
+ ArgumentNullException.ThrowIfNull(principal);
+ ArgumentException.ThrowIfNullOrEmpty(type);
return string.Equals(principal.GetTokenType(), type, StringComparison.OrdinalIgnoreCase);
}
@@ -4118,10 +3546,7 @@ public static class OpenIddictExtensions
private static TimeSpan? GetLifetime(ClaimsIdentity identity, string type)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
+ ArgumentNullException.ThrowIfNull(identity);
var value = identity.GetClaim(type);
if (string.IsNullOrEmpty(value))
@@ -4139,10 +3564,7 @@ public static class OpenIddictExtensions
private static TimeSpan? GetLifetime(ClaimsPrincipal principal, string type)
{
- if (principal is null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
+ ArgumentNullException.ThrowIfNull(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 aa3cf153..ae9fed9f 100644
--- a/src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs
+++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs
@@ -75,10 +75,7 @@ public class OpenIddictMessage
/// Parameters with a null or empty key are always ignored.
public OpenIddictMessage(JsonObject parameters)
{
- if (parameters is null)
- {
- throw new ArgumentNullException(nameof(parameters));
- }
+ ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters)
{
@@ -106,10 +103,7 @@ public class OpenIddictMessage
/// Parameters with a null or empty key are always ignored.
public OpenIddictMessage(IEnumerable> parameters)
{
- if (parameters is null)
- {
- throw new ArgumentNullException(nameof(parameters));
- }
+ ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters)
{
@@ -130,10 +124,7 @@ public class OpenIddictMessage
/// Parameters with a null or empty key are always ignored.
public OpenIddictMessage(IEnumerable> parameters)
{
- if (parameters is null)
- {
- throw new ArgumentNullException(nameof(parameters));
- }
+ ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters.GroupBy(parameter => parameter.Key))
{
@@ -163,10 +154,7 @@ public class OpenIddictMessage
/// Parameters with a null or empty key are always ignored.
public OpenIddictMessage(IEnumerable?>> parameters)
{
- if (parameters is null)
- {
- throw new ArgumentNullException(nameof(parameters));
- }
+ ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters)
{
@@ -196,10 +184,7 @@ public class OpenIddictMessage
/// Parameters with a null or empty key are always ignored.
public OpenIddictMessage(IEnumerable> parameters)
{
- if (parameters is null)
- {
- throw new ArgumentNullException(nameof(parameters));
- }
+ ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters)
{
@@ -229,10 +214,7 @@ public class OpenIddictMessage
/// Parameters with a null or empty key are always ignored.
public OpenIddictMessage(NameValueCollection parameters)
{
- if (parameters is null)
- {
- throw new ArgumentNullException(nameof(parameters));
- }
+ ArgumentNullException.ThrowIfNull(parameters);
for (var index = 0; index < parameters.AllKeys.Length; index++)
{
@@ -286,10 +268,7 @@ public class OpenIddictMessage
/// The current instance, which allows chaining calls.
public OpenIddictMessage AddParameter(string name, OpenIddictParameter value)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (Parameters.ContainsKey(name))
{
@@ -323,10 +302,7 @@ public class OpenIddictMessage
/// if the parameter is present, otherwise.
public bool HasParameter(string name)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
return Parameters.ContainsKey(name);
}
@@ -338,10 +314,7 @@ public class OpenIddictMessage
/// The current instance, which allows chaining calls.
public OpenIddictMessage RemoveParameter(string name)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
Parameters.Remove(name);
@@ -357,10 +330,7 @@ public class OpenIddictMessage
/// The current instance, which allows chaining calls.
public OpenIddictMessage SetParameter(string name, OpenIddictParameter? value)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
// If the parameter value is null or empty, remove the corresponding entry from the collection.
if (value is null || OpenIddictParameter.IsNullOrEmpty(value.GetValueOrDefault()))
@@ -384,10 +354,7 @@ public class OpenIddictMessage
/// if the parameter could be found, otherwise.
public bool TryGetParameter(string name, out OpenIddictParameter value)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
return Parameters.TryGetValue(name, out value);
}
@@ -445,10 +412,7 @@ public class OpenIddictMessage
/// The UTF-8 JSON writer.
public void WriteTo(Utf8JsonWriter writer)
{
- if (writer is null)
- {
- throw new ArgumentNullException(nameof(writer));
- }
+ ArgumentNullException.ThrowIfNull(writer);
writer.WriteStartObject();
diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs
index 35823237..c3a810a8 100644
--- a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs
+++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs
@@ -673,10 +673,7 @@ public readonly struct OpenIddictParameter : IEquatable
/// if the parameter could be found, otherwise.
public bool TryGetNamedParameter(string name, out OpenIddictParameter value)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0192), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
var result = _value switch
{
@@ -709,10 +706,7 @@ public readonly struct OpenIddictParameter : IEquatable
/// if the parameter could be found, otherwise.
public bool TryGetUnnamedParameter(int index, out OpenIddictParameter value)
{
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.GetResourceString(SR.ID0193));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(index);
var result = _value switch
{
@@ -746,10 +740,7 @@ public readonly struct OpenIddictParameter : IEquatable
/// The UTF-8 JSON writer.
public void WriteTo(Utf8JsonWriter writer)
{
- if (writer is null)
- {
- throw new ArgumentNullException(nameof(writer));
- }
+ ArgumentNullException.ThrowIfNull(writer);
switch (_value)
{
diff --git a/src/OpenIddict.AspNetCore/OpenIddict.AspNetCore.csproj b/src/OpenIddict.AspNetCore/OpenIddict.AspNetCore.csproj
index 8cc45bfb..3e39660c 100644
--- a/src/OpenIddict.AspNetCore/OpenIddict.AspNetCore.csproj
+++ b/src/OpenIddict.AspNetCore/OpenIddict.AspNetCore.csproj
@@ -4,6 +4,7 @@
$(NetFrameworkTargetFrameworks);$(NetCoreTargetFrameworks)
false
false
+ false
false
diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs
index e0fe1034..1aa96570 100644
--- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs
+++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs
@@ -38,10 +38,7 @@ public sealed class OpenIddictClientAspNetCoreBuilder
/// The instance.
public OpenIddictClientAspNetCoreBuilder Configure(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@@ -74,10 +71,7 @@ public sealed class OpenIddictClientAspNetCoreBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientAspNetCoreBuilder AddForwardedAuthenticationScheme(string provider, string? caption)
{
- if (string.IsNullOrEmpty(provider))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
- }
+ ArgumentException.ThrowIfNullOrEmpty(provider);
return Configure(options => options.ForwardedAuthenticationSchemes.Add(
new AuthenticationScheme(provider, caption, typeof(OpenIddictClientAspNetCoreForwarder))));
diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs
index 5ea75824..cf699322 100644
--- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs
+++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs
@@ -31,10 +31,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
///
public void Configure(AuthenticationOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(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) &&
@@ -64,10 +61,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
///
public void PostConfigure(string? name, OpenIddictClientAspNetCoreOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
if (!options.DisableAutomaticAuthenticationSchemeForwarding)
{
@@ -102,10 +96,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
///
public void Configure(OpenIddictClientOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict ASP.NET Core client components.
options.Handlers.AddRange(OpenIddictClientAspNetCoreHandlers.DefaultHandlers);
@@ -114,10 +105,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
///
public void PostConfigure(string? name, AuthenticationOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
if (!TryValidate(options.SchemeMap, options.DefaultAuthenticateScheme) ||
!TryValidate(options.SchemeMap, options.DefaultScheme) ||
diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs
index 83b3fa35..cac9e143 100644
--- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs
+++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs
@@ -24,10 +24,7 @@ public static class OpenIddictClientAspNetCoreExtensions
/// The instance.
public static OpenIddictClientAspNetCoreBuilder UseAspNetCore(this OpenIddictClientBuilder builder)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
+ ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddAuthentication();
@@ -73,15 +70,9 @@ public static class OpenIddictClientAspNetCoreExtensions
public static OpenIddictClientBuilder UseAspNetCore(
this OpenIddictClientBuilder builder, Action configuration)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(builder);
+
+ ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseAspNetCore());
diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs
index 0f50f2d0..e433b4d4 100644
--- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs
+++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs
@@ -29,7 +29,7 @@ public sealed class OpenIddictClientAspNetCoreHandler : AuthenticationHandler
/// Creates a new instance of the class.
///
-#if SUPPORTS_TIME_PROVIDER
+#if SUPPORTS_AUTHENTICATION_HANDLER_TIME_PROVIDER_ARGUMENT
public OpenIddictClientAspNetCoreHandler(
IOpenIddictClientDispatcher dispatcher,
IOpenIddictClientFactory factory,
diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs
index 4b7da143..57aad07f 100644
--- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs
+++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs
@@ -29,10 +29,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnableErrorPassthrough);
}
@@ -46,10 +43,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.Transaction.GetHttpRequest() is not null);
}
@@ -69,10 +63,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnablePostLogoutRedirectionEndpointPassthrough);
}
@@ -92,10 +83,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnableRedirectionEndpointPassthrough);
}
@@ -114,10 +102,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnableStatusCodePagesIntegration);
}
@@ -136,10 +121,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!_options.CurrentValue.DisableTransportSecurityRequirement);
}
diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs
index afd8be11..a071ebf7 100644
--- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs
+++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs
@@ -61,10 +61,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Session.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Session.cs
index 673a205f..855f7e4b 100644
--- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Session.cs
+++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Session.cs
@@ -61,10 +61,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ApplyEndSessionRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs
index 0c99cef6..82f213d3 100644
--- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs
+++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs
@@ -95,10 +95,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -149,10 +146,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -194,10 +188,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -239,10 +230,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public async ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -319,10 +307,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.GrantType is GrantTypes.DeviceCode)
{
@@ -353,10 +338,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (!string.IsNullOrEmpty(context.Nonce))
{
@@ -394,10 +376,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -511,10 +490,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.GrantType is GrantTypes.DeviceCode)
{
@@ -546,10 +522,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -656,10 +629,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -695,10 +665,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit response type was specified, don't overwrite it.
if (!string.IsNullOrEmpty(context.ResponseMode))
@@ -795,10 +762,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: using a correlation cookie serves as an injection/antiforgery protection as the request
// will always be rejected if a cookie corresponding to the request forgery protection claim
@@ -881,10 +845,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -981,10 +942,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1027,10 +985,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: using a correlation cookie serves as an injection/antiforgery protection as the request
// will always be rejected if a cookie corresponding to the request forgery protection claim
@@ -1115,10 +1070,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.SkipRequest();
@@ -1146,10 +1098,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1189,10 +1138,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1233,10 +1179,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007));
@@ -1273,10 +1216,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1329,10 +1269,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public async ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1403,10 +1340,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Logger.LogInformation(6145, SR.GetResourceString(SR.ID6145));
context.HandleRequest();
diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs
index ee856cf0..1806322d 100644
--- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs
+++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs
@@ -21,10 +21,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// The instance or if it couldn't be found.
public static HttpRequest? GetHttpRequest(this OpenIddictClientTransaction transaction)
{
- if (transaction is null)
- {
- throw new ArgumentNullException(nameof(transaction));
- }
+ ArgumentNullException.ThrowIfNull(transaction);
if (!transaction.Properties.TryGetValue(typeof(HttpRequest).FullName!, out object? property))
{
@@ -46,10 +43,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// The .
public static OpenIddictClientEndpointType GetOpenIddictClientEndpointType(this HttpContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return context.Features.Get()?.Transaction?.EndpointType ?? default;
}
@@ -61,10 +55,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// The instance or if it couldn't be found.
public static OpenIddictRequest? GetOpenIddictClientRequest(this HttpContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return context.Features.Get()?.Transaction?.Request;
}
@@ -76,10 +67,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// The instance or if it couldn't be found.
public static OpenIddictResponse? GetOpenIddictClientResponse(this HttpContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return context.Features.Get()?.Transaction?.Response;
}
diff --git a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs
index f4002367..aaef1ed1 100644
--- a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs
+++ b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs
@@ -37,10 +37,7 @@ public sealed class OpenIddictClientDataProtectionBuilder
/// The instance.
public OpenIddictClientDataProtectionBuilder Configure(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@@ -55,10 +52,7 @@ public sealed class OpenIddictClientDataProtectionBuilder
/// The instance.
public OpenIddictClientDataProtectionBuilder UseDataProtectionProvider(IDataProtectionProvider provider)
{
- if (provider is null)
- {
- throw new ArgumentNullException(nameof(provider));
- }
+ ArgumentNullException.ThrowIfNull(provider);
return Configure(options => options.DataProtectionProvider = provider);
}
@@ -70,10 +64,7 @@ public sealed class OpenIddictClientDataProtectionBuilder
/// The instance.
public OpenIddictClientDataProtectionBuilder UseFormatter(IOpenIddictClientDataProtectionFormatter formatter)
{
- if (formatter is null)
- {
- throw new ArgumentNullException(nameof(formatter));
- }
+ ArgumentNullException.ThrowIfNull(formatter);
return Configure(options => options.Formatter = formatter);
}
diff --git a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionConfiguration.cs b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionConfiguration.cs
index 2da06dd5..14b6dd7b 100644
--- a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionConfiguration.cs
+++ b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionConfiguration.cs
@@ -29,10 +29,7 @@ public sealed class OpenIddictClientDataProtectionConfiguration : IConfigureOpti
///
public void Configure(OpenIddictClientOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict Data Protection server components.
options.Handlers.AddRange(OpenIddictClientDataProtectionHandlers.DefaultHandlers);
@@ -41,10 +38,7 @@ public sealed class OpenIddictClientDataProtectionConfiguration : IConfigureOpti
///
public void PostConfigure(string? name, OpenIddictClientDataProtectionOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
options.DataProtectionProvider ??= _dataProtectionProvider;
}
diff --git a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs
index 2caac624..9703b04d 100644
--- a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs
+++ b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs
@@ -25,10 +25,7 @@ public static class OpenIddictClientDataProtectionExtensions
/// The instance.
public static OpenIddictClientDataProtectionBuilder UseDataProtection(this OpenIddictClientBuilder builder)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
+ ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddDataProtection();
@@ -60,15 +57,8 @@ public static class OpenIddictClientDataProtectionExtensions
public static OpenIddictClientBuilder UseDataProtection(
this OpenIddictClientBuilder builder, Action configuration)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseDataProtection());
diff --git a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs
index 8b593bcb..b5f72af2 100644
--- a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs
+++ b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs
@@ -20,10 +20,7 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD
{
public ClaimsPrincipal ReadToken(BinaryReader reader)
{
- if (reader is null)
- {
- throw new ArgumentNullException(nameof(reader));
- }
+ ArgumentNullException.ThrowIfNull(reader);
var (principal, properties) = Read(reader);
@@ -182,15 +179,8 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD
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));
- }
+ ArgumentNullException.ThrowIfNull(writer);
+ ArgumentNullException.ThrowIfNull(principal);
var properties = new Dictionary();
@@ -293,15 +283,8 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD
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));
- }
+ ArgumentNullException.ThrowIfNull(writer);
+ ArgumentNullException.ThrowIfNull(claim);
WriteWithDefault(writer, claim.Type, claim.Subject?.NameClaimType ?? ClaimsIdentity.DefaultNameClaimType);
writer.Write(claim.Value);
diff --git a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlerFilters.cs b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlerFilters.cs
index eb965363..ba04e380 100644
--- a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlerFilters.cs
+++ b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlerFilters.cs
@@ -20,10 +20,7 @@ public static class OpenIddictClientDataProtectionHandlerFilters
///
public ValueTask IsActiveAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.TokenFormat is TokenFormats.Private.DataProtection);
}
diff --git a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs
index 5d36c92c..4b8975ec 100644
--- a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs
+++ b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs
@@ -176,10 +176,7 @@ public static partial class OpenIddictClientDataProtectionHandlers
///
public ValueTask HandleAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// ASP.NET Core Data Protection can be used to format certain types of tokens in lieu
// of the default token format (typically, JSON Web Token). By default, Data Protection
@@ -223,10 +220,7 @@ public static partial class OpenIddictClientDataProtectionHandlers
///
public ValueTask HandleAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.Client.Owin/OpenIddictClientOwinBuilder.cs b/src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs
index f75d35bb..cfedce9c 100644
--- a/src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs
+++ b/src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs
@@ -74,10 +74,7 @@ public sealed class OpenIddictClientOwinBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientOwinBuilder AddForwardedAuthenticationType(string provider, string? caption)
{
- if (string.IsNullOrEmpty(provider))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
- }
+ ArgumentException.ThrowIfNullOrEmpty(provider);
return Configure(options => options.ForwardedAuthenticationTypes.Add(new AuthenticationDescription
{
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddict.Client.SystemIntegration.csproj b/src/OpenIddict.Client.SystemIntegration/OpenIddict.Client.SystemIntegration.csproj
index 14f25394..7c8cc5ca 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddict.Client.SystemIntegration.csproj
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddict.Client.SystemIntegration.csproj
@@ -30,6 +30,7 @@
allow loading dependencies that are not strong-named), the warning can be safely disabled.
-->
$(NoWarn);CS8002
+ $(DefineConstants);FeatureRuntimeInformation;FeatureValueTuple
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivation.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivation.cs
index 9d2de71e..d20484f8 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivation.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivation.cs
@@ -21,10 +21,7 @@ public sealed class OpenIddictClientSystemIntegrationActivation
/// is .
public OpenIddictClientSystemIntegrationActivation(Uri uri)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs
index 866b0742..948c59b4 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs
@@ -40,10 +40,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
/// The .
public OpenIddictClientSystemIntegrationBuilder Configure(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@@ -209,10 +206,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemIntegrationBuilder SetApplicationDiscriminator(string discriminator)
{
- if (string.IsNullOrEmpty(discriminator))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(discriminator)), nameof(discriminator));
- }
+ ArgumentException.ThrowIfNullOrEmpty(discriminator);
return Configure(options => options.ApplicationDiscriminator = discriminator);
}
@@ -226,10 +220,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemIntegrationBuilder SetInstanceIdentifier(string identifier)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
return Configure(options => options.InstanceIdentifier = identifier);
}
@@ -243,10 +234,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemIntegrationBuilder SetPipeName(string name)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
return Configure(options => options.PipeName = name);
}
@@ -270,10 +258,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced), SupportedOSPlatform("windows")]
public OpenIddictClientSystemIntegrationBuilder SetPipeSecurity(PipeSecurity security)
{
- if (security is null)
- {
- throw new ArgumentNullException(nameof(security));
- }
+ ArgumentNullException.ThrowIfNull(security);
return Configure(options => options.PipeSecurity = security);
}
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs
index 336f7393..ed274d2d 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs
@@ -7,7 +7,6 @@
using System.ComponentModel;
using System.IO.Pipes;
using System.Net;
-using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
@@ -38,10 +37,7 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
///
public void Configure(OpenIddictClientOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict client system integration components.
options.Handlers.AddRange(OpenIddictClientSystemIntegrationHandlers.DefaultHandlers);
@@ -53,10 +49,7 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
///
public void PostConfigure(string? name, OpenIddictClientOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
// If no explicit client URI was set, default to the static "http://localhost/" address, which is
// adequate for a native/mobile client and points to the embedded web server when it is enabled.
@@ -66,18 +59,15 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
///
public void PostConfigure(string? name, OpenIddictClientSystemIntegrationOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
- // Ensure the operating system is supported.
- if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ // Ensure the operating system version is supported.
+ if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
+ (OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
+ OperatingSystem.IsLinux() ||
+ (OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
+ (OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
+ (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
@@ -87,37 +77,19 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
// is used to prevent the generic/non-OS specific TFM from being used as launching the system
// browser cannot be done using Process.Start() and requires using OS-specific APIs that are
// not available on the portable version of the OpenIddict.Client.SystemIntegration package.
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")))
+ if (OperatingSystem.IsAndroid())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
#if !SUPPORTS_UIKIT
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) ||
- RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")))
+ if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
-#if SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
- // Ensure the operating system version is supported.
- if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
- (OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
- (OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
- (OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
- (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
- {
- throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
- }
-#else
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !IsWindowsVersionAtLeast(7))
- {
- throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
- }
-#endif
-
#pragma warning disable CA1416
// If explicitly set, ensure the specified authentication mode is supported.
if (options.AuthenticationMode is ASWebAuthenticationSession && !IsASWebAuthenticationSessionSupported())
@@ -141,10 +113,8 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
IsASWebAuthenticationSessionSupported() ? ASWebAuthenticationSession :
IsCustomTabsIntentSupported() ? CustomTabsIntent : SystemBrowser;
- if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ if (!OperatingSystem.IsAndroid() && !OperatingSystem.IsIOS() &&
+ !OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacOS())
{
options.EnableActivationHandling ??= true;
options.EnableActivationRedirection ??= true;
@@ -189,13 +159,13 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
// Note: on Windows, the name is deliberately prefixed with "LOCAL\" to support
// partial trust/sandboxed applications that are executed in an AppContainer
// and cannot communicate with applications outside the sandbox container.
- options.PipeName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
+ options.PipeName = OperatingSystem.IsWindows() ?
@$"LOCAL\{options.ApplicationDiscriminator}" :
options.ApplicationDiscriminator;
}
#if SUPPORTS_CURRENT_USER_ONLY_PIPE_OPTION
- if (options.PipeOptions is null && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (options.PipeOptions is null && !OperatingSystem.IsWindows())
{
// Note: the CurrentUserOnly option is also supported on Windows, but is less
// flexible than using a PipeSecurity object (e.g cross-process communication
@@ -214,11 +184,11 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
// between elevated and non-elevated processes. Note: if the process executes
// inside an AppContainer, don't override the default OS pipe security policy
// to allow all applications with the same identity to access the named pipe.
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && options.PipeSecurity is null)
+ if (OperatingSystem.IsWindows() && options.PipeSecurity is null)
{
using var identity = WindowsIdentity.GetCurrent(TokenAccessLevels.Query);
- if (!IsWindowsVersionAtLeast(10, 0, 10240) || !HasAppContainerToken(identity))
+ if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 10240) || !HasAppContainerToken(identity))
{
options.PipeSecurity = new PipeSecurity();
options.PipeSecurity.SetOwner(identity.User!);
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs
index bb83a7fe..31f6d5c1 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs
@@ -4,7 +4,6 @@
* the license and the contributors participating to this project.
*/
-using System.Runtime.InteropServices;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
@@ -26,18 +25,15 @@ public static class OpenIddictClientSystemIntegrationExtensions
/// The .
public static OpenIddictClientSystemIntegrationBuilder UseSystemIntegration(this OpenIddictClientBuilder builder)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
+ ArgumentNullException.ThrowIfNull(builder);
- // Ensure the operating system is supported.
- if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
- !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ // Ensure the operating system version is supported.
+ if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
+ (OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
+ OperatingSystem.IsLinux() ||
+ (OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
+ (OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
+ (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
@@ -47,37 +43,19 @@ public static class OpenIddictClientSystemIntegrationExtensions
// is used to prevent the generic/non-OS specific TFM from being used as launching the system
// browser cannot be done using Process.Start() and requires using OS-specific APIs that are
// not available on the portable version of the OpenIddict.Client.SystemIntegration package.
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")))
+ if (OperatingSystem.IsAndroid())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
#if !SUPPORTS_UIKIT
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) ||
- RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")))
+ if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
-#if SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
- // Ensure the operating system version is supported.
- if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
- (OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
- (OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
- (OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
- (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
- {
- throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
- }
-#else
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !IsWindowsVersionAtLeast(7))
- {
- throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
- }
-#endif
-
// Note: the OpenIddict activation handler service is deliberately registered as early as possible to
// ensure protocol activations can be handled before another service can stop the initialization of the
// application (e.g Dapplo.Microsoft.Extensions.Hosting.AppServices relies on an IHostedService to implement
@@ -142,15 +120,8 @@ public static class OpenIddictClientSystemIntegrationExtensions
public static OpenIddictClientBuilder UseSystemIntegration(
this OpenIddictClientBuilder builder, Action configuration)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseSystemIntegration());
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs
index 8af45ee5..f7475691 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs
@@ -30,10 +30,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_AUTHENTICATION_SERVICES
if (IsASWebAuthenticationSessionSupported())
@@ -61,10 +58,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!string.IsNullOrEmpty(context.Nonce));
}
@@ -83,10 +77,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
if (IsCustomTabsIntentSupported())
@@ -118,10 +109,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnableEmbeddedWebServer is true);
}
@@ -135,10 +123,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.Transaction.GetHttpListenerContext() is not null);
}
@@ -152,10 +137,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(Environment.UserInteractive);
}
@@ -170,10 +152,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.Transaction.GetPlatformCallback() is not null);
}
@@ -187,10 +166,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.Transaction.GetProtocolActivation() is not null);
}
@@ -210,10 +186,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (!context.Transaction.Properties.TryGetValue(
typeof(OpenIddictClientSystemIntegrationAuthenticationMode).FullName!, out var result) ||
@@ -240,10 +213,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_WINDOWS_RUNTIME
if (IsWebAuthenticationBrokerSupported())
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs
index 2fda605a..7f322196 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs
@@ -5,7 +5,6 @@
*/
using System.Collections.Immutable;
-using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using Microsoft.Extensions.Primitives;
@@ -99,10 +98,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
#pragma warning restore CS1998
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (string.IsNullOrEmpty(context.RedirectUri) ||
@@ -322,10 +318,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
#pragma warning restore CS1998
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
if (string.IsNullOrEmpty(context.RedirectUri))
@@ -398,10 +391,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
#pragma warning restore CS1998
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_WINDOWS_RUNTIME
if (string.IsNullOrEmpty(context.RedirectUri))
@@ -543,10 +533,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var uri = OpenIddictHelpers.AddQueryStringParameters(
uri: new Uri(context.AuthorizationEndpoint, UriKind.Absolute),
@@ -554,7 +541,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
static parameter => parameter.Key,
static parameter => (StringValues) parameter.Value));
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (OperatingSystem.IsWindows())
{
// Note: on Windows, multiple application models exist and must be supported to cover most scenarios:
//
@@ -612,13 +599,13 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
return;
}
#endif
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && await TryLaunchBrowserWithOpenAsync(uri))
+ if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri))
{
context.HandleRequest();
return;
}
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && await TryLaunchBrowserWithXdgOpenAsync(uri))
+ if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri))
{
context.HandleRequest();
return;
@@ -648,10 +635,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(ApplyRedirectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@@ -671,11 +655,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
_ => "Authentication failed. Please return to the application."
});
-#if SUPPORTS_STREAM_MEMORY_METHODS
await response.OutputStream.WriteAsync(buffer);
-#else
- await response.OutputStream.WriteAsync(buffer, 0, buffer.Length);
-#endif
await response.OutputStream.FlushAsync();
context.HandleRequest();
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs
index 1a00d5ac..85ca7b75 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs
@@ -5,7 +5,6 @@
*/
using System.Collections.Immutable;
-using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using Microsoft.Extensions.Primitives;
@@ -99,10 +98,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
#pragma warning restore CS1998
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri) ||
@@ -322,10 +318,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
#pragma warning restore CS1998
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
@@ -398,10 +391,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
#pragma warning restore CS1998
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_WINDOWS_RUNTIME
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
@@ -543,10 +533,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var uri = OpenIddictHelpers.AddQueryStringParameters(
uri: new Uri(context.EndSessionEndpoint, UriKind.Absolute),
@@ -554,7 +541,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
static parameter => parameter.Key,
static parameter => (StringValues) parameter.Value));
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (OperatingSystem.IsWindows())
{
// Note: on Windows, multiple application models exist and must be supported to cover most scenarios:
//
@@ -612,13 +599,13 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
return;
}
#endif
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && await TryLaunchBrowserWithOpenAsync(uri))
+ if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri))
{
context.HandleRequest();
return;
}
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && await TryLaunchBrowserWithXdgOpenAsync(uri))
+ if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri))
{
context.HandleRequest();
return;
@@ -648,10 +635,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(ApplyPostLogoutRedirectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@@ -671,11 +655,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
_ => "Logout failed. Please return to the application."
});
-#if SUPPORTS_STREAM_MEMORY_METHODS
await response.OutputStream.WriteAsync(buffer);
-#else
- await response.OutputStream.WriteAsync(buffer, 0, buffer.Length);
-#endif
await response.OutputStream.FlushAsync();
context.HandleRequest();
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs
index 12a6f172..16b5df0d 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs
@@ -108,10 +108,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// When using the OpenIddict client system integration, requests can originate from multiple sources:
//
@@ -177,10 +174,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.BaseUri, context.RequestUri) = context.Transaction.GetProtocolActivation() switch
{
@@ -215,10 +209,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.BaseUri, context.RequestUri) = context.Transaction.GetPlatformCallback() switch
{
@@ -254,10 +245,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the base or request URIs couldn't be resolved, don't try to infer the endpoint type.
if (context is not { BaseUri.IsAbsoluteUri: true, RequestUri.IsAbsoluteUri: true })
@@ -332,10 +320,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@@ -377,10 +362,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@@ -430,10 +412,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@@ -520,10 +499,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Transaction.GetProtocolActivation() is not { ActivationUri: Uri uri })
{
@@ -578,10 +554,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Transaction.GetPlatformCallback() is not OpenIddictClientSystemIntegrationPlatformCallback callback)
{
@@ -624,10 +597,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -721,10 +691,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -767,10 +734,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -813,10 +777,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -860,10 +821,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -918,10 +876,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -1002,10 +957,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1053,10 +1005,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1101,10 +1050,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1148,10 +1094,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1195,10 +1138,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1242,10 +1182,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1288,10 +1225,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1336,10 +1270,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1383,10 +1314,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1430,10 +1358,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1477,10 +1402,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1522,10 +1444,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1569,10 +1488,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1611,10 +1527,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@@ -1649,10 +1562,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.BaseUri ??= context.Options.ClientUri;
@@ -1692,10 +1602,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the redirect_uri uses a loopback host/IP as the authority and doesn't include a non-default port,
// determine whether the embedded web server is running: if so, override the port in the redirect_uri
@@ -1747,10 +1654,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit response type was specified, don't overwrite it.
if (!string.IsNullOrEmpty(context.ResponseMode))
@@ -1931,10 +1835,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -1976,10 +1877,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.Nonce))
{
@@ -2020,10 +1918,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.BaseUri ??= context.Options.ClientUri;
@@ -2062,10 +1957,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public async ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the post_logout_redirect_uri uses a loopback host/IP as the authority and doesn't include a non-default port,
// determine whether the embedded web server is running: if so, override the port in the post_logout_redirect_uri
@@ -2113,10 +2005,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -2158,10 +2047,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.Nonce))
{
@@ -2211,10 +2097,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(ProcessErrorContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Try to resolve the authentication context from the transaction, if available.
var notification = context.Transaction.GetProperty(
@@ -2262,10 +2145,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@@ -2305,10 +2185,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@@ -2345,10 +2222,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// For both protocol activations (initial or redirected) and web-view-like results,
// no proper response can be generated and eventually displayed to the user. In this
@@ -2381,10 +2255,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// For both protocol activations (initial or redirected) and web-view-like results,
// no proper response can be generated and eventually displayed to the user. In this
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs
index d0ee6c13..9ff291fe 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs
@@ -68,38 +68,6 @@ public static class OpenIddictClientSystemIntegrationHelpers
public static HttpListenerContext? GetHttpListenerContext(this OpenIddictClientTransaction transaction)
=> transaction.GetProperty(typeof(HttpListenerContext).FullName!);
- ///
- /// Determines whether the current Windows version
- /// is greater than or equals to the specified version.
- ///
- ///
- /// if the current Windows version is greater than
- /// or equals to the specified version, otherwise.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [SupportedOSPlatformGuard("windows")]
- internal static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)
- {
-#if SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
- return OperatingSystem.IsWindowsVersionAtLeast(major, minor, build, revision);
-#else
- if (Environment.OSVersion.Platform is PlatformID.Win32NT &&
- Environment.OSVersion.Version >= new Version(major, minor, build, revision))
- {
- return true;
- }
-
- // Note: on older versions of .NET, Environment.OSVersion.Version is known to be affected by
- // the compatibility shims used by Windows 10+ when the application doesn't have a manifest
- // that explicitly indicates it's compatible with Windows 10 and higher. To avoid that, a
- // second pass using RuntimeInformation.OSDescription (that calls NtDll.RtlGetVersion() under
- // the hood) is made. Note: no version is returned on UWP due to the missing Win32 API.
- return RuntimeInformation.OSDescription.StartsWith("Microsoft Windows ", StringComparison.OrdinalIgnoreCase) &&
- RuntimeInformation.OSDescription["Microsoft Windows ".Length..] is string value &&
- Version.TryParse(value, out Version? version) && version >= new Version(major, minor, build, revision);
-#endif
- }
-
///
/// Determines whether the ASWebAuthenticationSession API is supported on this platform.
///
@@ -144,7 +112,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
// oldest supported version in the package, it is also used for the runtime check.
internal static bool IsWindowsRuntimeSupported()
#if SUPPORTS_WINDOWS_RUNTIME
- => IsWindowsVersionAtLeast(10, 0, 17763);
+ => OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17763);
#else
=> false;
#endif
@@ -227,10 +195,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
[SupportedOSPlatform("windows10.0.10240")]
internal static unsafe bool HasAppContainerToken(WindowsIdentity identity)
{
- if (identity is null)
- {
- throw new ArgumentNullException(nameof(identity));
- }
+ ArgumentNullException.ThrowIfNull(identity);
int* buffer = stackalloc int[1];
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs
index 2a1b40d9..0bde64a6 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs
@@ -8,7 +8,6 @@ using System.ComponentModel;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
-using System.Runtime.InteropServices;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@@ -146,7 +145,7 @@ public sealed class OpenIddictClientSystemIntegrationHttpListener : BackgroundSe
// non-Windows operating systems) and doesn't require running the application
// as an administrator or adding a namespace reservation/ACL rule on Windows.
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (OperatingSystem.IsWindows())
{
// On Windows 10 1511 and higher, listening on 127.0.0.1 and ::1 is preferred
// to localhost as it allows ignoring requests that are sent by other machines
@@ -154,7 +153,7 @@ public sealed class OpenIddictClientSystemIntegrationHttpListener : BackgroundSe
// configured to reject such requests) without requiring administrator rights.
//
// See https://www.rfc-editor.org/rfc/rfc8252#section-8.3 for more information.
- if (IsWindowsVersionAtLeast(10, 0, 10586))
+ if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 10586))
{
if (Socket.OSSupportsIPv4)
{
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs
index 6cc07603..3f4c23b5 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs
@@ -6,7 +6,6 @@
using System.ComponentModel;
using System.IO.Pipes;
-using System.Runtime.InteropServices;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@@ -131,7 +130,7 @@ public sealed class OpenIddictClientSystemIntegrationPipeListener : BackgroundSe
static NamedPipeServerStream CreatePipeServerStream(OpenIddictClientSystemIntegrationOptions options)
// Note: the ACL-based PipeSecurity class is only supported on Windows. On other operating systems,
// PipeOptions.CurrentUserOnly can be used as an alternative, but only for TFMs that implement it.
- => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
+ => OperatingSystem.IsWindows() ?
#if SUPPORTS_NAMED_PIPE_CONSTRUCTOR_WITH_ACL
new NamedPipeServerStream(
#elif SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPlatformCallback.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPlatformCallback.cs
index 215ea1e0..ed35a309 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPlatformCallback.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPlatformCallback.cs
@@ -25,20 +25,14 @@ public sealed class OpenIddictClientSystemIntegrationPlatformCallback
public OpenIddictClientSystemIntegrationPlatformCallback(
Uri uri, IReadOnlyDictionary parameters)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0144), nameof(uri));
}
- if (parameters is null)
- {
- throw new ArgumentNullException(nameof(parameters));
- }
+ ArgumentNullException.ThrowIfNull(parameters);
CallbackUri = uri;
Parameters = parameters.ToImmutableDictionary();
diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs
index 84a8d027..288f6cdd 100644
--- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs
+++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs
@@ -53,10 +53,7 @@ public sealed class OpenIddictClientSystemIntegrationService
[EditorBrowsable(EditorBrowsableState.Advanced)]
public Task HandleCustomTabsIntentAsync(Intent intent, CancellationToken cancellationToken = default)
{
- if (intent is null)
- {
- throw new ArgumentNullException(nameof(intent));
- }
+ ArgumentNullException.ThrowIfNull(intent);
if (intent.Data is null)
{
@@ -139,10 +136,7 @@ public sealed class OpenIddictClientSystemIntegrationService
/// is .
private async Task HandleRequestAsync(TProperty property, CancellationToken cancellationToken) where TProperty : class
{
- if (property is null)
- {
- throw new ArgumentNullException(nameof(property));
- }
+ ArgumentNullException.ThrowIfNull(property);
cancellationToken.ThrowIfCancellationRequested();
@@ -188,15 +182,8 @@ public sealed class OpenIddictClientSystemIntegrationService
OpenIddictClientSystemIntegrationActivation activation,
string identifier, CancellationToken cancellationToken = default)
{
- if (activation is null)
- {
- throw new ArgumentNullException(nameof(activation));
- }
-
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
- }
+ ArgumentNullException.ThrowIfNull(activation);
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
using var buffer = new MemoryStream();
using var writer = new BinaryWriter(buffer);
diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddict.Client.SystemNetHttp.csproj b/src/OpenIddict.Client.SystemNetHttp/OpenIddict.Client.SystemNetHttp.csproj
index 968b12e7..ea267002 100644
--- a/src/OpenIddict.Client.SystemNetHttp/OpenIddict.Client.SystemNetHttp.csproj
+++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddict.Client.SystemNetHttp.csproj
@@ -6,6 +6,7 @@
$(NetCoreTargetFrameworks);
$(NetStandardTargetFrameworks)
+ $(DefineConstants);FeatureRuntimeInformation
diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs
index 8aa39b44..0def36f1 100644
--- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs
+++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs
@@ -42,10 +42,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// The instance.
public OpenIddictClientSystemNetHttpBuilder Configure(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@@ -63,10 +60,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
return ConfigureHttpClient((registration, client) => configuration(client));
}
@@ -84,15 +78,8 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(string provider, Action configuration)
{
- if (string.IsNullOrEmpty(provider))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
+ ArgumentException.ThrowIfNullOrEmpty(provider);
return ConfigureHttpClient((registration, client) =>
{
@@ -115,10 +102,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
return Configure(options => options.HttpClientActions.Add(configuration));
}
@@ -134,10 +118,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
return ConfigureHttpClientHandler((registration, handler) => configuration(handler));
}
@@ -155,15 +136,8 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(string provider, Action configuration)
{
- if (string.IsNullOrEmpty(provider))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
+ ArgumentException.ThrowIfNullOrEmpty(provider);
return ConfigureHttpClientHandler((registration, handler) =>
{
@@ -187,10 +161,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(
Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
return Configure(options => options.HttpClientHandlerActions.Add(configuration));
}
@@ -203,10 +174,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// The instance.
public OpenIddictClientSystemNetHttpBuilder SetContactAddress(MailAddress address)
{
- if (address is null)
- {
- throw new ArgumentNullException(nameof(address));
- }
+ ArgumentNullException.ThrowIfNull(address);
return Configure(options => options.ContactAddress = address);
}
@@ -219,10 +187,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// The instance.
public OpenIddictClientSystemNetHttpBuilder SetContactAddress(string address)
{
- if (string.IsNullOrEmpty(address))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(address)), nameof(address));
- }
+ ArgumentException.ThrowIfNullOrEmpty(address);
return SetContactAddress(new MailAddress(address));
}
@@ -234,10 +199,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// The instance.
public OpenIddictClientSystemNetHttpBuilder SetHttpErrorPolicy(IAsyncPolicy policy)
{
- if (policy is null)
- {
- throw new ArgumentNullException(nameof(policy));
- }
+ ArgumentNullException.ThrowIfNull(policy);
return Configure(options => options.HttpErrorPolicy = policy);
}
@@ -257,10 +219,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder SetHttpResiliencePipeline(
Action> configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
var builder = new ResiliencePipelineBuilder();
configuration(builder);
@@ -279,10 +238,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// The instance.
public OpenIddictClientSystemNetHttpBuilder SetHttpResiliencePipeline(ResiliencePipeline pipeline)
{
- if (pipeline is null)
- {
- throw new ArgumentNullException(nameof(pipeline));
- }
+ ArgumentNullException.ThrowIfNull(pipeline);
return Configure(options => options.HttpResiliencePipeline = pipeline);
}
@@ -296,10 +252,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// The instance.
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(ProductInfoHeaderValue information)
{
- if (information is null)
- {
- throw new ArgumentNullException(nameof(information));
- }
+ ArgumentNullException.ThrowIfNull(information);
return Configure(options => options.ProductInformation = information);
}
@@ -313,10 +266,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// The instance.
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(string name, string? version)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0345), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
return SetProductInformation(new ProductInfoHeaderValue(name, version));
}
@@ -330,10 +280,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// The instance.
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(Assembly assembly)
{
- if (assembly is null)
- {
- throw new ArgumentNullException(nameof(assembly));
- }
+ ArgumentNullException.ThrowIfNull(assembly);
return SetProductInformation(new ProductInfoHeaderValue(
productName: assembly.GetName().Name!,
@@ -356,10 +303,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder SetSelfSignedTlsClientAuthenticationCertificateSelector(
Func selector)
{
- if (selector is null)
- {
- throw new ArgumentNullException(nameof(selector));
- }
+ ArgumentNullException.ThrowIfNull(selector);
return Configure(options => options.SelfSignedTlsClientAuthenticationCertificateSelector = selector);
}
@@ -380,10 +324,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder SetTlsClientAuthenticationCertificateSelector(
Func selector)
{
- if (selector is null)
- {
- throw new ArgumentNullException(nameof(selector));
- }
+ ArgumentNullException.ThrowIfNull(selector);
return Configure(options => options.TlsClientAuthenticationCertificateSelector = selector);
}
diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs
index be289c8b..fb84d7da 100644
--- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs
+++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs
@@ -42,10 +42,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
///
public void Configure(OpenIddictClientOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict System.Net.Http client components.
options.Handlers.AddRange(OpenIddictClientSystemNetHttpHandlers.DefaultHandlers);
@@ -62,10 +59,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
///
public void Configure(string? name, HttpClientFactoryOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName();
@@ -179,10 +173,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
///
public void PostConfigure(string? name, HttpClientFactoryOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName();
@@ -270,10 +261,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
///
public void PostConfigure(string? name, OpenIddictClientSystemNetHttpOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
// If no client authentication certificate selector was provided, use fallback delegates that
// automatically use the first X.509 signing certificate attached to the client registration
diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs
index 2273ba1a..9cbf374e 100644
--- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs
+++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs
@@ -25,10 +25,7 @@ public static class OpenIddictClientSystemNetHttpExtensions
/// The instance.
public static OpenIddictClientSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictClientBuilder builder)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
+ ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddHttpClient();
@@ -65,15 +62,8 @@ public static class OpenIddictClientSystemNetHttpExtensions
public static OpenIddictClientBuilder UseSystemNetHttp(
this OpenIddictClientBuilder builder, Action configuration)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseSystemNetHttp());
diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs
index 5b610d8b..bd74edec 100644
--- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs
+++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs
@@ -19,10 +19,7 @@ public static class OpenIddictClientSystemNetHttpHandlerFilters
///
public ValueTask IsActiveAsync(BaseExternalContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(
string.Equals(context.RemoteUri?.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||
diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs
index c94a3502..79a210b7 100644
--- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs
+++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs
@@ -62,10 +62,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008));
@@ -103,10 +100,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public async ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the response if one was already provided.
if (context.Response is not null || !string.IsNullOrEmpty(context.UserInfoToken))
diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs
index b15f3aae..058cb87d 100644
--- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs
+++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs
@@ -10,7 +10,6 @@ using System.Diagnostics;
using System.IO.Compression;
using System.Net.Http;
using System.Net.Http.Headers;
-using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@@ -82,10 +81,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.TokenEndpointClientAuthenticationMethod))
@@ -204,10 +200,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Unlike DPoP, the mTLS specification doesn't use a specific token type to represent
// certificate-bound tokens. As such, most implementations (e.g Keycloak) simply return
@@ -269,10 +262,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.DeviceAuthorizationEndpointClientAuthenticationMethod))
@@ -399,10 +389,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.PushedAuthorizationEndpointClientAuthenticationMethod))
@@ -530,10 +517,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.IntrospectionEndpointClientAuthenticationMethod))
@@ -652,10 +636,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.RevocationEndpointClientAuthenticationMethod))
@@ -772,10 +753,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: HttpClientFactory doesn't support flowing a list of properties that can be
// accessed from the HttpClientAction or HttpMessageHandlerBuilderAction delegates
@@ -856,10 +834,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Store the HttpRequestMessage in the transaction properties.
context.Transaction.SetProperty(typeof(HttpRequestMessage).FullName!,
@@ -888,10 +863,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Store the HttpRequestMessage in the transaction properties.
context.Transaction.SetProperty(typeof(HttpRequestMessage).FullName!,
@@ -920,10 +892,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION || SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
@@ -968,10 +937,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1013,10 +979,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1067,10 +1030,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1103,10 +1063,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@@ -1160,10 +1117,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@@ -1220,10 +1174,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public async ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1284,10 +1235,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1322,10 +1270,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public async ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: automatic content decompression can be enabled by constructing an HttpClient wrapping
// a generic HttpClientHandler, a SocketsHttpHandler or a WinHttpHandler instance with the
@@ -1367,7 +1312,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
// Content-Encoding header from the response, which leads to incorrect results when trying
// to decompress the content a second time. To avoid that, the entire logic used in this
// handler is ignored on iOS if the native HTTP handler (NSUrlSessionHandler) is used.
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
+ if (OperatingSystem.IsIOS() &&
AppContext.TryGetSwitch("System.Net.Http.UseNativeHttpHandler", out bool value) && value)
{
return;
@@ -1468,10 +1413,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public async ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the response if one was already provided.
if (context.Transaction.Response is not null)
@@ -1547,10 +1489,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the response if one was already provided.
if (context.Transaction.Response is not null)
@@ -1676,10 +1615,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the response if one was already provided.
if (context.Transaction.Response is not null)
@@ -1722,10 +1658,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public async ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -1792,10 +1725,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
///
public ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs
index cea98c36..406fd217 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs
@@ -35,10 +35,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// The instance.
public OpenIddictClientWebIntegrationBuilder Configure(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationConfiguration.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationConfiguration.cs
index b1bc3e0c..3e0e462b 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationConfiguration.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationConfiguration.cs
@@ -23,10 +23,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfi
///
public void Configure(OpenIddictClientOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict client Web components.
options.Handlers.AddRange(OpenIddictClientWebIntegrationHandlers.DefaultHandlers);
@@ -35,10 +32,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfi
///
public void PostConfigure(string? name, OpenIddictClientOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
options.Registrations.ForEach(static registration =>
{
@@ -54,10 +48,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfi
///
public void PostConfigure(string? name, OpenIddictClientSystemNetHttpOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
// Override the default/user-defined selectors to support attaching TLS client
// certificates that don't meet the requirements enforced by default by OpenIddict.
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs
index 1ad21802..a79f6f2e 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs
@@ -25,10 +25,7 @@ public static partial class OpenIddictClientWebIntegrationExtensions
/// The instance.
public static OpenIddictClientWebIntegrationBuilder UseWebProviders(this OpenIddictClientBuilder builder)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
+ ArgumentNullException.ThrowIfNull(builder);
// Register the System.Net.Http integration.
builder.UseSystemNetHttp();
@@ -68,15 +65,8 @@ public static partial class OpenIddictClientWebIntegrationExtensions
public static OpenIddictClientBuilder UseWebProviders(
this OpenIddictClientBuilder builder, Action configuration)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseWebProviders());
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Authentication.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Authentication.cs
index f86eba65..8d5c9a57 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Authentication.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Authentication.cs
@@ -40,10 +40,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareAuthorizationRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Some providers implement old drafts of the OAuth 2.0 specification that didn't support
// the "response_type" parameter but relied on a "type" parameter to determine the type
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Device.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Device.cs
index 2433c1f3..742c2d5c 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Device.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Device.cs
@@ -41,10 +41,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ExtractDeviceAuthorizationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Response is null)
{
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs
index 3c6c05c4..d85628e1 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs
@@ -45,10 +45,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Response[Metadata.Issuer] = context.Registration.ProviderType switch
{
@@ -97,10 +94,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: some providers don't list the grant types they support, which prevents the OpenIddict
// client from using them (unless they are assumed to be enabled by default, like the
@@ -182,10 +176,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Some providers support Proof Key for Code Exchange but don't list any supported code
// challenge method in the server configuration metadata. To ensure the OpenIddict client
@@ -227,10 +218,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Atlassian includes the "openid" scope in its server configuration but doesn't currently allow
// requesting it. To prevent an error from being returned, OpenID Connect support is disabled.
@@ -280,10 +268,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Alibaba Cloud doesn't document whether sending client credentials using basic authentication
// is supported and doesn't return a "token_endpoint_auth_methods_supported" nor a
@@ -394,10 +379,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// While Atlassian implements an OpenID Connect userinfo endpoint, using it requires
// requesting the "openid" scope, which isn't allowed yet. To work around this
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs
index af53b926..0abf1b5e 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs
@@ -60,10 +60,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Amazon doesn't support the standard "urn:ietf:params:oauth:grant-type:device_code"
// grant type and requires using the non-standard "device_code" grant type instead.
@@ -138,10 +135,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Some providers are known to incorrectly implement basic authentication support, either because
// an incorrect encoding scheme is used (e.g the credentials are not formURL-encoded as required
@@ -199,10 +193,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -251,10 +242,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -312,10 +300,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@@ -362,10 +347,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ExtractTokenResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Response is null)
{
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Introspection.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Introspection.cs
index 7ab01f8c..f15f8c66 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Introspection.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Introspection.cs
@@ -41,10 +41,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ExtractIntrospectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Response is null)
{
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Protection.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Protection.cs
index 64957ba1..2f9bac60 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Protection.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Protection.cs
@@ -45,10 +45,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: the client registration may be null (e.g when validating a state token).
// In this case, don't amend the default token validation parameters.
@@ -103,10 +100,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: the client registration may be null (e.g when generating a state token).
// In this case, don't amend the default security token descriptor.
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Revocation.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Revocation.cs
index da40d51c..c56cea79 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Revocation.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Revocation.cs
@@ -55,10 +55,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@@ -106,10 +103,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// These providers don't support the standard "token" parameter and
// require using the non-standard "access_token" parameter instead.
@@ -167,10 +161,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -208,10 +199,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -260,10 +248,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ExtractRevocationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
index 6ab14581..7d3e3f63 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
@@ -59,10 +59,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -106,10 +103,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -169,10 +163,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -233,10 +224,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// ArcGIS Online doesn't support header-based content negotiation and requires using
// the non-standard "f" parameter to get back JSON responses instead of HTML pages.
@@ -274,10 +262,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@@ -325,10 +310,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -390,10 +372,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007));
@@ -511,10 +490,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007));
diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
index 1a0db913..3e83a74e 100644
--- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
+++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
@@ -87,10 +87,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Shopify returns custom/non-standard parameters like the name of the shop for which the
// installation request was initiated. To prevent these parameters from being tampered with,
@@ -151,7 +148,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
try
{
if (!OpenIddictHelpers.FixedTimeEquals(
- left : OpenIddictHelpers.ConvertFromHexadecimalString(signature),
+ left : Convert.FromHexString(signature),
right: OpenIddictHelpers.ComputeSha256MessageAuthenticationCode(
key : Encoding.UTF8.GetBytes(context.Registration.ClientSecret),
data: Encoding.UTF8.GetBytes(builder.ToString()))))
@@ -200,10 +197,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: some providers are known to return non-standard errors.
// To normalize the set of errors handled by the OpenIddict client,
@@ -349,10 +343,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -466,10 +457,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.TokenEndpointClientAuthenticationMethod = context.Registration.ProviderType switch
{
@@ -509,10 +497,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.TokenEndpoint = context.Registration.ProviderType switch
{
@@ -596,10 +581,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.ClientAssertionPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -641,10 +623,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -707,10 +686,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -752,10 +728,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -810,10 +783,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.ExtractBackchannelIdentityToken,
context.RequireBackchannelIdentityToken,
@@ -860,10 +830,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: despite implementing OpenID Connect, some providers are known to implement the
// specification incorrectly and either don't support the "nonce" authorization request
@@ -905,10 +872,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.SendUserInfoRequest = context.Registration.ProviderType switch
{
@@ -996,10 +960,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: despite implementing OpenID Connect, some providers are known to implement completely custom
// userinfo endpoints or semi-standard endpoints that don't fully conform to the core specification.
@@ -1038,10 +999,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.UserInfoEndpoint = context.Registration.ProviderType switch
{
@@ -1131,10 +1089,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.UserInfoRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -1267,10 +1222,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
Debug.Assert(context.TokenResponse is not null, SR.GetResourceString(SR.ID4007));
@@ -1372,10 +1324,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@@ -1636,10 +1585,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If no explicit shop name was attached to the challenge properties, use the
// shop name set in the provider settings, if set. Otherwise, throw an exception.
@@ -1679,10 +1625,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.AuthorizationEndpoint = context.Registration.ProviderType switch
{
@@ -1755,10 +1698,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.ResponseMode = context.Registration.ProviderType switch
{
@@ -1793,10 +1733,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Request.Scope = context.Registration.ProviderType switch
{
@@ -1837,10 +1774,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.RedirectUri is null)
{
@@ -1891,10 +1825,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Active Directory Federation Services allows sending an optional custom "resource"
// parameter to define what API resources the access token will give access to.
@@ -2084,10 +2015,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.RevocationEndpointClientAuthenticationMethod = context.Registration.ProviderType switch
{
@@ -2122,10 +2050,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.ClientAssertionPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -2167,10 +2092,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.RevocationRequest is not null, SR.GetResourceString(SR.ID4008));
diff --git a/src/OpenIddict.Client/OpenIddictClientBuilder.cs b/src/OpenIddict.Client/OpenIddictClientBuilder.cs
index b513b44a..8f27ebbc 100644
--- a/src/OpenIddict.Client/OpenIddictClientBuilder.cs
+++ b/src/OpenIddict.Client/OpenIddictClientBuilder.cs
@@ -7,7 +7,6 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
-using System.Runtime.InteropServices;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
@@ -46,10 +45,7 @@ public sealed class OpenIddictClientBuilder
Action> configuration)
where TContext : BaseContext
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
// Note: handlers registered using this API are assumed to be custom handlers by default.
var builder = OpenIddictClientHandlerDescriptor.CreateBuilder()
@@ -68,10 +64,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder AddEventHandler(OpenIddictClientHandlerDescriptor descriptor)
{
- if (descriptor is null)
- {
- throw new ArgumentNullException(nameof(descriptor));
- }
+ ArgumentNullException.ThrowIfNull(descriptor);
// Register the handler in the services collection.
Services.Add(descriptor.ServiceDescriptor);
@@ -87,10 +80,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder RemoveEventHandler(OpenIddictClientHandlerDescriptor descriptor)
{
- if (descriptor is null)
- {
- throw new ArgumentNullException(nameof(descriptor));
- }
+ ArgumentNullException.ThrowIfNull(descriptor);
Services.RemoveAll(descriptor.ServiceDescriptor.ServiceType);
@@ -116,10 +106,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder Configure(Action configuration)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@@ -133,10 +120,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEncryptionCredentials(EncryptingCredentials credentials)
{
- if (credentials is null)
- {
- throw new ArgumentNullException(nameof(credentials));
- }
+ ArgumentNullException.ThrowIfNull(credentials);
return Configure(options => options.EncryptionCredentials.Add(credentials));
}
@@ -148,10 +132,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEncryptionKey(SecurityKey key)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
// If the encryption key is an asymmetric security key, ensure it has a private key.
if (key is AsymmetricSecurityKey asymmetricSecurityKey &&
@@ -187,10 +168,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEncryptionKeys(IEnumerable keys)
{
- if (keys is null)
- {
- throw new ArgumentNullException(nameof(keys));
- }
+ ArgumentNullException.ThrowIfNull(keys);
return keys.Aggregate(this, static (builder, key) => builder.AddEncryptionKey(key));
}
@@ -209,10 +187,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddDevelopmentEncryptionCertificate(X500DistinguishedName subject)
{
- if (subject is null)
- {
- throw new ArgumentNullException(nameof(subject));
- }
+ ArgumentNullException.ThrowIfNull(subject);
Services.AddOptions().Configure((options, provider) =>
{
@@ -242,7 +217,7 @@ public sealed class OpenIddictClientBuilder
// Note: setting the friendly name is not supported on Unix machines (including Linux and macOS).
// To ensure an exception is not thrown by the property setter, an OS runtime check is used here.
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (OperatingSystem.IsWindows())
{
certificate.FriendlyName = "OpenIddict Client Development Encryption Certificate";
}
@@ -259,7 +234,7 @@ public sealed class OpenIddictClientBuilder
// Note: macOS requires marking the certificate private key as exportable.
// If this flag is not set, a CryptographicException is thrown at runtime.
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ if (OperatingSystem.IsMacOS())
{
flags |= X509KeyStorageFlags.Exportable;
}
@@ -313,10 +288,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEphemeralEncryptionKey(string algorithm)
{
- if (string.IsNullOrEmpty(algorithm))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0057), nameof(algorithm));
- }
+ ArgumentException.ThrowIfNullOrEmpty(algorithm);
return algorithm switch
{
@@ -342,10 +314,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEncryptionCertificate(X509Certificate2 certificate)
{
- if (certificate is null)
- {
- throw new ArgumentNullException(nameof(certificate));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -377,7 +346,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddEncryptionCertificate(Assembly assembly, string resource, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
- => AddEncryptionCertificate(assembly, resource, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
+ => AddEncryptionCertificate(assembly, resource, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@@ -396,15 +365,8 @@ public sealed class OpenIddictClientBuilder
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));
- }
+ ArgumentNullException.ThrowIfNull(assembly);
+ ArgumentException.ThrowIfNullOrEmpty(resource);
using var stream = assembly.GetManifestResourceStream(resource) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0064));
@@ -421,7 +383,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
- => AddEncryptionCertificate(stream, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
+ => AddEncryptionCertificate(stream, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@@ -437,10 +399,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream, string? password, X509KeyStorageFlags flags)
{
- if (stream is null)
- {
- throw new ArgumentNullException(nameof(stream));
- }
+ ArgumentNullException.ThrowIfNull(stream);
using var buffer = new MemoryStream();
stream.CopyTo(buffer);
@@ -465,10 +424,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEncryptionCertificate(string thumbprint)
{
- if (string.IsNullOrEmpty(thumbprint))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
- }
+ ArgumentException.ThrowIfNullOrEmpty(thumbprint);
return AddEncryptionCertificate(
GetCertificate(StoreLocation.CurrentUser, thumbprint) ??
@@ -495,10 +451,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEncryptionCertificate(string thumbprint, StoreName name, StoreLocation location)
{
- if (string.IsNullOrEmpty(thumbprint))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
- }
+ ArgumentException.ThrowIfNullOrEmpty(thumbprint);
using var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly);
@@ -516,11 +469,8 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEncryptionCertificates(IEnumerable certificates)
{
- if (certificates is null)
- {
- throw new ArgumentNullException(nameof(certificates));
- }
-
+ ArgumentNullException.ThrowIfNull(certificates);
+
return certificates.Aggregate(this, static (builder, certificate) => builder.AddEncryptionCertificate(certificate));
}
@@ -531,10 +481,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddSigningCredentials(SigningCredentials credentials)
{
- if (credentials is null)
- {
- throw new ArgumentNullException(nameof(credentials));
- }
+ ArgumentNullException.ThrowIfNull(credentials);
return Configure(options => options.SigningCredentials.Add(credentials));
}
@@ -546,10 +493,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddSigningKey(SecurityKey key)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
// If the signing key is an asymmetric security key, ensure it has a private key.
if (key is AsymmetricSecurityKey asymmetricSecurityKey &&
@@ -603,10 +547,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddSigningKeys(IEnumerable keys)
{
- if (keys is null)
- {
- throw new ArgumentNullException(nameof(keys));
- }
+ ArgumentNullException.ThrowIfNull(keys);
return keys.Aggregate(this, static (builder, key) => builder.AddSigningKey(key));
}
@@ -625,10 +566,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddDevelopmentSigningCertificate(X500DistinguishedName subject)
{
- if (subject is null)
- {
- throw new ArgumentNullException(nameof(subject));
- }
+ ArgumentNullException.ThrowIfNull(subject);
Services.AddOptions().Configure((options, provider) =>
{
@@ -658,7 +596,7 @@ public sealed class OpenIddictClientBuilder
// Note: setting the friendly name is not supported on Unix machines (including Linux and macOS).
// To ensure an exception is not thrown by the property setter, an OS runtime check is used here.
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (OperatingSystem.IsWindows())
{
certificate.FriendlyName = "OpenIddict Client Development Signing Certificate";
}
@@ -675,7 +613,7 @@ public sealed class OpenIddictClientBuilder
// Note: macOS requires marking the certificate private key as exportable.
// If this flag is not set, a CryptographicException is thrown at runtime.
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ if (OperatingSystem.IsMacOS())
{
flags |= X509KeyStorageFlags.Exportable;
}
@@ -728,10 +666,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddEphemeralSigningKey(string algorithm)
{
- if (string.IsNullOrEmpty(algorithm))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0057), nameof(algorithm));
- }
+ ArgumentException.ThrowIfNullOrEmpty(algorithm);
return algorithm switch
{
@@ -786,10 +721,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddSigningCertificate(X509Certificate2 certificate)
{
- if (certificate is null)
- {
- throw new ArgumentNullException(nameof(certificate));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -821,7 +753,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddSigningCertificate(Assembly assembly, string resource, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
- => AddSigningCertificate(assembly, resource, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
+ => AddSigningCertificate(assembly, resource, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@@ -840,15 +772,8 @@ public sealed class OpenIddictClientBuilder
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));
- }
+ ArgumentNullException.ThrowIfNull(assembly);
+ ArgumentException.ThrowIfNullOrEmpty(resource);
using var stream = assembly.GetManifestResourceStream(resource) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0064));
@@ -865,7 +790,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddSigningCertificate(Stream stream, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
- => AddSigningCertificate(stream, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
+ => AddSigningCertificate(stream, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@@ -881,10 +806,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddSigningCertificate(Stream stream, string? password, X509KeyStorageFlags flags)
{
- if (stream is null)
- {
- throw new ArgumentNullException(nameof(stream));
- }
+ ArgumentNullException.ThrowIfNull(stream);
using var buffer = new MemoryStream();
stream.CopyTo(buffer);
@@ -909,10 +831,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddSigningCertificate(string thumbprint)
{
- if (string.IsNullOrEmpty(thumbprint))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
- }
+ ArgumentException.ThrowIfNullOrEmpty(thumbprint);
return AddSigningCertificate(
GetCertificate(StoreLocation.CurrentUser, thumbprint) ??
@@ -939,10 +858,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddSigningCertificate(string thumbprint, StoreName name, StoreLocation location)
{
- if (string.IsNullOrEmpty(thumbprint))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
- }
+ ArgumentException.ThrowIfNullOrEmpty(thumbprint);
using var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly);
@@ -960,11 +876,8 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddSigningCertificates(IEnumerable certificates)
{
- if (certificates is null)
- {
- throw new ArgumentNullException(nameof(certificates));
- }
-
+ ArgumentNullException.ThrowIfNull(certificates);
+
return certificates.Aggregate(this, static (builder, certificate) => builder.AddSigningCertificate(certificate));
}
@@ -975,10 +888,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder AddRegistration(OpenIddictClientRegistration registration)
{
- if (registration is null)
- {
- throw new ArgumentNullException(nameof(registration));
- }
+ ArgumentNullException.ThrowIfNull(registration);
return Configure(options => options.Registrations.Add(registration));
}
@@ -1038,10 +948,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder AllowCustomFlow(string type)
{
- if (string.IsNullOrEmpty(type))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0071), nameof(type));
- }
+ ArgumentException.ThrowIfNullOrEmpty(type);
return Configure(options => options.GrantTypes.Add(type));
}
@@ -1138,10 +1045,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder SetPostLogoutRedirectionEndpointUris(
[StringSyntax(StringSyntaxAttribute.Uri)] params string[] uris)
{
- if (uris is null)
- {
- throw new ArgumentNullException(nameof(uris));
- }
+ ArgumentNullException.ThrowIfNull(uris);
return SetPostLogoutRedirectionEndpointUris([.. uris.Select(uri => new Uri(uri, UriKind.RelativeOrAbsolute))]);
}
@@ -1154,10 +1058,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder SetPostLogoutRedirectionEndpointUris(params Uri[] uris)
{
- if (uris is null)
- {
- throw new ArgumentNullException(nameof(uris));
- }
+ ArgumentNullException.ThrowIfNull(uris);
if (Array.Exists(uris, OpenIddictHelpers.IsImplicitFileUri))
{
@@ -1191,10 +1092,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder SetRedirectionEndpointUris(
[StringSyntax(StringSyntaxAttribute.Uri)] params string[] uris)
{
- if (uris is null)
- {
- throw new ArgumentNullException(nameof(uris));
- }
+ ArgumentNullException.ThrowIfNull(uris);
return SetRedirectionEndpointUris([.. uris.Select(uri => new Uri(uri, UriKind.RelativeOrAbsolute))]);
}
@@ -1213,10 +1111,7 @@ public sealed class OpenIddictClientBuilder
/// The instance.
public OpenIddictClientBuilder SetRedirectionEndpointUris(params Uri[] uris)
{
- if (uris is null)
- {
- throw new ArgumentNullException(nameof(uris));
- }
+ ArgumentNullException.ThrowIfNull(uris);
if (Array.Exists(uris, OpenIddictHelpers.IsImplicitFileUri))
{
@@ -1265,10 +1160,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder SetClientUri(Uri uri)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(uri);
return Configure(options => options.ClientUri = uri);
}
@@ -1282,10 +1174,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder SetClientUri(
[StringSyntax(StringSyntaxAttribute.Uri, UriKind.Absolute)] string uri)
{
- if (string.IsNullOrEmpty(uri))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(uri)), nameof(uri));
- }
+ ArgumentException.ThrowIfNullOrEmpty(uri);
if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value))
{
diff --git a/src/OpenIddict.Client/OpenIddictClientConfiguration.cs b/src/OpenIddict.Client/OpenIddictClientConfiguration.cs
index df0d4abe..cb615005 100644
--- a/src/OpenIddict.Client/OpenIddictClientConfiguration.cs
+++ b/src/OpenIddict.Client/OpenIddictClientConfiguration.cs
@@ -40,10 +40,7 @@ public sealed class OpenIddictClientConfiguration : IPostConfigureOptions
public void PostConfigure(string? name, OpenIddictClientOptions options)
{
- if (options is null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(options);
if (options.JsonWebTokenHandler is null)
{
diff --git a/src/OpenIddict.Client/OpenIddictClientDispatcher.cs b/src/OpenIddict.Client/OpenIddictClientDispatcher.cs
index d793a23e..e0373ba6 100644
--- a/src/OpenIddict.Client/OpenIddictClientDispatcher.cs
+++ b/src/OpenIddict.Client/OpenIddictClientDispatcher.cs
@@ -36,10 +36,7 @@ public sealed class OpenIddictClientDispatcher : IOpenIddictClientDispatcher
///
public async ValueTask DispatchAsync(TContext context) where TContext : BaseContext
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
await foreach (var handler in GetHandlersAsync())
{
diff --git a/src/OpenIddict.Client/OpenIddictClientExtensions.cs b/src/OpenIddict.Client/OpenIddictClientExtensions.cs
index 2be9937c..0465e0c9 100644
--- a/src/OpenIddict.Client/OpenIddictClientExtensions.cs
+++ b/src/OpenIddict.Client/OpenIddictClientExtensions.cs
@@ -23,10 +23,7 @@ public static class OpenIddictClientExtensions
/// The instance.
public static OpenIddictClientBuilder AddClient(this OpenIddictBuilder builder)
{
- if (builder is null)
- {
- throw new ArgumentNullException(nameof(builder));
- }
+ ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddLogging();
builder.Services.AddOptions();
@@ -98,15 +95,8 @@ public static class OpenIddictClientExtensions
/// The instance.
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));
- }
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.AddClient());
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs b/src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs
index 77c046c5..7b380cc9 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs
@@ -88,10 +88,7 @@ public sealed class OpenIddictClientHandlerDescriptor
/// The builder instance, so that calls can be easily chained.
public Builder Import(OpenIddictClientHandlerDescriptor descriptor)
{
- if (descriptor is null)
- {
- throw new ArgumentNullException(nameof(descriptor));
- }
+ ArgumentNullException.ThrowIfNull(descriptor);
if (descriptor.ContextType != typeof(TContext))
{
@@ -114,10 +111,7 @@ public sealed class OpenIddictClientHandlerDescriptor
/// The builder instance, so that calls can be easily chained.
public Builder SetServiceDescriptor(ServiceDescriptor descriptor)
{
- if (descriptor is null)
- {
- throw new ArgumentNullException(nameof(descriptor));
- }
+ ArgumentNullException.ThrowIfNull(descriptor);
if (!typeof(IOpenIddictClientHandler).IsAssignableFrom(descriptor.ServiceType))
{
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs b/src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs
index ce80ee5c..d3991c91 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs
@@ -19,10 +19,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateAuthorizationCode);
}
@@ -36,10 +33,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateBackchannelAccessToken);
}
@@ -53,10 +47,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableBackchannelIdentityTokenNonceValidation);
}
@@ -70,10 +61,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.BackchannelIdentityTokenPrincipal is not null);
}
@@ -87,10 +75,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateBackchannelIdentityToken);
}
@@ -104,10 +89,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@@ -123,10 +105,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@@ -134,10 +113,7 @@ public static class OpenIddictClientHandlerFilters
///
ValueTask IOpenIddictClientHandlerFilter.IsActiveAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@@ -152,10 +128,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.GrantType is GrantTypes.DeviceCode);
}
@@ -169,10 +142,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.SendDeviceAuthorizationRequest);
}
@@ -186,10 +156,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateFrontchannelAccessToken);
}
@@ -203,10 +170,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableFrontchannelIdentityTokenNonceValidation);
}
@@ -220,10 +184,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.FrontchannelIdentityTokenPrincipal is not null);
}
@@ -237,10 +198,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateFrontchannelIdentityToken);
}
@@ -255,10 +213,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.GrantType switch
{
@@ -277,10 +232,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@@ -294,10 +246,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.SendIntrospectionRequest);
}
@@ -311,10 +260,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateIssuedToken);
}
@@ -328,10 +274,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.TokenFormat is TokenFormats.Private.JsonWebToken);
}
@@ -345,10 +288,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateStateToken);
}
@@ -362,10 +302,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateStateToken);
}
@@ -379,10 +316,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.EndpointType is OpenIddictClientEndpointType.PostLogoutRedirection);
}
@@ -396,10 +330,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.SendPushedAuthorizationRequest);
}
@@ -413,10 +344,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.EndpointType is OpenIddictClientEndpointType.Redirection);
}
@@ -430,10 +358,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateRefreshToken);
}
@@ -447,10 +372,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@@ -464,10 +386,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.SendRevocationRequest);
}
@@ -481,10 +400,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.StateTokenPrincipal is not null);
}
@@ -498,10 +414,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateStateToken);
}
@@ -515,10 +428,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableAudienceValidation);
}
@@ -532,10 +442,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.CreateTokenEntry);
}
@@ -549,10 +456,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!string.IsNullOrEmpty(context.TokenId));
}
@@ -566,10 +470,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableLifetimeValidation);
}
@@ -583,10 +484,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.PersistTokenPayload);
}
@@ -600,10 +498,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!context.DisablePresenterValidation);
}
@@ -617,10 +512,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.SendTokenRequest);
}
@@ -634,10 +526,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!context.Options.DisableTokenStorage);
}
@@ -651,10 +540,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.SendUserInfoRequest);
}
@@ -668,10 +554,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.ExtractUserInfoToken);
}
@@ -685,10 +568,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(context.UserInfoTokenPrincipal is not null);
}
@@ -702,10 +582,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableUserInfoValidation);
}
@@ -719,10 +596,7 @@ public static class OpenIddictClientHandlerFilters
///
public ValueTask IsActiveAsync(BaseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
return new(!context.Options.DisableWebServicesFederationClaimMapping);
}
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs
index ca259ad8..9173eb8b 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs
@@ -78,10 +78,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new PrepareAuthorizationRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -123,10 +120,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ApplyAuthorizationRequestContext(context.Transaction)
{
@@ -178,10 +172,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the endpoint URI if it was already set.
if (!string.IsNullOrEmpty(context.AuthorizationEndpoint))
@@ -220,10 +211,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@@ -284,10 +272,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
if (!string.IsNullOrEmpty(context.Response.Error))
@@ -331,10 +316,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Return an error if the mandatory "request_uri" parameter is missing.
//
@@ -384,10 +366,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Return an error if the mandatory "expires_in" parameter is missing.
//
@@ -429,10 +408,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ExtractRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -491,10 +467,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ValidateRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -547,10 +520,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new HandleRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -604,10 +574,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ApplyRedirectionResponseContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -646,10 +613,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(PrepareAuthorizationRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// When the response mode corresponds to the default mode assigned to the selected
// response type, the specification explicitly recommends omitting the response mode.
@@ -697,10 +661,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ValidateRedirectionRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ProcessAuthenticationContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Device.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Device.cs
index 47fa72c1..ba05df2b 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.Device.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Device.cs
@@ -43,10 +43,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@@ -113,10 +110,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
if (!string.IsNullOrEmpty(context.Response.Error))
@@ -161,10 +155,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Return an error if the mandatory "verification_uri" parameter is missing.
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
@@ -227,10 +218,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Return an error if the mandatory "expires_in" parameter is missing.
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs
index 13235fa0..c9687c7d 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs
@@ -78,10 +78,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@@ -171,10 +168,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: the specification doesn't define a standard way to return an error other than
// returning a 4xx status code. That said, some implementations are known to return
@@ -214,10 +208,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: the issuer returned in the discovery document must exactly match the URI used to access it.
// See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationValidation.
@@ -278,10 +269,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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
@@ -330,10 +318,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -382,10 +367,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.DeviceAuthorizationEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@@ -425,10 +407,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.IntrospectionEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@@ -468,10 +447,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.EndSessionEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@@ -512,10 +488,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@@ -548,10 +521,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@@ -583,10 +553,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@@ -618,10 +585,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@@ -653,10 +617,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@@ -688,10 +649,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@@ -723,10 +681,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.PushedAuthorizationRequestEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@@ -766,10 +721,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.RevocationEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@@ -809,10 +761,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.TokenEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@@ -852,10 +801,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.UserInfoEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@@ -895,10 +841,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the grant types supported by the authorization endpoint, if available.
foreach (var type in (ImmutableArray?) context.Response[Metadata.GrantTypesSupported] ?? [])
@@ -931,10 +874,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the response modes supported by the authorization endpoint, if available.
foreach (var mode in (ImmutableArray?) context.Response[Metadata.ResponseModesSupported] ?? [])
@@ -967,10 +907,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the response types supported by the authorization endpoint, if available.
foreach (var type in (ImmutableArray?) context.Response[Metadata.ResponseTypesSupported] ?? [])
@@ -1003,10 +940,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the code challenge methods supported by the authorization endpoint, if available.
foreach (var method in (ImmutableArray?) context.Response[Metadata.CodeChallengeMethodsSupported] ?? [])
@@ -1039,10 +973,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the scopes supported by the remote server, if available.
foreach (var scope in (ImmutableArray?) context.Response[Metadata.ScopesSupported] ?? [])
@@ -1076,10 +1007,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Configuration.AuthorizationResponseIssParameterSupported = (bool?)
context.Response[Metadata.AuthorizationResponseIssParameterSupported];
@@ -1107,10 +1035,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Configuration.TlsClientCertificateBoundAccessTokens = (bool?)
context.Response[Metadata.TlsClientCertificateBoundAccessTokens];
@@ -1138,10 +1063,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Configuration.RequirePushedAuthorizationRequests = (bool?)
context.Response[Metadata.RequirePushedAuthorizationRequests];
@@ -1169,10 +1091,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the device authorization endpoint, if available.
//
@@ -1209,10 +1128,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the introspection endpoint, if available.
foreach (var method in (ImmutableArray?) context.Response[Metadata.IntrospectionEndpointAuthMethodsSupported] ?? [])
@@ -1246,10 +1162,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the pushed authorization endpoint, if available.
//
@@ -1286,10 +1199,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the revocation endpoint, if available.
foreach (var method in (ImmutableArray?) context.Response[Metadata.RevocationEndpointAuthMethodsSupported] ?? [])
@@ -1323,10 +1233,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the token endpoint, if available.
foreach (var method in (ImmutableArray?) context.Response[Metadata.TokenEndpointAuthMethodsSupported] ?? [])
@@ -1359,10 +1266,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@@ -1421,10 +1325,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: the specification doesn't define a standard way to return an error other than
// returning a 4xx status code. That said, some implementations are known to return
@@ -1464,10 +1365,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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 e4eb8f2b..98abf700 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs
@@ -41,10 +41,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleTokenResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@@ -107,10 +104,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleTokenResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// For more information, see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2.
if (!string.IsNullOrEmpty(context.Response.Error))
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Introspection.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Introspection.cs
index 27097be0..69e3e4f2 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.Introspection.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Introspection.cs
@@ -50,10 +50,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@@ -127,10 +124,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: the specification requires returning most errors (e.g invalid token errors)
// as "active: false" responses instead of as proper OAuth 2.0 error responses.
@@ -173,10 +167,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -226,10 +217,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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.
@@ -280,10 +268,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: in most cases, an expired token should lead to an errored or "active=false" response
// being returned by the authorization server. Unfortunately, some implementations are known not
@@ -327,10 +312,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// OpenIddict-based authorization servers always return the actual token type using
// the special "token_usage" claim, that helps resource servers determine whether the
@@ -383,10 +365,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@@ -476,10 +455,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs
index d43f7224..d2239576 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs
@@ -64,10 +64,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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).
@@ -206,10 +203,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If no character was explicitly added, all characters are considered valid.
if (context.AllowedCharset.Count is 0)
@@ -262,10 +256,7 @@ public static partial class OpenIddictClientHandlers
public async ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: reference tokens are only used for state tokens.
if (context.ValidTokenTypes.Count is not 1 ||
@@ -336,10 +327,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If a principal was already attached, don't overwrite it.
if (context.Principal is not null)
@@ -494,10 +482,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: only map the private claims from fully trusted tokens.
if (context.Principal is null || !context.Principal.HasTokenType(TokenTypeIdentifiers.Private.StateToken))
@@ -559,10 +544,7 @@ public static partial class OpenIddictClientHandlers
public async ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Principal is null)
{
@@ -625,10 +607,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Principal is null)
{
@@ -678,10 +657,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -719,10 +695,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -782,10 +755,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -855,10 +825,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ValidateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
Debug.Assert(!string.IsNullOrEmpty(context.TokenId), SR.GetResourceString(SR.ID4017));
@@ -920,10 +887,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.SecurityTokenHandler = context.Options.JsonWebTokenHandler;
@@ -980,10 +944,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var descriptor = new OpenIddictTokenDescriptor
{
@@ -1028,10 +989,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Principal is not { Identity: ClaimsIdentity } principal)
{
@@ -1077,10 +1035,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var claims = context.SecurityTokenDescriptor.Claims is not null ?
new Dictionary(context.SecurityTokenDescriptor.Claims, StringComparer.Ordinal) :
@@ -1143,10 +1098,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If a token was already attached by another handler, don't overwrite it.
if (!string.IsNullOrEmpty(context.Token))
@@ -1191,10 +1143,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(GenerateTokenContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var identifier = context.Principal.GetTokenId();
if (string.IsNullOrEmpty(identifier))
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Revocation.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Revocation.cs
index 2f89cf1d..1668b86d 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.Revocation.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Revocation.cs
@@ -41,10 +41,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleRevocationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@@ -98,10 +95,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleRevocationResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (!string.IsNullOrEmpty(context.Response.Error))
{
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Session.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Session.cs
index 0886ba53..84518dae 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.Session.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Session.cs
@@ -63,10 +63,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new PrepareEndSessionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -107,10 +104,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ApplyEndSessionRequestContext(context.Transaction)
{
@@ -161,10 +155,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ApplyEndSessionRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the endpoint URI if it was already set.
if (!string.IsNullOrEmpty(context.EndSessionEndpoint))
@@ -208,10 +199,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ExtractPostLogoutRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -270,10 +258,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ValidatePostLogoutRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -326,10 +311,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new HandlePostLogoutRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -383,10 +365,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(TContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ApplyPostLogoutRedirectionResponseContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@@ -431,10 +410,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ValidatePostLogoutRedirectionRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new ProcessAuthenticationContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs
index 3fca98b4..f3bcbf2e 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs
@@ -44,10 +44,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleUserInfoResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Ignore the response instance if a userinfo token was extracted.
if (!string.IsNullOrEmpty(context.UserInfoToken))
@@ -110,10 +107,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleUserInfoResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// For more information, see https://openid.net/specs/openid-connect-core-1_0.html#UserInfoError.
if (!string.IsNullOrEmpty(context.Response.Error))
@@ -156,10 +150,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(HandleUserInfoResponseContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.cs
index 5be35496..7919982b 100644
--- a/src/OpenIddict.Client/OpenIddictClientHandlers.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHandlers.cs
@@ -238,10 +238,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRequestContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the base or request URIs couldn't be resolved, don't try to infer the endpoint type.
if (context is not { BaseUri.IsAbsoluteUri: true, RequestUri.IsAbsoluteUri: true })
@@ -319,10 +316,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Authentication demands can be triggered from the redirection endpoints
// to handle authorization/logout callbacks but also from unknown endpoints
@@ -445,10 +439,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: this handler only applies to authentication demands triggered from unknown endpoints.
//
@@ -564,10 +555,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.ExtractStateToken,
context.RequireStateToken,
@@ -613,10 +601,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.StateToken = context.EndpointType switch
{
@@ -650,10 +635,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.RequireStateToken && string.IsNullOrEmpty(context.StateToken))
{
@@ -693,10 +675,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.StateToken))
{
@@ -762,10 +741,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -804,10 +780,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -855,10 +828,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -904,10 +874,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -956,10 +923,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -1019,10 +983,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -1130,10 +1091,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -1206,10 +1164,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// To help mitigate mix-up attacks, the identity of the issuer can be returned by
// authorization servers that support it as a part of the "iss" parameter, which
@@ -1287,10 +1242,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: unlike the redirection endpoint, the post-logout redirection endpoint is not expected
// to be called with an error attached (in this case, the error is typically displayed directly
@@ -1389,10 +1341,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -1441,10 +1390,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.ExtractAuthorizationCode,
context.RequireAuthorizationCode,
@@ -1530,10 +1476,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.AuthorizationCode = context.EndpointType switch
{
@@ -1592,10 +1535,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if ((context.RequireAuthorizationCode && string.IsNullOrEmpty(context.AuthorizationCode)) ||
(context.RequireFrontchannelAccessToken && string.IsNullOrEmpty(context.FrontchannelAccessToken)) ||
@@ -1637,10 +1577,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.FrontchannelIdentityToken))
{
@@ -1707,10 +1644,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.FrontchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -1836,10 +1770,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.FrontchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -1881,10 +1812,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.FrontchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -1927,10 +1855,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: the OpenID Connect specification relies on nonces as a way to detect and
// prevent replay attacks by binding the returned identity token(s) to a specific
@@ -2028,10 +1953,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.FrontchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -2160,10 +2082,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.FrontchannelAccessToken))
{
@@ -2234,10 +2153,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.AuthorizationCode))
{
@@ -2300,10 +2216,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.SendTokenRequest = context.GrantType switch
{
@@ -2355,10 +2268,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.TokenEndpointClientAuthenticationMethod))
@@ -2418,10 +2328,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the URI of the token endpoint wasn't explicitly set at
// this stage, try to extract it from the server configuration.
@@ -2462,10 +2369,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Attach a new request instance if necessary.
context.TokenRequest ??= new OpenIddictRequest();
@@ -2585,10 +2489,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.GenerateClientAssertion,
context.IncludeClientAssertion) = context.TokenEndpointClientAuthenticationMethod switch
@@ -2624,10 +2525,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@@ -2701,10 +2599,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new GenerateTokenContext(context.Transaction)
{
@@ -2768,10 +2663,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -2821,10 +2713,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -2873,10 +2762,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.ExtractBackchannelAccessToken,
context.RequireBackchannelAccessToken,
@@ -3034,10 +2920,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.TokenResponse is not null, SR.GetResourceString(SR.ID4007));
@@ -3097,10 +2980,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if ((context.RequireBackchannelAccessToken && string.IsNullOrEmpty(context.BackchannelAccessToken)) ||
(context.RequireBackchannelIdentityToken && string.IsNullOrEmpty(context.BackchannelIdentityToken)) ||
@@ -3143,10 +3023,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.BackchannelIdentityToken))
{
@@ -3213,10 +3090,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.BackchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -3342,10 +3216,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.BackchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -3387,10 +3258,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.BackchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -3433,10 +3301,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: the OpenID Connect specification relies on nonces as a way to detect and
// prevent replay attacks by binding the returned identity token(s) to a specific
@@ -3534,10 +3399,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.BackchannelIdentityTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
Debug.Assert(!string.IsNullOrEmpty(context.BackchannelAccessToken), SR.GetResourceString(SR.ID4010));
@@ -3630,10 +3492,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.BackchannelAccessToken))
{
@@ -3702,10 +3561,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.IssuedToken))
{
@@ -3776,10 +3632,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.RefreshToken))
{
@@ -3842,10 +3695,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.SendUserInfoRequest = context.GrantType switch
{
@@ -3942,10 +3792,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// By default, assume that sending the access token is enough and doesn't require using
// an additional token binding method. To support advanced scenarios like mTLS-protected
@@ -3975,10 +3822,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the URI of the userinfo endpoint wasn't explicitly set at
// this stage, try to extract it from the server configuration.
@@ -4021,10 +3865,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Attach a new request instance if necessary.
context.UserInfoRequest ??= new OpenIddictRequest();
@@ -4074,10 +3915,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.UserInfoRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -4131,10 +3969,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.ExtractUserInfoToken,
context.RequireUserInfoToken,
@@ -4188,10 +4023,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.RequireUserInfoToken && string.IsNullOrEmpty(context.UserInfoToken))
{
@@ -4231,10 +4063,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.UserInfoToken))
{
@@ -4299,10 +4128,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.UserInfoTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -4352,10 +4178,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.UserInfoTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -4423,10 +4246,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@@ -4521,10 +4341,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@@ -4582,10 +4399,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.EndpointType is not OpenIddictClientEndpointType.Unknown)
{
@@ -4717,10 +4531,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Registration ??= context switch
{
@@ -4811,10 +4622,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit grant or response type was specified, don't overwrite it.
if (!string.IsNullOrEmpty(context.GrantType) || !string.IsNullOrEmpty(context.ResponseType))
@@ -5038,10 +4846,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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
@@ -5083,10 +4888,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -5113,10 +4915,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.ClientId ??= context.Registration.ClientId switch
{
@@ -5156,10 +4955,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the redirect_uri if one was already explicitly attached.
if (context.RedirectUri is not null)
@@ -5209,10 +5005,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit set of scopes was specified, don't overwrite it.
if (context.Scopes.Count is > 0)
@@ -5256,10 +5049,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Generate a new crypto-secure random identifier that will
// be used as the non-guessable part of the state token.
@@ -5288,10 +5078,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Generate a new crypto-secure random identifier that will be used as the nonce.
//
@@ -5328,10 +5115,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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
@@ -5425,10 +5209,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit response type was specified, don't overwrite it.
if (!string.IsNullOrEmpty(context.ResponseMode))
@@ -5493,10 +5274,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -5618,10 +5396,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new GenerateTokenContext(context.Transaction)
{
@@ -5679,10 +5454,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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
@@ -5759,10 +5531,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Parameters.Count is > 0)
{
@@ -5794,10 +5563,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.SendDeviceAuthorizationRequest = context.GrantType is GrantTypes.DeviceCode;
@@ -5825,10 +5591,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.DeviceAuthorizationEndpointClientAuthenticationMethod))
@@ -5896,10 +5659,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the URI of the device authorization endpoint endpoint wasn't explicitly
// set at this stage, try to extract it from the server configuration.
@@ -5940,10 +5700,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Attach a new request instance if necessary.
context.DeviceAuthorizationRequest ??= new OpenIddictRequest();
@@ -5978,10 +5735,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.SendPushedAuthorizationRequest = context.GrantType switch
{
@@ -6025,10 +5779,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.PushedAuthorizationEndpointClientAuthenticationMethod))
@@ -6097,10 +5848,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the URI of the pushed authorization endpoint endpoint wasn't
// explicitly set at this stage, try to extract it from the server configuration.
@@ -6141,10 +5889,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Attach a new request instance if necessary.
context.PushedAuthorizationRequest ??= new OpenIddictRequest();
@@ -6178,10 +5923,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.GenerateClientAssertion, context.IncludeClientAssertion) = context switch
{
@@ -6217,10 +5959,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@@ -6280,10 +6019,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new GenerateTokenContext(context.Transaction)
{
@@ -6347,10 +6083,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.DeviceAuthorizationRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -6400,10 +6133,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.DeviceAuthorizationRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -6452,10 +6182,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.ExtractDeviceCode,
context.RequireDeviceCode,
@@ -6510,10 +6237,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.DeviceAuthorizationResponse is not null, SR.GetResourceString(SR.ID4007));
@@ -6545,10 +6269,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if ((context.RequireDeviceCode && string.IsNullOrEmpty(context.DeviceCode)) ||
(context.RequireUserCode && string.IsNullOrEmpty(context.UserCode)))
@@ -6583,10 +6304,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.PushedAuthorizationRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -6631,10 +6349,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (!context.SendPushedAuthorizationRequest && context.Configuration.RequirePushedAuthorizationRequests is true)
{
@@ -6668,10 +6383,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.PushedAuthorizationRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -6720,10 +6432,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.ExtractRequestToken,
context.RequireRequestToken,
@@ -6765,10 +6474,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.PushedAuthorizationResponse is not null, SR.GetResourceString(SR.ID4007));
@@ -6799,10 +6505,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.RequireRequestToken && string.IsNullOrEmpty(context.RequestToken))
{
@@ -6837,10 +6540,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Request.RequestUri = context.RequestToken;
@@ -6869,10 +6569,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessChallengeContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.PushedAuthorizationRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -6906,10 +6603,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.Token))
{
@@ -6952,10 +6646,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Registration ??= context switch
{
@@ -7044,10 +6735,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.ClientId ??= context.Registration.ClientId;
@@ -7073,10 +6761,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.SendIntrospectionRequest = true;
@@ -7104,10 +6789,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.IntrospectionEndpointClientAuthenticationMethod))
@@ -7167,10 +6849,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the URI of the introspection endpoint endpoint wasn't explicitly
// set at this stage, try to extract it from the server configuration.
@@ -7211,10 +6890,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Attach a new request instance if necessary.
context.IntrospectionRequest ??= new OpenIddictRequest();
@@ -7245,10 +6921,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.GenerateClientAssertion,
context.IncludeClientAssertion) = context.IntrospectionEndpointClientAuthenticationMethod switch
@@ -7284,10 +6957,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@@ -7347,10 +7017,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new GenerateTokenContext(context.Transaction)
{
@@ -7414,10 +7081,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.IntrospectionRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -7467,10 +7131,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
Debug.Assert(context.IntrospectionRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -7529,10 +7190,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -7577,10 +7235,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.Token))
{
@@ -7623,10 +7278,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Registration ??= context switch
{
@@ -7715,10 +7367,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.ClientId ??= context.Registration.ClientId;
@@ -7744,10 +7393,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.SendRevocationRequest = true;
@@ -7775,10 +7421,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.RevocationEndpointClientAuthenticationMethod))
@@ -7838,10 +7481,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// If the URI of the revocation endpoint endpoint wasn't explicitly
// set at this stage, try to extract it from the server configuration.
@@ -7882,10 +7522,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Attach a new request instance if necessary.
context.RevocationRequest ??= new OpenIddictRequest();
@@ -7916,10 +7553,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.GenerateClientAssertion,
context.IncludeClientAssertion) = context.RevocationEndpointClientAuthenticationMethod switch
@@ -7955,10 +7589,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@@ -8018,10 +7649,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new GenerateTokenContext(context.Transaction)
{
@@ -8085,10 +7713,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.RevocationRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -8138,10 +7763,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessRevocationContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.RevocationRequest is not null, SR.GetResourceString(SR.ID4008));
@@ -8191,10 +7813,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.EndpointType is not OpenIddictClientEndpointType.Unknown)
{
@@ -8293,10 +7912,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Registration ??= context switch
{
@@ -8385,10 +8001,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Note: the client_id parameter is optional.
context.ClientId ??= context.Registration.ClientId;
@@ -8414,10 +8027,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the post_logout_redirect_uri if one was already explicitly attached.
if (context.PostLogoutRedirectUri is not null)
@@ -8465,10 +8075,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
(context.GenerateStateToken, context.IncludeStateToken) = (true, true);
@@ -8494,10 +8101,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -8524,10 +8128,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Generate a new crypto-secure random identifier that will
// be used as the non-guessable part of the state token.
@@ -8555,10 +8156,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
// Generate a new crypto-secure random identifier that will be used as the nonce.
context.Nonce = Base64UrlEncoder.Encode(OpenIddictHelpers.CreateRandomArray(size: 256));
@@ -8587,10 +8185,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@@ -8691,10 +8286,7 @@ public static partial class OpenIddictClientHandlers
///
public async ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
var notification = new GenerateTokenContext(context.Transaction)
{
@@ -8751,10 +8343,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(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 post_logout_redirect_uri are
@@ -8794,10 +8383,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessSignOutContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Parameters.Count is > 0)
{
@@ -8829,10 +8415,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessErrorContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
context.Response.Error = context.Error;
context.Response.ErrorDescription = context.ErrorDescription;
@@ -8861,10 +8444,7 @@ public static partial class OpenIddictClientHandlers
///
public ValueTask HandleAsync(ProcessErrorContext context)
{
- if (context is null)
- {
- throw new ArgumentNullException(nameof(context));
- }
+ ArgumentNullException.ThrowIfNull(context);
if (context.Parameters.Count is > 0)
{
diff --git a/src/OpenIddict.Client/OpenIddictClientHelpers.cs b/src/OpenIddict.Client/OpenIddictClientHelpers.cs
index 3bbce2e9..cf2948b6 100644
--- a/src/OpenIddict.Client/OpenIddictClientHelpers.cs
+++ b/src/OpenIddict.Client/OpenIddictClientHelpers.cs
@@ -21,15 +21,8 @@ public static class OpenIddictClientHelpers
public static TProperty? GetProperty(
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));
- }
+ ArgumentNullException.ThrowIfNull(transaction);
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (transaction.Properties.TryGetValue(name, out var property) && property is TProperty result)
{
@@ -51,15 +44,8 @@ public static class OpenIddictClientHelpers
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));
- }
+ ArgumentNullException.ThrowIfNull(transaction);
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (value is null)
{
diff --git a/src/OpenIddict.Client/OpenIddictClientRetriever.cs b/src/OpenIddict.Client/OpenIddictClientRetriever.cs
index ecf3a97c..7b777fe3 100644
--- a/src/OpenIddict.Client/OpenIddictClientRetriever.cs
+++ b/src/OpenIddict.Client/OpenIddictClientRetriever.cs
@@ -38,10 +38,7 @@ public sealed class OpenIddictClientRetriever : IConfigurationRetriever IConfigurationRetriever.GetConfigurationAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string address, IDocumentRetriever retriever, CancellationToken cancel)
{
- if (string.IsNullOrEmpty(address))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(address));
- }
+ ArgumentException.ThrowIfNullOrEmpty(address);
if (!Uri.TryCreate(address, UriKind.Absolute, out Uri? uri) || OpenIddictHelpers.IsImplicitFileUri(uri))
{
diff --git a/src/OpenIddict.Client/OpenIddictClientService.cs b/src/OpenIddict.Client/OpenIddictClientService.cs
index c5bfe3ab..25a4e864 100644
--- a/src/OpenIddict.Client/OpenIddictClientService.cs
+++ b/src/OpenIddict.Client/OpenIddictClientService.cs
@@ -68,10 +68,7 @@ public class OpenIddictClientService
public virtual ValueTask GetClientRegistrationByIssuerAsync(
Uri uri, CancellationToken cancellationToken = default)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(uri);
if (cancellationToken.IsCancellationRequested)
{
@@ -108,10 +105,7 @@ public class OpenIddictClientService
public virtual ValueTask GetClientRegistrationByProviderNameAsync(
string name, CancellationToken cancellationToken = default)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (cancellationToken.IsCancellationRequested)
{
@@ -146,10 +140,7 @@ public class OpenIddictClientService
public virtual ValueTask GetClientRegistrationByIdAsync(
string identifier, CancellationToken cancellationToken = default)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
if (cancellationToken.IsCancellationRequested)
{
@@ -179,10 +170,7 @@ public class OpenIddictClientService
public virtual async ValueTask GetServerConfigurationByIssuerAsync(
Uri uri, CancellationToken cancellationToken = default)
{
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(uri);
var registration = await GetClientRegistrationByIssuerAsync(uri, cancellationToken);
if (registration.ConfigurationManager is null)
@@ -212,10 +200,7 @@ public class OpenIddictClientService
public virtual async ValueTask GetServerConfigurationByProviderNameAsync(
string name, CancellationToken cancellationToken = default)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
var registration = await GetClientRegistrationByProviderNameAsync(name, cancellationToken);
if (registration.ConfigurationManager is null)
@@ -242,10 +227,7 @@ public class OpenIddictClientService
public virtual async ValueTask GetServerConfigurationByRegistrationIdAsync(
string identifier, CancellationToken cancellationToken = default)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
var registration = await GetClientRegistrationByIdAsync(identifier, cancellationToken);
if (registration.ConfigurationManager is null)
@@ -271,10 +253,7 @@ public class OpenIddictClientService
/// The interactive authentication result.
public async ValueTask AuthenticateInteractivelyAsync(InteractiveAuthenticationRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -344,10 +323,7 @@ public class OpenIddictClientService
/// The interactive challenge result.
public async ValueTask ChallengeInteractivelyAsync(InteractiveChallengeRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -430,10 +406,7 @@ public class OpenIddictClientService
public async ValueTask AuthenticateWithClientCredentialsAsync(
ClientCredentialsAuthenticationRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -515,10 +488,7 @@ public class OpenIddictClientService
[EditorBrowsable(EditorBrowsableState.Advanced)]
public async ValueTask AuthenticateWithCustomGrantAsync(CustomGrantAuthenticationRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
// Prevent well-known/non-custom grant types from being used with this API.
if (request.GrantType is GrantTypes.AuthorizationCode or GrantTypes.ClientCredentials or
@@ -608,10 +578,7 @@ public class OpenIddictClientService
/// The device authentication result.
public async ValueTask AuthenticateWithDeviceAsync(DeviceAuthenticationRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
using var source = CancellationTokenSource.CreateLinkedTokenSource(request.CancellationToken);
source.CancelAfter(request.Timeout);
@@ -725,10 +692,7 @@ public class OpenIddictClientService
/// The device challenge result.
public async ValueTask ChallengeUsingDeviceAsync(DeviceChallengeRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -808,10 +772,7 @@ public class OpenIddictClientService
/// The resource owner password credentials authentication result.
public async ValueTask AuthenticateWithPasswordAsync(PasswordAuthenticationRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -897,10 +858,7 @@ public class OpenIddictClientService
public async ValueTask AuthenticateWithTokenExchangeAsync(
TokenExchangeAuthenticationRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -986,10 +944,7 @@ public class OpenIddictClientService
public async ValueTask AuthenticateWithRefreshTokenAsync(
RefreshTokenAuthenticationRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -1073,10 +1028,7 @@ public class OpenIddictClientService
/// The introspection result.
public async ValueTask IntrospectTokenAsync(IntrospectionRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -1136,10 +1088,7 @@ public class OpenIddictClientService
/// The revocation result.
public async ValueTask RevokeTokenAsync(RevocationRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -1201,15 +1150,8 @@ public class OpenIddictClientService
internal async ValueTask GetConfigurationAsync(
OpenIddictClientRegistration registration, Uri uri, CancellationToken cancellationToken = default)
{
- if (registration is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
-
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(registration);
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@@ -1338,10 +1280,7 @@ public class OpenIddictClientService
/// The interactive sign-out result.
public async ValueTask SignOutInteractivelyAsync(InteractiveSignOutRequest request)
{
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
+ ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@@ -1407,15 +1346,8 @@ public class OpenIddictClientService
internal async ValueTask GetSecurityKeysAsync(
OpenIddictClientRegistration registration, Uri uri, CancellationToken cancellationToken = default)
{
- if (registration is null)
- {
- throw new ArgumentNullException(nameof(registration));
- }
-
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(registration);
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@@ -1552,25 +1484,10 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
- if (registration is null)
- {
- throw new ArgumentNullException(nameof(registration));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
-
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
-
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(registration);
+ ArgumentNullException.ThrowIfNull(configuration);
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@@ -1710,20 +1627,9 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
-
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
-
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@@ -1865,25 +1771,10 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
- if (registration is null)
- {
- throw new ArgumentNullException(nameof(registration));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
-
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
-
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(registration);
+ ArgumentNullException.ThrowIfNull(configuration);
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@@ -2023,20 +1914,9 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
-
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
-
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(configuration);
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@@ -2176,25 +2056,10 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
- if (registration is null)
- {
- throw new ArgumentNullException(nameof(registration));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
-
- if (request is null)
- {
- throw new ArgumentNullException(nameof(request));
- }
-
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(registration);
+ ArgumentNullException.ThrowIfNull(configuration);
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@@ -2334,20 +2199,9 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, HashSet methods, CancellationToken cancellationToken = default)
{
- if (registration is null)
- {
- throw new ArgumentNullException(nameof(registration));
- }
-
- if (configuration is null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
-
- if (uri is null)
- {
- throw new ArgumentNullException(nameof(uri));
- }
+ ArgumentNullException.ThrowIfNull(registration);
+ ArgumentNullException.ThrowIfNull(configuration);
+ ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
diff --git a/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs b/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs
index 1620026b..58cedd0b 100644
--- a/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs
+++ b/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs
@@ -45,10 +45,7 @@ public sealed class OpenIddictApplicationCache : IOpenIddictApplic
///
public async ValueTask AddAsync(TApplication application, CancellationToken cancellationToken)
{
- if (application is null)
- {
- throw new ArgumentNullException(nameof(application));
- }
+ ArgumentNullException.ThrowIfNull(application);
_cache.Remove(new
{
@@ -107,10 +104,7 @@ public sealed class OpenIddictApplicationCache : IOpenIddictApplic
///
public ValueTask FindByClientIdAsync(string identifier, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@@ -141,10 +135,7 @@ public sealed class OpenIddictApplicationCache : IOpenIddictApplic
///
public ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@@ -176,10 +167,7 @@ public sealed class OpenIddictApplicationCache : IOpenIddictApplic
public IAsyncEnumerable FindByPostLogoutRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(uri))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
- }
+ ArgumentException.ThrowIfNullOrEmpty(uri);
return ExecuteAsync(cancellationToken);
@@ -218,10 +206,7 @@ public sealed class OpenIddictApplicationCache : IOpenIddictApplic
public IAsyncEnumerable FindByRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(uri))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
- }
+ ArgumentException.ThrowIfNullOrEmpty(uri);
return ExecuteAsync(cancellationToken);
@@ -259,10 +244,7 @@ public sealed class OpenIddictApplicationCache : IOpenIddictApplic
///
public async ValueTask RemoveAsync(TApplication application, CancellationToken cancellationToken)
{
- if (application is null)
- {
- throw new ArgumentNullException(nameof(application));
- }
+ ArgumentNullException.ThrowIfNull(application);
var identifier = await _store.GetIdAsync(application, cancellationToken);
if (string.IsNullOrEmpty(identifier))
@@ -286,10 +268,7 @@ public sealed class OpenIddictApplicationCache : IOpenIddictApplic
/// A that can be used to monitor the asynchronous operation.
private async ValueTask CreateEntryAsync(object key, TApplication? application, CancellationToken cancellationToken)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@@ -312,10 +291,7 @@ public sealed class OpenIddictApplicationCache : IOpenIddictApplic
/// A that can be used to monitor the asynchronous operation.
private async ValueTask CreateEntryAsync(object key, ImmutableArray applications, CancellationToken cancellationToken)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@@ -341,10 +317,7 @@ public sealed class OpenIddictApplicationCache : IOpenIddictApplic
///
private async ValueTask CreateExpirationSignalAsync(TApplication application, CancellationToken cancellationToken)
{
- if (application is null)
- {
- throw new ArgumentNullException(nameof(application));
- }
+ ArgumentNullException.ThrowIfNull(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 81ac2b79..be80393a 100644
--- a/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs
+++ b/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs
@@ -44,10 +44,7 @@ public sealed class OpenIddictAuthorizationCache : IOpenIddictAu
///
public async ValueTask AddAsync(TAuthorization authorization, CancellationToken cancellationToken)
{
- if (authorization is null)
- {
- throw new ArgumentNullException(nameof(authorization));
- }
+ ArgumentNullException.ThrowIfNull(authorization);
_cache.Remove(new
{
@@ -104,10 +101,7 @@ public sealed class OpenIddictAuthorizationCache : IOpenIddictAu
///
public IAsyncEnumerable FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
return ExecuteAsync(cancellationToken);
@@ -145,10 +139,7 @@ public sealed class OpenIddictAuthorizationCache : IOpenIddictAu
///
public ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@@ -179,10 +170,7 @@ public sealed class OpenIddictAuthorizationCache : IOpenIddictAu
///
public IAsyncEnumerable FindBySubjectAsync(string subject, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(subject))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
- }
+ ArgumentException.ThrowIfNullOrEmpty(subject);
return ExecuteAsync(cancellationToken);
@@ -220,10 +208,7 @@ public sealed class OpenIddictAuthorizationCache : IOpenIddictAu
///
public async ValueTask RemoveAsync(TAuthorization authorization, CancellationToken cancellationToken)
{
- if (authorization is null)
- {
- throw new ArgumentNullException(nameof(authorization));
- }
+ ArgumentNullException.ThrowIfNull(authorization);
var identifier = await _store.GetIdAsync(authorization, cancellationToken);
if (string.IsNullOrEmpty(identifier))
@@ -247,10 +232,7 @@ public sealed class OpenIddictAuthorizationCache : IOpenIddictAu
/// A that can be used to monitor the asynchronous operation.
private async ValueTask CreateEntryAsync(object key, TAuthorization? authorization, CancellationToken cancellationToken)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@@ -273,10 +255,7 @@ public sealed class OpenIddictAuthorizationCache : IOpenIddictAu
/// A that can be used to monitor the asynchronous operation.
private async ValueTask CreateEntryAsync(object key, ImmutableArray authorizations, CancellationToken cancellationToken)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@@ -302,10 +281,7 @@ public sealed class OpenIddictAuthorizationCache : IOpenIddictAu
///
private async ValueTask CreateExpirationSignalAsync(TAuthorization authorization, CancellationToken cancellationToken)
{
- if (authorization is null)
- {
- throw new ArgumentNullException(nameof(authorization));
- }
+ ArgumentNullException.ThrowIfNull(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 c973dfbc..1bf96a42 100644
--- a/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs
+++ b/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs
@@ -44,10 +44,7 @@ public sealed class OpenIddictScopeCache : IOpenIddictScopeCache
///
public async ValueTask AddAsync(TScope scope, CancellationToken cancellationToken)
{
- if (scope is null)
- {
- throw new ArgumentNullException(nameof(scope));
- }
+ ArgumentNullException.ThrowIfNull(scope);
_cache.Remove(new
{
@@ -97,10 +94,7 @@ public sealed class OpenIddictScopeCache : IOpenIddictScopeCache
///
public ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@@ -131,10 +125,7 @@ public sealed class OpenIddictScopeCache : IOpenIddictScopeCache
///
public ValueTask FindByNameAsync(string name, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0202), nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
var parameters = new
{
@@ -188,10 +179,7 @@ public sealed class OpenIddictScopeCache : IOpenIddictScopeCache
///
public IAsyncEnumerable FindByResourceAsync(string resource, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(resource))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
- }
+ ArgumentException.ThrowIfNullOrEmpty(resource);
return ExecuteAsync(cancellationToken);
@@ -229,10 +217,7 @@ public sealed class OpenIddictScopeCache : IOpenIddictScopeCache
///
public async ValueTask RemoveAsync(TScope scope, CancellationToken cancellationToken)
{
- if (scope is null)
- {
- throw new ArgumentNullException(nameof(scope));
- }
+ ArgumentNullException.ThrowIfNull(scope);
var identifier = await _store.GetIdAsync(scope, cancellationToken);
if (string.IsNullOrEmpty(identifier))
@@ -256,10 +241,7 @@ public sealed class OpenIddictScopeCache : IOpenIddictScopeCache
/// A that can be used to monitor the asynchronous operation.
private async ValueTask CreateEntryAsync(object key, TScope? scope, CancellationToken cancellationToken)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@@ -282,10 +264,7 @@ public sealed class OpenIddictScopeCache : IOpenIddictScopeCache
/// A that can be used to monitor the asynchronous operation.
private async ValueTask CreateEntryAsync(object key, ImmutableArray scopes, CancellationToken cancellationToken)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@@ -311,10 +290,7 @@ public sealed class OpenIddictScopeCache : IOpenIddictScopeCache
///
private async ValueTask CreateExpirationSignalAsync(TScope scope, CancellationToken cancellationToken)
{
- if (scope is null)
- {
- throw new ArgumentNullException(nameof(scope));
- }
+ ArgumentNullException.ThrowIfNull(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 91321968..71edcf8f 100644
--- a/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs
+++ b/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs
@@ -44,10 +44,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
///
public async ValueTask AddAsync(TToken token, CancellationToken cancellationToken)
{
- if (token is null)
- {
- throw new ArgumentNullException(nameof(token));
- }
+ ArgumentNullException.ThrowIfNull(token);
_cache.Remove(new
{
@@ -121,10 +118,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
///
public IAsyncEnumerable FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
return ExecuteAsync(cancellationToken);
@@ -162,10 +156,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
///
public IAsyncEnumerable FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
return ExecuteAsync(cancellationToken);
@@ -203,10 +194,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
///
public ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@@ -237,10 +225,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
///
public ValueTask FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@@ -271,10 +256,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
///
public IAsyncEnumerable FindBySubjectAsync(string subject, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(subject))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
- }
+ ArgumentException.ThrowIfNullOrEmpty(subject);
return ExecuteAsync(cancellationToken);
@@ -312,10 +294,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
///
public async ValueTask RemoveAsync(TToken token, CancellationToken cancellationToken)
{
- if (token is null)
- {
- throw new ArgumentNullException(nameof(token));
- }
+ ArgumentNullException.ThrowIfNull(token);
var identifier = await _store.GetIdAsync(token, cancellationToken);
if (string.IsNullOrEmpty(identifier))
@@ -339,10 +318,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
/// A that can be used to monitor the asynchronous operation.
private async ValueTask CreateEntryAsync(object key, TToken? token, CancellationToken cancellationToken)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@@ -365,10 +341,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
/// A that can be used to monitor the asynchronous operation.
private async ValueTask CreateEntryAsync(object key, ImmutableArray tokens, CancellationToken cancellationToken)
{
- if (key is null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@@ -394,10 +367,7 @@ public sealed class OpenIddictTokenCache : IOpenIddictTokenCache
///
private async ValueTask CreateExpirationSignalAsync(TToken token, CancellationToken cancellationToken)
{
- if (token is null)
- {
- throw new ArgumentNullException(nameof(token));
- }
+ ArgumentNullException.ThrowIfNull(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 abfcbf1b..bb529182 100644
--- a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
+++ b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
@@ -18,6 +18,7 @@ using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using ValidationException = OpenIddict.Abstractions.OpenIddictExceptions.ValidationException;
+
#if !SUPPORTS_KEY_DERIVATION_WITH_SPECIFIED_HASH_ALGORITHM
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Digests;
@@ -100,10 +101,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
public virtual ValueTask CountAsync(
Func, IQueryable> query, CancellationToken cancellationToken = default)
{
- if (query is null)
- {
- throw new ArgumentNullException(nameof(query));
- }
+ ArgumentNullException.ThrowIfNull(query);
return Store.CountAsync(query, cancellationToken);
}
@@ -132,10 +130,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
///
public virtual async ValueTask CreateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default)
{
- if (application is null)
- {
- throw new ArgumentNullException(nameof(application));
- }
+ ArgumentNullException.ThrowIfNull(application);
if (!string.IsNullOrEmpty(await Store.GetClientSecretAsync(application, cancellationToken)))
{
@@ -226,10 +221,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
public virtual async ValueTask CreateAsync(
OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default)
{
- if (descriptor is null)
- {
- throw new ArgumentNullException(nameof(descriptor));
- }
+ ArgumentNullException.ThrowIfNull(descriptor);
var application = await Store.InstantiateAsync(cancellationToken) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0208));
@@ -260,10 +252,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
///
public virtual async ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken = default)
{
- if (application is null)
- {
- throw new ArgumentNullException(nameof(application));
- }
+ ArgumentNullException.ThrowIfNull(application);
if (!Options.CurrentValue.DisableEntityCaching)
{
@@ -285,10 +274,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
public virtual async ValueTask FindByClientIdAsync(
string identifier, CancellationToken cancellationToken = default)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
var application = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByClientIdAsync(identifier, cancellationToken) :
@@ -322,10 +308,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
///
public virtual async ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken = default)
{
- if (string.IsNullOrEmpty(identifier))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
- }
+ ArgumentException.ThrowIfNullOrEmpty(identifier);
var application = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByIdAsync(identifier, cancellationToken) :
@@ -357,10 +340,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
public virtual IAsyncEnumerable FindByPostLogoutRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{
- if (string.IsNullOrEmpty(uri))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
- }
+ ArgumentException.ThrowIfNullOrEmpty(uri);
var applications = Options.CurrentValue.DisableEntityCaching ?
Store.FindByPostLogoutRedirectUriAsync(uri, cancellationToken) :
@@ -399,10 +379,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
public virtual IAsyncEnumerable FindByRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{
- if (string.IsNullOrEmpty(uri))
- {
- throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
- }
+ ArgumentException.ThrowIfNullOrEmpty(uri);
var applications = Options.CurrentValue.DisableEntityCaching ?
Store.FindByRedirectUriAsync(uri, cancellationToken) :
@@ -444,10 +421,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
public virtual async ValueTask GetApplicationTypeAsync(
TApplication application, CancellationToken cancellationToken = default)
{
- if (application is null)
- {
- throw new ArgumentNullException(nameof(application));
- }
+ ArgumentNullException.ThrowIfNull(application);
var type = await Store.GetApplicationTypeAsync(application, cancellationToken);
if (string.IsNullOrEmpty(type))
@@ -471,10 +445,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
public virtual ValueTask GetAsync(
Func, IQueryable> query, CancellationToken cancellationToken = default)
{
- if (query is null)
- {
- throw new ArgumentNullException(nameof(query));
- }
+ ArgumentNullException.ThrowIfNull(query);
return GetAsync(static (applications, query) => query(applications), query, cancellationToken);
}
@@ -495,10 +466,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
Func, TState, IQueryable> query,
TState state, CancellationToken cancellationToken = default)
{
- if (query is null)
- {
- throw new ArgumentNullException(nameof(query));
- }
+ ArgumentNullException.ThrowIfNull(query);
return Store.GetAsync(query, state, cancellationToken);
}
@@ -515,10 +483,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
public virtual ValueTask GetClientIdAsync(
TApplication application, CancellationToken cancellationToken = default)
{
- if (application is null)
- {
- throw new ArgumentNullException(nameof(application));
- }
+ ArgumentNullException.ThrowIfNull(application);
return Store.GetClientIdAsync(application, cancellationToken);
}
@@ -535,10 +500,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication
public virtual ValueTask