Browse Source

Replace PolySharp by the Polyfill source package and adopt ArgumentNullException.ThrowIfNull()/ArgumentException.ThrowIfNullOrEmpty()

pull/2408/head
Kévin Chalet 9 months ago
parent
commit
9797f86194
  1. 2
      .editorconfig
  2. 7
      Directory.Build.props
  3. 41
      Directory.Build.targets
  4. 144
      Directory.Packages.props
  5. 117
      gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs
  6. 2
      sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj
  7. 2
      sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj
  8. 47
      sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs
  9. 1
      shared/OpenIddict.Extensions/OpenIddict.Extensions.csproj
  10. 150
      shared/OpenIddict.Extensions/OpenIddictHelpers.cs
  11. 170
      shared/OpenIddict.Extensions/OpenIddictPolyfills.cs
  12. 40
      src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
  13. 16
      src/OpenIddict.Abstractions/OpenIddictExtensions.cs
  14. 21
      src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs
  15. 916
      src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs
  16. 60
      src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs
  17. 15
      src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs
  18. 1
      src/OpenIddict.AspNetCore/OpenIddict.AspNetCore.csproj
  19. 10
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs
  20. 20
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs
  21. 17
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs
  22. 2
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs
  23. 30
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs
  24. 5
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs
  25. 5
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Session.cs
  26. 110
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs
  27. 20
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs
  28. 15
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs
  29. 10
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionConfiguration.cs
  30. 16
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs
  31. 27
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs
  32. 5
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlerFilters.cs
  33. 10
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs
  34. 5
      src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs
  35. 1
      src/OpenIddict.Client.SystemIntegration/OpenIddict.Client.SystemIntegration.csproj
  36. 5
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivation.cs
  37. 25
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs
  38. 66
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs
  39. 53
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs
  40. 50
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs
  41. 36
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs
  42. 36
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs
  43. 215
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs
  44. 39
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs
  45. 5
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs
  46. 3
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs
  47. 10
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPlatformCallback.cs
  48. 21
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs
  49. 1
      src/OpenIddict.Client.SystemNetHttp/OpenIddict.Client.SystemNetHttp.csproj
  50. 97
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs
  51. 20
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs
  52. 16
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs
  53. 5
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs
  54. 10
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs
  55. 118
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs
  56. 5
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs
  57. 15
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationConfiguration.cs
  58. 16
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs
  59. 5
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Authentication.cs
  60. 5
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Device.cs
  61. 30
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs
  62. 30
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs
  63. 5
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Introspection.cs
  64. 10
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Protection.cs
  65. 25
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Revocation.cs
  66. 40
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
  67. 132
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
  68. 203
      src/OpenIddict.Client/OpenIddictClientBuilder.cs
  69. 5
      src/OpenIddict.Client/OpenIddictClientConfiguration.cs
  70. 5
      src/OpenIddict.Client/OpenIddictClientDispatcher.cs
  71. 16
      src/OpenIddict.Client/OpenIddictClientExtensions.cs
  72. 10
      src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs
  73. 210
      src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs
  74. 65
      src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs
  75. 20
      src/OpenIddict.Client/OpenIddictClientHandlers.Device.cs
  76. 170
      src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs
  77. 10
      src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs
  78. 40
      src/OpenIddict.Client/OpenIddictClientHandlers.Introspection.cs
  79. 85
      src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs
  80. 10
      src/OpenIddict.Client/OpenIddictClientHandlers.Revocation.cs
  81. 40
      src/OpenIddict.Client/OpenIddictClientHandlers.Session.cs
  82. 15
      src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs
  83. 700
      src/OpenIddict.Client/OpenIddictClientHandlers.cs
  84. 22
      src/OpenIddict.Client/OpenIddictClientHelpers.cs
  85. 5
      src/OpenIddict.Client/OpenIddictClientRetriever.cs
  86. 232
      src/OpenIddict.Client/OpenIddictClientService.cs
  87. 45
      src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs
  88. 40
      src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs
  89. 40
      src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs
  90. 50
      src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs
  91. 301
      src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
  92. 203
      src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
  93. 160
      src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs
  94. 230
      src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs
  95. 10
      src/OpenIddict.Core/OpenIddictCoreBuilder.cs
  96. 16
      src/OpenIddict.Core/OpenIddictCoreExtensions.cs
  97. 4
      src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj
  98. 5
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs
  99. 16
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs
  100. 15
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs

2
.editorconfig

@ -95,7 +95,7 @@ csharp_using_directive_placement = outside_namespace
[*.{cs,vb}] [*.{cs,vb}]
dotnet_code_quality_unused_parameters = all dotnet_code_quality_unused_parameters = all
dotnet_diagnostic.CA1510.severity = none dotnet_diagnostic.CA1510.severity = suggestion
dotnet_diagnostic.CA2254.severity = none dotnet_diagnostic.CA2254.severity = none
dotnet_diagnostic.IDE0002.severity = none dotnet_diagnostic.IDE0002.severity = none
dotnet_diagnostic.IDE0305.severity = none dotnet_diagnostic.IDE0305.severity = none

7
Directory.Build.props

@ -16,12 +16,15 @@
<DebugType>portable</DebugType> <DebugType>portable</DebugType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat> <SymbolPackageFormat>snupkg</SymbolPackageFormat>
<SuppressSymbolPackageFormatValidation>true</SuppressSymbolPackageFormatValidation> <SuppressSymbolPackageFormatValidation>true</SuppressSymbolPackageFormatValidation>
<EmbedAllSources>true</EmbedAllSources>
<EnableXlfLocalization>false</EnableXlfLocalization> <EnableXlfLocalization>false</EnableXlfLocalization>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly> <ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled> <CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
<RestoreEnablePackagePruning>false</RestoreEnablePackagePruning> <RestoreEnablePackagePruning>false</RestoreEnablePackagePruning>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio> <AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<PolyUseEmbeddedAttribute>true</PolyUseEmbeddedAttribute>
<PolyArgumentExceptions>true</PolyArgumentExceptions>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
@ -207,10 +210,6 @@
<IncludeInternalExtensions Condition=" '$(IncludeInternalExtensions)' == '' ">true</IncludeInternalExtensions> <IncludeInternalExtensions Condition=" '$(IncludeInternalExtensions)' == '' ">true</IncludeInternalExtensions>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectCapability Include="DynamicDependentFile" /> <ProjectCapability Include="DynamicDependentFile" />
<ProjectCapability Include="DynamicFileNesting" /> <ProjectCapability Include="DynamicFileNesting" />

41
Directory.Build.targets

@ -55,30 +55,24 @@
<PropertyGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' "> <PropertyGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">
<DefineConstants>$(DefineConstants);SUPPORTS_APPLICATION_CONFIGURATION_INITIALIZATION</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_APPLICATION_CONFIGURATION_INITIALIZATION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHENTICATION_HANDLER_SELECTION_FALLBACK</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_AUTHENTICATION_HANDLER_SELECTION_FALLBACK</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHENTICATION_HANDLER_TIME_PROVIDER_ARGUMENT</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHORIZATION_MIDDLEWARE</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_AUTHORIZATION_MIDDLEWARE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_BCL_ASYNC_ENUMERABLE</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_BCL_ASYNC_ENUMERABLE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_BULK_DBSET_OPERATIONS</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_BULK_DBSET_OPERATIONS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CHUNK_LINQ_EXTENSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_DBSET_VALUETASK_FINDASYNC</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_DBSET_VALUETASK_FINDASYNC</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ENDPOINT_ROUTING</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_ENDPOINT_ROUTING</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ENVIRONMENT_PROCESS_PATH</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_ENVIRONMENT_PROCESS_PATH</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HEXADECIMAL_STRING_CONVERSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_RESILIENCE</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_RESILIENCE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_INT32_RANDOM_NUMBER_GENERATOR_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_MULTIPLE_VALUES_IN_QUERYHELPERS</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_MULTIPLE_VALUES_IN_QUERYHELPERS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_HASHING_METHODS</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_HASHING_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_KEY_DERIVATION_METHODS</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_KEY_DERIVATION_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_RANDOM_NUMBER_GENERATOR_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_PEM_ENCODED_KEY_IMPORT</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_PEM_ENCODED_KEY_IMPORT</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_REDIRECTION_ON_SIGN_IN</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_REDIRECTION_ON_SIGN_IN</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TASK_WAIT_ASYNC</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TEXT_ELEMENT_ENUMERATOR</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_TEXT_ELEMENT_ENUMERATOR</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TIME_PROVIDER</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_VALUETASK_COMPLETED_TASK</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_WINFORMS_TASK_DIALOG</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_WINFORMS_TASK_DIALOG</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ZLIB_COMPRESSION</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_ZLIB_COMPRESSION</DefineConstants>
</PropertyGroup> </PropertyGroup>
@ -98,7 +92,6 @@
<DefineConstants>$(DefineConstants);SUPPORTS_EPHEMERAL_KEY_SETS</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_EPHEMERAL_KEY_SETS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_KEY_DERIVATION_WITH_SPECIFIED_HASH_ALGORITHM</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_KEY_DERIVATION_WITH_SPECIFIED_HASH_ALGORITHM</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_RSA_KEY_CREATION_WITH_SPECIFIED_SIZE</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_RSA_KEY_CREATION_WITH_SPECIFIED_SIZE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TOHASHSET_LINQ_EXTENSION</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup <PropertyGroup
@ -107,8 +100,6 @@
<DefineConstants>$(DefineConstants);SUPPORTS_BROTLI_COMPRESSION</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_BROTLI_COMPRESSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CURRENT_USER_ONLY_PIPE_OPTION</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_CURRENT_USER_ONLY_PIPE_OPTION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_SERVICE_PROVIDER_IN_HTTP_MESSAGE_HANDLER_BUILDER</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_SERVICE_PROVIDER_IN_HTTP_MESSAGE_HANDLER_BUILDER</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_STATIC_RANDOM_NUMBER_GENERATOR_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_STREAM_MEMORY_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TIME_CONSTANT_COMPARISONS</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_TIME_CONSTANT_COMPARISONS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_WEB_INTEGRATION_IN_GENERIC_HOST</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_WEB_INTEGRATION_IN_GENERIC_HOST</DefineConstants>
</PropertyGroup> </PropertyGroup>
@ -164,6 +155,19 @@
<DefineConstants>$(DefineConstants);SUPPORTS_WINDOWS_RUNTIME</DefineConstants> <DefineConstants>$(DefineConstants);SUPPORTS_WINDOWS_RUNTIME</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCore') Or
('$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '4.7'))) ">
<!--
Note: Polyfill only generates the OperatingSystem APIs if the System.Runtime.InteropServices.RuntimeInformation
package is referenced. Yet, this package isn't necessary on UWP and .NET Framework 4.7+ and is deliberately not
referenced by OpenIddict due to its problematic dependencies graph. To ensure the OperatingSystem APIs are
still correctly generated, the FeatureRuntimeInformation compilation flag is manually added here.
-->
<DefineConstants>$(DefineConstants);FeatureRuntimeInformation</DefineConstants>
</PropertyGroup>
<!-- <!--
Note: Entity Framework Core 2.x references System.Interactive.Async 3.x, that includes Note: Entity Framework Core 2.x references System.Interactive.Async 3.x, that includes
its own IAsyncEnumerable. To work around collisions between this type and the new type its own IAsyncEnumerable. To work around collisions between this type and the new type
@ -219,4 +223,21 @@
<Target Name="_CalculateXbfSupport" <Target Name="_CalculateXbfSupport"
Condition=" '$(TargetFrameworkIdentifier)' == '.NETCore' And '$(TargetPlatformIdentifier)' == 'UAP' " /> Condition=" '$(TargetFrameworkIdentifier)' == '.NETCore' And '$(TargetPlatformIdentifier)' == 'UAP' " />
<!--
Note: Polyfill internally references RequiredMemberAttribute without using "global::", which collides with
the type of the same name exposed by the iOS/Mac Catalyst/macOS reference assemblies. To work around that,
the RequiredMemberAttribute.cs file imported by Polyfill is excluded from compilation on these platforms.
-->
<Target Name="RemoveRequiredMemberAttribute" BeforeTargets="CoreCompile">
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And
('$(TargetPlatformIdentifier)' == 'iOS' Or
'$(TargetPlatformIdentifier)' == 'MacCatalyst' Or
'$(TargetPlatformIdentifier)' == 'macOS' ) ">
<Compile Remove="@(Compile)"
Condition=" %(Compile.NuGetPackageId) == 'Polyfill' And
'%(Compile.Filename)%(Compile.Extension)' == 'RequiredMemberAttribute.cs' " />
</ItemGroup>
</Target>
</Project> </Project>

144
Directory.Packages.props

@ -11,15 +11,117 @@
--> -->
<!-- <!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█████ ▀██ ██ ▄▄▄█▄▄ ▄▄████ ▄▄▄██ ▄▄▀█ ▄▄▀██ ▄▀▄ ██ ▄▄▄██ ███ ██ ▄▄▄ ██ ▄▄▀██ █▀▄████ ▄ █████▀▄▄▀████ ▄ ██████ █████ ▀██ ██ ▄▄▄█▄▄ ▄▄████ ▄▄▄██ ▄▄▀█ ▄▄▀██ ▄▀▄ ██ ▄▄▄██ ███ ██ ▄▄▄ ██ ▄▄▀██ █▀▄████ ▄ █████▀▄▄▀████ ▄ ██
█▀▀██ █ █ ██ ▄▄▄███ ██████ ▄▄███ ▀▀▄█ ▀▀ ██ █ █ ██ ▄▄▄██ █ █ ██ ███ ██ ▀▀▄██ ▄▀████ ▀▀ ▀█▀▀█ ▀▀██▀▀██▀▄█▀ ▀██ █▀▀██ █ █ ██ ▄▄▄███ ██████ ▄▄███ ▀▀▄█ ▀▀ ██ █ █ ██ ▄▄▄██ █ █ ██ ███ ██ ▀▀▄██ ▄▀████ ▀▀ ▀█▀▀█ ▀▀██▀▀██▀▄██
█▄▄██ ██▄ ██ ▀▀▀███ ██████ █████ ██ █ ██ ██ ███ ██ ▀▀▀██▄▀▄▀▄██ ▀▀▀ ██ ██ ██ ██ ██████ ██▄▄█▄▀▀▄█▄▄█ ▀▀██▄███ █▄▄██ ██▄ ██ ▀▀▀███ ██████ █████ ██ █ ██ ██ ███ ██ ▀▀▀██▄▀▄▀▄██ ▀▀▀ ██ ██ ██ ██ ██████ ██▄▄█▄▀▀▄█▄▄█ ▀▀██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
--> -->
<ItemGroup Label="Package versions for .NET Framework 4.6.2 and higher" <ItemGroup Label="Package versions for .NET Framework 4.6.2"
Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '4.6.2')) "> Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.6.2')) ">
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.6.2" />
<PackageVersion Include="EntityFramework" Version="6.5.1" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.DataProtection" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="2.3.0" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="2.3.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.21" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Primitives" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.WebEncoders" Version="8.0.21" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.14.0" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols" Version="8.14.0" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
<PackageVersion Include="Microsoft.Net.Http.Headers" Version="2.3.4" />
<PackageVersion Include="Microsoft.Owin.Security" Version="4.2.3" />
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.17763.1000" />
<PackageVersion Include="MongoDB.Bson" Version="3.5.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.5.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.15.1" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Interactive.Async" Version="3.2.0" />
<PackageVersion Include="System.Net.Http.Json" Version="8.0.1" />
<!--
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█████ ▀██ ██ ▄▄▄█▄▄ ▄▄████ ▄▄▄██ ▄▄▀█ ▄▄▀██ ▄▀▄ ██ ▄▄▄██ ███ ██ ▄▄▄ ██ ▄▄▀██ █▀▄████ ▄ █████▄▄▄ ████ ▄ ██
█▀▀██ █ █ ██ ▄▄▄███ ██████ ▄▄███ ▀▀▄█ ▀▀ ██ █ █ ██ ▄▄▄██ █ █ ██ ███ ██ ▀▀▄██ ▄▀████ ▀▀ ▀█▀▀███ ██▀▀██▀▄██
█▄▄██ ██▄ ██ ▀▀▀███ ██████ █████ ██ █ ██ ██ ███ ██ ▀▀▀██▄▀▄▀▄██ ▀▀▀ ██ ██ ██ ██ ██████ ██▄▄██▌▐██▄▄█ ▀▀██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<ItemGroup Label="Package versions for .NET Framework 4.7.2"
Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.7.2')) ">
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.6.2" />
<PackageVersion Include="EntityFramework" Version="6.5.1" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.DataProtection" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="2.3.0" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="2.3.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.21" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Primitives" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.WebEncoders" Version="8.0.21" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.14.0" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols" Version="8.14.0" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
<PackageVersion Include="Microsoft.Net.Http.Headers" Version="2.3.4" />
<PackageVersion Include="Microsoft.Owin.Security" Version="4.2.3" />
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.17763.1000" />
<PackageVersion Include="MongoDB.Bson" Version="3.5.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.5.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.15.1" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Interactive.Async" Version="3.2.0" />
<PackageVersion Include="System.Net.Http.Json" Version="8.0.1" />
<!--
Note: the following references are exclusively used in the test projects:
-->
<PackageVersion Include="AngleSharp" Version="1.3.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.6.0" />
<PackageVersion Include="Microsoft.AspNetCore.Server.Kestrel.Core" Version="2.3.6" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="2.3.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Microsoft.Owin.Testing" Version="4.2.3" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="System.Linq.Async" Version="6.0.3" />
<!--
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█████ ▀██ ██ ▄▄▄█▄▄ ▄▄████ ▄▄▄██ ▄▄▀█ ▄▄▀██ ▄▀▄ ██ ▄▄▄██ ███ ██ ▄▄▄ ██ ▄▄▀██ █▀▄████ ▄ █████▀▄▄▀██
█▀▀██ █ █ ██ ▄▄▄███ ██████ ▄▄███ ▀▀▄█ ▀▀ ██ █ █ ██ ▄▄▄██ █ █ ██ ███ ██ ▀▀▄██ ▄▀████ ▀▀ ▀█▀▀█▀▄▄▀██
█▄▄██ ██▄ ██ ▀▀▀███ ██████ █████ ██ █ ██ ██ ███ ██ ▀▀▀██▄▀▄▀▄██ ▀▀▀ ██ ██ ██ ██ ██████ ██▄▄█▄▀▀▄██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<ItemGroup Label="Package versions for .NET Framework 4.8"
Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.8.0')) ">
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.6.2" /> <PackageVersion Include="BouncyCastle.Cryptography" Version="2.6.2" />
<PackageVersion Include="EntityFramework" Version="6.5.1" /> <PackageVersion Include="EntityFramework" Version="6.5.1" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication" Version="2.3.0" /> <PackageVersion Include="Microsoft.AspNetCore.Authentication" Version="2.3.0" />
@ -96,10 +198,10 @@
<PackageVersion Include="WebGrease" Version="1.6.0" /> <PackageVersion Include="WebGrease" Version="1.6.0" />
<!-- <!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard). some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
--> -->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" /> <GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup> </ItemGroup>
<!-- <!--
@ -143,10 +245,10 @@
<PackageVersion Include="System.Linq.Async" Version="6.0.3" /> <PackageVersion Include="System.Linq.Async" Version="6.0.3" />
<!-- <!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard). some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
--> -->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" /> <GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup> </ItemGroup>
<!-- <!--
@ -189,10 +291,10 @@
<PackageVersion Include="System.Linq.Async" Version="6.0.3" /> <PackageVersion Include="System.Linq.Async" Version="6.0.3" />
<!-- <!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard). some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
--> -->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" /> <GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup> </ItemGroup>
<!-- <!--
@ -248,10 +350,10 @@
<PackageVersion Include="Spectre.Console" Version="0.53.0" /> <PackageVersion Include="Spectre.Console" Version="0.53.0" />
<!-- <!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard). some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
--> -->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" /> <GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup> </ItemGroup>
<!-- <!--
@ -299,10 +401,10 @@
<PackageVersion Include="System.Interactive" Version="6.0.3" /> <PackageVersion Include="System.Interactive" Version="6.0.3" />
<!-- <!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard). some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
--> -->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" /> <GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup> </ItemGroup>
<!-- <!--
@ -340,10 +442,10 @@
<PackageVersion Include="System.Net.Http.Json" Version="8.0.1" /> <PackageVersion Include="System.Net.Http.Json" Version="8.0.1" />
<!-- <!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard). some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
--> -->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" /> <GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup> </ItemGroup>
<!-- <!--
@ -362,10 +464,10 @@
<PackageVersion Include="NamedPipeServerStream.NetFrameworkVersion" Version="1.1.7" /> <PackageVersion Include="NamedPipeServerStream.NetFrameworkVersion" Version="1.1.7" />
<!-- <!--
Note: OpenIddict uses PolySharp to dynamically generate pstring?[]olyfills for types that are not available on Note: OpenIddict uses Polyfill to dynamically generate pstring?[]olyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard). some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
--> -->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" /> <GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

117
gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs

@ -241,10 +241,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetClaimsIssuer(string issuer) public {{ provider.name }} SetClaimsIssuer(string issuer)
{ {
if (string.IsNullOrEmpty(issuer)) ArgumentException.ThrowIfNullOrEmpty(issuer);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(issuer));
}
return Set(registration => registration.ClaimsIssuer = issuer); return Set(registration => registration.ClaimsIssuer = issuer);
} }
@ -256,10 +253,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetProviderName(string name) public {{ provider.name }} SetProviderName(string name)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(name));
}
return Set(registration => registration.ProviderName = name); return Set(registration => registration.ProviderName = name);
} }
@ -271,10 +265,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetProviderDisplayName(string name) public {{ provider.name }} SetProviderDisplayName(string name)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(name));
}
return Set(registration => registration.ProviderDisplayName = name); return Set(registration => registration.ProviderDisplayName = name);
} }
@ -286,10 +277,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetRegistrationId(string identifier) public {{ provider.name }} SetRegistrationId(string identifier)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(identifier));
}
return Set(registration => registration.RegistrationId = identifier); return Set(registration => registration.RegistrationId = identifier);
} }
@ -301,10 +289,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetClientId(string identifier) public {{ provider.name }} SetClientId(string identifier)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(identifier));
}
return Set(registration => registration.ClientId = identifier); return Set(registration => registration.ClientId = identifier);
} }
@ -316,10 +301,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetClientSecret(string secret) public {{ provider.name }} SetClientSecret(string secret)
{ {
if (string.IsNullOrEmpty(secret)) ArgumentException.ThrowIfNullOrEmpty(secret);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0125), nameof(secret));
}
return Set(registration => registration.ClientSecret = secret); return Set(registration => registration.ClientSecret = secret);
} }
@ -335,10 +317,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetPostLogoutRedirectUri(Uri uri) public {{ provider.name }} SetPostLogoutRedirectUri(Uri uri)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{
throw new ArgumentNullException(nameof(uri));
}
return Set(registration => registration.PostLogoutRedirectUri = uri); return Set(registration => registration.PostLogoutRedirectUri = uri);
} }
@ -354,10 +333,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetPostLogoutRedirectUri([StringSyntax(StringSyntaxAttribute.Uri)] string uri) public {{ provider.name }} SetPostLogoutRedirectUri([StringSyntax(StringSyntaxAttribute.Uri)] string uri)
{ {
if (string.IsNullOrEmpty(uri)) ArgumentException.ThrowIfNullOrEmpty(uri);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
return SetPostLogoutRedirectUri(new Uri(uri, UriKind.RelativeOrAbsolute)); return SetPostLogoutRedirectUri(new Uri(uri, UriKind.RelativeOrAbsolute));
} }
@ -373,10 +349,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetRedirectUri(Uri uri) public {{ provider.name }} SetRedirectUri(Uri uri)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{
throw new ArgumentNullException(nameof(uri));
}
return Set(registration => registration.RedirectUri = uri); return Set(registration => registration.RedirectUri = uri);
} }
@ -392,10 +365,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetRedirectUri([StringSyntax(StringSyntaxAttribute.Uri)] string uri) public {{ provider.name }} SetRedirectUri([StringSyntax(StringSyntaxAttribute.Uri)] string uri)
{ {
if (string.IsNullOrEmpty(uri)) ArgumentException.ThrowIfNullOrEmpty(uri);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
return SetRedirectUri(new Uri(uri, UriKind.RelativeOrAbsolute)); return SetRedirectUri(new Uri(uri, UriKind.RelativeOrAbsolute));
} }
@ -421,10 +391,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}} {{~ end ~}}
public {{ provider.name }} Add{{ setting.property_name }}(params {{ setting.clr_type }}[] {{ setting.parameter_name }}) public {{ provider.name }} Add{{ setting.property_name }}(params {{ setting.clr_type }}[] {{ setting.parameter_name }})
{ {
if ({{ setting.parameter_name }} is null) ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
return Set(registration => registration.Get{{ provider.name }}Settings().{{ setting.property_name }}.UnionWith({{ 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 ~}} {{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(ECDsaSecurityKey {{ setting.parameter_name }}) public {{ provider.name }} Set{{ setting.property_name }}(ECDsaSecurityKey {{ setting.parameter_name }})
{ {
if ({{ setting.parameter_name }} is null) ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
if ({{ setting.parameter_name }}.PrivateKeyStatus is PrivateKeyStatus.DoesNotExist) if ({{ setting.parameter_name }}.PrivateKeyStatus is PrivateKeyStatus.DoesNotExist)
{ {
@ -524,10 +488,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}} {{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(Uri {{ setting.parameter_name }}) public {{ provider.name }} Set{{ setting.property_name }}(Uri {{ setting.parameter_name }})
{ {
if ({{ setting.parameter_name }} is null) ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
if (!{{ setting.parameter_name }}.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri({{ setting.parameter_name }})) if (!{{ setting.parameter_name }}.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri({{ setting.parameter_name }}))
{ {
@ -547,10 +508,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}} {{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(string {{ setting.parameter_name }}) public {{ provider.name }} Set{{ setting.property_name }}(string {{ setting.parameter_name }})
{ {
if (string.IsNullOrEmpty({{ setting.parameter_name }})) ArgumentException.ThrowIfNullOrEmpty({{ setting.parameter_name }});
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof({{ setting.parameter_name }}));
}
return Set{{ setting.property_name }}(new Uri({{ setting.parameter_name }}, UriKind.RelativeOrAbsolute)); return Set{{ setting.property_name }}(new Uri({{ setting.parameter_name }}, UriKind.RelativeOrAbsolute));
} }
@ -565,10 +523,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}} {{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(X509Certificate2 {{ setting.parameter_name }}) public {{ provider.name }} Set{{ setting.property_name }}(X509Certificate2 {{ setting.parameter_name }})
{ {
if ({{ setting.parameter_name }} is null) ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
if (!{{ setting.parameter_name }}.HasPrivateKey) 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) public {{ provider.name }} Set{{ setting.property_name }}(Assembly assembly, string resource, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS #if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS. // 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.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet); X509KeyStorageFlags.EphemeralKeySet);
#else #else
@ -613,15 +568,8 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
Assembly assembly, string resource, Assembly assembly, string resource,
string? password, X509KeyStorageFlags flags) string? password, X509KeyStorageFlags flags)
{ {
if (assembly is null) ArgumentNullException.ThrowIfNull(assembly);
{ ArgumentException.ThrowIfNullOrEmpty(resource);
throw new ArgumentNullException(nameof(assembly));
}
if (string.IsNullOrEmpty(resource))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
using var stream = assembly.GetManifestResourceStream(resource) ?? using var stream = assembly.GetManifestResourceStream(resource) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0064)); 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) public {{ provider.name }} Set{{ setting.property_name }}(Stream stream, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS #if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS. // 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.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet); X509KeyStorageFlags.EphemeralKeySet);
#else #else
@ -660,10 +608,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}} {{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(Stream stream, string? password, X509KeyStorageFlags flags) public {{ provider.name }} Set{{ setting.property_name }}(Stream stream, string? password, X509KeyStorageFlags flags)
{ {
if (stream is null) ArgumentNullException.ThrowIfNull(stream);
{
throw new ArgumentNullException(nameof(stream));
}
using var buffer = new MemoryStream(); using var buffer = new MemoryStream();
stream.CopyTo(buffer); stream.CopyTo(buffer);
@ -691,10 +636,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}} {{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(string thumbprint) public {{ provider.name }} Set{{ setting.property_name }}(string thumbprint)
{ {
if (string.IsNullOrEmpty(thumbprint)) ArgumentException.ThrowIfNullOrEmpty(thumbprint);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
return Set{{ setting.property_name }}( return Set{{ setting.property_name }}(
GetCertificate(StoreLocation.CurrentUser, thumbprint) ?? GetCertificate(StoreLocation.CurrentUser, thumbprint) ??
@ -724,10 +666,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}} {{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(string thumbprint, StoreName name, StoreLocation location) public {{ provider.name }} Set{{ setting.property_name }}(string thumbprint, StoreName name, StoreLocation location)
{ {
if (string.IsNullOrEmpty(thumbprint)) ArgumentException.ThrowIfNullOrEmpty(thumbprint);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
using var store = new X509Store(name, location); using var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly); store.Open(OpenFlags.ReadOnly);
@ -759,10 +698,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}} {{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}({{ setting.clr_type }} {{ setting.parameter_name }}) public {{ provider.name }} Set{{ setting.property_name }}({{ setting.clr_type }} {{ setting.parameter_name }})
{ {
if ({{ setting.parameter_name }} is null) ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
return Set(registration => registration.Get{{ provider.name }}Settings().{{ setting.property_name }} = {{ 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
/// <returns>The <see cref=""OpenIddictClientRegistration""/> instance.</returns> /// <returns>The <see cref=""OpenIddictClientRegistration""/> instance.</returns>
private {{ provider.name }} Set(Action<OpenIddictClientRegistration> configuration) private {{ provider.name }} Set(Action<OpenIddictClientRegistration> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(Registration); configuration(Registration);
@ -973,6 +906,8 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration
{ {
public static partial void ConfigureProvider(OpenIddictClientRegistration registration) public static partial void ConfigureProvider(OpenIddictClientRegistration registration)
{ {
ArgumentNullException.ThrowIfNull(registration);
{{~ for provider in providers ~}} {{~ for provider in providers ~}}
{{~ if for.index == 0 ~}} {{~ if for.index == 0 ~}}
if (registration.ProviderType is ProviderTypes.{{ provider.name }}) if (registration.ProviderType is ProviderTypes.{{ provider.name }})

2
sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj

@ -7,7 +7,7 @@
<MvcBuildViews>false</MvcBuildViews> <MvcBuildViews>false</MvcBuildViews>
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<NoWarn>CA3147</NoWarn> <NoWarn>CA3147</NoWarn>
<DisablePolySharp>true</DisablePolySharp> <IncludePolyfills>false</IncludePolyfills>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

2
sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj

@ -7,7 +7,7 @@
<MvcBuildViews>false</MvcBuildViews> <MvcBuildViews>false</MvcBuildViews>
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<NoWarn>CA3147</NoWarn> <NoWarn>CA3147</NoWarn>
<DisablePolySharp>true</DisablePolySharp> <IncludePolyfills>false</IncludePolyfills>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

47
sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs

@ -436,7 +436,7 @@ public class InteractiveService : BackgroundService
select registration) select registration)
.UseConverter(registration => registration.ProviderDisplayName!)).ProviderName!; .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( Task<(string? GrantType, string? ResponseType)> GetSelectedFlowAsync(
@ -557,7 +557,7 @@ public class InteractiveService : BackgroundService
.UseConverter(choice => choice.DisplayName)).Item1; .UseConverter(choice => choice.DisplayName)).Item1;
} }
return WaitAsync(Task.Run(() => Prompt(registration, configuration), cancellationToken), cancellationToken); return Task.Run(() => Prompt(registration, configuration), cancellationToken).WaitAsync(cancellationToken);
} }
Task<string> GetSelectedGrantTypeAsync( Task<string> GetSelectedGrantTypeAsync(
@ -608,7 +608,7 @@ public class InteractiveService : BackgroundService
.UseConverter(choice => choice.DisplayName)).GrantType; .UseConverter(choice => choice.DisplayName)).GrantType;
} }
return WaitAsync(Task.Run(() => Prompt(registration, configuration), cancellationToken), cancellationToken); return Task.Run(() => Prompt(registration, configuration), cancellationToken).WaitAsync(cancellationToken);
} }
Task<bool> AuthenticateUserInteractivelyAsync( Task<bool> AuthenticateUserInteractivelyAsync(
@ -632,7 +632,7 @@ public class InteractiveService : BackgroundService
registration.GrantTypes.Any(static type => type is not ( registration.GrantTypes.Any(static type => type is not (
GrantTypes.AuthorizationCode or GrantTypes.Implicit or GrantTypes.RefreshToken)))) 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); return Task.FromResult(true);
@ -647,7 +647,7 @@ public class InteractiveService : BackgroundService
registration.GrantTypes.Any(static type => type is not ( registration.GrantTypes.Any(static type => type is not (
GrantTypes.AuthorizationCode or GrantTypes.Implicit or GrantTypes.RefreshToken)))) 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); return Task.FromResult(true);
@ -664,7 +664,7 @@ public class InteractiveService : BackgroundService
IsSecret = false IsSecret = false
}); });
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken); return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
} }
Task<string> GetPasswordAsync(CancellationToken cancellationToken) Task<string> GetPasswordAsync(CancellationToken cancellationToken)
@ -675,7 +675,7 @@ public class InteractiveService : BackgroundService
IsSecret = true IsSecret = true
}); });
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken); return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
} }
static Task<bool> RefreshTokenAsync(CancellationToken cancellationToken) static Task<bool> RefreshTokenAsync(CancellationToken cancellationToken)
@ -688,7 +688,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true ShowDefaultValue = true
}); });
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken); return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
} }
Task<string?> GetRequestedTokenTypeAsync(CancellationToken cancellationToken) Task<string?> GetRequestedTokenTypeAsync(CancellationToken cancellationToken)
@ -704,7 +704,7 @@ public class InteractiveService : BackgroundService
]) ])
.UseConverter(choice => choice.DisplayName)).TokenType; .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) Task<(string TokenType, string Token)> GetSubjectTokenAsync(CancellationToken cancellationToken)
@ -730,7 +730,7 @@ public class InteractiveService : BackgroundService
return (type, token); 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) 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<bool> IntrospectAccessTokenAsync(CancellationToken cancellationToken) static Task<bool> IntrospectAccessTokenAsync(CancellationToken cancellationToken)
@ -773,7 +773,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true ShowDefaultValue = true
}); });
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken); return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
} }
static Task<bool> LogOutAsync(CancellationToken cancellationToken) static Task<bool> LogOutAsync(CancellationToken cancellationToken)
@ -785,7 +785,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true ShowDefaultValue = true
}); });
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken); return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
} }
static Task<bool> RevokeAccessTokenAsync(CancellationToken cancellationToken) static Task<bool> RevokeAccessTokenAsync(CancellationToken cancellationToken)
@ -798,26 +798,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true ShowDefaultValue = true
}); });
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken); return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
static async Task<T> WaitAsync<T>(Task<T> task, CancellationToken cancellationToken)
{
#if SUPPORTS_TASK_WAIT_ASYNC
return await task.WaitAsync(cancellationToken);
#else
var source = new TaskCompletionSource<bool>(TaskCreationOptions.None);
using (cancellationToken.Register(static state => ((TaskCompletionSource<bool>) state!).SetResult(true), source))
{
if (await Task.WhenAny(task, source.Task) == source.Task)
{
throw new OperationCanceledException(cancellationToken);
}
return await task;
}
#endif
} }
} }
} }

1
shared/OpenIddict.Extensions/OpenIddict.Extensions.csproj

@ -3,6 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<DefineConstants>$(DefineConstants);FeatureValueTuple</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

150
shared/OpenIddict.Extensions/OpenIddictHelpers.cs

@ -35,10 +35,7 @@ internal static class OpenIddictHelpers
/// </returns> /// </returns>
public static bool IncludesAnyFromSet<T>(IReadOnlyList<T> array, ISet<T> set) public static bool IncludesAnyFromSet<T>(IReadOnlyList<T> array, ISet<T> set)
{ {
if (set is null) ArgumentNullException.ThrowIfNull(set);
{
throw new ArgumentNullException(nameof(set));
}
for (var index = 0; index < array.Count; index++) for (var index = 0; index < array.Count; index++)
{ {
@ -150,15 +147,8 @@ internal static class OpenIddictHelpers
/// <exception cref="InvalidOperationException"><paramref name="left"/> is not an absolute URI.</exception> /// <exception cref="InvalidOperationException"><paramref name="left"/> is not an absolute URI.</exception>
public static bool IsBaseOf(Uri left, Uri right) public static bool IsBaseOf(Uri left, Uri right)
{ {
if (left is null) ArgumentNullException.ThrowIfNull(left);
{ ArgumentNullException.ThrowIfNull(right);
throw new ArgumentNullException(nameof(left));
}
if (right is null)
{
throw new ArgumentNullException(nameof(right));
}
if (left is not { IsAbsoluteUri: true }) if (left is not { IsAbsoluteUri: true })
{ {
@ -188,10 +178,7 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
public static bool IsImplicitFileUri(Uri uri) public static bool IsImplicitFileUri(Uri uri)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{
throw new ArgumentNullException(nameof(uri));
}
return uri.IsAbsoluteUri && uri.IsFile && return uri.IsAbsoluteUri && uri.IsFile &&
!uri.OriginalString.StartsWith(uri.Scheme, StringComparison.OrdinalIgnoreCase); !uri.OriginalString.StartsWith(uri.Scheme, StringComparison.OrdinalIgnoreCase);
@ -206,10 +193,7 @@ internal static class OpenIddictHelpers
/// <returns>The final <see cref="Uri"/> instance, with the specified parameter appended.</returns> /// <returns>The final <see cref="Uri"/> instance, with the specified parameter appended.</returns>
public static Uri AddQueryStringParameter(Uri uri, string name, string? value) public static Uri AddQueryStringParameter(Uri uri, string name, string? value)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{
throw new ArgumentNullException(nameof(uri));
}
var builder = new StringBuilder(uri.Query); var builder = new StringBuilder(uri.Query);
if (builder.Length > 0) if (builder.Length > 0)
@ -238,15 +222,8 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="parameters"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="parameters"/> is <see langword="null"/>.</exception>
public static Uri AddQueryStringParameters(Uri uri, IReadOnlyDictionary<string, StringValues> parameters) public static Uri AddQueryStringParameters(Uri uri, IReadOnlyDictionary<string, StringValues> parameters)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{ ArgumentNullException.ThrowIfNull(parameters);
throw new ArgumentNullException(nameof(uri));
}
if (parameters is null)
{
throw new ArgumentNullException(nameof(parameters));
}
if (parameters.Count is 0) if (parameters.Count is 0)
{ {
@ -302,10 +279,7 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="query"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="query"/> is <see langword="null"/>.</exception>
public static IReadOnlyDictionary<string, StringValues> ParseQuery(string query) public static IReadOnlyDictionary<string, StringValues> ParseQuery(string query)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return query.TrimStart(Separators.QuestionMark[0]) return query.TrimStart(Separators.QuestionMark[0])
.Split([Separators.Ampersand[0], Separators.Semicolon[0]], StringSplitOptions.RemoveEmptyEntries) .Split([Separators.Ampersand[0], Separators.Semicolon[0]], StringSplitOptions.RemoveEmptyEntries)
@ -326,10 +300,7 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="fragment"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="fragment"/> is <see langword="null"/>.</exception>
public static IReadOnlyDictionary<string, StringValues> ParseFragment(string fragment) public static IReadOnlyDictionary<string, StringValues> ParseFragment(string fragment)
{ {
if (fragment is null) ArgumentNullException.ThrowIfNull(fragment);
{
throw new ArgumentNullException(nameof(fragment));
}
return fragment.TrimStart(Separators.Hash[0]) return fragment.TrimStart(Separators.Hash[0])
.Split([Separators.Ampersand[0], Separators.Semicolon[0]], StringSplitOptions.RemoveEmptyEntries) .Split([Separators.Ampersand[0], Separators.Semicolon[0]], StringSplitOptions.RemoveEmptyEntries)
@ -353,15 +324,8 @@ internal static class OpenIddictHelpers
public static async ValueTask<IReadOnlyDictionary<string, StringValues>> ParseFormAsync( public static async ValueTask<IReadOnlyDictionary<string, StringValues>> ParseFormAsync(
Stream stream, Encoding encoding, CancellationToken cancellationToken) Stream stream, Encoding encoding, CancellationToken cancellationToken)
{ {
if (stream is null) ArgumentNullException.ThrowIfNull(stream);
{ ArgumentNullException.ThrowIfNull(encoding);
throw new ArgumentNullException(nameof(stream));
}
if (encoding is null)
{
throw new ArgumentNullException(nameof(encoding));
}
var reader = new FormReader(stream, encoding); var reader = new FormReader(stream, encoding);
return await reader.ReadFormAsync(cancellationToken); return await reader.ReadFormAsync(cancellationToken);
@ -692,7 +656,7 @@ internal static class OpenIddictHelpers
/// </exception> /// </exception>
public static byte[] CreateRandomArray(int size) public static byte[] CreateRandomArray(int size)
{ {
var algorithm = GetAlgorithmFromConfig() switch using var algorithm = GetAlgorithmFromConfig() switch
{ {
RandomNumberGenerator result => result, RandomNumberGenerator result => result,
null => null, null => null,
@ -701,32 +665,13 @@ internal static class OpenIddictHelpers
// If no custom random number generator was registered, use either the static GetBytes() or // 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. // 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) if (algorithm is null)
{ {
return RandomNumberGenerator.GetBytes(size / 8); 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 var array = new byte[size / 8];
{ algorithm.GetBytes(array);
algorithm.Dispose();
}
return array; return array;
@ -747,40 +692,30 @@ internal static class OpenIddictHelpers
/// </exception> /// </exception>
public static string CreateRandomString(ReadOnlySpan<string> charset, int count) public static string CreateRandomString(ReadOnlySpan<string> charset, int count)
{ {
var algorithm = GetAlgorithmFromConfig() switch using var algorithm = GetAlgorithmFromConfig() switch
{ {
RandomNumberGenerator result => result, RandomNumberGenerator result => result,
null => null, null => null,
var result => throw new CryptographicException(SR.FormatID0351(result.GetType().FullName)) 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. // If no custom random number generator was registered, use the static GetInt32() API.
builder.Append(charset[index: algorithm switch null => RandomNumberGenerator.GetInt32(0, charset.Length),
{
#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)
}]);
}
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 return builder.ToString();
{
algorithm?.Dispose();
}
static int GetInt32(RandomNumberGenerator algorithm, Range range) static int GetInt32(RandomNumberGenerator algorithm, Range range)
{ {
@ -867,32 +802,6 @@ internal static class OpenIddictHelpers
#endif #endif
} }
/// <summary>
/// Converts the specified hex-encoded <paramref name="value"/> to a byte array.
/// </summary>
/// <param name="value">The hexadecimal string.</param>
/// <returns>The byte array.</returns>
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
}
/// <summary> /// <summary>
/// Removes the characters that are not part of <paramref name="charset"/> /// Removes the characters that are not part of <paramref name="charset"/>
/// from the specified <paramref name="value"/> string. /// from the specified <paramref name="value"/> string.
@ -906,10 +815,7 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="charset"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="charset"/> is <see langword="null"/>.</exception>
public static string? RemoveDisallowedCharacters(string? value, IReadOnlyCollection<string> charset) public static string? RemoveDisallowedCharacters(string? value, IReadOnlyCollection<string> charset)
{ {
if (charset is null) ArgumentNullException.ThrowIfNull(charset);
{
throw new ArgumentNullException(nameof(charset));
}
if (charset.Count is 0 || string.IsNullOrEmpty(value)) if (charset.Count is 0 || string.IsNullOrEmpty(value))
{ {

170
shared/OpenIddict.Extensions/OpenIddictPolyfills.cs

@ -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;
/// <summary>
/// Exposes common polyfills used by the OpenIddict assemblies.
/// </summary>
internal static class OpenIddictPolyfills
{
extension<TSource>(IEnumerable<TSource> source)
{
#if !SUPPORTS_CHUNK_LINQ_EXTENSION
/// <summary>
/// Split the elements of a sequence into chunks of size at most <paramref name="size"/>.
/// </summary>
/// <remarks>
/// Every chunk except the last will be of size <paramref name="size"/>.
/// The last chunk will contain the remaining elements and may be of a smaller size.
/// </remarks>
/// <param name="size">Maximum size of each chunk.</param>
/// <returns>
/// An <see cref="IEnumerable{T}"/> that contains the elements of the input
/// sequence split into chunks of size <paramref name="size"/>.
/// </returns>
public IEnumerable<TSource[]> 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<TSource> 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
/// <summary>
/// Creates a new <see cref="HashSet{T}"/> instance and imports the elements present in the specified source.
/// </summary>
/// <param name="comparer">The comparer to use.</param>
/// <returns>A new <see cref="HashSet{T}"/> instance and imports the elements present in the specified source.</returns>
public HashSet<TSource> ToHashSet(IEqualityComparer<TSource>? comparer) => new(source, comparer);
#endif
}
extension(Task task)
{
#if !SUPPORTS_TASK_WAIT_ASYNC
/// <summary>
/// Waits until the specified task returns a result or the cancellation token is signaled.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
/// <exception cref="OperationCanceledException">The specified <paramref name="cancellationToken"/> is signaled.</exception>
public async Task WaitAsync(CancellationToken cancellationToken)
{
var source = new TaskCompletionSource<bool>(TaskCreationOptions.None);
using (cancellationToken.Register(static state => ((TaskCompletionSource<bool>) state!).SetResult(true), source))
{
if (await Task.WhenAny(task, source.Task) == source.Task)
{
throw new OperationCanceledException(cancellationToken);
}
await task;
}
}
#endif
}
extension<TResult>(Task<TResult> task)
{
#if !SUPPORTS_TASK_WAIT_ASYNC
/// <summary>
/// Waits until the specified task returns a result or the cancellation token is signaled.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
/// <exception cref="OperationCanceledException">The specified <paramref name="cancellationToken"/> is signaled.</exception>
public async Task<TResult> WaitAsync(CancellationToken cancellationToken)
{
var source = new TaskCompletionSource<bool>(TaskCreationOptions.None);
using (cancellationToken.Register(static state => ((TaskCompletionSource<bool>) 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
/// <summary>
/// Gets a task that has already completed successfully.
/// </summary>
public static ValueTask CompletedTask => default;
#endif
}
extension<TResult>(ValueTask<TResult>)
{
#if !SUPPORTS_VALUETASK_COMPLETED_TASK
/// <summary>
/// Gets a task that has already completed successfully.
/// </summary>
public static ValueTask<TResult> CompletedTask => default;
#endif
}
}

40
src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs

@ -89,10 +89,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="audiences"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="audiences"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor AddAudiencePermissions(params string[] audiences) public OpenIddictApplicationDescriptor AddAudiencePermissions(params string[] audiences)
{ {
if (audiences is null) ArgumentNullException.ThrowIfNull(audiences);
{
throw new ArgumentNullException(nameof(audiences));
}
foreach (var audience in audiences) foreach (var audience in audiences)
{ {
@ -110,10 +107,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="types"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="types"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor AddGrantTypePermissions(params string[] types) public OpenIddictApplicationDescriptor AddGrantTypePermissions(params string[] types)
{ {
if (types is null) ArgumentNullException.ThrowIfNull(types);
{
throw new ArgumentNullException(nameof(types));
}
foreach (var type in types) foreach (var type in types)
{ {
@ -131,10 +125,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="resources"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="resources"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor AddResourcePermissions(params string[] resources) public OpenIddictApplicationDescriptor AddResourcePermissions(params string[] resources)
{ {
if (resources is null) ArgumentNullException.ThrowIfNull(resources);
{
throw new ArgumentNullException(nameof(resources));
}
foreach (var resource in resources) foreach (var resource in resources)
{ {
@ -152,10 +143,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="scopes"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="scopes"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor AddScopePermissions(params string[] scopes) public OpenIddictApplicationDescriptor AddScopePermissions(params string[] scopes)
{ {
if (scopes is null) ArgumentNullException.ThrowIfNull(scopes);
{
throw new ArgumentNullException(nameof(scopes));
}
foreach (var scope in scopes) foreach (var scope in scopes)
{ {
@ -341,10 +329,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="audiences"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="audiences"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor RemoveAudiencePermissions(params string[] audiences) public OpenIddictApplicationDescriptor RemoveAudiencePermissions(params string[] audiences)
{ {
if (audiences is null) ArgumentNullException.ThrowIfNull(audiences);
{
throw new ArgumentNullException(nameof(audiences));
}
foreach (var audience in audiences) foreach (var audience in audiences)
{ {
@ -362,10 +347,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="types"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="types"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor RemoveGrantTypePermissions(params string[] types) public OpenIddictApplicationDescriptor RemoveGrantTypePermissions(params string[] types)
{ {
if (types is null) ArgumentNullException.ThrowIfNull(types);
{
throw new ArgumentNullException(nameof(types));
}
foreach (var type in types) foreach (var type in types)
{ {
@ -383,10 +365,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="resources"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="resources"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor RemoveResourcePermissions(params string[] resources) public OpenIddictApplicationDescriptor RemoveResourcePermissions(params string[] resources)
{ {
if (resources is null) ArgumentNullException.ThrowIfNull(resources);
{
throw new ArgumentNullException(nameof(resources));
}
foreach (var resource in resources) foreach (var resource in resources)
{ {
@ -404,10 +383,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="scopes"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="scopes"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor RemoveScopePermissions(params string[] scopes) public OpenIddictApplicationDescriptor RemoveScopePermissions(params string[] scopes)
{ {
if (scopes is null) ArgumentNullException.ThrowIfNull(scopes);
{
throw new ArgumentNullException(nameof(scopes));
}
foreach (var scope in scopes) foreach (var scope in scopes)
{ {

16
src/OpenIddict.Abstractions/OpenIddictExtensions.cs

@ -19,10 +19,7 @@ public static class OpenIddictExtensions
/// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns>
public static OpenIddictBuilder AddOpenIddict(this IServiceCollection services) public static OpenIddictBuilder AddOpenIddict(this IServiceCollection services)
{ {
if (services is null) ArgumentNullException.ThrowIfNull(services);
{
throw new ArgumentNullException(nameof(services));
}
return new OpenIddictBuilder(services); return new OpenIddictBuilder(services);
} }
@ -36,15 +33,8 @@ public static class OpenIddictExtensions
/// <returns>The <see cref="IServiceCollection"/>.</returns> /// <returns>The <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection AddOpenIddict(this IServiceCollection services, Action<OpenIddictBuilder> configuration) public static IServiceCollection AddOpenIddict(this IServiceCollection services, Action<OpenIddictBuilder> configuration)
{ {
if (services is null) ArgumentNullException.ThrowIfNull(services);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(services));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(services.AddOpenIddict()); configuration(services.AddOpenIddict());

21
src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs

@ -21,10 +21,7 @@ public sealed class OpenIddictConverter : JsonConverter<OpenIddictMessage>
/// <returns><see langword="true"/> if the type is supported, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the type is supported, <see langword="false"/> otherwise.</returns>
public override bool CanConvert(Type typeToConvert) public override bool CanConvert(Type typeToConvert)
{ {
if (typeToConvert is null) ArgumentNullException.ThrowIfNull(typeToConvert);
{
throw new ArgumentNullException(nameof(typeToConvert));
}
return typeToConvert == typeof(OpenIddictMessage) || return typeToConvert == typeof(OpenIddictMessage) ||
typeToConvert == typeof(OpenIddictRequest) || typeToConvert == typeof(OpenIddictRequest) ||
@ -40,10 +37,7 @@ public sealed class OpenIddictConverter : JsonConverter<OpenIddictMessage>
/// <returns>The deserialized <see cref="OpenIddictMessage"/> instance.</returns> /// <returns>The deserialized <see cref="OpenIddictMessage"/> instance.</returns>
public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {
if (typeToConvert is null) ArgumentNullException.ThrowIfNull(typeToConvert);
{
throw new ArgumentNullException(nameof(typeToConvert));
}
using var document = JsonDocument.ParseValue(ref reader); using var document = JsonDocument.ParseValue(ref reader);
@ -61,15 +55,8 @@ public sealed class OpenIddictConverter : JsonConverter<OpenIddictMessage>
/// <param name="options">The JSON serializer options.</param> /// <param name="options">The JSON serializer options.</param>
public override void Write(Utf8JsonWriter writer, OpenIddictMessage value, JsonSerializerOptions options) public override void Write(Utf8JsonWriter writer, OpenIddictMessage value, JsonSerializerOptions options)
{ {
if (writer is null) ArgumentNullException.ThrowIfNull(writer);
{ ArgumentNullException.ThrowIfNull(value);
throw new ArgumentNullException(nameof(writer));
}
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
value.WriteTo(writer); value.WriteTo(writer);
} }

916
src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs

File diff suppressed because it is too large

60
src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs

@ -75,10 +75,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks> /// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(JsonObject parameters) public OpenIddictMessage(JsonObject parameters)
{ {
if (parameters is null) ArgumentNullException.ThrowIfNull(parameters);
{
throw new ArgumentNullException(nameof(parameters));
}
foreach (var parameter in parameters) foreach (var parameter in parameters)
{ {
@ -106,10 +103,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks> /// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(IEnumerable<KeyValuePair<string, OpenIddictParameter>> parameters) public OpenIddictMessage(IEnumerable<KeyValuePair<string, OpenIddictParameter>> parameters)
{ {
if (parameters is null) ArgumentNullException.ThrowIfNull(parameters);
{
throw new ArgumentNullException(nameof(parameters));
}
foreach (var parameter in parameters) foreach (var parameter in parameters)
{ {
@ -130,10 +124,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks> /// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(IEnumerable<KeyValuePair<string, string?>> parameters) public OpenIddictMessage(IEnumerable<KeyValuePair<string, string?>> parameters)
{ {
if (parameters is null) ArgumentNullException.ThrowIfNull(parameters);
{
throw new ArgumentNullException(nameof(parameters));
}
foreach (var parameter in parameters.GroupBy(parameter => parameter.Key)) foreach (var parameter in parameters.GroupBy(parameter => parameter.Key))
{ {
@ -163,10 +154,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks> /// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(IEnumerable<KeyValuePair<string, ImmutableArray<string?>?>> parameters) public OpenIddictMessage(IEnumerable<KeyValuePair<string, ImmutableArray<string?>?>> parameters)
{ {
if (parameters is null) ArgumentNullException.ThrowIfNull(parameters);
{
throw new ArgumentNullException(nameof(parameters));
}
foreach (var parameter in parameters) foreach (var parameter in parameters)
{ {
@ -196,10 +184,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks> /// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(IEnumerable<KeyValuePair<string, StringValues>> parameters) public OpenIddictMessage(IEnumerable<KeyValuePair<string, StringValues>> parameters)
{ {
if (parameters is null) ArgumentNullException.ThrowIfNull(parameters);
{
throw new ArgumentNullException(nameof(parameters));
}
foreach (var parameter in parameters) foreach (var parameter in parameters)
{ {
@ -229,10 +214,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks> /// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(NameValueCollection parameters) public OpenIddictMessage(NameValueCollection parameters)
{ {
if (parameters is null) ArgumentNullException.ThrowIfNull(parameters);
{
throw new ArgumentNullException(nameof(parameters));
}
for (var index = 0; index < parameters.AllKeys.Length; index++) for (var index = 0; index < parameters.AllKeys.Length; index++)
{ {
@ -286,10 +268,7 @@ public class OpenIddictMessage
/// <returns>The current instance, which allows chaining calls.</returns> /// <returns>The current instance, which allows chaining calls.</returns>
public OpenIddictMessage AddParameter(string name, OpenIddictParameter value) public OpenIddictMessage AddParameter(string name, OpenIddictParameter value)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
if (Parameters.ContainsKey(name)) if (Parameters.ContainsKey(name))
{ {
@ -323,10 +302,7 @@ public class OpenIddictMessage
/// <returns><see langword="true"/> if the parameter is present, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the parameter is present, <see langword="false"/> otherwise.</returns>
public bool HasParameter(string name) public bool HasParameter(string name)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
return Parameters.ContainsKey(name); return Parameters.ContainsKey(name);
} }
@ -338,10 +314,7 @@ public class OpenIddictMessage
/// <returns>The current instance, which allows chaining calls.</returns> /// <returns>The current instance, which allows chaining calls.</returns>
public OpenIddictMessage RemoveParameter(string name) public OpenIddictMessage RemoveParameter(string name)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
Parameters.Remove(name); Parameters.Remove(name);
@ -357,10 +330,7 @@ public class OpenIddictMessage
/// <returns>The current instance, which allows chaining calls.</returns> /// <returns>The current instance, which allows chaining calls.</returns>
public OpenIddictMessage SetParameter(string name, OpenIddictParameter? value) public OpenIddictMessage SetParameter(string name, OpenIddictParameter? value)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
// If the parameter value is null or empty, remove the corresponding entry from the collection. // If the parameter value is null or empty, remove the corresponding entry from the collection.
if (value is null || OpenIddictParameter.IsNullOrEmpty(value.GetValueOrDefault())) if (value is null || OpenIddictParameter.IsNullOrEmpty(value.GetValueOrDefault()))
@ -384,10 +354,7 @@ public class OpenIddictMessage
/// <returns><see langword="true"/> if the parameter could be found, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the parameter could be found, <see langword="false"/> otherwise.</returns>
public bool TryGetParameter(string name, out OpenIddictParameter value) public bool TryGetParameter(string name, out OpenIddictParameter value)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
return Parameters.TryGetValue(name, out value); return Parameters.TryGetValue(name, out value);
} }
@ -445,10 +412,7 @@ public class OpenIddictMessage
/// <param name="writer">The UTF-8 JSON writer.</param> /// <param name="writer">The UTF-8 JSON writer.</param>
public void WriteTo(Utf8JsonWriter writer) public void WriteTo(Utf8JsonWriter writer)
{ {
if (writer is null) ArgumentNullException.ThrowIfNull(writer);
{
throw new ArgumentNullException(nameof(writer));
}
writer.WriteStartObject(); writer.WriteStartObject();

15
src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs

@ -673,10 +673,7 @@ public readonly struct OpenIddictParameter : IEquatable<OpenIddictParameter>
/// <returns><see langword="true"/> if the parameter could be found, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the parameter could be found, <see langword="false"/> otherwise.</returns>
public bool TryGetNamedParameter(string name, out OpenIddictParameter value) public bool TryGetNamedParameter(string name, out OpenIddictParameter value)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0192), nameof(name));
}
var result = _value switch var result = _value switch
{ {
@ -709,10 +706,7 @@ public readonly struct OpenIddictParameter : IEquatable<OpenIddictParameter>
/// <returns><see langword="true"/> if the parameter could be found, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the parameter could be found, <see langword="false"/> otherwise.</returns>
public bool TryGetUnnamedParameter(int index, out OpenIddictParameter value) public bool TryGetUnnamedParameter(int index, out OpenIddictParameter value)
{ {
if (index < 0) ArgumentOutOfRangeException.ThrowIfNegative(index);
{
throw new ArgumentOutOfRangeException(nameof(index), SR.GetResourceString(SR.ID0193));
}
var result = _value switch var result = _value switch
{ {
@ -746,10 +740,7 @@ public readonly struct OpenIddictParameter : IEquatable<OpenIddictParameter>
/// <param name="writer">The UTF-8 JSON writer.</param> /// <param name="writer">The UTF-8 JSON writer.</param>
public void WriteTo(Utf8JsonWriter writer) public void WriteTo(Utf8JsonWriter writer)
{ {
if (writer is null) ArgumentNullException.ThrowIfNull(writer);
{
throw new ArgumentNullException(nameof(writer));
}
switch (_value) switch (_value)
{ {

1
src/OpenIddict.AspNetCore/OpenIddict.AspNetCore.csproj

@ -4,6 +4,7 @@
<TargetFrameworks>$(NetFrameworkTargetFrameworks);$(NetCoreTargetFrameworks)</TargetFrameworks> <TargetFrameworks>$(NetFrameworkTargetFrameworks);$(NetCoreTargetFrameworks)</TargetFrameworks>
<IncludeBuildOutput>false</IncludeBuildOutput> <IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeSymbols>false</IncludeSymbols> <IncludeSymbols>false</IncludeSymbols>
<IncludePolyfills>false</IncludePolyfills>
<IncludeInternalExtensions>false</IncludeInternalExtensions> <IncludeInternalExtensions>false</IncludeInternalExtensions>
</PropertyGroup> </PropertyGroup>

10
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs

@ -38,10 +38,7 @@ public sealed class OpenIddictClientAspNetCoreBuilder
/// <returns>The <see cref="OpenIddictClientAspNetCoreBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientAspNetCoreBuilder"/> instance.</returns>
public OpenIddictClientAspNetCoreBuilder Configure(Action<OpenIddictClientAspNetCoreOptions> configuration) public OpenIddictClientAspNetCoreBuilder Configure(Action<OpenIddictClientAspNetCoreOptions> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure(configuration); Services.Configure(configuration);
@ -74,10 +71,7 @@ public sealed class OpenIddictClientAspNetCoreBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientAspNetCoreBuilder AddForwardedAuthenticationScheme(string provider, string? caption) public OpenIddictClientAspNetCoreBuilder AddForwardedAuthenticationScheme(string provider, string? caption)
{ {
if (string.IsNullOrEmpty(provider)) ArgumentException.ThrowIfNullOrEmpty(provider);
{
throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
}
return Configure(options => options.ForwardedAuthenticationSchemes.Add( return Configure(options => options.ForwardedAuthenticationSchemes.Add(
new AuthenticationScheme(provider, caption, typeof(OpenIddictClientAspNetCoreForwarder)))); new AuthenticationScheme(provider, caption, typeof(OpenIddictClientAspNetCoreForwarder))));

20
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs

@ -31,10 +31,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
/// <inheritdoc/> /// <inheritdoc/>
public void Configure(AuthenticationOptions options) public void Configure(AuthenticationOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// If a handler was already registered and the type doesn't correspond to the OpenIddict handler, throw an exception. // If 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) && if (options.SchemeMap.TryGetValue(OpenIddictClientAspNetCoreDefaults.AuthenticationScheme, out var builder) &&
@ -64,10 +61,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientAspNetCoreOptions options) public void PostConfigure(string? name, OpenIddictClientAspNetCoreOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
if (!options.DisableAutomaticAuthenticationSchemeForwarding) if (!options.DisableAutomaticAuthenticationSchemeForwarding)
{ {
@ -102,10 +96,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
/// <inheritdoc/> /// <inheritdoc/>
public void Configure(OpenIddictClientOptions options) public void Configure(OpenIddictClientOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// Register the built-in event handlers used by the OpenIddict ASP.NET Core client components. // Register the built-in event handlers used by the OpenIddict ASP.NET Core client components.
options.Handlers.AddRange(OpenIddictClientAspNetCoreHandlers.DefaultHandlers); options.Handlers.AddRange(OpenIddictClientAspNetCoreHandlers.DefaultHandlers);
@ -114,10 +105,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, AuthenticationOptions options) public void PostConfigure(string? name, AuthenticationOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
if (!TryValidate(options.SchemeMap, options.DefaultAuthenticateScheme) || if (!TryValidate(options.SchemeMap, options.DefaultAuthenticateScheme) ||
!TryValidate(options.SchemeMap, options.DefaultScheme) || !TryValidate(options.SchemeMap, options.DefaultScheme) ||

17
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs

@ -24,10 +24,7 @@ public static class OpenIddictClientAspNetCoreExtensions
/// <returns>The <see cref="OpenIddictClientAspNetCoreBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientAspNetCoreBuilder"/> instance.</returns>
public static OpenIddictClientAspNetCoreBuilder UseAspNetCore(this OpenIddictClientBuilder builder) public static OpenIddictClientAspNetCoreBuilder UseAspNetCore(this OpenIddictClientBuilder builder)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddAuthentication(); builder.Services.AddAuthentication();
@ -73,15 +70,9 @@ public static class OpenIddictClientAspNetCoreExtensions
public static OpenIddictClientBuilder UseAspNetCore( public static OpenIddictClientBuilder UseAspNetCore(
this OpenIddictClientBuilder builder, Action<OpenIddictClientAspNetCoreBuilder> configuration) this OpenIddictClientBuilder builder, Action<OpenIddictClientAspNetCoreBuilder> configuration)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder)); ArgumentNullException.ThrowIfNull(configuration);
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(builder.UseAspNetCore()); configuration(builder.UseAspNetCore());

2
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs

@ -29,7 +29,7 @@ public sealed class OpenIddictClientAspNetCoreHandler : AuthenticationHandler<Op
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="OpenIddictClientAspNetCoreHandler"/> class. /// Creates a new instance of the <see cref="OpenIddictClientAspNetCoreHandler"/> class.
/// </summary> /// </summary>
#if SUPPORTS_TIME_PROVIDER #if SUPPORTS_AUTHENTICATION_HANDLER_TIME_PROVIDER_ARGUMENT
public OpenIddictClientAspNetCoreHandler( public OpenIddictClientAspNetCoreHandler(
IOpenIddictClientDispatcher dispatcher, IOpenIddictClientDispatcher dispatcher,
IOpenIddictClientFactory factory, IOpenIddictClientFactory factory,

30
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs

@ -29,10 +29,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(_options.CurrentValue.EnableErrorPassthrough); return new(_options.CurrentValue.EnableErrorPassthrough);
} }
@ -46,10 +43,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.Transaction.GetHttpRequest() is not null); return new(context.Transaction.GetHttpRequest() is not null);
} }
@ -69,10 +63,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(_options.CurrentValue.EnablePostLogoutRedirectionEndpointPassthrough); return new(_options.CurrentValue.EnablePostLogoutRedirectionEndpointPassthrough);
} }
@ -92,10 +83,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(_options.CurrentValue.EnableRedirectionEndpointPassthrough); return new(_options.CurrentValue.EnableRedirectionEndpointPassthrough);
} }
@ -114,10 +102,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(_options.CurrentValue.EnableStatusCodePagesIntegration); return new(_options.CurrentValue.EnableStatusCodePagesIntegration);
} }
@ -136,10 +121,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!_options.CurrentValue.DisableTransportSecurityRequirement); return new(!_options.CurrentValue.DisableTransportSecurityRequirement);
} }

5
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs

@ -61,10 +61,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ApplyAuthorizationRequestContext context) public ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.

5
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Session.cs

@ -61,10 +61,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ApplyEndSessionRequestContext context) public ValueTask HandleAsync(ApplyEndSessionRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.

110
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs

@ -95,10 +95,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context) public ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -149,10 +146,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context) public ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -194,10 +188,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context) public ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -239,10 +230,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(TContext context) public async ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -319,10 +307,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.GrantType is GrantTypes.DeviceCode) if (context.GrantType is GrantTypes.DeviceCode)
{ {
@ -353,10 +338,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (!string.IsNullOrEmpty(context.Nonce)) if (!string.IsNullOrEmpty(context.Nonce))
{ {
@ -394,10 +376,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -511,10 +490,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.GrantType is GrantTypes.DeviceCode) if (context.GrantType is GrantTypes.DeviceCode)
{ {
@ -546,10 +522,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -656,10 +629,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -695,10 +665,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If an explicit response type was specified, don't overwrite it. // If an explicit response type was specified, don't overwrite it.
if (!string.IsNullOrEmpty(context.ResponseMode)) if (!string.IsNullOrEmpty(context.ResponseMode))
@ -795,10 +762,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: using a correlation cookie serves as an injection/antiforgery protection as the request // 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 // will always be rejected if a cookie corresponding to the request forgery protection claim
@ -881,10 +845,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context) public ValueTask HandleAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -981,10 +942,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context) public ValueTask HandleAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -1027,10 +985,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context) public ValueTask HandleAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: using a correlation cookie serves as an injection/antiforgery protection as the request // 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 // will always be rejected if a cookie corresponding to the request forgery protection claim
@ -1115,10 +1070,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.SkipRequest(); context.SkipRequest();
@ -1146,10 +1098,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -1189,10 +1138,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -1233,10 +1179,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007)); Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007));
@ -1273,10 +1216,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -1329,10 +1269,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(TContext context) public async ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -1403,10 +1340,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.Logger.LogInformation(6145, SR.GetResourceString(SR.ID6145)); context.Logger.LogInformation(6145, SR.GetResourceString(SR.ID6145));
context.HandleRequest(); context.HandleRequest();

20
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs

@ -21,10 +21,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// <returns>The <see cref="HttpRequest"/> instance or <see langword="null"/> if it couldn't be found.</returns> /// <returns>The <see cref="HttpRequest"/> instance or <see langword="null"/> if it couldn't be found.</returns>
public static HttpRequest? GetHttpRequest(this OpenIddictClientTransaction transaction) public static HttpRequest? GetHttpRequest(this OpenIddictClientTransaction transaction)
{ {
if (transaction is null) ArgumentNullException.ThrowIfNull(transaction);
{
throw new ArgumentNullException(nameof(transaction));
}
if (!transaction.Properties.TryGetValue(typeof(HttpRequest).FullName!, out object? property)) if (!transaction.Properties.TryGetValue(typeof(HttpRequest).FullName!, out object? property))
{ {
@ -46,10 +43,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// <returns>The <see cref="OpenIddictClientEndpointType"/>.</returns> /// <returns>The <see cref="OpenIddictClientEndpointType"/>.</returns>
public static OpenIddictClientEndpointType GetOpenIddictClientEndpointType(this HttpContext context) public static OpenIddictClientEndpointType GetOpenIddictClientEndpointType(this HttpContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return context.Features.Get<OpenIddictClientAspNetCoreFeature>()?.Transaction?.EndpointType ?? default; return context.Features.Get<OpenIddictClientAspNetCoreFeature>()?.Transaction?.EndpointType ?? default;
} }
@ -61,10 +55,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// <returns>The <see cref="OpenIddictRequest"/> instance or <see langword="null"/> if it couldn't be found.</returns> /// <returns>The <see cref="OpenIddictRequest"/> instance or <see langword="null"/> if it couldn't be found.</returns>
public static OpenIddictRequest? GetOpenIddictClientRequest(this HttpContext context) public static OpenIddictRequest? GetOpenIddictClientRequest(this HttpContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return context.Features.Get<OpenIddictClientAspNetCoreFeature>()?.Transaction?.Request; return context.Features.Get<OpenIddictClientAspNetCoreFeature>()?.Transaction?.Request;
} }
@ -76,10 +67,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// <returns>The <see cref="OpenIddictResponse"/> instance or <see langword="null"/> if it couldn't be found.</returns> /// <returns>The <see cref="OpenIddictResponse"/> instance or <see langword="null"/> if it couldn't be found.</returns>
public static OpenIddictResponse? GetOpenIddictClientResponse(this HttpContext context) public static OpenIddictResponse? GetOpenIddictClientResponse(this HttpContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return context.Features.Get<OpenIddictClientAspNetCoreFeature>()?.Transaction?.Response; return context.Features.Get<OpenIddictClientAspNetCoreFeature>()?.Transaction?.Response;
} }

15
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs

@ -37,10 +37,7 @@ public sealed class OpenIddictClientDataProtectionBuilder
/// <returns>The <see cref="OpenIddictClientDataProtectionBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientDataProtectionBuilder"/> instance.</returns>
public OpenIddictClientDataProtectionBuilder Configure(Action<OpenIddictClientDataProtectionOptions> configuration) public OpenIddictClientDataProtectionBuilder Configure(Action<OpenIddictClientDataProtectionOptions> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure(configuration); Services.Configure(configuration);
@ -55,10 +52,7 @@ public sealed class OpenIddictClientDataProtectionBuilder
/// <returns>The <see cref="OpenIddictClientDataProtectionBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientDataProtectionBuilder"/> instance.</returns>
public OpenIddictClientDataProtectionBuilder UseDataProtectionProvider(IDataProtectionProvider provider) public OpenIddictClientDataProtectionBuilder UseDataProtectionProvider(IDataProtectionProvider provider)
{ {
if (provider is null) ArgumentNullException.ThrowIfNull(provider);
{
throw new ArgumentNullException(nameof(provider));
}
return Configure(options => options.DataProtectionProvider = provider); return Configure(options => options.DataProtectionProvider = provider);
} }
@ -70,10 +64,7 @@ public sealed class OpenIddictClientDataProtectionBuilder
/// <returns>The <see cref="OpenIddictClientDataProtectionBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientDataProtectionBuilder"/> instance.</returns>
public OpenIddictClientDataProtectionBuilder UseFormatter(IOpenIddictClientDataProtectionFormatter formatter) public OpenIddictClientDataProtectionBuilder UseFormatter(IOpenIddictClientDataProtectionFormatter formatter)
{ {
if (formatter is null) ArgumentNullException.ThrowIfNull(formatter);
{
throw new ArgumentNullException(nameof(formatter));
}
return Configure(options => options.Formatter = formatter); return Configure(options => options.Formatter = formatter);
} }

10
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionConfiguration.cs

@ -29,10 +29,7 @@ public sealed class OpenIddictClientDataProtectionConfiguration : IConfigureOpti
/// <inheritdoc/> /// <inheritdoc/>
public void Configure(OpenIddictClientOptions options) public void Configure(OpenIddictClientOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// Register the built-in event handlers used by the OpenIddict Data Protection server components. // Register the built-in event handlers used by the OpenIddict Data Protection server components.
options.Handlers.AddRange(OpenIddictClientDataProtectionHandlers.DefaultHandlers); options.Handlers.AddRange(OpenIddictClientDataProtectionHandlers.DefaultHandlers);
@ -41,10 +38,7 @@ public sealed class OpenIddictClientDataProtectionConfiguration : IConfigureOpti
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientDataProtectionOptions options) public void PostConfigure(string? name, OpenIddictClientDataProtectionOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
options.DataProtectionProvider ??= _dataProtectionProvider; options.DataProtectionProvider ??= _dataProtectionProvider;
} }

16
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs

@ -25,10 +25,7 @@ public static class OpenIddictClientDataProtectionExtensions
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public static OpenIddictClientDataProtectionBuilder UseDataProtection(this OpenIddictClientBuilder builder) public static OpenIddictClientDataProtectionBuilder UseDataProtection(this OpenIddictClientBuilder builder)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddDataProtection(); builder.Services.AddDataProtection();
@ -60,15 +57,8 @@ public static class OpenIddictClientDataProtectionExtensions
public static OpenIddictClientBuilder UseDataProtection( public static OpenIddictClientBuilder UseDataProtection(
this OpenIddictClientBuilder builder, Action<OpenIddictClientDataProtectionBuilder> configuration) this OpenIddictClientBuilder builder, Action<OpenIddictClientDataProtectionBuilder> configuration)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(builder.UseDataProtection()); configuration(builder.UseDataProtection());

27
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs

@ -20,10 +20,7 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD
{ {
public ClaimsPrincipal ReadToken(BinaryReader reader) public ClaimsPrincipal ReadToken(BinaryReader reader)
{ {
if (reader is null) ArgumentNullException.ThrowIfNull(reader);
{
throw new ArgumentNullException(nameof(reader));
}
var (principal, properties) = Read(reader); var (principal, properties) = Read(reader);
@ -182,15 +179,8 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD
public void WriteToken(BinaryWriter writer, ClaimsPrincipal principal) public void WriteToken(BinaryWriter writer, ClaimsPrincipal principal)
{ {
if (writer is null) ArgumentNullException.ThrowIfNull(writer);
{ ArgumentNullException.ThrowIfNull(principal);
throw new ArgumentNullException(nameof(writer));
}
if (principal is null)
{
throw new ArgumentNullException(nameof(principal));
}
var properties = new Dictionary<string, string>(); var properties = new Dictionary<string, string>();
@ -293,15 +283,8 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD
static void WriteClaim(BinaryWriter writer, Claim claim) static void WriteClaim(BinaryWriter writer, Claim claim)
{ {
if (writer is null) ArgumentNullException.ThrowIfNull(writer);
{ ArgumentNullException.ThrowIfNull(claim);
throw new ArgumentNullException(nameof(writer));
}
if (claim is null)
{
throw new ArgumentNullException(nameof(claim));
}
WriteWithDefault(writer, claim.Type, claim.Subject?.NameClaimType ?? ClaimsIdentity.DefaultNameClaimType); WriteWithDefault(writer, claim.Type, claim.Subject?.NameClaimType ?? ClaimsIdentity.DefaultNameClaimType);
writer.Write(claim.Value); writer.Write(claim.Value);

5
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlerFilters.cs

@ -20,10 +20,7 @@ public static class OpenIddictClientDataProtectionHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(GenerateTokenContext context) public ValueTask<bool> IsActiveAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.TokenFormat is TokenFormats.Private.DataProtection); return new(context.TokenFormat is TokenFormats.Private.DataProtection);
} }

10
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs

@ -176,10 +176,7 @@ public static partial class OpenIddictClientDataProtectionHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context) public ValueTask HandleAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// ASP.NET Core Data Protection can be used to format certain types of tokens in lieu // 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 // of the default token format (typically, JSON Web Token). By default, Data Protection
@ -223,10 +220,7 @@ public static partial class OpenIddictClientDataProtectionHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context) public ValueTask HandleAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If an access token was already attached by another handler, don't overwrite it. // If an access token was already attached by another handler, don't overwrite it.
if (!string.IsNullOrEmpty(context.Token)) if (!string.IsNullOrEmpty(context.Token))

5
src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs

@ -74,10 +74,7 @@ public sealed class OpenIddictClientOwinBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientOwinBuilder AddForwardedAuthenticationType(string provider, string? caption) public OpenIddictClientOwinBuilder AddForwardedAuthenticationType(string provider, string? caption)
{ {
if (string.IsNullOrEmpty(provider)) ArgumentException.ThrowIfNullOrEmpty(provider);
{
throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
}
return Configure(options => options.ForwardedAuthenticationTypes.Add(new AuthenticationDescription return Configure(options => options.ForwardedAuthenticationTypes.Add(new AuthenticationDescription
{ {

1
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. allow loading dependencies that are not strong-named), the warning can be safely disabled.
--> -->
<NoWarn>$(NoWarn);CS8002</NoWarn> <NoWarn>$(NoWarn);CS8002</NoWarn>
<DefineConstants>$(DefineConstants);FeatureRuntimeInformation;FeatureValueTuple</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

5
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivation.cs

@ -21,10 +21,7 @@ public sealed class OpenIddictClientSystemIntegrationActivation
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
public OpenIddictClientSystemIntegrationActivation(Uri uri) public OpenIddictClientSystemIntegrationActivation(Uri uri)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{
throw new ArgumentNullException(nameof(uri));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {

25
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs

@ -40,10 +40,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
/// <returns>The <see cref="OpenIddictClientSystemIntegrationBuilder"/>.</returns> /// <returns>The <see cref="OpenIddictClientSystemIntegrationBuilder"/>.</returns>
public OpenIddictClientSystemIntegrationBuilder Configure(Action<OpenIddictClientSystemIntegrationOptions> configuration) public OpenIddictClientSystemIntegrationBuilder Configure(Action<OpenIddictClientSystemIntegrationOptions> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure(configuration); Services.Configure(configuration);
@ -209,10 +206,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemIntegrationBuilder SetApplicationDiscriminator(string discriminator) public OpenIddictClientSystemIntegrationBuilder SetApplicationDiscriminator(string discriminator)
{ {
if (string.IsNullOrEmpty(discriminator)) ArgumentException.ThrowIfNullOrEmpty(discriminator);
{
throw new ArgumentException(SR.FormatID0366(nameof(discriminator)), nameof(discriminator));
}
return Configure(options => options.ApplicationDiscriminator = discriminator); return Configure(options => options.ApplicationDiscriminator = discriminator);
} }
@ -226,10 +220,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemIntegrationBuilder SetInstanceIdentifier(string identifier) public OpenIddictClientSystemIntegrationBuilder SetInstanceIdentifier(string identifier)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
}
return Configure(options => options.InstanceIdentifier = identifier); return Configure(options => options.InstanceIdentifier = identifier);
} }
@ -243,10 +234,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemIntegrationBuilder SetPipeName(string name) public OpenIddictClientSystemIntegrationBuilder SetPipeName(string name)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name));
}
return Configure(options => options.PipeName = name); return Configure(options => options.PipeName = name);
} }
@ -270,10 +258,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced), SupportedOSPlatform("windows")] [EditorBrowsable(EditorBrowsableState.Advanced), SupportedOSPlatform("windows")]
public OpenIddictClientSystemIntegrationBuilder SetPipeSecurity(PipeSecurity security) public OpenIddictClientSystemIntegrationBuilder SetPipeSecurity(PipeSecurity security)
{ {
if (security is null) ArgumentNullException.ThrowIfNull(security);
{
throw new ArgumentNullException(nameof(security));
}
return Configure(options => options.PipeSecurity = security); return Configure(options => options.PipeSecurity = security);
} }

66
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs

@ -7,7 +7,6 @@
using System.ComponentModel; using System.ComponentModel;
using System.IO.Pipes; using System.IO.Pipes;
using System.Net; using System.Net;
using System.Runtime.InteropServices;
using System.Security.AccessControl; using System.Security.AccessControl;
using System.Security.Principal; using System.Security.Principal;
using System.Text; using System.Text;
@ -38,10 +37,7 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
/// <inheritdoc/> /// <inheritdoc/>
public void Configure(OpenIddictClientOptions options) public void Configure(OpenIddictClientOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// Register the built-in event handlers used by the OpenIddict client system integration components. // Register the built-in event handlers used by the OpenIddict client system integration components.
options.Handlers.AddRange(OpenIddictClientSystemIntegrationHandlers.DefaultHandlers); options.Handlers.AddRange(OpenIddictClientSystemIntegrationHandlers.DefaultHandlers);
@ -53,10 +49,7 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientOptions options) public void PostConfigure(string? name, OpenIddictClientOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// If no explicit client URI was set, default to the static "http://localhost/" address, which is // 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. // 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
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientSystemIntegrationOptions options) public void PostConfigure(string? name, OpenIddictClientSystemIntegrationOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// Ensure the operating system is supported. // Ensure the operating system version is supported.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")) && if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) && (OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && OperatingSystem.IsLinux() ||
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) && (OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && (OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
{ {
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389)); 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 // 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 // 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. // 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)); throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
} }
#endif #endif
#if !SUPPORTS_UIKIT #if !SUPPORTS_UIKIT
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) || if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")))
{ {
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449)); throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
} }
#endif #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 #pragma warning disable CA1416
// If explicitly set, ensure the specified authentication mode is supported. // If explicitly set, ensure the specified authentication mode is supported.
if (options.AuthenticationMode is ASWebAuthenticationSession && !IsASWebAuthenticationSessionSupported()) if (options.AuthenticationMode is ASWebAuthenticationSession && !IsASWebAuthenticationSessionSupported())
@ -141,10 +113,8 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
IsASWebAuthenticationSessionSupported() ? ASWebAuthenticationSession : IsASWebAuthenticationSessionSupported() ? ASWebAuthenticationSession :
IsCustomTabsIntentSupported() ? CustomTabsIntent : SystemBrowser; IsCustomTabsIntentSupported() ? CustomTabsIntent : SystemBrowser;
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")) && if (!OperatingSystem.IsAndroid() && !OperatingSystem.IsIOS() &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) && !OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacOS())
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{ {
options.EnableActivationHandling ??= true; options.EnableActivationHandling ??= true;
options.EnableActivationRedirection ??= 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 // Note: on Windows, the name is deliberately prefixed with "LOCAL\" to support
// partial trust/sandboxed applications that are executed in an AppContainer // partial trust/sandboxed applications that are executed in an AppContainer
// and cannot communicate with applications outside the sandbox container. // and cannot communicate with applications outside the sandbox container.
options.PipeName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? options.PipeName = OperatingSystem.IsWindows() ?
@$"LOCAL\{options.ApplicationDiscriminator}" : @$"LOCAL\{options.ApplicationDiscriminator}" :
options.ApplicationDiscriminator; options.ApplicationDiscriminator;
} }
#if SUPPORTS_CURRENT_USER_ONLY_PIPE_OPTION #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 // Note: the CurrentUserOnly option is also supported on Windows, but is less
// flexible than using a PipeSecurity object (e.g cross-process communication // 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 // between elevated and non-elevated processes. Note: if the process executes
// inside an AppContainer, don't override the default OS pipe security policy // 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. // 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); 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 = new PipeSecurity();
options.PipeSecurity.SetOwner(identity.User!); options.PipeSecurity.SetOwner(identity.User!);

53
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs

@ -4,7 +4,6 @@
* the license and the contributors participating to this project. * the license and the contributors participating to this project.
*/ */
using System.Runtime.InteropServices;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -26,18 +25,15 @@ public static class OpenIddictClientSystemIntegrationExtensions
/// <returns>The <see cref="OpenIddictClientSystemIntegrationBuilder"/>.</returns> /// <returns>The <see cref="OpenIddictClientSystemIntegrationBuilder"/>.</returns>
public static OpenIddictClientSystemIntegrationBuilder UseSystemIntegration(this OpenIddictClientBuilder builder) public static OpenIddictClientSystemIntegrationBuilder UseSystemIntegration(this OpenIddictClientBuilder builder)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder));
}
// Ensure the operating system is supported. // Ensure the operating system version is supported.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")) && if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) && (OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && OperatingSystem.IsLinux() ||
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) && (OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && (OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
{ {
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389)); 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 // 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 // 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. // 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)); throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
} }
#endif #endif
#if !SUPPORTS_UIKIT #if !SUPPORTS_UIKIT
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) || if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")))
{ {
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449)); throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
} }
#endif #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 // 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 // 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 // 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( public static OpenIddictClientBuilder UseSystemIntegration(
this OpenIddictClientBuilder builder, Action<OpenIddictClientSystemIntegrationBuilder> configuration) this OpenIddictClientBuilder builder, Action<OpenIddictClientSystemIntegrationBuilder> configuration)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(builder.UseSystemIntegration()); configuration(builder.UseSystemIntegration());

50
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs

@ -30,10 +30,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_AUTHENTICATION_SERVICES #if SUPPORTS_AUTHENTICATION_SERVICES
if (IsASWebAuthenticationSessionSupported()) if (IsASWebAuthenticationSessionSupported())
@ -61,10 +58,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!string.IsNullOrEmpty(context.Nonce)); return new(!string.IsNullOrEmpty(context.Nonce));
} }
@ -83,10 +77,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER #if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
if (IsCustomTabsIntentSupported()) if (IsCustomTabsIntentSupported())
@ -118,10 +109,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(_options.CurrentValue.EnableEmbeddedWebServer is true); return new(_options.CurrentValue.EnableEmbeddedWebServer is true);
} }
@ -135,10 +123,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.Transaction.GetHttpListenerContext() is not null); return new(context.Transaction.GetHttpListenerContext() is not null);
} }
@ -152,10 +137,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(Environment.UserInteractive); return new(Environment.UserInteractive);
} }
@ -170,10 +152,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.Transaction.GetPlatformCallback() is not null); return new(context.Transaction.GetPlatformCallback() is not null);
} }
@ -187,10 +166,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.Transaction.GetProtocolActivation() is not null); return new(context.Transaction.GetProtocolActivation() is not null);
} }
@ -210,10 +186,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (!context.Transaction.Properties.TryGetValue( if (!context.Transaction.Properties.TryGetValue(
typeof(OpenIddictClientSystemIntegrationAuthenticationMode).FullName!, out var result) || typeof(OpenIddictClientSystemIntegrationAuthenticationMode).FullName!, out var result) ||
@ -240,10 +213,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_WINDOWS_RUNTIME #if SUPPORTS_WINDOWS_RUNTIME
if (IsWebAuthenticationBrokerSupported()) if (IsWebAuthenticationBrokerSupported())

36
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs

@ -5,7 +5,6 @@
*/ */
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text; using System.Text;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
@ -99,10 +98,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context) public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
#pragma warning restore CS1998 #pragma warning restore CS1998
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION #if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (string.IsNullOrEmpty(context.RedirectUri) || if (string.IsNullOrEmpty(context.RedirectUri) ||
@ -322,10 +318,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context) public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
#pragma warning restore CS1998 #pragma warning restore CS1998
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER #if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
if (string.IsNullOrEmpty(context.RedirectUri)) if (string.IsNullOrEmpty(context.RedirectUri))
@ -398,10 +391,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context) public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
#pragma warning restore CS1998 #pragma warning restore CS1998
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_WINDOWS_RUNTIME #if SUPPORTS_WINDOWS_RUNTIME
if (string.IsNullOrEmpty(context.RedirectUri)) if (string.IsNullOrEmpty(context.RedirectUri))
@ -543,10 +533,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context) public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var uri = OpenIddictHelpers.AddQueryStringParameters( var uri = OpenIddictHelpers.AddQueryStringParameters(
uri: new Uri(context.AuthorizationEndpoint, UriKind.Absolute), uri: new Uri(context.AuthorizationEndpoint, UriKind.Absolute),
@ -554,7 +541,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
static parameter => parameter.Key, static parameter => parameter.Key,
static parameter => (StringValues) parameter.Value)); 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: // 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; return;
} }
#endif #endif
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && await TryLaunchBrowserWithOpenAsync(uri)) if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri))
{ {
context.HandleRequest(); context.HandleRequest();
return; return;
} }
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && await TryLaunchBrowserWithXdgOpenAsync(uri)) if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri))
{ {
context.HandleRequest(); context.HandleRequest();
return; return;
@ -648,10 +635,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ApplyRedirectionResponseContext context) public async ValueTask HandleAsync(ApplyRedirectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved, // 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. // 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." _ => "Authentication failed. Please return to the application."
}); });
#if SUPPORTS_STREAM_MEMORY_METHODS
await response.OutputStream.WriteAsync(buffer); await response.OutputStream.WriteAsync(buffer);
#else
await response.OutputStream.WriteAsync(buffer, 0, buffer.Length);
#endif
await response.OutputStream.FlushAsync(); await response.OutputStream.FlushAsync();
context.HandleRequest(); context.HandleRequest();

36
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs

@ -5,7 +5,6 @@
*/ */
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text; using System.Text;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
@ -99,10 +98,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context) public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
#pragma warning restore CS1998 #pragma warning restore CS1998
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION #if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri) || if (string.IsNullOrEmpty(context.PostLogoutRedirectUri) ||
@ -322,10 +318,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context) public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
#pragma warning restore CS1998 #pragma warning restore CS1998
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER #if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri)) if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
@ -398,10 +391,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context) public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
#pragma warning restore CS1998 #pragma warning restore CS1998
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_WINDOWS_RUNTIME #if SUPPORTS_WINDOWS_RUNTIME
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri)) if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
@ -543,10 +533,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context) public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var uri = OpenIddictHelpers.AddQueryStringParameters( var uri = OpenIddictHelpers.AddQueryStringParameters(
uri: new Uri(context.EndSessionEndpoint, UriKind.Absolute), uri: new Uri(context.EndSessionEndpoint, UriKind.Absolute),
@ -554,7 +541,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
static parameter => parameter.Key, static parameter => parameter.Key,
static parameter => (StringValues) parameter.Value)); 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: // 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; return;
} }
#endif #endif
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && await TryLaunchBrowserWithOpenAsync(uri)) if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri))
{ {
context.HandleRequest(); context.HandleRequest();
return; return;
} }
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && await TryLaunchBrowserWithXdgOpenAsync(uri)) if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri))
{ {
context.HandleRequest(); context.HandleRequest();
return; return;
@ -648,10 +635,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ApplyPostLogoutRedirectionResponseContext context) public async ValueTask HandleAsync(ApplyPostLogoutRedirectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved, // 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. // 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." _ => "Logout failed. Please return to the application."
}); });
#if SUPPORTS_STREAM_MEMORY_METHODS
await response.OutputStream.WriteAsync(buffer); await response.OutputStream.WriteAsync(buffer);
#else
await response.OutputStream.WriteAsync(buffer, 0, buffer.Length);
#endif
await response.OutputStream.FlushAsync(); await response.OutputStream.FlushAsync();
context.HandleRequest(); context.HandleRequest();

215
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs

@ -108,10 +108,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context) public ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// When using the OpenIddict client system integration, requests can originate from multiple sources: // When using the OpenIddict client system integration, requests can originate from multiple sources:
// //
@ -177,10 +174,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context) public ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
(context.BaseUri, context.RequestUri) = context.Transaction.GetProtocolActivation() switch (context.BaseUri, context.RequestUri) = context.Transaction.GetProtocolActivation() switch
{ {
@ -215,10 +209,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context) public ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
(context.BaseUri, context.RequestUri) = context.Transaction.GetPlatformCallback() switch (context.BaseUri, context.RequestUri) = context.Transaction.GetPlatformCallback() switch
{ {
@ -254,10 +245,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context) public ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If the base or request URIs couldn't be resolved, don't try to infer the endpoint type. // 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 }) if (context is not { BaseUri.IsAbsoluteUri: true, RequestUri.IsAbsoluteUri: true })
@ -332,10 +320,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context) public ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -377,10 +362,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -430,10 +412,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(TContext context) public async ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -520,10 +499,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.Transaction.GetProtocolActivation() is not { ActivationUri: Uri uri }) if (context.Transaction.GetProtocolActivation() is not { ActivationUri: Uri uri })
{ {
@ -578,10 +554,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.Transaction.GetPlatformCallback() is not OpenIddictClientSystemIntegrationPlatformCallback callback) if (context.Transaction.GetPlatformCallback() is not OpenIddictClientSystemIntegrationPlatformCallback callback)
{ {
@ -624,10 +597,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessAuthenticationContext context) public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -721,10 +691,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -767,10 +734,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -813,10 +777,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -860,10 +821,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -918,10 +876,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessAuthenticationContext context) public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -1002,10 +957,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1053,10 +1005,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1101,10 +1050,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1148,10 +1094,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1195,10 +1138,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1242,10 +1182,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1288,10 +1225,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1336,10 +1270,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1383,10 +1314,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1430,10 +1358,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1477,10 +1402,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1522,10 +1444,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1569,10 +1488,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1611,10 +1527,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019)); Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1649,10 +1562,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.BaseUri ??= context.Options.ClientUri; context.BaseUri ??= context.Options.ClientUri;
@ -1692,10 +1602,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessChallengeContext context) public async ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If the redirect_uri uses a loopback host/IP as the authority and doesn't include a non-default port, // 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 // 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
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessChallengeContext context) public async ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If an explicit response type was specified, don't overwrite it. // If an explicit response type was specified, don't overwrite it.
if (!string.IsNullOrEmpty(context.ResponseMode)) if (!string.IsNullOrEmpty(context.ResponseMode))
@ -1931,10 +1835,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -1976,10 +1877,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (string.IsNullOrEmpty(context.Nonce)) if (string.IsNullOrEmpty(context.Nonce))
{ {
@ -2020,10 +1918,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context) public ValueTask HandleAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.BaseUri ??= context.Options.ClientUri; context.BaseUri ??= context.Options.ClientUri;
@ -2062,10 +1957,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessSignOutContext context) public async ValueTask HandleAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If the post_logout_redirect_uri uses a loopback host/IP as the authority and doesn't include a non-default port, // 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 // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context) public ValueTask HandleAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -2158,10 +2047,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context) public ValueTask HandleAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (string.IsNullOrEmpty(context.Nonce)) if (string.IsNullOrEmpty(context.Nonce))
{ {
@ -2211,10 +2097,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessErrorContext context) public ValueTask HandleAsync(ProcessErrorContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Try to resolve the authentication context from the transaction, if available. // Try to resolve the authentication context from the transaction, if available.
var notification = context.Transaction.GetProperty<ProcessAuthenticationContext>( var notification = context.Transaction.GetProperty<ProcessAuthenticationContext>(
@ -2262,10 +2145,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -2305,10 +2185,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another server stack.
@ -2345,10 +2222,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// For both protocol activations (initial or redirected) and web-view-like results, // 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 // no proper response can be generated and eventually displayed to the user. In this
@ -2381,10 +2255,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// For both protocol activations (initial or redirected) and web-view-like results, // 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 // no proper response can be generated and eventually displayed to the user. In this

39
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs

@ -68,38 +68,6 @@ public static class OpenIddictClientSystemIntegrationHelpers
public static HttpListenerContext? GetHttpListenerContext(this OpenIddictClientTransaction transaction) public static HttpListenerContext? GetHttpListenerContext(this OpenIddictClientTransaction transaction)
=> transaction.GetProperty<HttpListenerContext>(typeof(HttpListenerContext).FullName!); => transaction.GetProperty<HttpListenerContext>(typeof(HttpListenerContext).FullName!);
/// <summary>
/// Determines whether the current Windows version
/// is greater than or equals to the specified version.
/// </summary>
/// <returns>
/// <see langword="true"/> if the current Windows version is greater than
/// or equals to the specified version, <see langword="false"/> otherwise.
/// </returns>
[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
}
/// <summary> /// <summary>
/// Determines whether the ASWebAuthenticationSession API is supported on this platform. /// Determines whether the ASWebAuthenticationSession API is supported on this platform.
/// </summary> /// </summary>
@ -144,7 +112,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
// oldest supported version in the package, it is also used for the runtime check. // oldest supported version in the package, it is also used for the runtime check.
internal static bool IsWindowsRuntimeSupported() internal static bool IsWindowsRuntimeSupported()
#if SUPPORTS_WINDOWS_RUNTIME #if SUPPORTS_WINDOWS_RUNTIME
=> IsWindowsVersionAtLeast(10, 0, 17763); => OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17763);
#else #else
=> false; => false;
#endif #endif
@ -227,10 +195,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
[SupportedOSPlatform("windows10.0.10240")] [SupportedOSPlatform("windows10.0.10240")]
internal static unsafe bool HasAppContainerToken(WindowsIdentity identity) internal static unsafe bool HasAppContainerToken(WindowsIdentity identity)
{ {
if (identity is null) ArgumentNullException.ThrowIfNull(identity);
{
throw new ArgumentNullException(nameof(identity));
}
int* buffer = stackalloc int[1]; int* buffer = stackalloc int[1];

5
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs

@ -8,7 +8,6 @@ using System.ComponentModel;
using System.Globalization; using System.Globalization;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -146,7 +145,7 @@ public sealed class OpenIddictClientSystemIntegrationHttpListener : BackgroundSe
// non-Windows operating systems) and doesn't require running the application // non-Windows operating systems) and doesn't require running the application
// as an administrator or adding a namespace reservation/ACL rule on Windows. // 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 // 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 // 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. // configured to reject such requests) without requiring administrator rights.
// //
// See https://www.rfc-editor.org/rfc/rfc8252#section-8.3 for more information. // 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) if (Socket.OSSupportsIPv4)
{ {

3
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs

@ -6,7 +6,6 @@
using System.ComponentModel; using System.ComponentModel;
using System.IO.Pipes; using System.IO.Pipes;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -131,7 +130,7 @@ public sealed class OpenIddictClientSystemIntegrationPipeListener : BackgroundSe
static NamedPipeServerStream CreatePipeServerStream(OpenIddictClientSystemIntegrationOptions options) static NamedPipeServerStream CreatePipeServerStream(OpenIddictClientSystemIntegrationOptions options)
// Note: the ACL-based PipeSecurity class is only supported on Windows. On other operating systems, // 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. // 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 #if SUPPORTS_NAMED_PIPE_CONSTRUCTOR_WITH_ACL
new NamedPipeServerStream( new NamedPipeServerStream(
#elif SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL #elif SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL

10
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPlatformCallback.cs

@ -25,20 +25,14 @@ public sealed class OpenIddictClientSystemIntegrationPlatformCallback
public OpenIddictClientSystemIntegrationPlatformCallback( public OpenIddictClientSystemIntegrationPlatformCallback(
Uri uri, IReadOnlyDictionary<string, OpenIddictParameter> parameters) Uri uri, IReadOnlyDictionary<string, OpenIddictParameter> parameters)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{
throw new ArgumentNullException(nameof(uri));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {
throw new ArgumentException(SR.GetResourceString(SR.ID0144), nameof(uri)); throw new ArgumentException(SR.GetResourceString(SR.ID0144), nameof(uri));
} }
if (parameters is null) ArgumentNullException.ThrowIfNull(parameters);
{
throw new ArgumentNullException(nameof(parameters));
}
CallbackUri = uri; CallbackUri = uri;
Parameters = parameters.ToImmutableDictionary(); Parameters = parameters.ToImmutableDictionary();

21
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs

@ -53,10 +53,7 @@ public sealed class OpenIddictClientSystemIntegrationService
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public Task HandleCustomTabsIntentAsync(Intent intent, CancellationToken cancellationToken = default) public Task HandleCustomTabsIntentAsync(Intent intent, CancellationToken cancellationToken = default)
{ {
if (intent is null) ArgumentNullException.ThrowIfNull(intent);
{
throw new ArgumentNullException(nameof(intent));
}
if (intent.Data is null) if (intent.Data is null)
{ {
@ -139,10 +136,7 @@ public sealed class OpenIddictClientSystemIntegrationService
/// <exception cref="ArgumentNullException"><paramref name="property"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="property"/> is <see langword="null"/>.</exception>
private async Task HandleRequestAsync<TProperty>(TProperty property, CancellationToken cancellationToken) where TProperty : class private async Task HandleRequestAsync<TProperty>(TProperty property, CancellationToken cancellationToken) where TProperty : class
{ {
if (property is null) ArgumentNullException.ThrowIfNull(property);
{
throw new ArgumentNullException(nameof(property));
}
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -188,15 +182,8 @@ public sealed class OpenIddictClientSystemIntegrationService
OpenIddictClientSystemIntegrationActivation activation, OpenIddictClientSystemIntegrationActivation activation,
string identifier, CancellationToken cancellationToken = default) string identifier, CancellationToken cancellationToken = default)
{ {
if (activation is null) ArgumentNullException.ThrowIfNull(activation);
{ ArgumentException.ThrowIfNullOrEmpty(identifier);
throw new ArgumentNullException(nameof(activation));
}
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
}
using var buffer = new MemoryStream(); using var buffer = new MemoryStream();
using var writer = new BinaryWriter(buffer); using var writer = new BinaryWriter(buffer);

1
src/OpenIddict.Client.SystemNetHttp/OpenIddict.Client.SystemNetHttp.csproj

@ -6,6 +6,7 @@
$(NetCoreTargetFrameworks); $(NetCoreTargetFrameworks);
$(NetStandardTargetFrameworks) $(NetStandardTargetFrameworks)
</TargetFrameworks> </TargetFrameworks>
<DefineConstants>$(DefineConstants);FeatureRuntimeInformation</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

97
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs

@ -42,10 +42,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder Configure(Action<OpenIddictClientSystemNetHttpOptions> configuration) public OpenIddictClientSystemNetHttpBuilder Configure(Action<OpenIddictClientSystemNetHttpOptions> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure(configuration); Services.Configure(configuration);
@ -63,10 +60,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(Action<HttpClient> configuration) public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(Action<HttpClient> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
return ConfigureHttpClient((registration, client) => configuration(client)); return ConfigureHttpClient((registration, client) => configuration(client));
} }
@ -84,15 +78,8 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(string provider, Action<HttpClient> configuration) public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(string provider, Action<HttpClient> configuration)
{ {
if (string.IsNullOrEmpty(provider)) ArgumentNullException.ThrowIfNull(configuration);
{ ArgumentException.ThrowIfNullOrEmpty(provider);
throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
return ConfigureHttpClient((registration, client) => return ConfigureHttpClient((registration, client) =>
{ {
@ -115,10 +102,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(Action<OpenIddictClientRegistration, HttpClient> configuration) public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(Action<OpenIddictClientRegistration, HttpClient> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
return Configure(options => options.HttpClientActions.Add(configuration)); return Configure(options => options.HttpClientActions.Add(configuration));
} }
@ -134,10 +118,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(Action<HttpClientHandler> configuration) public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(Action<HttpClientHandler> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
return ConfigureHttpClientHandler((registration, handler) => configuration(handler)); return ConfigureHttpClientHandler((registration, handler) => configuration(handler));
} }
@ -155,15 +136,8 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(string provider, Action<HttpClientHandler> configuration) public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(string provider, Action<HttpClientHandler> configuration)
{ {
if (string.IsNullOrEmpty(provider)) ArgumentNullException.ThrowIfNull(configuration);
{ ArgumentException.ThrowIfNullOrEmpty(provider);
throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
return ConfigureHttpClientHandler((registration, handler) => return ConfigureHttpClientHandler((registration, handler) =>
{ {
@ -187,10 +161,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler( public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(
Action<OpenIddictClientRegistration, HttpClientHandler> configuration) Action<OpenIddictClientRegistration, HttpClientHandler> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
return Configure(options => options.HttpClientHandlerActions.Add(configuration)); return Configure(options => options.HttpClientHandlerActions.Add(configuration));
} }
@ -203,10 +174,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetContactAddress(MailAddress address) public OpenIddictClientSystemNetHttpBuilder SetContactAddress(MailAddress address)
{ {
if (address is null) ArgumentNullException.ThrowIfNull(address);
{
throw new ArgumentNullException(nameof(address));
}
return Configure(options => options.ContactAddress = address); return Configure(options => options.ContactAddress = address);
} }
@ -219,10 +187,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetContactAddress(string address) public OpenIddictClientSystemNetHttpBuilder SetContactAddress(string address)
{ {
if (string.IsNullOrEmpty(address)) ArgumentException.ThrowIfNullOrEmpty(address);
{
throw new ArgumentException(SR.FormatID0366(nameof(address)), nameof(address));
}
return SetContactAddress(new MailAddress(address)); return SetContactAddress(new MailAddress(address));
} }
@ -234,10 +199,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetHttpErrorPolicy(IAsyncPolicy<HttpResponseMessage> policy) public OpenIddictClientSystemNetHttpBuilder SetHttpErrorPolicy(IAsyncPolicy<HttpResponseMessage> policy)
{ {
if (policy is null) ArgumentNullException.ThrowIfNull(policy);
{
throw new ArgumentNullException(nameof(policy));
}
return Configure(options => options.HttpErrorPolicy = policy); return Configure(options => options.HttpErrorPolicy = policy);
} }
@ -257,10 +219,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder SetHttpResiliencePipeline( public OpenIddictClientSystemNetHttpBuilder SetHttpResiliencePipeline(
Action<ResiliencePipelineBuilder<HttpResponseMessage>> configuration) Action<ResiliencePipelineBuilder<HttpResponseMessage>> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
var builder = new ResiliencePipelineBuilder<HttpResponseMessage>(); var builder = new ResiliencePipelineBuilder<HttpResponseMessage>();
configuration(builder); configuration(builder);
@ -279,10 +238,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetHttpResiliencePipeline(ResiliencePipeline<HttpResponseMessage> pipeline) public OpenIddictClientSystemNetHttpBuilder SetHttpResiliencePipeline(ResiliencePipeline<HttpResponseMessage> pipeline)
{ {
if (pipeline is null) ArgumentNullException.ThrowIfNull(pipeline);
{
throw new ArgumentNullException(nameof(pipeline));
}
return Configure(options => options.HttpResiliencePipeline = pipeline); return Configure(options => options.HttpResiliencePipeline = pipeline);
} }
@ -296,10 +252,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(ProductInfoHeaderValue information) public OpenIddictClientSystemNetHttpBuilder SetProductInformation(ProductInfoHeaderValue information)
{ {
if (information is null) ArgumentNullException.ThrowIfNull(information);
{
throw new ArgumentNullException(nameof(information));
}
return Configure(options => options.ProductInformation = information); return Configure(options => options.ProductInformation = information);
} }
@ -313,10 +266,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(string name, string? version) public OpenIddictClientSystemNetHttpBuilder SetProductInformation(string name, string? version)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0345), nameof(name));
}
return SetProductInformation(new ProductInfoHeaderValue(name, version)); return SetProductInformation(new ProductInfoHeaderValue(name, version));
} }
@ -330,10 +280,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(Assembly assembly) public OpenIddictClientSystemNetHttpBuilder SetProductInformation(Assembly assembly)
{ {
if (assembly is null) ArgumentNullException.ThrowIfNull(assembly);
{
throw new ArgumentNullException(nameof(assembly));
}
return SetProductInformation(new ProductInfoHeaderValue( return SetProductInformation(new ProductInfoHeaderValue(
productName: assembly.GetName().Name!, productName: assembly.GetName().Name!,
@ -356,10 +303,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder SetSelfSignedTlsClientAuthenticationCertificateSelector( public OpenIddictClientSystemNetHttpBuilder SetSelfSignedTlsClientAuthenticationCertificateSelector(
Func<OpenIddictClientRegistration, X509Certificate2?> selector) Func<OpenIddictClientRegistration, X509Certificate2?> selector)
{ {
if (selector is null) ArgumentNullException.ThrowIfNull(selector);
{
throw new ArgumentNullException(nameof(selector));
}
return Configure(options => options.SelfSignedTlsClientAuthenticationCertificateSelector = selector); return Configure(options => options.SelfSignedTlsClientAuthenticationCertificateSelector = selector);
} }
@ -380,10 +324,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder SetTlsClientAuthenticationCertificateSelector( public OpenIddictClientSystemNetHttpBuilder SetTlsClientAuthenticationCertificateSelector(
Func<OpenIddictClientRegistration, X509Certificate2?> selector) Func<OpenIddictClientRegistration, X509Certificate2?> selector)
{ {
if (selector is null) ArgumentNullException.ThrowIfNull(selector);
{
throw new ArgumentNullException(nameof(selector));
}
return Configure(options => options.TlsClientAuthenticationCertificateSelector = selector); return Configure(options => options.TlsClientAuthenticationCertificateSelector = selector);
} }

20
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs

@ -42,10 +42,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
/// <inheritdoc/> /// <inheritdoc/>
public void Configure(OpenIddictClientOptions options) public void Configure(OpenIddictClientOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// Register the built-in event handlers used by the OpenIddict System.Net.Http client components. // Register the built-in event handlers used by the OpenIddict System.Net.Http client components.
options.Handlers.AddRange(OpenIddictClientSystemNetHttpHandlers.DefaultHandlers); options.Handlers.AddRange(OpenIddictClientSystemNetHttpHandlers.DefaultHandlers);
@ -62,10 +59,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
/// <inheritdoc/> /// <inheritdoc/>
public void Configure(string? name, HttpClientFactoryOptions options) public void Configure(string? name, HttpClientFactoryOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName(); var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName();
@ -179,10 +173,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, HttpClientFactoryOptions options) public void PostConfigure(string? name, HttpClientFactoryOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName(); var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName();
@ -270,10 +261,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientSystemNetHttpOptions options) public void PostConfigure(string? name, OpenIddictClientSystemNetHttpOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// If no client authentication certificate selector was provided, use fallback delegates that // 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 // automatically use the first X.509 signing certificate attached to the client registration

16
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs

@ -25,10 +25,7 @@ public static class OpenIddictClientSystemNetHttpExtensions
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public static OpenIddictClientSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictClientBuilder builder) public static OpenIddictClientSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictClientBuilder builder)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddHttpClient(); builder.Services.AddHttpClient();
@ -65,15 +62,8 @@ public static class OpenIddictClientSystemNetHttpExtensions
public static OpenIddictClientBuilder UseSystemNetHttp( public static OpenIddictClientBuilder UseSystemNetHttp(
this OpenIddictClientBuilder builder, Action<OpenIddictClientSystemNetHttpBuilder> configuration) this OpenIddictClientBuilder builder, Action<OpenIddictClientSystemNetHttpBuilder> configuration)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(builder.UseSystemNetHttp()); configuration(builder.UseSystemNetHttp());

5
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs

@ -19,10 +19,7 @@ public static class OpenIddictClientSystemNetHttpHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseExternalContext context) public ValueTask<bool> IsActiveAsync(BaseExternalContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new( return new(
string.Equals(context.RemoteUri?.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || string.Equals(context.RemoteUri?.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||

10
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs

@ -62,10 +62,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context) public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008));
@ -103,10 +100,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ExtractUserInfoResponseContext context) public async ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Don't overwrite the response if one was already provided. // Don't overwrite the response if one was already provided.
if (context.Response is not null || !string.IsNullOrEmpty(context.UserInfoToken)) if (context.Response is not null || !string.IsNullOrEmpty(context.UserInfoToken))

118
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs

@ -10,7 +10,6 @@ using System.Diagnostics;
using System.IO.Compression; using System.IO.Compression;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -82,10 +81,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If an explicit client authentication method was attached, don't overwrite it. // If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.TokenEndpointClientAuthenticationMethod)) if (!string.IsNullOrEmpty(context.TokenEndpointClientAuthenticationMethod))
@ -204,10 +200,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Unlike DPoP, the mTLS specification doesn't use a specific token type to represent // 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 // certificate-bound tokens. As such, most implementations (e.g Keycloak) simply return
@ -269,10 +262,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If an explicit client authentication method was attached, don't overwrite it. // If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.DeviceAuthorizationEndpointClientAuthenticationMethod)) if (!string.IsNullOrEmpty(context.DeviceAuthorizationEndpointClientAuthenticationMethod))
@ -399,10 +389,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If an explicit client authentication method was attached, don't overwrite it. // If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.PushedAuthorizationEndpointClientAuthenticationMethod)) if (!string.IsNullOrEmpty(context.PushedAuthorizationEndpointClientAuthenticationMethod))
@ -530,10 +517,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessIntrospectionContext context) public ValueTask HandleAsync(ProcessIntrospectionContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If an explicit client authentication method was attached, don't overwrite it. // If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.IntrospectionEndpointClientAuthenticationMethod)) if (!string.IsNullOrEmpty(context.IntrospectionEndpointClientAuthenticationMethod))
@ -652,10 +636,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRevocationContext context) public ValueTask HandleAsync(ProcessRevocationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If an explicit client authentication method was attached, don't overwrite it. // If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.RevocationEndpointClientAuthenticationMethod)) if (!string.IsNullOrEmpty(context.RevocationEndpointClientAuthenticationMethod))
@ -772,10 +753,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: HttpClientFactory doesn't support flowing a list of properties that can be // Note: HttpClientFactory doesn't support flowing a list of properties that can be
// accessed from the HttpClientAction or HttpMessageHandlerBuilderAction delegates // accessed from the HttpClientAction or HttpMessageHandlerBuilderAction delegates
@ -856,10 +834,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Store the HttpRequestMessage in the transaction properties. // Store the HttpRequestMessage in the transaction properties.
context.Transaction.SetProperty(typeof(HttpRequestMessage).FullName!, context.Transaction.SetProperty(typeof(HttpRequestMessage).FullName!,
@ -888,10 +863,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Store the HttpRequestMessage in the transaction properties. // Store the HttpRequestMessage in the transaction properties.
context.Transaction.SetProperty(typeof(HttpRequestMessage).FullName!, context.Transaction.SetProperty(typeof(HttpRequestMessage).FullName!,
@ -920,10 +892,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION || SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY #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, // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -1013,10 +979,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -1067,10 +1030,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -1103,10 +1063,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -1160,10 +1117,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -1220,10 +1174,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(TContext context) public async ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -1284,10 +1235,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -1322,10 +1270,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(TContext context) public async ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: automatic content decompression can be enabled by constructing an HttpClient wrapping // Note: automatic content decompression can be enabled by constructing an HttpClient wrapping
// a generic HttpClientHandler, a SocketsHttpHandler or a WinHttpHandler instance with the // 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 // 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 // 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. // 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) AppContext.TryGetSwitch("System.Net.Http.UseNativeHttpHandler", out bool value) && value)
{ {
return; return;
@ -1468,10 +1413,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(TContext context) public async ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Don't overwrite the response if one was already provided. // Don't overwrite the response if one was already provided.
if (context.Transaction.Response is not null) if (context.Transaction.Response is not null)
@ -1547,10 +1489,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Don't overwrite the response if one was already provided. // Don't overwrite the response if one was already provided.
if (context.Transaction.Response is not null) if (context.Transaction.Response is not null)
@ -1676,10 +1615,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Don't overwrite the response if one was already provided. // Don't overwrite the response if one was already provided.
if (context.Transaction.Response is not null) if (context.Transaction.Response is not null)
@ -1722,10 +1658,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(TContext context) public async ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -1792,10 +1725,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(TContext context) public ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.

5
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs

@ -35,10 +35,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref="OpenIddictClientWebIntegrationBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientWebIntegrationBuilder"/> instance.</returns>
public OpenIddictClientWebIntegrationBuilder Configure(Action<OpenIddictClientWebIntegrationOptions> configuration) public OpenIddictClientWebIntegrationBuilder Configure(Action<OpenIddictClientWebIntegrationOptions> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure(configuration); Services.Configure(configuration);

15
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationConfiguration.cs

@ -23,10 +23,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfi
/// <inheritdoc/> /// <inheritdoc/>
public void Configure(OpenIddictClientOptions options) public void Configure(OpenIddictClientOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// Register the built-in event handlers used by the OpenIddict client Web components. // Register the built-in event handlers used by the OpenIddict client Web components.
options.Handlers.AddRange(OpenIddictClientWebIntegrationHandlers.DefaultHandlers); options.Handlers.AddRange(OpenIddictClientWebIntegrationHandlers.DefaultHandlers);
@ -35,10 +32,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfi
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientOptions options) public void PostConfigure(string? name, OpenIddictClientOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
options.Registrations.ForEach(static registration => options.Registrations.ForEach(static registration =>
{ {
@ -54,10 +48,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfi
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientSystemNetHttpOptions options) public void PostConfigure(string? name, OpenIddictClientSystemNetHttpOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
// Override the default/user-defined selectors to support attaching TLS client // Override the default/user-defined selectors to support attaching TLS client
// certificates that don't meet the requirements enforced by default by OpenIddict. // certificates that don't meet the requirements enforced by default by OpenIddict.

16
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs

@ -25,10 +25,7 @@ public static partial class OpenIddictClientWebIntegrationExtensions
/// <returns>The <see cref="OpenIddictClientWebIntegrationBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientWebIntegrationBuilder"/> instance.</returns>
public static OpenIddictClientWebIntegrationBuilder UseWebProviders(this OpenIddictClientBuilder builder) public static OpenIddictClientWebIntegrationBuilder UseWebProviders(this OpenIddictClientBuilder builder)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder));
}
// Register the System.Net.Http integration. // Register the System.Net.Http integration.
builder.UseSystemNetHttp(); builder.UseSystemNetHttp();
@ -68,15 +65,8 @@ public static partial class OpenIddictClientWebIntegrationExtensions
public static OpenIddictClientBuilder UseWebProviders( public static OpenIddictClientBuilder UseWebProviders(
this OpenIddictClientBuilder builder, Action<OpenIddictClientWebIntegrationBuilder> configuration) this OpenIddictClientBuilder builder, Action<OpenIddictClientWebIntegrationBuilder> configuration)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(builder.UseWebProviders()); configuration(builder.UseWebProviders());

5
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Authentication.cs

@ -40,10 +40,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareAuthorizationRequestContext context) public ValueTask HandleAsync(PrepareAuthorizationRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Some providers implement old drafts of the OAuth 2.0 specification that didn't support // 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 // the "response_type" parameter but relied on a "type" parameter to determine the type

5
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Device.cs

@ -41,10 +41,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ExtractDeviceAuthorizationResponseContext context) public ValueTask HandleAsync(ExtractDeviceAuthorizationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.Response is null) if (context.Response is null)
{ {

30
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs

@ -45,10 +45,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.Response[Metadata.Issuer] = context.Registration.ProviderType switch context.Response[Metadata.Issuer] = context.Registration.ProviderType switch
{ {
@ -97,10 +94,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: some providers don't list the grant types they support, which prevents the OpenIddict // 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 // client from using them (unless they are assumed to be enabled by default, like the
@ -182,10 +176,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Some providers support Proof Key for Code Exchange but don't list any supported code // 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 // challenge method in the server configuration metadata. To ensure the OpenIddict client
@ -227,10 +218,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Atlassian includes the "openid" scope in its server configuration but doesn't currently allow // 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. // requesting it. To prevent an error from being returned, OpenID Connect support is disabled.
@ -280,10 +268,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Alibaba Cloud doesn't document whether sending client credentials using basic authentication // 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 // is supported and doesn't return a "token_endpoint_auth_methods_supported" nor a
@ -394,10 +379,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// While Atlassian implements an OpenID Connect userinfo endpoint, using it requires // While Atlassian implements an OpenID Connect userinfo endpoint, using it requires
// requesting the "openid" scope, which isn't allowed yet. To work around this // requesting the "openid" scope, which isn't allowed yet. To work around this

30
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs

@ -60,10 +60,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context) public ValueTask HandleAsync(PrepareTokenRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Amazon doesn't support the standard "urn:ietf:params:oauth:grant-type:device_code" // 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. // grant type and requires using the non-standard "device_code" grant type instead.
@ -138,10 +135,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context) public ValueTask HandleAsync(PrepareTokenRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Some providers are known to incorrectly implement basic authentication support, either because // 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 // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context) public ValueTask HandleAsync(PrepareTokenRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -251,10 +242,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context) public ValueTask HandleAsync(PrepareTokenRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -312,10 +300,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context) public ValueTask HandleAsync(PrepareTokenRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -362,10 +347,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ExtractTokenResponseContext context) public ValueTask HandleAsync(ExtractTokenResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.Response is null) if (context.Response is null)
{ {

5
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Introspection.cs

@ -41,10 +41,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ExtractIntrospectionResponseContext context) public ValueTask HandleAsync(ExtractIntrospectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.Response is null) if (context.Response is null)
{ {

10
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Protection.cs

@ -45,10 +45,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context) public ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: the client registration may be null (e.g when validating a state token). // 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. // In this case, don't amend the default token validation parameters.
@ -103,10 +100,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context) public ValueTask HandleAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: the client registration may be null (e.g when generating a state token). // 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. // In this case, don't amend the default security token descriptor.

25
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Revocation.cs

@ -55,10 +55,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareRevocationRequestContext context) public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -106,10 +103,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareRevocationRequestContext context) public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// These providers don't support the standard "token" parameter and // These providers don't support the standard "token" parameter and
// require using the non-standard "access_token" parameter instead. // require using the non-standard "access_token" parameter instead.
@ -167,10 +161,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareRevocationRequestContext context) public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -208,10 +199,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareRevocationRequestContext context) public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -260,10 +248,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ExtractRevocationResponseContext context) public ValueTask HandleAsync(ExtractRevocationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.

40
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs

@ -59,10 +59,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context) public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -106,10 +103,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context) public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -169,10 +163,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context) public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -233,10 +224,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context) public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// ArcGIS Online doesn't support header-based content negotiation and requires using // 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. // the non-standard "f" parameter to get back JSON responses instead of HTML pages.
@ -274,10 +262,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context) public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -325,10 +310,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ExtractUserInfoResponseContext context) public ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved, // 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. // this may indicate that the request was incorrectly processed by another client stack.
@ -390,10 +372,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ExtractUserInfoResponseContext context) public ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007)); Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007));
@ -511,10 +490,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ExtractUserInfoResponseContext context) public ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007)); Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007));

132
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs

@ -87,10 +87,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Shopify returns custom/non-standard parameters like the name of the shop for which the // 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, // installation request was initiated. To prevent these parameters from being tampered with,
@ -151,7 +148,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
try try
{ {
if (!OpenIddictHelpers.FixedTimeEquals( if (!OpenIddictHelpers.FixedTimeEquals(
left : OpenIddictHelpers.ConvertFromHexadecimalString(signature), left : Convert.FromHexString(signature),
right: OpenIddictHelpers.ComputeSha256MessageAuthenticationCode( right: OpenIddictHelpers.ComputeSha256MessageAuthenticationCode(
key : Encoding.UTF8.GetBytes(context.Registration.ClientSecret), key : Encoding.UTF8.GetBytes(context.Registration.ClientSecret),
data: Encoding.UTF8.GetBytes(builder.ToString())))) data: Encoding.UTF8.GetBytes(builder.ToString()))))
@ -200,10 +197,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: some providers are known to return non-standard errors. // Note: some providers are known to return non-standard errors.
// To normalize the set of errors handled by the OpenIddict client, // To normalize the set of errors handled by the OpenIddict client,
@ -349,10 +343,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -466,10 +457,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.TokenEndpointClientAuthenticationMethod = context.Registration.ProviderType switch context.TokenEndpointClientAuthenticationMethod = context.Registration.ProviderType switch
{ {
@ -509,10 +497,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.TokenEndpoint = context.Registration.ProviderType switch context.TokenEndpoint = context.Registration.ProviderType switch
{ {
@ -596,10 +581,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.ClientAssertionPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.ClientAssertionPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -641,10 +623,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@ -707,10 +686,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@ -752,10 +728,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@ -810,10 +783,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
(context.ExtractBackchannelIdentityToken, (context.ExtractBackchannelIdentityToken,
context.RequireBackchannelIdentityToken, context.RequireBackchannelIdentityToken,
@ -860,10 +830,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: despite implementing OpenID Connect, some providers are known to implement the // Note: despite implementing OpenID Connect, some providers are known to implement the
// specification incorrectly and either don't support the "nonce" authorization request // specification incorrectly and either don't support the "nonce" authorization request
@ -905,10 +872,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.SendUserInfoRequest = context.Registration.ProviderType switch context.SendUserInfoRequest = context.Registration.ProviderType switch
{ {
@ -996,10 +960,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: despite implementing OpenID Connect, some providers are known to implement completely custom // 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. // userinfo endpoints or semi-standard endpoints that don't fully conform to the core specification.
@ -1038,10 +999,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.UserInfoEndpoint = context.Registration.ProviderType switch context.UserInfoEndpoint = context.Registration.ProviderType switch
{ {
@ -1131,10 +1089,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.UserInfoRequest is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.UserInfoRequest is not null, SR.GetResourceString(SR.ID4008));
@ -1267,10 +1222,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013)); Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
Debug.Assert(context.TokenResponse is not null, SR.GetResourceString(SR.ID4007)); Debug.Assert(context.TokenResponse is not null, SR.GetResourceString(SR.ID4007));
@ -1372,10 +1324,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context) public ValueTask HandleAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013)); Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@ -1636,10 +1585,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If no explicit shop name was attached to the challenge properties, use the // 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. // shop name set in the provider settings, if set. Otherwise, throw an exception.
@ -1679,10 +1625,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.AuthorizationEndpoint = context.Registration.ProviderType switch context.AuthorizationEndpoint = context.Registration.ProviderType switch
{ {
@ -1755,10 +1698,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.ResponseMode = context.Registration.ProviderType switch context.ResponseMode = context.Registration.ProviderType switch
{ {
@ -1793,10 +1733,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.Request.Scope = context.Registration.ProviderType switch context.Request.Scope = context.Registration.ProviderType switch
{ {
@ -1837,10 +1774,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.RedirectUri is null) if (context.RedirectUri is null)
{ {
@ -1891,10 +1825,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context) public ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Active Directory Federation Services allows sending an optional custom "resource" // Active Directory Federation Services allows sending an optional custom "resource"
// parameter to define what API resources the access token will give access to. // parameter to define what API resources the access token will give access to.
@ -2084,10 +2015,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRevocationContext context) public ValueTask HandleAsync(ProcessRevocationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.RevocationEndpointClientAuthenticationMethod = context.Registration.ProviderType switch context.RevocationEndpointClientAuthenticationMethod = context.Registration.ProviderType switch
{ {
@ -2122,10 +2050,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRevocationContext context) public ValueTask HandleAsync(ProcessRevocationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.ClientAssertionPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.ClientAssertionPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -2167,10 +2092,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ProcessRevocationContext context) public ValueTask HandleAsync(ProcessRevocationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.RevocationRequest is not null, SR.GetResourceString(SR.ID4008)); Debug.Assert(context.RevocationRequest is not null, SR.GetResourceString(SR.ID4008));

203
src/OpenIddict.Client/OpenIddictClientBuilder.cs

@ -7,7 +7,6 @@
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Claims; using System.Security.Claims;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
@ -46,10 +45,7 @@ public sealed class OpenIddictClientBuilder
Action<OpenIddictClientHandlerDescriptor.Builder<TContext>> configuration) Action<OpenIddictClientHandlerDescriptor.Builder<TContext>> configuration)
where TContext : BaseContext where TContext : BaseContext
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
// Note: handlers registered using this API are assumed to be custom handlers by default. // Note: handlers registered using this API are assumed to be custom handlers by default.
var builder = OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>() var builder = OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>()
@ -68,10 +64,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder AddEventHandler(OpenIddictClientHandlerDescriptor descriptor) public OpenIddictClientBuilder AddEventHandler(OpenIddictClientHandlerDescriptor descriptor)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{
throw new ArgumentNullException(nameof(descriptor));
}
// Register the handler in the services collection. // Register the handler in the services collection.
Services.Add(descriptor.ServiceDescriptor); Services.Add(descriptor.ServiceDescriptor);
@ -87,10 +80,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder RemoveEventHandler(OpenIddictClientHandlerDescriptor descriptor) public OpenIddictClientBuilder RemoveEventHandler(OpenIddictClientHandlerDescriptor descriptor)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{
throw new ArgumentNullException(nameof(descriptor));
}
Services.RemoveAll(descriptor.ServiceDescriptor.ServiceType); Services.RemoveAll(descriptor.ServiceDescriptor.ServiceType);
@ -116,10 +106,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder Configure(Action<OpenIddictClientOptions> configuration) public OpenIddictClientBuilder Configure(Action<OpenIddictClientOptions> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure(configuration); Services.Configure(configuration);
@ -133,10 +120,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCredentials(EncryptingCredentials credentials) public OpenIddictClientBuilder AddEncryptionCredentials(EncryptingCredentials credentials)
{ {
if (credentials is null) ArgumentNullException.ThrowIfNull(credentials);
{
throw new ArgumentNullException(nameof(credentials));
}
return Configure(options => options.EncryptionCredentials.Add(credentials)); return Configure(options => options.EncryptionCredentials.Add(credentials));
} }
@ -148,10 +132,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionKey(SecurityKey key) public OpenIddictClientBuilder AddEncryptionKey(SecurityKey key)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
// If the encryption key is an asymmetric security key, ensure it has a private key. // If the encryption key is an asymmetric security key, ensure it has a private key.
if (key is AsymmetricSecurityKey asymmetricSecurityKey && if (key is AsymmetricSecurityKey asymmetricSecurityKey &&
@ -187,10 +168,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionKeys(IEnumerable<SecurityKey> keys) public OpenIddictClientBuilder AddEncryptionKeys(IEnumerable<SecurityKey> keys)
{ {
if (keys is null) ArgumentNullException.ThrowIfNull(keys);
{
throw new ArgumentNullException(nameof(keys));
}
return keys.Aggregate(this, static (builder, key) => builder.AddEncryptionKey(key)); return keys.Aggregate(this, static (builder, key) => builder.AddEncryptionKey(key));
} }
@ -209,10 +187,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddDevelopmentEncryptionCertificate(X500DistinguishedName subject) public OpenIddictClientBuilder AddDevelopmentEncryptionCertificate(X500DistinguishedName subject)
{ {
if (subject is null) ArgumentNullException.ThrowIfNull(subject);
{
throw new ArgumentNullException(nameof(subject));
}
Services.AddOptions<OpenIddictClientOptions>().Configure<IServiceProvider>((options, provider) => Services.AddOptions<OpenIddictClientOptions>().Configure<IServiceProvider>((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). // 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. // 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"; 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. // Note: macOS requires marking the certificate private key as exportable.
// If this flag is not set, a CryptographicException is thrown at runtime. // If this flag is not set, a CryptographicException is thrown at runtime.
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) if (OperatingSystem.IsMacOS())
{ {
flags |= X509KeyStorageFlags.Exportable; flags |= X509KeyStorageFlags.Exportable;
} }
@ -313,10 +288,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEphemeralEncryptionKey(string algorithm) public OpenIddictClientBuilder AddEphemeralEncryptionKey(string algorithm)
{ {
if (string.IsNullOrEmpty(algorithm)) ArgumentException.ThrowIfNullOrEmpty(algorithm);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0057), nameof(algorithm));
}
return algorithm switch return algorithm switch
{ {
@ -342,10 +314,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificate(X509Certificate2 certificate) public OpenIddictClientBuilder AddEncryptionCertificate(X509Certificate2 certificate)
{ {
if (certificate is null) ArgumentNullException.ThrowIfNull(certificate);
{
throw new ArgumentNullException(nameof(certificate));
}
// If the certificate is a X.509v3 certificate that specifies at least one // 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. // 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) public OpenIddictClientBuilder AddEncryptionCertificate(Assembly assembly, string resource, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS #if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS. // 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.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet); X509KeyStorageFlags.EphemeralKeySet);
#else #else
@ -396,15 +365,8 @@ public sealed class OpenIddictClientBuilder
Assembly assembly, string resource, Assembly assembly, string resource,
string? password, X509KeyStorageFlags flags) string? password, X509KeyStorageFlags flags)
{ {
if (assembly is null) ArgumentNullException.ThrowIfNull(assembly);
{ ArgumentException.ThrowIfNullOrEmpty(resource);
throw new ArgumentNullException(nameof(assembly));
}
if (string.IsNullOrEmpty(resource))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
using var stream = assembly.GetManifestResourceStream(resource) ?? using var stream = assembly.GetManifestResourceStream(resource) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0064)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0064));
@ -421,7 +383,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream, string? password) public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS #if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS. // 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.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet); X509KeyStorageFlags.EphemeralKeySet);
#else #else
@ -437,10 +399,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream, string? password, X509KeyStorageFlags flags) public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream, string? password, X509KeyStorageFlags flags)
{ {
if (stream is null) ArgumentNullException.ThrowIfNull(stream);
{
throw new ArgumentNullException(nameof(stream));
}
using var buffer = new MemoryStream(); using var buffer = new MemoryStream();
stream.CopyTo(buffer); stream.CopyTo(buffer);
@ -465,10 +424,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificate(string thumbprint) public OpenIddictClientBuilder AddEncryptionCertificate(string thumbprint)
{ {
if (string.IsNullOrEmpty(thumbprint)) ArgumentException.ThrowIfNullOrEmpty(thumbprint);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
return AddEncryptionCertificate( return AddEncryptionCertificate(
GetCertificate(StoreLocation.CurrentUser, thumbprint) ?? GetCertificate(StoreLocation.CurrentUser, thumbprint) ??
@ -495,10 +451,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificate(string thumbprint, StoreName name, StoreLocation location) public OpenIddictClientBuilder AddEncryptionCertificate(string thumbprint, StoreName name, StoreLocation location)
{ {
if (string.IsNullOrEmpty(thumbprint)) ArgumentException.ThrowIfNullOrEmpty(thumbprint);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
using var store = new X509Store(name, location); using var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly); store.Open(OpenFlags.ReadOnly);
@ -516,11 +469,8 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificates(IEnumerable<X509Certificate2> certificates) public OpenIddictClientBuilder AddEncryptionCertificates(IEnumerable<X509Certificate2> certificates)
{ {
if (certificates is null) ArgumentNullException.ThrowIfNull(certificates);
{
throw new ArgumentNullException(nameof(certificates));
}
return certificates.Aggregate(this, static (builder, certificate) => builder.AddEncryptionCertificate(certificate)); return certificates.Aggregate(this, static (builder, certificate) => builder.AddEncryptionCertificate(certificate));
} }
@ -531,10 +481,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCredentials(SigningCredentials credentials) public OpenIddictClientBuilder AddSigningCredentials(SigningCredentials credentials)
{ {
if (credentials is null) ArgumentNullException.ThrowIfNull(credentials);
{
throw new ArgumentNullException(nameof(credentials));
}
return Configure(options => options.SigningCredentials.Add(credentials)); return Configure(options => options.SigningCredentials.Add(credentials));
} }
@ -546,10 +493,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningKey(SecurityKey key) public OpenIddictClientBuilder AddSigningKey(SecurityKey key)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
// If the signing key is an asymmetric security key, ensure it has a private key. // If the signing key is an asymmetric security key, ensure it has a private key.
if (key is AsymmetricSecurityKey asymmetricSecurityKey && if (key is AsymmetricSecurityKey asymmetricSecurityKey &&
@ -603,10 +547,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningKeys(IEnumerable<SecurityKey> keys) public OpenIddictClientBuilder AddSigningKeys(IEnumerable<SecurityKey> keys)
{ {
if (keys is null) ArgumentNullException.ThrowIfNull(keys);
{
throw new ArgumentNullException(nameof(keys));
}
return keys.Aggregate(this, static (builder, key) => builder.AddSigningKey(key)); return keys.Aggregate(this, static (builder, key) => builder.AddSigningKey(key));
} }
@ -625,10 +566,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddDevelopmentSigningCertificate(X500DistinguishedName subject) public OpenIddictClientBuilder AddDevelopmentSigningCertificate(X500DistinguishedName subject)
{ {
if (subject is null) ArgumentNullException.ThrowIfNull(subject);
{
throw new ArgumentNullException(nameof(subject));
}
Services.AddOptions<OpenIddictClientOptions>().Configure<IServiceProvider>((options, provider) => Services.AddOptions<OpenIddictClientOptions>().Configure<IServiceProvider>((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). // 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. // 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"; 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. // Note: macOS requires marking the certificate private key as exportable.
// If this flag is not set, a CryptographicException is thrown at runtime. // If this flag is not set, a CryptographicException is thrown at runtime.
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) if (OperatingSystem.IsMacOS())
{ {
flags |= X509KeyStorageFlags.Exportable; flags |= X509KeyStorageFlags.Exportable;
} }
@ -728,10 +666,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEphemeralSigningKey(string algorithm) public OpenIddictClientBuilder AddEphemeralSigningKey(string algorithm)
{ {
if (string.IsNullOrEmpty(algorithm)) ArgumentException.ThrowIfNullOrEmpty(algorithm);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0057), nameof(algorithm));
}
return algorithm switch return algorithm switch
{ {
@ -786,10 +721,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificate(X509Certificate2 certificate) public OpenIddictClientBuilder AddSigningCertificate(X509Certificate2 certificate)
{ {
if (certificate is null) ArgumentNullException.ThrowIfNull(certificate);
{
throw new ArgumentNullException(nameof(certificate));
}
// If the certificate is a X.509v3 certificate that specifies at least // 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. // 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) public OpenIddictClientBuilder AddSigningCertificate(Assembly assembly, string resource, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS #if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS. // 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.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet); X509KeyStorageFlags.EphemeralKeySet);
#else #else
@ -840,15 +772,8 @@ public sealed class OpenIddictClientBuilder
Assembly assembly, string resource, Assembly assembly, string resource,
string? password, X509KeyStorageFlags flags) string? password, X509KeyStorageFlags flags)
{ {
if (assembly is null) ArgumentNullException.ThrowIfNull(assembly);
{ ArgumentException.ThrowIfNullOrEmpty(resource);
throw new ArgumentNullException(nameof(assembly));
}
if (string.IsNullOrEmpty(resource))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
using var stream = assembly.GetManifestResourceStream(resource) ?? using var stream = assembly.GetManifestResourceStream(resource) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0064)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0064));
@ -865,7 +790,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddSigningCertificate(Stream stream, string? password) public OpenIddictClientBuilder AddSigningCertificate(Stream stream, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS #if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS. // 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.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet); X509KeyStorageFlags.EphemeralKeySet);
#else #else
@ -881,10 +806,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificate(Stream stream, string? password, X509KeyStorageFlags flags) public OpenIddictClientBuilder AddSigningCertificate(Stream stream, string? password, X509KeyStorageFlags flags)
{ {
if (stream is null) ArgumentNullException.ThrowIfNull(stream);
{
throw new ArgumentNullException(nameof(stream));
}
using var buffer = new MemoryStream(); using var buffer = new MemoryStream();
stream.CopyTo(buffer); stream.CopyTo(buffer);
@ -909,10 +831,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificate(string thumbprint) public OpenIddictClientBuilder AddSigningCertificate(string thumbprint)
{ {
if (string.IsNullOrEmpty(thumbprint)) ArgumentException.ThrowIfNullOrEmpty(thumbprint);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
return AddSigningCertificate( return AddSigningCertificate(
GetCertificate(StoreLocation.CurrentUser, thumbprint) ?? GetCertificate(StoreLocation.CurrentUser, thumbprint) ??
@ -939,10 +858,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificate(string thumbprint, StoreName name, StoreLocation location) public OpenIddictClientBuilder AddSigningCertificate(string thumbprint, StoreName name, StoreLocation location)
{ {
if (string.IsNullOrEmpty(thumbprint)) ArgumentException.ThrowIfNullOrEmpty(thumbprint);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
using var store = new X509Store(name, location); using var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly); store.Open(OpenFlags.ReadOnly);
@ -960,11 +876,8 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificates(IEnumerable<X509Certificate2> certificates) public OpenIddictClientBuilder AddSigningCertificates(IEnumerable<X509Certificate2> certificates)
{ {
if (certificates is null) ArgumentNullException.ThrowIfNull(certificates);
{
throw new ArgumentNullException(nameof(certificates));
}
return certificates.Aggregate(this, static (builder, certificate) => builder.AddSigningCertificate(certificate)); return certificates.Aggregate(this, static (builder, certificate) => builder.AddSigningCertificate(certificate));
} }
@ -975,10 +888,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddRegistration(OpenIddictClientRegistration registration) public OpenIddictClientBuilder AddRegistration(OpenIddictClientRegistration registration)
{ {
if (registration is null) ArgumentNullException.ThrowIfNull(registration);
{
throw new ArgumentNullException(nameof(registration));
}
return Configure(options => options.Registrations.Add(registration)); return Configure(options => options.Registrations.Add(registration));
} }
@ -1038,10 +948,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder AllowCustomFlow(string type) public OpenIddictClientBuilder AllowCustomFlow(string type)
{ {
if (string.IsNullOrEmpty(type)) ArgumentException.ThrowIfNullOrEmpty(type);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0071), nameof(type));
}
return Configure(options => options.GrantTypes.Add(type)); return Configure(options => options.GrantTypes.Add(type));
} }
@ -1138,10 +1045,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder SetPostLogoutRedirectionEndpointUris( public OpenIddictClientBuilder SetPostLogoutRedirectionEndpointUris(
[StringSyntax(StringSyntaxAttribute.Uri)] params string[] uris) [StringSyntax(StringSyntaxAttribute.Uri)] params string[] uris)
{ {
if (uris is null) ArgumentNullException.ThrowIfNull(uris);
{
throw new ArgumentNullException(nameof(uris));
}
return SetPostLogoutRedirectionEndpointUris([.. uris.Select(uri => new Uri(uri, UriKind.RelativeOrAbsolute))]); return SetPostLogoutRedirectionEndpointUris([.. uris.Select(uri => new Uri(uri, UriKind.RelativeOrAbsolute))]);
} }
@ -1154,10 +1058,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder SetPostLogoutRedirectionEndpointUris(params Uri[] uris) public OpenIddictClientBuilder SetPostLogoutRedirectionEndpointUris(params Uri[] uris)
{ {
if (uris is null) ArgumentNullException.ThrowIfNull(uris);
{
throw new ArgumentNullException(nameof(uris));
}
if (Array.Exists(uris, OpenIddictHelpers.IsImplicitFileUri)) if (Array.Exists(uris, OpenIddictHelpers.IsImplicitFileUri))
{ {
@ -1191,10 +1092,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder SetRedirectionEndpointUris( public OpenIddictClientBuilder SetRedirectionEndpointUris(
[StringSyntax(StringSyntaxAttribute.Uri)] params string[] uris) [StringSyntax(StringSyntaxAttribute.Uri)] params string[] uris)
{ {
if (uris is null) ArgumentNullException.ThrowIfNull(uris);
{
throw new ArgumentNullException(nameof(uris));
}
return SetRedirectionEndpointUris([.. uris.Select(uri => new Uri(uri, UriKind.RelativeOrAbsolute))]); return SetRedirectionEndpointUris([.. uris.Select(uri => new Uri(uri, UriKind.RelativeOrAbsolute))]);
} }
@ -1213,10 +1111,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder SetRedirectionEndpointUris(params Uri[] uris) public OpenIddictClientBuilder SetRedirectionEndpointUris(params Uri[] uris)
{ {
if (uris is null) ArgumentNullException.ThrowIfNull(uris);
{
throw new ArgumentNullException(nameof(uris));
}
if (Array.Exists(uris, OpenIddictHelpers.IsImplicitFileUri)) if (Array.Exists(uris, OpenIddictHelpers.IsImplicitFileUri))
{ {
@ -1265,10 +1160,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder SetClientUri(Uri uri) public OpenIddictClientBuilder SetClientUri(Uri uri)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{
throw new ArgumentNullException(nameof(uri));
}
return Configure(options => options.ClientUri = uri); return Configure(options => options.ClientUri = uri);
} }
@ -1282,10 +1174,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder SetClientUri( public OpenIddictClientBuilder SetClientUri(
[StringSyntax(StringSyntaxAttribute.Uri, UriKind.Absolute)] string uri) [StringSyntax(StringSyntaxAttribute.Uri, UriKind.Absolute)] string uri)
{ {
if (string.IsNullOrEmpty(uri)) ArgumentException.ThrowIfNullOrEmpty(uri);
{
throw new ArgumentException(SR.FormatID0366(nameof(uri)), nameof(uri));
}
if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value)) if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value))
{ {

5
src/OpenIddict.Client/OpenIddictClientConfiguration.cs

@ -40,10 +40,7 @@ public sealed class OpenIddictClientConfiguration : IPostConfigureOptions<OpenId
/// <inheritdoc/> /// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientOptions options) public void PostConfigure(string? name, OpenIddictClientOptions options)
{ {
if (options is null) ArgumentNullException.ThrowIfNull(options);
{
throw new ArgumentNullException(nameof(options));
}
if (options.JsonWebTokenHandler is null) if (options.JsonWebTokenHandler is null)
{ {

5
src/OpenIddict.Client/OpenIddictClientDispatcher.cs

@ -36,10 +36,7 @@ public sealed class OpenIddictClientDispatcher : IOpenIddictClientDispatcher
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask DispatchAsync<TContext>(TContext context) where TContext : BaseContext public async ValueTask DispatchAsync<TContext>(TContext context) where TContext : BaseContext
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
await foreach (var handler in GetHandlersAsync()) await foreach (var handler in GetHandlersAsync())
{ {

16
src/OpenIddict.Client/OpenIddictClientExtensions.cs

@ -23,10 +23,7 @@ public static class OpenIddictClientExtensions
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public static OpenIddictClientBuilder AddClient(this OpenIddictBuilder builder) public static OpenIddictClientBuilder AddClient(this OpenIddictBuilder builder)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddLogging(); builder.Services.AddLogging();
builder.Services.AddOptions(); builder.Services.AddOptions();
@ -98,15 +95,8 @@ public static class OpenIddictClientExtensions
/// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns>
public static OpenIddictBuilder AddClient(this OpenIddictBuilder builder, Action<OpenIddictClientBuilder> configuration) public static OpenIddictBuilder AddClient(this OpenIddictBuilder builder, Action<OpenIddictClientBuilder> configuration)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(builder.AddClient()); configuration(builder.AddClient());

10
src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs

@ -88,10 +88,7 @@ public sealed class OpenIddictClientHandlerDescriptor
/// <returns>The builder instance, so that calls can be easily chained.</returns> /// <returns>The builder instance, so that calls can be easily chained.</returns>
public Builder<TContext> Import(OpenIddictClientHandlerDescriptor descriptor) public Builder<TContext> Import(OpenIddictClientHandlerDescriptor descriptor)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{
throw new ArgumentNullException(nameof(descriptor));
}
if (descriptor.ContextType != typeof(TContext)) if (descriptor.ContextType != typeof(TContext))
{ {
@ -114,10 +111,7 @@ public sealed class OpenIddictClientHandlerDescriptor
/// <returns>The builder instance, so that calls can be easily chained.</returns> /// <returns>The builder instance, so that calls can be easily chained.</returns>
public Builder<TContext> SetServiceDescriptor(ServiceDescriptor descriptor) public Builder<TContext> SetServiceDescriptor(ServiceDescriptor descriptor)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{
throw new ArgumentNullException(nameof(descriptor));
}
if (!typeof(IOpenIddictClientHandler<TContext>).IsAssignableFrom(descriptor.ServiceType)) if (!typeof(IOpenIddictClientHandler<TContext>).IsAssignableFrom(descriptor.ServiceType))
{ {

210
src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs

@ -19,10 +19,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.ValidateAuthorizationCode); return new(context.ValidateAuthorizationCode);
} }
@ -36,10 +33,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.ValidateBackchannelAccessToken); return new(context.ValidateBackchannelAccessToken);
} }
@ -53,10 +47,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!context.DisableBackchannelIdentityTokenNonceValidation); return new(!context.DisableBackchannelIdentityTokenNonceValidation);
} }
@ -70,10 +61,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.BackchannelIdentityTokenPrincipal is not null); return new(context.BackchannelIdentityTokenPrincipal is not null);
} }
@ -87,10 +75,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.ValidateBackchannelIdentityToken); return new(context.ValidateBackchannelIdentityToken);
} }
@ -104,10 +89,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context) public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.GenerateClientAssertion); return new(context.GenerateClientAssertion);
} }
@ -123,10 +105,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.GenerateClientAssertion); return new(context.GenerateClientAssertion);
} }
@ -134,10 +113,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
ValueTask<bool> IOpenIddictClientHandlerFilter<ProcessRevocationContext>.IsActiveAsync(ProcessRevocationContext context) ValueTask<bool> IOpenIddictClientHandlerFilter<ProcessRevocationContext>.IsActiveAsync(ProcessRevocationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.GenerateClientAssertion); return new(context.GenerateClientAssertion);
} }
@ -152,10 +128,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context) public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.GrantType is GrantTypes.DeviceCode); return new(context.GrantType is GrantTypes.DeviceCode);
} }
@ -169,10 +142,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context) public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.SendDeviceAuthorizationRequest); return new(context.SendDeviceAuthorizationRequest);
} }
@ -186,10 +156,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.ValidateFrontchannelAccessToken); return new(context.ValidateFrontchannelAccessToken);
} }
@ -203,10 +170,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!context.DisableFrontchannelIdentityTokenNonceValidation); return new(!context.DisableFrontchannelIdentityTokenNonceValidation);
} }
@ -220,10 +184,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.FrontchannelIdentityTokenPrincipal is not null); return new(context.FrontchannelIdentityTokenPrincipal is not null);
} }
@ -237,10 +198,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.ValidateFrontchannelIdentityToken); return new(context.ValidateFrontchannelIdentityToken);
} }
@ -255,10 +213,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context) public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.GrantType switch return new(context.GrantType switch
{ {
@ -277,10 +232,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessIntrospectionContext context) public ValueTask<bool> IsActiveAsync(ProcessIntrospectionContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.GenerateClientAssertion); return new(context.GenerateClientAssertion);
} }
@ -294,10 +246,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessIntrospectionContext context) public ValueTask<bool> IsActiveAsync(ProcessIntrospectionContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.SendIntrospectionRequest); return new(context.SendIntrospectionRequest);
} }
@ -311,10 +260,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.ValidateIssuedToken); return new(context.ValidateIssuedToken);
} }
@ -328,10 +274,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(GenerateTokenContext context) public ValueTask<bool> IsActiveAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.TokenFormat is TokenFormats.Private.JsonWebToken); return new(context.TokenFormat is TokenFormats.Private.JsonWebToken);
} }
@ -345,10 +288,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context) public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.GenerateStateToken); return new(context.GenerateStateToken);
} }
@ -362,10 +302,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessSignOutContext context) public ValueTask<bool> IsActiveAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.GenerateStateToken); return new(context.GenerateStateToken);
} }
@ -379,10 +316,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.EndpointType is OpenIddictClientEndpointType.PostLogoutRedirection); return new(context.EndpointType is OpenIddictClientEndpointType.PostLogoutRedirection);
} }
@ -396,10 +330,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context) public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.SendPushedAuthorizationRequest); return new(context.SendPushedAuthorizationRequest);
} }
@ -413,10 +344,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.EndpointType is OpenIddictClientEndpointType.Redirection); return new(context.EndpointType is OpenIddictClientEndpointType.Redirection);
} }
@ -430,10 +358,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.ValidateRefreshToken); return new(context.ValidateRefreshToken);
} }
@ -447,10 +372,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessRevocationContext context) public ValueTask<bool> IsActiveAsync(ProcessRevocationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.GenerateClientAssertion); return new(context.GenerateClientAssertion);
} }
@ -464,10 +386,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessRevocationContext context) public ValueTask<bool> IsActiveAsync(ProcessRevocationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.SendRevocationRequest); return new(context.SendRevocationRequest);
} }
@ -481,10 +400,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.StateTokenPrincipal is not null); return new(context.StateTokenPrincipal is not null);
} }
@ -498,10 +414,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.ValidateStateToken); return new(context.ValidateStateToken);
} }
@ -515,10 +428,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ValidateTokenContext context) public ValueTask<bool> IsActiveAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!context.DisableAudienceValidation); return new(!context.DisableAudienceValidation);
} }
@ -532,10 +442,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(GenerateTokenContext context) public ValueTask<bool> IsActiveAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.CreateTokenEntry); return new(context.CreateTokenEntry);
} }
@ -549,10 +456,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ValidateTokenContext context) public ValueTask<bool> IsActiveAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!string.IsNullOrEmpty(context.TokenId)); return new(!string.IsNullOrEmpty(context.TokenId));
} }
@ -566,10 +470,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ValidateTokenContext context) public ValueTask<bool> IsActiveAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!context.DisableLifetimeValidation); return new(!context.DisableLifetimeValidation);
} }
@ -583,10 +484,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(GenerateTokenContext context) public ValueTask<bool> IsActiveAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.PersistTokenPayload); return new(context.PersistTokenPayload);
} }
@ -600,10 +498,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ValidateTokenContext context) public ValueTask<bool> IsActiveAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!context.DisablePresenterValidation); return new(!context.DisablePresenterValidation);
} }
@ -617,10 +512,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.SendTokenRequest); return new(context.SendTokenRequest);
} }
@ -634,10 +526,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!context.Options.DisableTokenStorage); return new(!context.Options.DisableTokenStorage);
} }
@ -651,10 +540,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.SendUserInfoRequest); return new(context.SendUserInfoRequest);
} }
@ -668,10 +554,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.ExtractUserInfoToken); return new(context.ExtractUserInfoToken);
} }
@ -685,10 +568,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(context.UserInfoTokenPrincipal is not null); return new(context.UserInfoTokenPrincipal is not null);
} }
@ -702,10 +582,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context) public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!context.DisableUserInfoValidation); return new(!context.DisableUserInfoValidation);
} }
@ -719,10 +596,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context) public ValueTask<bool> IsActiveAsync(BaseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
return new(!context.Options.DisableWebServicesFederationClaimMapping); return new(!context.Options.DisableWebServicesFederationClaimMapping);
} }

65
src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs

@ -78,10 +78,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessChallengeContext context) public async ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new PrepareAuthorizationRequestContext(context.Transaction); var notification = new PrepareAuthorizationRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -123,10 +120,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessChallengeContext context) public async ValueTask HandleAsync(ProcessChallengeContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ApplyAuthorizationRequestContext(context.Transaction) var notification = new ApplyAuthorizationRequestContext(context.Transaction)
{ {
@ -178,10 +172,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ApplyAuthorizationRequestContext context) public ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Don't overwrite the endpoint URI if it was already set. // Don't overwrite the endpoint URI if it was already set.
if (!string.IsNullOrEmpty(context.AuthorizationEndpoint)) if (!string.IsNullOrEmpty(context.AuthorizationEndpoint))
@ -220,10 +211,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context) public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
foreach (var parameter in context.Response.GetParameters()) foreach (var parameter in context.Response.GetParameters())
{ {
@ -284,10 +272,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context) public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2. // For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
if (!string.IsNullOrEmpty(context.Response.Error)) if (!string.IsNullOrEmpty(context.Response.Error))
@ -331,10 +316,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context) public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Return an error if the mandatory "request_uri" parameter is missing. // Return an error if the mandatory "request_uri" parameter is missing.
// //
@ -384,10 +366,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context) public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Return an error if the mandatory "expires_in" parameter is missing. // Return an error if the mandatory "expires_in" parameter is missing.
// //
@ -429,10 +408,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context) public async ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ExtractRedirectionRequestContext(context.Transaction); var notification = new ExtractRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -491,10 +467,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context) public async ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ValidateRedirectionRequestContext(context.Transaction); var notification = new ValidateRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -547,10 +520,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context) public async ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new HandleRedirectionRequestContext(context.Transaction); var notification = new HandleRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -604,10 +574,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(TContext context) public async ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ApplyRedirectionResponseContext(context.Transaction); var notification = new ApplyRedirectionResponseContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -646,10 +613,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(PrepareAuthorizationRequestContext context) public ValueTask HandleAsync(PrepareAuthorizationRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// When the response mode corresponds to the default mode assigned to the selected // When the response mode corresponds to the default mode assigned to the selected
// response type, the specification explicitly recommends omitting the response mode. // response type, the specification explicitly recommends omitting the response mode.
@ -697,10 +661,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ValidateRedirectionRequestContext context) public async ValueTask HandleAsync(ValidateRedirectionRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ProcessAuthenticationContext(context.Transaction); var notification = new ProcessAuthenticationContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);

20
src/OpenIddict.Client/OpenIddictClientHandlers.Device.cs

@ -43,10 +43,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context) public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
foreach (var parameter in context.Response.GetParameters()) foreach (var parameter in context.Response.GetParameters())
{ {
@ -113,10 +110,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context) public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2. // For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
if (!string.IsNullOrEmpty(context.Response.Error)) if (!string.IsNullOrEmpty(context.Response.Error))
@ -161,10 +155,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context) public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Return an error if the mandatory "verification_uri" parameter is missing. // 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. // For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
@ -227,10 +218,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context) public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Return an error if the mandatory "expires_in" parameter is missing. // 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. // For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.

170
src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs

@ -78,10 +78,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
foreach (var parameter in context.Response.GetParameters()) foreach (var parameter in context.Response.GetParameters())
{ {
@ -171,10 +168,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: the specification doesn't define a standard way to return an error other than // 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 // returning a 4xx status code. That said, some implementations are known to return
@ -214,10 +208,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: the issuer returned in the discovery document must exactly match the URI used to access it. // 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. // See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationValidation.
@ -278,10 +269,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: the authorization_endpoint node is required by the OpenID Connect discovery specification // 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 // but is optional in the OAuth 2.0 authorization server metadata specification. To make OpenIddict
@ -330,10 +318,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: the jwks_uri node is required by the OpenID Connect discovery specification. // 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. // See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationClient.
@ -382,10 +367,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var endpoint = (string?) context.Response[Metadata.DeviceAuthorizationEndpoint]; var endpoint = (string?) context.Response[Metadata.DeviceAuthorizationEndpoint];
if (!string.IsNullOrEmpty(endpoint)) if (!string.IsNullOrEmpty(endpoint))
@ -425,10 +407,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var endpoint = (string?) context.Response[Metadata.IntrospectionEndpoint]; var endpoint = (string?) context.Response[Metadata.IntrospectionEndpoint];
if (!string.IsNullOrEmpty(endpoint)) if (!string.IsNullOrEmpty(endpoint))
@ -468,10 +447,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var endpoint = (string?) context.Response[Metadata.EndSessionEndpoint]; var endpoint = (string?) context.Response[Metadata.EndSessionEndpoint];
if (!string.IsNullOrEmpty(endpoint)) if (!string.IsNullOrEmpty(endpoint))
@ -512,10 +488,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node // 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. // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node // 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. // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node // 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. // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node // 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. // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node // 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. // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node // 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. // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var endpoint = (string?) context.Response[Metadata.PushedAuthorizationRequestEndpoint]; var endpoint = (string?) context.Response[Metadata.PushedAuthorizationRequestEndpoint];
if (!string.IsNullOrEmpty(endpoint)) if (!string.IsNullOrEmpty(endpoint))
@ -766,10 +721,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var endpoint = (string?) context.Response[Metadata.RevocationEndpoint]; var endpoint = (string?) context.Response[Metadata.RevocationEndpoint];
if (!string.IsNullOrEmpty(endpoint)) if (!string.IsNullOrEmpty(endpoint))
@ -809,10 +761,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var endpoint = (string?) context.Response[Metadata.TokenEndpoint]; var endpoint = (string?) context.Response[Metadata.TokenEndpoint];
if (!string.IsNullOrEmpty(endpoint)) if (!string.IsNullOrEmpty(endpoint))
@ -852,10 +801,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var endpoint = (string?) context.Response[Metadata.UserInfoEndpoint]; var endpoint = (string?) context.Response[Metadata.UserInfoEndpoint];
if (!string.IsNullOrEmpty(endpoint)) if (!string.IsNullOrEmpty(endpoint))
@ -895,10 +841,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the grant types supported by the authorization endpoint, if available. // Resolve the grant types supported by the authorization endpoint, if available.
foreach (var type in (ImmutableArray<string?>?) context.Response[Metadata.GrantTypesSupported] ?? []) foreach (var type in (ImmutableArray<string?>?) context.Response[Metadata.GrantTypesSupported] ?? [])
@ -931,10 +874,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the response modes supported by the authorization endpoint, if available. // Resolve the response modes supported by the authorization endpoint, if available.
foreach (var mode in (ImmutableArray<string?>?) context.Response[Metadata.ResponseModesSupported] ?? []) foreach (var mode in (ImmutableArray<string?>?) context.Response[Metadata.ResponseModesSupported] ?? [])
@ -967,10 +907,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the response types supported by the authorization endpoint, if available. // Resolve the response types supported by the authorization endpoint, if available.
foreach (var type in (ImmutableArray<string?>?) context.Response[Metadata.ResponseTypesSupported] ?? []) foreach (var type in (ImmutableArray<string?>?) context.Response[Metadata.ResponseTypesSupported] ?? [])
@ -1003,10 +940,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the code challenge methods supported by the authorization endpoint, if available. // Resolve the code challenge methods supported by the authorization endpoint, if available.
foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.CodeChallengeMethodsSupported] ?? []) foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.CodeChallengeMethodsSupported] ?? [])
@ -1039,10 +973,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the scopes supported by the remote server, if available. // Resolve the scopes supported by the remote server, if available.
foreach (var scope in (ImmutableArray<string?>?) context.Response[Metadata.ScopesSupported] ?? []) foreach (var scope in (ImmutableArray<string?>?) context.Response[Metadata.ScopesSupported] ?? [])
@ -1076,10 +1007,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.Configuration.AuthorizationResponseIssParameterSupported = (bool?) context.Configuration.AuthorizationResponseIssParameterSupported = (bool?)
context.Response[Metadata.AuthorizationResponseIssParameterSupported]; context.Response[Metadata.AuthorizationResponseIssParameterSupported];
@ -1107,10 +1035,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.Configuration.TlsClientCertificateBoundAccessTokens = (bool?) context.Configuration.TlsClientCertificateBoundAccessTokens = (bool?)
context.Response[Metadata.TlsClientCertificateBoundAccessTokens]; context.Response[Metadata.TlsClientCertificateBoundAccessTokens];
@ -1138,10 +1063,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.Configuration.RequirePushedAuthorizationRequests = (bool?) context.Configuration.RequirePushedAuthorizationRequests = (bool?)
context.Response[Metadata.RequirePushedAuthorizationRequests]; context.Response[Metadata.RequirePushedAuthorizationRequests];
@ -1169,10 +1091,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the client authentication methods supported by the device authorization endpoint, if available. // Resolve the client authentication methods supported by the device authorization endpoint, if available.
// //
@ -1209,10 +1128,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the client authentication methods supported by the introspection endpoint, if available. // Resolve the client authentication methods supported by the introspection endpoint, if available.
foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.IntrospectionEndpointAuthMethodsSupported] ?? []) foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.IntrospectionEndpointAuthMethodsSupported] ?? [])
@ -1246,10 +1162,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the client authentication methods supported by the pushed authorization endpoint, if available. // Resolve the client authentication methods supported by the pushed authorization endpoint, if available.
// //
@ -1286,10 +1199,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the client authentication methods supported by the revocation endpoint, if available. // Resolve the client authentication methods supported by the revocation endpoint, if available.
foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.RevocationEndpointAuthMethodsSupported] ?? []) foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.RevocationEndpointAuthMethodsSupported] ?? [])
@ -1323,10 +1233,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context) public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Resolve the client authentication methods supported by the token endpoint, if available. // Resolve the client authentication methods supported by the token endpoint, if available.
foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.TokenEndpointAuthMethodsSupported] ?? []) foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.TokenEndpointAuthMethodsSupported] ?? [])
@ -1359,10 +1266,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context) public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
foreach (var parameter in context.Response.GetParameters()) foreach (var parameter in context.Response.GetParameters())
{ {
@ -1421,10 +1325,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context) public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: the specification doesn't define a standard way to return an error other than // 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 // returning a 4xx status code. That said, some implementations are known to return
@ -1464,10 +1365,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context) public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var keys = context.Response[JsonWebKeySetParameterNames.Keys]?.GetUnnamedParameters(); var keys = context.Response[JsonWebKeySetParameterNames.Keys]?.GetUnnamedParameters();
if (keys is not { Count: > 0 }) if (keys is not { Count: > 0 })

10
src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs

@ -41,10 +41,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleTokenResponseContext context) public ValueTask HandleAsync(HandleTokenResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
foreach (var parameter in context.Response.GetParameters()) foreach (var parameter in context.Response.GetParameters())
{ {
@ -107,10 +104,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleTokenResponseContext context) public ValueTask HandleAsync(HandleTokenResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// For more information, see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2. // For more information, see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2.
if (!string.IsNullOrEmpty(context.Response.Error)) if (!string.IsNullOrEmpty(context.Response.Error))

40
src/OpenIddict.Client/OpenIddictClientHandlers.Introspection.cs

@ -50,10 +50,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context) public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
foreach (var parameter in context.Response.GetParameters()) foreach (var parameter in context.Response.GetParameters())
{ {
@ -127,10 +124,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context) public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: the specification requires returning most errors (e.g invalid token errors) // 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. // as "active: false" responses instead of as proper OAuth 2.0 error responses.
@ -173,10 +167,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context) public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: the introspection specification requires that server return "active: false" instead of a proper // 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. // 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
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context) public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// The issuer claim is optional. If it's not null or empty, validate it to // 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. // ensure it matches the issuer registered in the server configuration.
@ -280,10 +268,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context) public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: in most cases, an expired token should lead to an errored or "active=false" response // 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 // being returned by the authorization server. Unfortunately, some implementations are known not
@ -327,10 +312,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context) public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// OpenIddict-based authorization servers always return the actual token type using // OpenIddict-based authorization servers always return the actual token type using
// the special "token_usage" claim, that helps resource servers determine whether the // the special "token_usage" claim, that helps resource servers determine whether the
@ -383,10 +365,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context) public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013)); Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@ -476,10 +455,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context) public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));

85
src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs

@ -64,10 +64,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context) public ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// The OpenIddict client is expected to validate tokens it creates (e.g state tokens) and // 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). // tokens that are created by one or multiple authorization servers (e.g identity tokens).
@ -206,10 +203,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context) public ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If no character was explicitly added, all characters are considered valid. // If no character was explicitly added, all characters are considered valid.
if (context.AllowedCharset.Count is 0) if (context.AllowedCharset.Count is 0)
@ -262,10 +256,7 @@ public static partial class OpenIddictClientHandlers
public async ValueTask HandleAsync(ValidateTokenContext context) public async ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: reference tokens are only used for state tokens. // Note: reference tokens are only used for state tokens.
if (context.ValidTokenTypes.Count is not 1 || if (context.ValidTokenTypes.Count is not 1 ||
@ -336,10 +327,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ValidateTokenContext context) public async ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If a principal was already attached, don't overwrite it. // If a principal was already attached, don't overwrite it.
if (context.Principal is not null) if (context.Principal is not null)
@ -494,10 +482,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context) public ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Note: only map the private claims from fully trusted tokens. // Note: only map the private claims from fully trusted tokens.
if (context.Principal is null || !context.Principal.HasTokenType(TokenTypeIdentifiers.Private.StateToken)) 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) public async ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.Principal is null) if (context.Principal is null)
{ {
@ -625,10 +607,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context) public ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.Principal is null) if (context.Principal is null)
{ {
@ -678,10 +657,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context) public ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -719,10 +695,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context) public ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -782,10 +755,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context) public ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -855,10 +825,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ValidateTokenContext context) public async ValueTask HandleAsync(ValidateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006)); Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
Debug.Assert(!string.IsNullOrEmpty(context.TokenId), SR.GetResourceString(SR.ID4017)); Debug.Assert(!string.IsNullOrEmpty(context.TokenId), SR.GetResourceString(SR.ID4017));
@ -920,10 +887,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context) public ValueTask HandleAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
context.SecurityTokenHandler = context.Options.JsonWebTokenHandler; context.SecurityTokenHandler = context.Options.JsonWebTokenHandler;
@ -980,10 +944,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(GenerateTokenContext context) public async ValueTask HandleAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var descriptor = new OpenIddictTokenDescriptor var descriptor = new OpenIddictTokenDescriptor
{ {
@ -1028,10 +989,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context) public ValueTask HandleAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (context.Principal is not { Identity: ClaimsIdentity } principal) if (context.Principal is not { Identity: ClaimsIdentity } principal)
{ {
@ -1077,10 +1035,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context) public ValueTask HandleAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var claims = context.SecurityTokenDescriptor.Claims is not null ? var claims = context.SecurityTokenDescriptor.Claims is not null ?
new Dictionary<string, object>(context.SecurityTokenDescriptor.Claims, StringComparer.Ordinal) : new Dictionary<string, object>(context.SecurityTokenDescriptor.Claims, StringComparer.Ordinal) :
@ -1143,10 +1098,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context) public ValueTask HandleAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// If a token was already attached by another handler, don't overwrite it. // If a token was already attached by another handler, don't overwrite it.
if (!string.IsNullOrEmpty(context.Token)) if (!string.IsNullOrEmpty(context.Token))
@ -1191,10 +1143,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(GenerateTokenContext context) public async ValueTask HandleAsync(GenerateTokenContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var identifier = context.Principal.GetTokenId(); var identifier = context.Principal.GetTokenId();
if (string.IsNullOrEmpty(identifier)) if (string.IsNullOrEmpty(identifier))

10
src/OpenIddict.Client/OpenIddictClientHandlers.Revocation.cs

@ -41,10 +41,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleRevocationResponseContext context) public ValueTask HandleAsync(HandleRevocationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
foreach (var parameter in context.Response.GetParameters()) foreach (var parameter in context.Response.GetParameters())
{ {
@ -98,10 +95,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleRevocationResponseContext context) public ValueTask HandleAsync(HandleRevocationResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
if (!string.IsNullOrEmpty(context.Response.Error)) if (!string.IsNullOrEmpty(context.Response.Error))
{ {

40
src/OpenIddict.Client/OpenIddictClientHandlers.Session.cs

@ -63,10 +63,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessSignOutContext context) public async ValueTask HandleAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new PrepareEndSessionRequestContext(context.Transaction); var notification = new PrepareEndSessionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -107,10 +104,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessSignOutContext context) public async ValueTask HandleAsync(ProcessSignOutContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ApplyEndSessionRequestContext(context.Transaction) var notification = new ApplyEndSessionRequestContext(context.Transaction)
{ {
@ -161,10 +155,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(ApplyEndSessionRequestContext context) public ValueTask HandleAsync(ApplyEndSessionRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Don't overwrite the endpoint URI if it was already set. // Don't overwrite the endpoint URI if it was already set.
if (!string.IsNullOrEmpty(context.EndSessionEndpoint)) if (!string.IsNullOrEmpty(context.EndSessionEndpoint))
@ -208,10 +199,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context) public async ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ExtractPostLogoutRedirectionRequestContext(context.Transaction); var notification = new ExtractPostLogoutRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -270,10 +258,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context) public async ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ValidatePostLogoutRedirectionRequestContext(context.Transaction); var notification = new ValidatePostLogoutRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -326,10 +311,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context) public async ValueTask HandleAsync(ProcessRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new HandlePostLogoutRedirectionRequestContext(context.Transaction); var notification = new HandlePostLogoutRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -383,10 +365,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(TContext context) public async ValueTask HandleAsync(TContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ApplyPostLogoutRedirectionResponseContext(context.Transaction); var notification = new ApplyPostLogoutRedirectionResponseContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
@ -431,10 +410,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask HandleAsync(ValidatePostLogoutRedirectionRequestContext context) public async ValueTask HandleAsync(ValidatePostLogoutRedirectionRequestContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
var notification = new ProcessAuthenticationContext(context.Transaction); var notification = new ProcessAuthenticationContext(context.Transaction);
await _dispatcher.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);

15
src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs

@ -44,10 +44,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleUserInfoResponseContext context) public ValueTask HandleAsync(HandleUserInfoResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// Ignore the response instance if a userinfo token was extracted. // Ignore the response instance if a userinfo token was extracted.
if (!string.IsNullOrEmpty(context.UserInfoToken)) if (!string.IsNullOrEmpty(context.UserInfoToken))
@ -110,10 +107,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleUserInfoResponseContext context) public ValueTask HandleAsync(HandleUserInfoResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
// For more information, see https://openid.net/specs/openid-connect-core-1_0.html#UserInfoError. // For more information, see https://openid.net/specs/openid-connect-core-1_0.html#UserInfoError.
if (!string.IsNullOrEmpty(context.Response.Error)) if (!string.IsNullOrEmpty(context.Response.Error))
@ -156,10 +150,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask HandleAsync(HandleUserInfoResponseContext context) public ValueTask HandleAsync(HandleUserInfoResponseContext context)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013)); Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));

700
src/OpenIddict.Client/OpenIddictClientHandlers.cs

File diff suppressed because it is too large

22
src/OpenIddict.Client/OpenIddictClientHelpers.cs

@ -21,15 +21,8 @@ public static class OpenIddictClientHelpers
public static TProperty? GetProperty<TProperty>( public static TProperty? GetProperty<TProperty>(
this OpenIddictClientTransaction transaction, string name) where TProperty : class this OpenIddictClientTransaction transaction, string name) where TProperty : class
{ {
if (transaction is null) ArgumentNullException.ThrowIfNull(transaction);
{ ArgumentException.ThrowIfNullOrEmpty(name);
throw new ArgumentNullException(nameof(transaction));
}
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name));
}
if (transaction.Properties.TryGetValue(name, out var property) && property is TProperty result) if (transaction.Properties.TryGetValue(name, out var property) && property is TProperty result)
{ {
@ -51,15 +44,8 @@ public static class OpenIddictClientHelpers
this OpenIddictClientTransaction transaction, this OpenIddictClientTransaction transaction,
string name, TProperty? value) where TProperty : class string name, TProperty? value) where TProperty : class
{ {
if (transaction is null) ArgumentNullException.ThrowIfNull(transaction);
{ ArgumentException.ThrowIfNullOrEmpty(name);
throw new ArgumentNullException(nameof(transaction));
}
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name));
}
if (value is null) if (value is null)
{ {

5
src/OpenIddict.Client/OpenIddictClientRetriever.cs

@ -38,10 +38,7 @@ public sealed class OpenIddictClientRetriever : IConfigurationRetriever<OpenIddi
async Task<OpenIddictConfiguration> IConfigurationRetriever<OpenIddictConfiguration>.GetConfigurationAsync( async Task<OpenIddictConfiguration> IConfigurationRetriever<OpenIddictConfiguration>.GetConfigurationAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string address, IDocumentRetriever retriever, CancellationToken cancel) [StringSyntax(StringSyntaxAttribute.Uri)] string address, IDocumentRetriever retriever, CancellationToken cancel)
{ {
if (string.IsNullOrEmpty(address)) ArgumentException.ThrowIfNullOrEmpty(address);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(address));
}
if (!Uri.TryCreate(address, UriKind.Absolute, out Uri? uri) || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!Uri.TryCreate(address, UriKind.Absolute, out Uri? uri) || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {

232
src/OpenIddict.Client/OpenIddictClientService.cs

@ -68,10 +68,7 @@ public class OpenIddictClientService
public virtual ValueTask<OpenIddictClientRegistration> GetClientRegistrationByIssuerAsync( public virtual ValueTask<OpenIddictClientRegistration> GetClientRegistrationByIssuerAsync(
Uri uri, CancellationToken cancellationToken = default) Uri uri, CancellationToken cancellationToken = default)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{
throw new ArgumentNullException(nameof(uri));
}
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
{ {
@ -108,10 +105,7 @@ public class OpenIddictClientService
public virtual ValueTask<OpenIddictClientRegistration> GetClientRegistrationByProviderNameAsync( public virtual ValueTask<OpenIddictClientRegistration> GetClientRegistrationByProviderNameAsync(
string name, CancellationToken cancellationToken = default) string name, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name));
}
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
{ {
@ -146,10 +140,7 @@ public class OpenIddictClientService
public virtual ValueTask<OpenIddictClientRegistration> GetClientRegistrationByIdAsync( public virtual ValueTask<OpenIddictClientRegistration> GetClientRegistrationByIdAsync(
string identifier, CancellationToken cancellationToken = default) string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
}
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
{ {
@ -179,10 +170,7 @@ public class OpenIddictClientService
public virtual async ValueTask<OpenIddictConfiguration> GetServerConfigurationByIssuerAsync( public virtual async ValueTask<OpenIddictConfiguration> GetServerConfigurationByIssuerAsync(
Uri uri, CancellationToken cancellationToken = default) Uri uri, CancellationToken cancellationToken = default)
{ {
if (uri is null) ArgumentNullException.ThrowIfNull(uri);
{
throw new ArgumentNullException(nameof(uri));
}
var registration = await GetClientRegistrationByIssuerAsync(uri, cancellationToken); var registration = await GetClientRegistrationByIssuerAsync(uri, cancellationToken);
if (registration.ConfigurationManager is null) if (registration.ConfigurationManager is null)
@ -212,10 +200,7 @@ public class OpenIddictClientService
public virtual async ValueTask<OpenIddictConfiguration> GetServerConfigurationByProviderNameAsync( public virtual async ValueTask<OpenIddictConfiguration> GetServerConfigurationByProviderNameAsync(
string name, CancellationToken cancellationToken = default) string name, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name));
}
var registration = await GetClientRegistrationByProviderNameAsync(name, cancellationToken); var registration = await GetClientRegistrationByProviderNameAsync(name, cancellationToken);
if (registration.ConfigurationManager is null) if (registration.ConfigurationManager is null)
@ -242,10 +227,7 @@ public class OpenIddictClientService
public virtual async ValueTask<OpenIddictConfiguration> GetServerConfigurationByRegistrationIdAsync( public virtual async ValueTask<OpenIddictConfiguration> GetServerConfigurationByRegistrationIdAsync(
string identifier, CancellationToken cancellationToken = default) string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
}
var registration = await GetClientRegistrationByIdAsync(identifier, cancellationToken); var registration = await GetClientRegistrationByIdAsync(identifier, cancellationToken);
if (registration.ConfigurationManager is null) if (registration.ConfigurationManager is null)
@ -271,10 +253,7 @@ public class OpenIddictClientService
/// <returns>The interactive authentication result.</returns> /// <returns>The interactive authentication result.</returns>
public async ValueTask<InteractiveAuthenticationResult> AuthenticateInteractivelyAsync(InteractiveAuthenticationRequest request) public async ValueTask<InteractiveAuthenticationResult> AuthenticateInteractivelyAsync(InteractiveAuthenticationRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -344,10 +323,7 @@ public class OpenIddictClientService
/// <returns>The interactive challenge result.</returns> /// <returns>The interactive challenge result.</returns>
public async ValueTask<InteractiveChallengeResult> ChallengeInteractivelyAsync(InteractiveChallengeRequest request) public async ValueTask<InteractiveChallengeResult> ChallengeInteractivelyAsync(InteractiveChallengeRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -430,10 +406,7 @@ public class OpenIddictClientService
public async ValueTask<ClientCredentialsAuthenticationResult> AuthenticateWithClientCredentialsAsync( public async ValueTask<ClientCredentialsAuthenticationResult> AuthenticateWithClientCredentialsAsync(
ClientCredentialsAuthenticationRequest request) ClientCredentialsAuthenticationRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -515,10 +488,7 @@ public class OpenIddictClientService
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public async ValueTask<CustomGrantAuthenticationResult> AuthenticateWithCustomGrantAsync(CustomGrantAuthenticationRequest request) public async ValueTask<CustomGrantAuthenticationResult> AuthenticateWithCustomGrantAsync(CustomGrantAuthenticationRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
// Prevent well-known/non-custom grant types from being used with this API. // Prevent well-known/non-custom grant types from being used with this API.
if (request.GrantType is GrantTypes.AuthorizationCode or GrantTypes.ClientCredentials or if (request.GrantType is GrantTypes.AuthorizationCode or GrantTypes.ClientCredentials or
@ -608,10 +578,7 @@ public class OpenIddictClientService
/// <returns>The device authentication result.</returns> /// <returns>The device authentication result.</returns>
public async ValueTask<DeviceAuthenticationResult> AuthenticateWithDeviceAsync(DeviceAuthenticationRequest request) public async ValueTask<DeviceAuthenticationResult> AuthenticateWithDeviceAsync(DeviceAuthenticationRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
using var source = CancellationTokenSource.CreateLinkedTokenSource(request.CancellationToken); using var source = CancellationTokenSource.CreateLinkedTokenSource(request.CancellationToken);
source.CancelAfter(request.Timeout); source.CancelAfter(request.Timeout);
@ -725,10 +692,7 @@ public class OpenIddictClientService
/// <returns>The device challenge result.</returns> /// <returns>The device challenge result.</returns>
public async ValueTask<DeviceChallengeResult> ChallengeUsingDeviceAsync(DeviceChallengeRequest request) public async ValueTask<DeviceChallengeResult> ChallengeUsingDeviceAsync(DeviceChallengeRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -808,10 +772,7 @@ public class OpenIddictClientService
/// <returns>The resource owner password credentials authentication result.</returns> /// <returns>The resource owner password credentials authentication result.</returns>
public async ValueTask<PasswordAuthenticationResult> AuthenticateWithPasswordAsync(PasswordAuthenticationRequest request) public async ValueTask<PasswordAuthenticationResult> AuthenticateWithPasswordAsync(PasswordAuthenticationRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -897,10 +858,7 @@ public class OpenIddictClientService
public async ValueTask<TokenExchangeAuthenticationResult> AuthenticateWithTokenExchangeAsync( public async ValueTask<TokenExchangeAuthenticationResult> AuthenticateWithTokenExchangeAsync(
TokenExchangeAuthenticationRequest request) TokenExchangeAuthenticationRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -986,10 +944,7 @@ public class OpenIddictClientService
public async ValueTask<RefreshTokenAuthenticationResult> AuthenticateWithRefreshTokenAsync( public async ValueTask<RefreshTokenAuthenticationResult> AuthenticateWithRefreshTokenAsync(
RefreshTokenAuthenticationRequest request) RefreshTokenAuthenticationRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -1073,10 +1028,7 @@ public class OpenIddictClientService
/// <returns>The introspection result.</returns> /// <returns>The introspection result.</returns>
public async ValueTask<IntrospectionResult> IntrospectTokenAsync(IntrospectionRequest request) public async ValueTask<IntrospectionResult> IntrospectTokenAsync(IntrospectionRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -1136,10 +1088,7 @@ public class OpenIddictClientService
/// <returns>The revocation result.</returns> /// <returns>The revocation result.</returns>
public async ValueTask<RevocationResult> RevokeTokenAsync(RevocationRequest request) public async ValueTask<RevocationResult> RevokeTokenAsync(RevocationRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -1201,15 +1150,8 @@ public class OpenIddictClientService
internal async ValueTask<OpenIddictConfiguration> GetConfigurationAsync( internal async ValueTask<OpenIddictConfiguration> GetConfigurationAsync(
OpenIddictClientRegistration registration, Uri uri, CancellationToken cancellationToken = default) OpenIddictClientRegistration registration, Uri uri, CancellationToken cancellationToken = default)
{ {
if (registration is null) ArgumentNullException.ThrowIfNull(registration);
{ ArgumentNullException.ThrowIfNull(uri);
throw new ArgumentNullException(nameof(uri));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {
@ -1338,10 +1280,7 @@ public class OpenIddictClientService
/// <returns>The interactive sign-out result.</returns> /// <returns>The interactive sign-out result.</returns>
public async ValueTask<InteractiveSignOutResult> SignOutInteractivelyAsync(InteractiveSignOutRequest request) public async ValueTask<InteractiveSignOutResult> SignOutInteractivelyAsync(InteractiveSignOutRequest request)
{ {
if (request is null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
request.CancellationToken.ThrowIfCancellationRequested(); request.CancellationToken.ThrowIfCancellationRequested();
@ -1407,15 +1346,8 @@ public class OpenIddictClientService
internal async ValueTask<JsonWebKeySet> GetSecurityKeysAsync( internal async ValueTask<JsonWebKeySet> GetSecurityKeysAsync(
OpenIddictClientRegistration registration, Uri uri, CancellationToken cancellationToken = default) OpenIddictClientRegistration registration, Uri uri, CancellationToken cancellationToken = default)
{ {
if (registration is null) ArgumentNullException.ThrowIfNull(registration);
{ ArgumentNullException.ThrowIfNull(uri);
throw new ArgumentNullException(nameof(registration));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {
@ -1552,25 +1484,10 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration, OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default) OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{ {
if (registration is null) ArgumentNullException.ThrowIfNull(registration);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(registration)); ArgumentNullException.ThrowIfNull(request);
} ArgumentNullException.ThrowIfNull(uri);
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));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {
@ -1710,20 +1627,9 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration, OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default) OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{ ArgumentNullException.ThrowIfNull(request);
throw new ArgumentNullException(nameof(configuration)); ArgumentNullException.ThrowIfNull(uri);
}
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {
@ -1865,25 +1771,10 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration, OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default) OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{ {
if (registration is null) ArgumentNullException.ThrowIfNull(registration);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(registration)); ArgumentNullException.ThrowIfNull(request);
} ArgumentNullException.ThrowIfNull(uri);
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));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {
@ -2023,20 +1914,9 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration, OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default) OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{ ArgumentNullException.ThrowIfNull(request);
throw new ArgumentNullException(nameof(configuration)); ArgumentNullException.ThrowIfNull(uri);
}
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {
@ -2176,25 +2056,10 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration, OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default) OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{ {
if (registration is null) ArgumentNullException.ThrowIfNull(registration);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(registration)); ArgumentNullException.ThrowIfNull(request);
} ArgumentNullException.ThrowIfNull(uri);
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));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {
@ -2334,20 +2199,9 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration, OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, HashSet<string> methods, CancellationToken cancellationToken = default) OpenIddictRequest request, Uri uri, HashSet<string> methods, CancellationToken cancellationToken = default)
{ {
if (registration is null) ArgumentNullException.ThrowIfNull(registration);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(registration)); ArgumentNullException.ThrowIfNull(uri);
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri)) if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{ {

45
src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs

@ -45,10 +45,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask AddAsync(TApplication application, CancellationToken cancellationToken) public async ValueTask AddAsync(TApplication application, CancellationToken cancellationToken)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
_cache.Remove(new _cache.Remove(new
{ {
@ -107,10 +104,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<TApplication?> FindByClientIdAsync(string identifier, CancellationToken cancellationToken) public ValueTask<TApplication?> FindByClientIdAsync(string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var parameters = new var parameters = new
{ {
@ -141,10 +135,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<TApplication?> FindByIdAsync(string identifier, CancellationToken cancellationToken) public ValueTask<TApplication?> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var parameters = new var parameters = new
{ {
@ -176,10 +167,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
public IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync( public IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken) [StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(uri)) ArgumentException.ThrowIfNullOrEmpty(uri);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -218,10 +206,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
public IAsyncEnumerable<TApplication> FindByRedirectUriAsync( public IAsyncEnumerable<TApplication> FindByRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken) [StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(uri)) ArgumentException.ThrowIfNullOrEmpty(uri);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -259,10 +244,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask RemoveAsync(TApplication application, CancellationToken cancellationToken) public async ValueTask RemoveAsync(TApplication application, CancellationToken cancellationToken)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
var identifier = await _store.GetIdAsync(application, cancellationToken); var identifier = await _store.GetIdAsync(application, cancellationToken);
if (string.IsNullOrEmpty(identifier)) if (string.IsNullOrEmpty(identifier))
@ -286,10 +268,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, TApplication? application, CancellationToken cancellationToken) private async ValueTask CreateEntryAsync(object key, TApplication? application, CancellationToken cancellationToken)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
using var entry = _cache.CreateEntry(key); using var entry = _cache.CreateEntry(key);
@ -312,10 +291,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, ImmutableArray<TApplication> applications, CancellationToken cancellationToken) private async ValueTask CreateEntryAsync(object key, ImmutableArray<TApplication> applications, CancellationToken cancellationToken)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
using var entry = _cache.CreateEntry(key); using var entry = _cache.CreateEntry(key);
@ -341,10 +317,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// </returns> /// </returns>
private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TApplication application, CancellationToken cancellationToken) private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TApplication application, CancellationToken cancellationToken)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
var identifier = await _store.GetIdAsync(application, cancellationToken); var identifier = await _store.GetIdAsync(application, cancellationToken);
if (string.IsNullOrEmpty(identifier)) if (string.IsNullOrEmpty(identifier))

40
src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs

@ -44,10 +44,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask AddAsync(TAuthorization authorization, CancellationToken cancellationToken) public async ValueTask AddAsync(TAuthorization authorization, CancellationToken cancellationToken)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
_cache.Remove(new _cache.Remove(new
{ {
@ -104,10 +101,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/> /// <inheritdoc/>
public IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken) public IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -145,10 +139,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<TAuthorization?> FindByIdAsync(string identifier, CancellationToken cancellationToken) public ValueTask<TAuthorization?> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var parameters = new var parameters = new
{ {
@ -179,10 +170,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/> /// <inheritdoc/>
public IAsyncEnumerable<TAuthorization> FindBySubjectAsync(string subject, CancellationToken cancellationToken) public IAsyncEnumerable<TAuthorization> FindBySubjectAsync(string subject, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(subject)) ArgumentException.ThrowIfNullOrEmpty(subject);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -220,10 +208,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask RemoveAsync(TAuthorization authorization, CancellationToken cancellationToken) public async ValueTask RemoveAsync(TAuthorization authorization, CancellationToken cancellationToken)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
var identifier = await _store.GetIdAsync(authorization, cancellationToken); var identifier = await _store.GetIdAsync(authorization, cancellationToken);
if (string.IsNullOrEmpty(identifier)) if (string.IsNullOrEmpty(identifier))
@ -247,10 +232,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, TAuthorization? authorization, CancellationToken cancellationToken) private async ValueTask CreateEntryAsync(object key, TAuthorization? authorization, CancellationToken cancellationToken)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
using var entry = _cache.CreateEntry(key); using var entry = _cache.CreateEntry(key);
@ -273,10 +255,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, ImmutableArray<TAuthorization> authorizations, CancellationToken cancellationToken) private async ValueTask CreateEntryAsync(object key, ImmutableArray<TAuthorization> authorizations, CancellationToken cancellationToken)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
using var entry = _cache.CreateEntry(key); using var entry = _cache.CreateEntry(key);
@ -302,10 +281,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// </returns> /// </returns>
private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TAuthorization authorization, CancellationToken cancellationToken) private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TAuthorization authorization, CancellationToken cancellationToken)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
var identifier = await _store.GetIdAsync(authorization, cancellationToken); var identifier = await _store.GetIdAsync(authorization, cancellationToken);
if (string.IsNullOrEmpty(identifier)) if (string.IsNullOrEmpty(identifier))

40
src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs

@ -44,10 +44,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask AddAsync(TScope scope, CancellationToken cancellationToken) public async ValueTask AddAsync(TScope scope, CancellationToken cancellationToken)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
_cache.Remove(new _cache.Remove(new
{ {
@ -97,10 +94,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<TScope?> FindByIdAsync(string identifier, CancellationToken cancellationToken) public ValueTask<TScope?> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var parameters = new var parameters = new
{ {
@ -131,10 +125,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<TScope?> FindByNameAsync(string name, CancellationToken cancellationToken) public ValueTask<TScope?> FindByNameAsync(string name, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0202), nameof(name));
}
var parameters = new var parameters = new
{ {
@ -188,10 +179,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/> /// <inheritdoc/>
public IAsyncEnumerable<TScope> FindByResourceAsync(string resource, CancellationToken cancellationToken) public IAsyncEnumerable<TScope> FindByResourceAsync(string resource, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(resource)) ArgumentException.ThrowIfNullOrEmpty(resource);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -229,10 +217,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask RemoveAsync(TScope scope, CancellationToken cancellationToken) public async ValueTask RemoveAsync(TScope scope, CancellationToken cancellationToken)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
var identifier = await _store.GetIdAsync(scope, cancellationToken); var identifier = await _store.GetIdAsync(scope, cancellationToken);
if (string.IsNullOrEmpty(identifier)) if (string.IsNullOrEmpty(identifier))
@ -256,10 +241,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, TScope? scope, CancellationToken cancellationToken) private async ValueTask CreateEntryAsync(object key, TScope? scope, CancellationToken cancellationToken)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
using var entry = _cache.CreateEntry(key); using var entry = _cache.CreateEntry(key);
@ -282,10 +264,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, ImmutableArray<TScope> scopes, CancellationToken cancellationToken) private async ValueTask CreateEntryAsync(object key, ImmutableArray<TScope> scopes, CancellationToken cancellationToken)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
using var entry = _cache.CreateEntry(key); using var entry = _cache.CreateEntry(key);
@ -311,10 +290,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// </returns> /// </returns>
private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TScope scope, CancellationToken cancellationToken) private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TScope scope, CancellationToken cancellationToken)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
var identifier = await _store.GetIdAsync(scope, cancellationToken); var identifier = await _store.GetIdAsync(scope, cancellationToken);
if (string.IsNullOrEmpty(identifier)) if (string.IsNullOrEmpty(identifier))

50
src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs

@ -44,10 +44,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask AddAsync(TToken token, CancellationToken cancellationToken) public async ValueTask AddAsync(TToken token, CancellationToken cancellationToken)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
_cache.Remove(new _cache.Remove(new
{ {
@ -121,10 +118,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/> /// <inheritdoc/>
public IAsyncEnumerable<TToken> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken) public IAsyncEnumerable<TToken> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -162,10 +156,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/> /// <inheritdoc/>
public IAsyncEnumerable<TToken> FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken) public IAsyncEnumerable<TToken> FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -203,10 +194,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<TToken?> FindByIdAsync(string identifier, CancellationToken cancellationToken) public ValueTask<TToken?> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var parameters = new var parameters = new
{ {
@ -237,10 +225,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/> /// <inheritdoc/>
public ValueTask<TToken?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken) public ValueTask<TToken?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var parameters = new var parameters = new
{ {
@ -271,10 +256,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/> /// <inheritdoc/>
public IAsyncEnumerable<TToken> FindBySubjectAsync(string subject, CancellationToken cancellationToken) public IAsyncEnumerable<TToken> FindBySubjectAsync(string subject, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(subject)) ArgumentException.ThrowIfNullOrEmpty(subject);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -312,10 +294,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/> /// <inheritdoc/>
public async ValueTask RemoveAsync(TToken token, CancellationToken cancellationToken) public async ValueTask RemoveAsync(TToken token, CancellationToken cancellationToken)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
var identifier = await _store.GetIdAsync(token, cancellationToken); var identifier = await _store.GetIdAsync(token, cancellationToken);
if (string.IsNullOrEmpty(identifier)) if (string.IsNullOrEmpty(identifier))
@ -339,10 +318,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, TToken? token, CancellationToken cancellationToken) private async ValueTask CreateEntryAsync(object key, TToken? token, CancellationToken cancellationToken)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
using var entry = _cache.CreateEntry(key); using var entry = _cache.CreateEntry(key);
@ -365,10 +341,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns> /// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, ImmutableArray<TToken> tokens, CancellationToken cancellationToken) private async ValueTask CreateEntryAsync(object key, ImmutableArray<TToken> tokens, CancellationToken cancellationToken)
{ {
if (key is null) ArgumentNullException.ThrowIfNull(key);
{
throw new ArgumentNullException(nameof(key));
}
using var entry = _cache.CreateEntry(key); using var entry = _cache.CreateEntry(key);
@ -394,10 +367,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// </returns> /// </returns>
private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TToken token, CancellationToken cancellationToken) private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TToken token, CancellationToken cancellationToken)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
var identifier = await _store.GetIdAsync(token, cancellationToken); var identifier = await _store.GetIdAsync(token, cancellationToken);
if (string.IsNullOrEmpty(identifier)) if (string.IsNullOrEmpty(identifier))

301
src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs

@ -18,6 +18,7 @@ using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using ValidationException = OpenIddict.Abstractions.OpenIddictExceptions.ValidationException; using ValidationException = OpenIddict.Abstractions.OpenIddictExceptions.ValidationException;
#if !SUPPORTS_KEY_DERIVATION_WITH_SPECIFIED_HASH_ALGORITHM #if !SUPPORTS_KEY_DERIVATION_WITH_SPECIFIED_HASH_ALGORITHM
using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Digests; using Org.BouncyCastle.Crypto.Digests;
@ -100,10 +101,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<long> CountAsync<TResult>( public virtual ValueTask<long> CountAsync<TResult>(
Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.CountAsync(query, cancellationToken); return Store.CountAsync(query, cancellationToken);
} }
@ -132,10 +130,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns> /// </returns>
public virtual async ValueTask CreateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default) public virtual async ValueTask CreateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
if (!string.IsNullOrEmpty(await Store.GetClientSecretAsync(application, cancellationToken))) if (!string.IsNullOrEmpty(await Store.GetClientSecretAsync(application, cancellationToken)))
{ {
@ -226,10 +221,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<TApplication> CreateAsync( public virtual async ValueTask<TApplication> CreateAsync(
OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{
throw new ArgumentNullException(nameof(descriptor));
}
var application = await Store.InstantiateAsync(cancellationToken) ?? var application = await Store.InstantiateAsync(cancellationToken) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0208)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0208));
@ -260,10 +252,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns> /// </returns>
public virtual async ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken = default) public virtual async ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
if (!Options.CurrentValue.DisableEntityCaching) if (!Options.CurrentValue.DisableEntityCaching)
{ {
@ -285,10 +274,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<TApplication?> FindByClientIdAsync( public virtual async ValueTask<TApplication?> FindByClientIdAsync(
string identifier, CancellationToken cancellationToken = default) string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var application = Options.CurrentValue.DisableEntityCaching ? var application = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByClientIdAsync(identifier, cancellationToken) : await Store.FindByClientIdAsync(identifier, cancellationToken) :
@ -322,10 +308,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns> /// </returns>
public virtual async ValueTask<TApplication?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default) public virtual async ValueTask<TApplication?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var application = Options.CurrentValue.DisableEntityCaching ? var application = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByIdAsync(identifier, cancellationToken) : await Store.FindByIdAsync(identifier, cancellationToken) :
@ -357,10 +340,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync( public virtual IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default) [StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(uri)) ArgumentException.ThrowIfNullOrEmpty(uri);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
var applications = Options.CurrentValue.DisableEntityCaching ? var applications = Options.CurrentValue.DisableEntityCaching ?
Store.FindByPostLogoutRedirectUriAsync(uri, cancellationToken) : Store.FindByPostLogoutRedirectUriAsync(uri, cancellationToken) :
@ -399,10 +379,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual IAsyncEnumerable<TApplication> FindByRedirectUriAsync( public virtual IAsyncEnumerable<TApplication> FindByRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default) [StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(uri)) ArgumentException.ThrowIfNullOrEmpty(uri);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
var applications = Options.CurrentValue.DisableEntityCaching ? var applications = Options.CurrentValue.DisableEntityCaching ?
Store.FindByRedirectUriAsync(uri, cancellationToken) : Store.FindByRedirectUriAsync(uri, cancellationToken) :
@ -444,10 +421,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<string?> GetApplicationTypeAsync( public virtual async ValueTask<string?> GetApplicationTypeAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
var type = await Store.GetApplicationTypeAsync(application, cancellationToken); var type = await Store.GetApplicationTypeAsync(application, cancellationToken);
if (string.IsNullOrEmpty(type)) if (string.IsNullOrEmpty(type))
@ -471,10 +445,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<TResult?> GetAsync<TResult>( public virtual ValueTask<TResult?> GetAsync<TResult>(
Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return GetAsync(static (applications, query) => query(applications), query, cancellationToken); return GetAsync(static (applications, query) => query(applications), query, cancellationToken);
} }
@ -495,10 +466,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query, Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default) TState state, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.GetAsync(query, state, cancellationToken); return Store.GetAsync(query, state, cancellationToken);
} }
@ -515,10 +483,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<string?> GetClientIdAsync( public virtual ValueTask<string?> GetClientIdAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetClientIdAsync(application, cancellationToken); return Store.GetClientIdAsync(application, cancellationToken);
} }
@ -535,10 +500,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<string?> GetClientTypeAsync( public virtual ValueTask<string?> GetClientTypeAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetClientTypeAsync(application, cancellationToken); return Store.GetClientTypeAsync(application, cancellationToken);
} }
@ -555,10 +517,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<string?> GetConsentTypeAsync( public virtual async ValueTask<string?> GetConsentTypeAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
var type = await Store.GetConsentTypeAsync(application, cancellationToken); var type = await Store.GetConsentTypeAsync(application, cancellationToken);
if (string.IsNullOrEmpty(type)) if (string.IsNullOrEmpty(type))
@ -581,10 +540,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<string?> GetDisplayNameAsync( public virtual ValueTask<string?> GetDisplayNameAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetDisplayNameAsync(application, cancellationToken); return Store.GetDisplayNameAsync(application, cancellationToken);
} }
@ -601,10 +557,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync( public virtual async ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
var names = await Store.GetDisplayNamesAsync(application, cancellationToken); var names = await Store.GetDisplayNamesAsync(application, cancellationToken);
if (names is not { Count: > 0 }) if (names is not { Count: > 0 })
@ -626,10 +579,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns> /// </returns>
public virtual ValueTask<string?> GetIdAsync(TApplication application, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetIdAsync(TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetIdAsync(application, cancellationToken); return Store.GetIdAsync(application, cancellationToken);
} }
@ -645,10 +595,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns> /// </returns>
public virtual ValueTask<JsonWebKeySet?> GetJsonWebKeySetAsync(TApplication application, CancellationToken cancellationToken = default) public virtual ValueTask<JsonWebKeySet?> GetJsonWebKeySetAsync(TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetJsonWebKeySetAsync(application, cancellationToken); return Store.GetJsonWebKeySetAsync(application, cancellationToken);
} }
@ -683,15 +630,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<string?> GetLocalizedDisplayNameAsync( public virtual async ValueTask<string?> GetLocalizedDisplayNameAsync(
TApplication application, CultureInfo culture, CancellationToken cancellationToken = default) TApplication application, CultureInfo culture, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentNullException.ThrowIfNull(culture);
throw new ArgumentNullException(nameof(application));
}
if (culture is null)
{
throw new ArgumentNullException(nameof(culture));
}
var names = await Store.GetDisplayNamesAsync(application, cancellationToken); var names = await Store.GetDisplayNamesAsync(application, cancellationToken);
if (names is not { Count: > 0 }) if (names is not { Count: > 0 })
@ -726,10 +666,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableArray<string>> GetPermissionsAsync( public virtual ValueTask<ImmutableArray<string>> GetPermissionsAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetPermissionsAsync(application, cancellationToken); return Store.GetPermissionsAsync(application, cancellationToken);
} }
@ -746,10 +683,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync( public virtual ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken); return Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken);
} }
@ -766,10 +700,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync( public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetPropertiesAsync(application, cancellationToken); return Store.GetPropertiesAsync(application, cancellationToken);
} }
@ -786,10 +717,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableArray<string>> GetRedirectUrisAsync( public virtual ValueTask<ImmutableArray<string>> GetRedirectUrisAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetRedirectUrisAsync(application, cancellationToken); return Store.GetRedirectUrisAsync(application, cancellationToken);
} }
@ -806,10 +734,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableArray<string>> GetRequirementsAsync( public virtual ValueTask<ImmutableArray<string>> GetRequirementsAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetRequirementsAsync(application, cancellationToken); return Store.GetRequirementsAsync(application, cancellationToken);
} }
@ -826,10 +751,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableDictionary<string, string>> GetSettingsAsync( public virtual ValueTask<ImmutableDictionary<string, string>> GetSettingsAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetSettingsAsync(application, cancellationToken); return Store.GetSettingsAsync(application, cancellationToken);
} }
@ -844,15 +766,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasApplicationTypeAsync( public virtual async ValueTask<bool> HasApplicationTypeAsync(
TApplication application, string type, CancellationToken cancellationToken = default) TApplication application, string type, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentException.ThrowIfNullOrEmpty(type);
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0209), nameof(type));
}
return string.Equals(await GetApplicationTypeAsync(application, cancellationToken), type, StringComparison.OrdinalIgnoreCase); return string.Equals(await GetApplicationTypeAsync(application, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
} }
@ -867,15 +782,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasClientTypeAsync( public virtual async ValueTask<bool> HasClientTypeAsync(
TApplication application, string type, CancellationToken cancellationToken = default) TApplication application, string type, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentException.ThrowIfNullOrEmpty(type);
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0209), nameof(type));
}
return string.Equals(await GetClientTypeAsync(application, cancellationToken), type, StringComparison.OrdinalIgnoreCase); return string.Equals(await GetClientTypeAsync(application, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
} }
@ -890,15 +798,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasConsentTypeAsync( public virtual async ValueTask<bool> HasConsentTypeAsync(
TApplication application, string type, CancellationToken cancellationToken = default) TApplication application, string type, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentException.ThrowIfNullOrEmpty(type);
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0210), nameof(type));
}
return string.Equals(await GetConsentTypeAsync(application, cancellationToken), type, StringComparison.OrdinalIgnoreCase); return string.Equals(await GetConsentTypeAsync(application, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
} }
@ -913,15 +814,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasPermissionAsync( public virtual async ValueTask<bool> HasPermissionAsync(
TApplication application, string permission, CancellationToken cancellationToken = default) TApplication application, string permission, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentException.ThrowIfNullOrEmpty(permission);
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(permission))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0211), nameof(permission));
}
return (await GetPermissionsAsync(application, cancellationToken)).Contains(permission, StringComparer.Ordinal); return (await GetPermissionsAsync(application, cancellationToken)).Contains(permission, StringComparer.Ordinal);
} }
@ -936,15 +830,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasRequirementAsync( public virtual async ValueTask<bool> HasRequirementAsync(
TApplication application, string requirement, CancellationToken cancellationToken = default) TApplication application, string requirement, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentException.ThrowIfNullOrEmpty(requirement);
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(requirement))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0212), nameof(requirement));
}
return (await GetRequirementsAsync(application, cancellationToken)).Contains(requirement, StringComparer.Ordinal); return (await GetRequirementsAsync(application, cancellationToken)).Contains(requirement, StringComparer.Ordinal);
} }
@ -970,10 +857,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual IAsyncEnumerable<TResult> ListAsync<TResult>( public virtual IAsyncEnumerable<TResult> ListAsync<TResult>(
Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return ListAsync(static (applications, query) => query(applications), query, cancellationToken); return ListAsync(static (applications, query) => query(applications), query, cancellationToken);
} }
@ -991,10 +875,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query, Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default) TState state, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.ListAsync(query, state, cancellationToken); return Store.ListAsync(query, state, cancellationToken);
} }
@ -1011,15 +892,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask PopulateAsync(TApplication application, public virtual async ValueTask PopulateAsync(TApplication application,
OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentNullException.ThrowIfNull(descriptor);
throw new ArgumentNullException(nameof(application));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
await Store.SetApplicationTypeAsync(application, descriptor.ApplicationType, cancellationToken); await Store.SetApplicationTypeAsync(application, descriptor.ApplicationType, cancellationToken);
await Store.SetClientIdAsync(application, descriptor.ClientId, cancellationToken); await Store.SetClientIdAsync(application, descriptor.ClientId, cancellationToken);
@ -1050,15 +924,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
OpenIddictApplicationDescriptor descriptor, OpenIddictApplicationDescriptor descriptor,
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{ ArgumentNullException.ThrowIfNull(application);
throw new ArgumentNullException(nameof(descriptor));
}
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
descriptor.ApplicationType = await Store.GetApplicationTypeAsync(application, cancellationToken); descriptor.ApplicationType = await Store.GetApplicationTypeAsync(application, cancellationToken);
descriptor.ClientId = await Store.GetClientIdAsync(application, cancellationToken); descriptor.ClientId = await Store.GetClientIdAsync(application, cancellationToken);
@ -1084,13 +951,13 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
// Ensure the URI is not null or empty. // Ensure the URI is not null or empty.
if (string.IsNullOrEmpty(uri)) if (string.IsNullOrEmpty(uri))
{ {
throw new ArgumentException(SR.GetResourceString(SR.ID0213)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0213));
} }
// Ensure the URI is a valid absolute URI. // Ensure the URI is a valid absolute URI.
if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value)) if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value))
{ {
throw new ArgumentException(SR.GetResourceString(SR.ID0214)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0214));
} }
descriptor.PostLogoutRedirectUris.Add(value); descriptor.PostLogoutRedirectUris.Add(value);
@ -1108,13 +975,13 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
// Ensure the URI is not null or empty. // Ensure the URI is not null or empty.
if (string.IsNullOrEmpty(uri)) if (string.IsNullOrEmpty(uri))
{ {
throw new ArgumentException(SR.GetResourceString(SR.ID0213)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0213));
} }
// Ensure the URI is a valid absolute URI. // Ensure the URI is a valid absolute URI.
if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value)) if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value))
{ {
throw new ArgumentException(SR.GetResourceString(SR.ID0214)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0214));
} }
descriptor.RedirectUris.Add(value); descriptor.RedirectUris.Add(value);
@ -1137,10 +1004,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns> /// </returns>
public virtual async ValueTask UpdateAsync(TApplication application, CancellationToken cancellationToken = default) public virtual async ValueTask UpdateAsync(TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
var results = await GetValidationResultsAsync(application, cancellationToken); var results = await GetValidationResultsAsync(application, cancellationToken);
if (results.Any(result => result != ValidationResult.Success)) if (results.Any(result => result != ValidationResult.Success))
@ -1196,10 +1060,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns> /// </returns>
public virtual async ValueTask UpdateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default) public virtual async ValueTask UpdateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(secret)) if (string.IsNullOrEmpty(secret))
{ {
@ -1227,15 +1088,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask UpdateAsync(TApplication application, public virtual async ValueTask UpdateAsync(TApplication application,
OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentNullException.ThrowIfNull(descriptor);
throw new ArgumentNullException(nameof(application));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
// Store the original client secret for later comparison. // Store the original client secret for later comparison.
var comparand = await Store.GetClientSecretAsync(application, cancellationToken); var comparand = await Store.GetClientSecretAsync(application, cancellationToken);
@ -1262,10 +1116,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual IAsyncEnumerable<ValidationResult> ValidateAsync( public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(
TApplication application, CancellationToken cancellationToken = default) TApplication application, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{
throw new ArgumentNullException(nameof(application));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -1389,14 +1240,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> ValidateClientSecretAsync( public virtual async ValueTask<bool> ValidateClientSecretAsync(
TApplication application, string secret, CancellationToken cancellationToken = default) TApplication application, string secret, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentException.ThrowIfNullOrEmpty(secret);
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(secret))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0216), nameof(secret));
}
if (await HasClientTypeAsync(application, ClientTypes.Public, cancellationToken)) if (await HasClientTypeAsync(application, ClientTypes.Public, cancellationToken))
{ {
@ -1437,15 +1282,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> ValidatePostLogoutRedirectUriAsync(TApplication application, public virtual async ValueTask<bool> ValidatePostLogoutRedirectUriAsync(TApplication application,
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default) [StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentException.ThrowIfNullOrEmpty(uri);
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
foreach (var candidate in await Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken)) foreach (var candidate in await Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken))
{ {
@ -1508,15 +1346,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> ValidateRedirectUriAsync(TApplication application, public virtual async ValueTask<bool> ValidateRedirectUriAsync(TApplication application,
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default) [StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{ {
if (application is null) ArgumentNullException.ThrowIfNull(application);
{ ArgumentException.ThrowIfNullOrEmpty(uri);
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
foreach (var candidate in await Store.GetRedirectUrisAsync(application, cancellationToken)) foreach (var candidate in await Store.GetRedirectUrisAsync(application, cancellationToken))
{ {
@ -1579,10 +1410,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns> /// </returns>
protected virtual ValueTask<string> ObfuscateClientSecretAsync(string secret, CancellationToken cancellationToken = default) protected virtual ValueTask<string> ObfuscateClientSecretAsync(string secret, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(secret)) ArgumentException.ThrowIfNullOrEmpty(secret);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0216), nameof(secret));
}
// Note: the PRF, iteration count, salt length and key length currently all match the default values // Note: the PRF, iteration count, salt length and key length currently all match the default values
// used by CryptoHelper and ASP.NET Core Identity but this may change in the future, if necessary. // used by CryptoHelper and ASP.NET Core Identity but this may change in the future, if necessary.
@ -1644,15 +1472,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
protected virtual ValueTask<bool> ValidateClientSecretAsync( protected virtual ValueTask<bool> ValidateClientSecretAsync(
string secret, string comparand, CancellationToken cancellationToken = default) string secret, string comparand, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(secret)) ArgumentException.ThrowIfNullOrEmpty(secret);
{ ArgumentException.ThrowIfNullOrEmpty(comparand);
throw new ArgumentException(SR.GetResourceString(SR.ID0216), nameof(secret));
}
if (string.IsNullOrEmpty(comparand))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0218), nameof(comparand));
}
try try
{ {

203
src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs

@ -90,10 +90,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<long> CountAsync<TResult>( public virtual ValueTask<long> CountAsync<TResult>(
Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.CountAsync(query, cancellationToken); return Store.CountAsync(query, cancellationToken);
} }
@ -108,10 +105,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns> /// </returns>
public virtual async ValueTask CreateAsync(TAuthorization authorization, CancellationToken cancellationToken = default) public virtual async ValueTask CreateAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
// If no status was explicitly specified, assume that the authorization is valid. // If no status was explicitly specified, assume that the authorization is valid.
if (string.IsNullOrEmpty(await Store.GetStatusAsync(authorization, cancellationToken))) if (string.IsNullOrEmpty(await Store.GetStatusAsync(authorization, cancellationToken)))
@ -166,10 +160,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask<TAuthorization> CreateAsync( public virtual async ValueTask<TAuthorization> CreateAsync(
OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{
throw new ArgumentNullException(nameof(descriptor));
}
var authorization = await Store.InstantiateAsync(cancellationToken) ?? var authorization = await Store.InstantiateAsync(cancellationToken) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0220)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0220));
@ -214,25 +205,10 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
ClaimsPrincipal principal, string subject, string client, ClaimsPrincipal principal, string subject, string client,
string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default) string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default)
{ {
if (principal is null) ArgumentNullException.ThrowIfNull(principal);
{ ArgumentException.ThrowIfNullOrEmpty(subject);
throw new ArgumentNullException(nameof(principal)); ArgumentException.ThrowIfNullOrEmpty(client);
} ArgumentException.ThrowIfNullOrEmpty(type);
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
if (string.IsNullOrEmpty(client))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(client));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type));
}
var descriptor = new OpenIddictAuthorizationDescriptor var descriptor = new OpenIddictAuthorizationDescriptor
{ {
@ -259,10 +235,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns> /// </returns>
public virtual async ValueTask DeleteAsync(TAuthorization authorization, CancellationToken cancellationToken = default) public virtual async ValueTask DeleteAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
if (!Options.CurrentValue.DisableEntityCaching) if (!Options.CurrentValue.DisableEntityCaching)
{ {
@ -331,10 +304,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync( public virtual IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync(
string identifier, CancellationToken cancellationToken = default) string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var authorizations = Options.CurrentValue.DisableEntityCaching ? var authorizations = Options.CurrentValue.DisableEntityCaching ?
Store.FindByApplicationIdAsync(identifier, cancellationToken) : Store.FindByApplicationIdAsync(identifier, cancellationToken) :
@ -374,10 +344,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns> /// </returns>
public virtual async ValueTask<TAuthorization?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default) public virtual async ValueTask<TAuthorization?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var authorization = Options.CurrentValue.DisableEntityCaching ? var authorization = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByIdAsync(identifier, cancellationToken) : await Store.FindByIdAsync(identifier, cancellationToken) :
@ -409,10 +376,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual IAsyncEnumerable<TAuthorization> FindBySubjectAsync( public virtual IAsyncEnumerable<TAuthorization> FindBySubjectAsync(
string subject, CancellationToken cancellationToken = default) string subject, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(subject)) ArgumentException.ThrowIfNullOrEmpty(subject);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
var authorizations = Options.CurrentValue.DisableEntityCaching ? var authorizations = Options.CurrentValue.DisableEntityCaching ?
Store.FindBySubjectAsync(subject, cancellationToken) : Store.FindBySubjectAsync(subject, cancellationToken) :
@ -453,10 +417,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<string?> GetApplicationIdAsync( public virtual ValueTask<string?> GetApplicationIdAsync(
TAuthorization authorization, CancellationToken cancellationToken = default) TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return Store.GetApplicationIdAsync(authorization, cancellationToken); return Store.GetApplicationIdAsync(authorization, cancellationToken);
} }
@ -474,10 +435,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<TResult?> GetAsync<TResult>( public virtual ValueTask<TResult?> GetAsync<TResult>(
Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return GetAsync(static (authorizations, query) => query(authorizations), query, cancellationToken); return GetAsync(static (authorizations, query) => query(authorizations), query, cancellationToken);
} }
@ -498,10 +456,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query, Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default) TState state, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.GetAsync(query, state, cancellationToken); return Store.GetAsync(query, state, cancellationToken);
} }
@ -518,10 +473,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<DateTimeOffset?> GetCreationDateAsync( public virtual ValueTask<DateTimeOffset?> GetCreationDateAsync(
TAuthorization authorization, CancellationToken cancellationToken = default) TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return Store.GetCreationDateAsync(authorization, cancellationToken); return Store.GetCreationDateAsync(authorization, cancellationToken);
} }
@ -537,10 +489,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns> /// </returns>
public virtual ValueTask<string?> GetIdAsync(TAuthorization authorization, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetIdAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return Store.GetIdAsync(authorization, cancellationToken); return Store.GetIdAsync(authorization, cancellationToken);
} }
@ -557,10 +506,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync( public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TAuthorization authorization, CancellationToken cancellationToken = default) TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return Store.GetPropertiesAsync(authorization, cancellationToken); return Store.GetPropertiesAsync(authorization, cancellationToken);
} }
@ -577,10 +523,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<ImmutableArray<string>> GetScopesAsync( public virtual ValueTask<ImmutableArray<string>> GetScopesAsync(
TAuthorization authorization, CancellationToken cancellationToken = default) TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return Store.GetScopesAsync(authorization, cancellationToken); return Store.GetScopesAsync(authorization, cancellationToken);
} }
@ -597,10 +540,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<string?> GetStatusAsync( public virtual ValueTask<string?> GetStatusAsync(
TAuthorization authorization, CancellationToken cancellationToken = default) TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return Store.GetStatusAsync(authorization, cancellationToken); return Store.GetStatusAsync(authorization, cancellationToken);
} }
@ -617,10 +557,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<string?> GetSubjectAsync( public virtual ValueTask<string?> GetSubjectAsync(
TAuthorization authorization, CancellationToken cancellationToken = default) TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return Store.GetSubjectAsync(authorization, cancellationToken); return Store.GetSubjectAsync(authorization, cancellationToken);
} }
@ -637,10 +574,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<string?> GetTypeAsync( public virtual ValueTask<string?> GetTypeAsync(
TAuthorization authorization, CancellationToken cancellationToken = default) TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return Store.GetTypeAsync(authorization, cancellationToken); return Store.GetTypeAsync(authorization, cancellationToken);
} }
@ -655,10 +589,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask<bool> HasScopesAsync(TAuthorization authorization, public virtual async ValueTask<bool> HasScopesAsync(TAuthorization authorization,
ImmutableArray<string> scopes, CancellationToken cancellationToken = default) ImmutableArray<string> scopes, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return (await GetScopesAsync(authorization, cancellationToken)) return (await GetScopesAsync(authorization, cancellationToken))
.ToHashSet(StringComparer.Ordinal) .ToHashSet(StringComparer.Ordinal)
@ -675,15 +606,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask<bool> HasStatusAsync(TAuthorization authorization, public virtual async ValueTask<bool> HasStatusAsync(TAuthorization authorization,
string status, CancellationToken cancellationToken = default) string status, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{ ArgumentException.ThrowIfNullOrEmpty(status);
throw new ArgumentNullException(nameof(authorization));
}
if (string.IsNullOrEmpty(status))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status));
}
return string.Equals(await GetStatusAsync(authorization, cancellationToken), status, StringComparison.OrdinalIgnoreCase); return string.Equals(await GetStatusAsync(authorization, cancellationToken), status, StringComparison.OrdinalIgnoreCase);
} }
@ -698,15 +622,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask<bool> HasTypeAsync( public virtual async ValueTask<bool> HasTypeAsync(
TAuthorization authorization, string type, CancellationToken cancellationToken = default) TAuthorization authorization, string type, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{ ArgumentException.ThrowIfNullOrEmpty(type);
throw new ArgumentNullException(nameof(authorization));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type));
}
return string.Equals(await GetTypeAsync(authorization, cancellationToken), type, StringComparison.OrdinalIgnoreCase); return string.Equals(await GetTypeAsync(authorization, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
} }
@ -732,10 +649,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual IAsyncEnumerable<TResult> ListAsync<TResult>( public virtual IAsyncEnumerable<TResult> ListAsync<TResult>(
Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return ListAsync(static (authorizations, query) => query(authorizations), query, cancellationToken); return ListAsync(static (authorizations, query) => query(authorizations), query, cancellationToken);
} }
@ -753,10 +667,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query, Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default) TState state, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.ListAsync(query, state, cancellationToken); return Store.ListAsync(query, state, cancellationToken);
} }
@ -773,15 +684,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask PopulateAsync(TAuthorization authorization, public virtual async ValueTask PopulateAsync(TAuthorization authorization,
OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{ ArgumentNullException.ThrowIfNull(descriptor);
throw new ArgumentNullException(nameof(authorization));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
await Store.SetApplicationIdAsync(authorization, descriptor.ApplicationId, cancellationToken); await Store.SetApplicationIdAsync(authorization, descriptor.ApplicationId, cancellationToken);
await Store.SetCreationDateAsync(authorization, descriptor.CreationDate, cancellationToken); await Store.SetCreationDateAsync(authorization, descriptor.CreationDate, cancellationToken);
@ -805,15 +709,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
OpenIddictAuthorizationDescriptor descriptor, OpenIddictAuthorizationDescriptor descriptor,
TAuthorization authorization, CancellationToken cancellationToken = default) TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{ ArgumentNullException.ThrowIfNull(authorization);
throw new ArgumentNullException(nameof(descriptor));
}
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
descriptor.ApplicationId = await Store.GetApplicationIdAsync(authorization, cancellationToken); descriptor.ApplicationId = await Store.GetApplicationIdAsync(authorization, cancellationToken);
descriptor.CreationDate = await Store.GetCreationDateAsync(authorization, cancellationToken); descriptor.CreationDate = await Store.GetCreationDateAsync(authorization, cancellationToken);
@ -864,10 +761,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// <returns>The number of authorizations associated with the specified application that were marked as revoked.</returns> /// <returns>The number of authorizations associated with the specified application that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken = default) public virtual ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
return Store.RevokeByApplicationIdAsync(identifier, cancellationToken); return Store.RevokeByApplicationIdAsync(identifier, cancellationToken);
} }
@ -880,10 +774,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// <returns>The number of authorizations associated with the specified subject that were marked as revoked.</returns> /// <returns>The number of authorizations associated with the specified subject that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken = default) public virtual ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(subject)) ArgumentException.ThrowIfNullOrEmpty(subject);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(subject));
}
return Store.RevokeBySubjectAsync(subject, cancellationToken); return Store.RevokeBySubjectAsync(subject, cancellationToken);
} }
@ -896,10 +787,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// <returns><see langword="true"/> if the authorization was successfully revoked, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the authorization was successfully revoked, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> TryRevokeAsync(TAuthorization authorization, CancellationToken cancellationToken = default) public virtual async ValueTask<bool> TryRevokeAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
var status = await Store.GetStatusAsync(authorization, cancellationToken); var status = await Store.GetStatusAsync(authorization, cancellationToken);
if (string.Equals(status, Statuses.Revoked, StringComparison.OrdinalIgnoreCase)) if (string.Equals(status, Statuses.Revoked, StringComparison.OrdinalIgnoreCase))
@ -943,10 +831,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns> /// </returns>
public virtual async ValueTask UpdateAsync(TAuthorization authorization, CancellationToken cancellationToken = default) public virtual async ValueTask UpdateAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
var results = await GetValidationResultsAsync(authorization, cancellationToken); var results = await GetValidationResultsAsync(authorization, cancellationToken);
if (results.Any(result => result != ValidationResult.Success)) if (results.Any(result => result != ValidationResult.Success))
@ -1001,15 +886,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask UpdateAsync(TAuthorization authorization, public virtual async ValueTask UpdateAsync(TAuthorization authorization,
OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{ ArgumentNullException.ThrowIfNull(descriptor);
throw new ArgumentNullException(nameof(authorization));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
await PopulateAsync(authorization, descriptor, cancellationToken); await PopulateAsync(authorization, descriptor, cancellationToken);
await UpdateAsync(authorization, cancellationToken); await UpdateAsync(authorization, cancellationToken);
@ -1024,10 +902,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual IAsyncEnumerable<ValidationResult> ValidateAsync( public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(
TAuthorization authorization, CancellationToken cancellationToken = default) TAuthorization authorization, CancellationToken cancellationToken = default)
{ {
if (authorization is null) ArgumentNullException.ThrowIfNull(authorization);
{
throw new ArgumentNullException(nameof(authorization));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);

160
src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs

@ -89,10 +89,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual ValueTask<long> CountAsync<TResult>( public virtual ValueTask<long> CountAsync<TResult>(
Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.CountAsync(query, cancellationToken); return Store.CountAsync(query, cancellationToken);
} }
@ -107,10 +104,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns> /// </returns>
public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cancellationToken = default) public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
var results = await GetValidationResultsAsync(scope, cancellationToken); var results = await GetValidationResultsAsync(scope, cancellationToken);
if (results.Any(result => result != ValidationResult.Success)) if (results.Any(result => result != ValidationResult.Success))
@ -159,10 +153,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<TScope> CreateAsync( public virtual async ValueTask<TScope> CreateAsync(
OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{
throw new ArgumentNullException(nameof(descriptor));
}
var scope = await Store.InstantiateAsync(cancellationToken) ?? var scope = await Store.InstantiateAsync(cancellationToken) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0223)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0223));
@ -183,10 +174,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns> /// </returns>
public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cancellationToken = default) public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
if (!Options.CurrentValue.DisableEntityCaching) if (!Options.CurrentValue.DisableEntityCaching)
{ {
@ -207,10 +195,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns> /// </returns>
public virtual async ValueTask<TScope?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default) public virtual async ValueTask<TScope?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var scope = Options.CurrentValue.DisableEntityCaching ? var scope = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByIdAsync(identifier, cancellationToken) : await Store.FindByIdAsync(identifier, cancellationToken) :
@ -244,10 +229,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns> /// </returns>
public virtual async ValueTask<TScope?> FindByNameAsync(string name, CancellationToken cancellationToken = default) public virtual async ValueTask<TScope?> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(name)) ArgumentException.ThrowIfNullOrEmpty(name);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0202), nameof(name));
}
var scope = Options.CurrentValue.DisableEntityCaching ? var scope = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByNameAsync(name, cancellationToken) : await Store.FindByNameAsync(name, cancellationToken) :
@ -322,10 +304,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual IAsyncEnumerable<TScope> FindByResourceAsync( public virtual IAsyncEnumerable<TScope> FindByResourceAsync(
string resource, CancellationToken cancellationToken = default) string resource, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(resource)) ArgumentException.ThrowIfNullOrEmpty(resource);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
var scopes = Options.CurrentValue.DisableEntityCaching ? var scopes = Options.CurrentValue.DisableEntityCaching ?
Store.FindByResourceAsync(resource, cancellationToken) : Store.FindByResourceAsync(resource, cancellationToken) :
@ -368,10 +347,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual ValueTask<TResult?> GetAsync<TResult>( public virtual ValueTask<TResult?> GetAsync<TResult>(
Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return GetAsync(static (scopes, query) => query(scopes), query, cancellationToken); return GetAsync(static (scopes, query) => query(scopes), query, cancellationToken);
} }
@ -392,10 +368,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
Func<IQueryable<TScope>, TState, IQueryable<TResult>> query, Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default) TState state, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.GetAsync(query, state, cancellationToken); return Store.GetAsync(query, state, cancellationToken);
} }
@ -411,10 +384,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns> /// </returns>
public virtual ValueTask<string?> GetDescriptionAsync(TScope scope, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetDescriptionAsync(TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
return Store.GetDescriptionAsync(scope, cancellationToken); return Store.GetDescriptionAsync(scope, cancellationToken);
} }
@ -431,10 +401,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<ImmutableDictionary<CultureInfo, string>> GetDescriptionsAsync( public virtual async ValueTask<ImmutableDictionary<CultureInfo, string>> GetDescriptionsAsync(
TScope scope, CancellationToken cancellationToken = default) TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
var descriptions = await Store.GetDescriptionsAsync(scope, cancellationToken); var descriptions = await Store.GetDescriptionsAsync(scope, cancellationToken);
if (descriptions is not { Count: > 0 }) if (descriptions is not { Count: > 0 })
@ -456,10 +423,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns> /// </returns>
public virtual ValueTask<string?> GetDisplayNameAsync(TScope scope, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetDisplayNameAsync(TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
return Store.GetDisplayNameAsync(scope, cancellationToken); return Store.GetDisplayNameAsync(scope, cancellationToken);
} }
@ -476,10 +440,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync( public virtual async ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(
TScope scope, CancellationToken cancellationToken = default) TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
var names = await Store.GetDisplayNamesAsync(scope, cancellationToken); var names = await Store.GetDisplayNamesAsync(scope, cancellationToken);
if (names is not { Count: > 0 }) if (names is not { Count: > 0 })
@ -501,10 +462,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns> /// </returns>
public virtual ValueTask<string?> GetIdAsync(TScope scope, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetIdAsync(TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
return Store.GetIdAsync(scope, cancellationToken); return Store.GetIdAsync(scope, cancellationToken);
} }
@ -538,15 +496,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<string?> GetLocalizedDisplayNameAsync( public virtual async ValueTask<string?> GetLocalizedDisplayNameAsync(
TScope scope, CultureInfo culture, CancellationToken cancellationToken = default) TScope scope, CultureInfo culture, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{ ArgumentNullException.ThrowIfNull(culture);
throw new ArgumentNullException(nameof(scope));
}
if (culture is null)
{
throw new ArgumentNullException(nameof(culture));
}
var names = await Store.GetDisplayNamesAsync(scope, cancellationToken); var names = await Store.GetDisplayNamesAsync(scope, cancellationToken);
if (names is not { Count: > 0 }) if (names is not { Count: > 0 })
@ -598,15 +549,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<string?> GetLocalizedDescriptionAsync( public virtual async ValueTask<string?> GetLocalizedDescriptionAsync(
TScope scope, CultureInfo culture, CancellationToken cancellationToken = default) TScope scope, CultureInfo culture, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{ ArgumentNullException.ThrowIfNull(culture);
throw new ArgumentNullException(nameof(scope));
}
if (culture is null)
{
throw new ArgumentNullException(nameof(culture));
}
var descriptions = await Store.GetDescriptionsAsync(scope, cancellationToken); var descriptions = await Store.GetDescriptionsAsync(scope, cancellationToken);
if (descriptions is not { Count: > 0 }) if (descriptions is not { Count: > 0 })
@ -640,10 +584,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns> /// </returns>
public virtual ValueTask<string?> GetNameAsync(TScope scope, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetNameAsync(TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
return Store.GetNameAsync(scope, cancellationToken); return Store.GetNameAsync(scope, cancellationToken);
} }
@ -660,10 +601,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync( public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TScope scope, CancellationToken cancellationToken = default) TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
return Store.GetPropertiesAsync(scope, cancellationToken); return Store.GetPropertiesAsync(scope, cancellationToken);
} }
@ -680,10 +618,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual ValueTask<ImmutableArray<string>> GetResourcesAsync( public virtual ValueTask<ImmutableArray<string>> GetResourcesAsync(
TScope scope, CancellationToken cancellationToken = default) TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
return Store.GetResourcesAsync(scope, cancellationToken); return Store.GetResourcesAsync(scope, cancellationToken);
} }
@ -709,10 +644,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual IAsyncEnumerable<TResult> ListAsync<TResult>( public virtual IAsyncEnumerable<TResult> ListAsync<TResult>(
Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return ListAsync(static (scopes, query) => query(scopes), query, cancellationToken); return ListAsync(static (scopes, query) => query(scopes), query, cancellationToken);
} }
@ -730,10 +662,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
Func<IQueryable<TScope>, TState, IQueryable<TResult>> query, Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default) TState state, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.ListAsync(query, state, cancellationToken); return Store.ListAsync(query, state, cancellationToken);
} }
@ -773,15 +702,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask PopulateAsync(TScope scope, public virtual async ValueTask PopulateAsync(TScope scope,
OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{ ArgumentNullException.ThrowIfNull(descriptor);
throw new ArgumentNullException(nameof(scope));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
await Store.SetDescriptionAsync(scope, descriptor.Description, cancellationToken); await Store.SetDescriptionAsync(scope, descriptor.Description, cancellationToken);
await Store.SetDescriptionsAsync(scope, descriptor.Descriptions.ToImmutableDictionary(), cancellationToken); await Store.SetDescriptionsAsync(scope, descriptor.Descriptions.ToImmutableDictionary(), cancellationToken);
@ -805,15 +727,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
OpenIddictScopeDescriptor descriptor, OpenIddictScopeDescriptor descriptor,
TScope scope, CancellationToken cancellationToken = default) TScope scope, CancellationToken cancellationToken = default)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{ ArgumentNullException.ThrowIfNull(scope);
throw new ArgumentNullException(nameof(descriptor));
}
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
descriptor.Description = await Store.GetDescriptionAsync(scope, cancellationToken); descriptor.Description = await Store.GetDescriptionAsync(scope, cancellationToken);
descriptor.DisplayName = await Store.GetDisplayNameAsync(scope, cancellationToken); descriptor.DisplayName = await Store.GetDisplayNameAsync(scope, cancellationToken);
@ -850,10 +765,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns> /// </returns>
public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cancellationToken = default) public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
var results = await GetValidationResultsAsync(scope, cancellationToken); var results = await GetValidationResultsAsync(scope, cancellationToken);
if (results.Any(result => result != ValidationResult.Success)) if (results.Any(result => result != ValidationResult.Success))
@ -908,15 +820,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask UpdateAsync(TScope scope, public virtual async ValueTask UpdateAsync(TScope scope,
OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{ ArgumentNullException.ThrowIfNull(descriptor);
throw new ArgumentNullException(nameof(scope));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
await PopulateAsync(scope, descriptor, cancellationToken); await PopulateAsync(scope, descriptor, cancellationToken);
await UpdateAsync(scope, cancellationToken); await UpdateAsync(scope, cancellationToken);
@ -930,10 +835,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// <returns>The validation error encountered when validating the scope.</returns> /// <returns>The validation error encountered when validating the scope.</returns>
public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(TScope scope, CancellationToken cancellationToken = default) public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(TScope scope, CancellationToken cancellationToken = default)
{ {
if (scope is null) ArgumentNullException.ThrowIfNull(scope);
{
throw new ArgumentNullException(nameof(scope));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);

230
src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs

@ -89,10 +89,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual ValueTask<long> CountAsync<TResult>( public virtual ValueTask<long> CountAsync<TResult>(
Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.CountAsync(query, cancellationToken); return Store.CountAsync(query, cancellationToken);
} }
@ -107,10 +104,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual async ValueTask CreateAsync(TToken token, CancellationToken cancellationToken = default) public virtual async ValueTask CreateAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
// If no status was explicitly specified, assume that the token is valid. // If no status was explicitly specified, assume that the token is valid.
if (string.IsNullOrEmpty(await Store.GetStatusAsync(token, cancellationToken))) if (string.IsNullOrEmpty(await Store.GetStatusAsync(token, cancellationToken)))
@ -173,10 +167,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual async ValueTask<TToken> CreateAsync( public virtual async ValueTask<TToken> CreateAsync(
OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{
throw new ArgumentNullException(nameof(descriptor));
}
var token = await Store.InstantiateAsync(cancellationToken) ?? var token = await Store.InstantiateAsync(cancellationToken) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0226)); throw new InvalidOperationException(SR.GetResourceString(SR.ID0226));
@ -197,10 +188,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken = default) public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
if (!Options.CurrentValue.DisableEntityCaching) if (!Options.CurrentValue.DisableEntityCaching)
{ {
@ -260,10 +248,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual IAsyncEnumerable<TToken> FindByApplicationIdAsync( public virtual IAsyncEnumerable<TToken> FindByApplicationIdAsync(
string identifier, CancellationToken cancellationToken = default) string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var tokens = Options.CurrentValue.DisableEntityCaching ? var tokens = Options.CurrentValue.DisableEntityCaching ?
Store.FindByApplicationIdAsync(identifier, cancellationToken) : Store.FindByApplicationIdAsync(identifier, cancellationToken) :
@ -301,10 +286,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual IAsyncEnumerable<TToken> FindByAuthorizationIdAsync( public virtual IAsyncEnumerable<TToken> FindByAuthorizationIdAsync(
string identifier, CancellationToken cancellationToken = default) string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var tokens = Options.CurrentValue.DisableEntityCaching ? var tokens = Options.CurrentValue.DisableEntityCaching ?
Store.FindByAuthorizationIdAsync(identifier, cancellationToken) : Store.FindByAuthorizationIdAsync(identifier, cancellationToken) :
@ -344,10 +326,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual async ValueTask<TToken?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default) public virtual async ValueTask<TToken?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
var token = Options.CurrentValue.DisableEntityCaching ? var token = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByIdAsync(identifier, cancellationToken) : await Store.FindByIdAsync(identifier, cancellationToken) :
@ -382,10 +361,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual async ValueTask<TToken?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken = default) public virtual async ValueTask<TToken?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
identifier = await ObfuscateReferenceIdAsync(identifier, cancellationToken); identifier = await ObfuscateReferenceIdAsync(identifier, cancellationToken);
@ -420,10 +396,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual IAsyncEnumerable<TToken> FindBySubjectAsync( public virtual IAsyncEnumerable<TToken> FindBySubjectAsync(
string subject, CancellationToken cancellationToken = default) string subject, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(subject)) ArgumentException.ThrowIfNullOrEmpty(subject);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
var tokens = Options.CurrentValue.DisableEntityCaching ? var tokens = Options.CurrentValue.DisableEntityCaching ?
Store.FindBySubjectAsync(subject, cancellationToken) : Store.FindBySubjectAsync(subject, cancellationToken) :
@ -463,10 +436,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<string?> GetApplicationIdAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetApplicationIdAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetApplicationIdAsync(token, cancellationToken); return Store.GetApplicationIdAsync(token, cancellationToken);
} }
@ -484,10 +454,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual ValueTask<TResult?> GetAsync<TResult>( public virtual ValueTask<TResult?> GetAsync<TResult>(
Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return GetAsync(static (tokens, query) => query(tokens), query, cancellationToken); return GetAsync(static (tokens, query) => query(tokens), query, cancellationToken);
} }
@ -508,10 +475,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
Func<IQueryable<TToken>, TState, IQueryable<TResult>> query, Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default) TState state, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.GetAsync(query, state, cancellationToken); return Store.GetAsync(query, state, cancellationToken);
} }
@ -527,10 +491,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<string?> GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetAuthorizationIdAsync(token, cancellationToken); return Store.GetAuthorizationIdAsync(token, cancellationToken);
} }
@ -546,10 +507,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<DateTimeOffset?> GetCreationDateAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<DateTimeOffset?> GetCreationDateAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetCreationDateAsync(token, cancellationToken); return Store.GetCreationDateAsync(token, cancellationToken);
} }
@ -565,10 +523,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<DateTimeOffset?> GetExpirationDateAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<DateTimeOffset?> GetExpirationDateAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetExpirationDateAsync(token, cancellationToken); return Store.GetExpirationDateAsync(token, cancellationToken);
} }
@ -584,10 +539,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<string?> GetIdAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetIdAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetIdAsync(token, cancellationToken); return Store.GetIdAsync(token, cancellationToken);
} }
@ -603,10 +555,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<string?> GetPayloadAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetPayloadAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetPayloadAsync(token, cancellationToken); return Store.GetPayloadAsync(token, cancellationToken);
} }
@ -623,10 +572,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync( public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TToken token, CancellationToken cancellationToken = default) TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetPropertiesAsync(token, cancellationToken); return Store.GetPropertiesAsync(token, cancellationToken);
} }
@ -642,10 +588,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<DateTimeOffset?> GetRedemptionDateAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<DateTimeOffset?> GetRedemptionDateAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetRedemptionDateAsync(token, cancellationToken); return Store.GetRedemptionDateAsync(token, cancellationToken);
} }
@ -663,10 +606,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<string?> GetReferenceIdAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetReferenceIdAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetReferenceIdAsync(token, cancellationToken); return Store.GetReferenceIdAsync(token, cancellationToken);
} }
@ -682,10 +622,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<string?> GetStatusAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetStatusAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetStatusAsync(token, cancellationToken); return Store.GetStatusAsync(token, cancellationToken);
} }
@ -701,10 +638,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual ValueTask<string?> GetSubjectAsync(TToken token, CancellationToken cancellationToken = default) public virtual ValueTask<string?> GetSubjectAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetSubjectAsync(token, cancellationToken); return Store.GetSubjectAsync(token, cancellationToken);
} }
@ -720,10 +654,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual async ValueTask<string?> GetTypeAsync(TToken token, CancellationToken cancellationToken = default) public virtual async ValueTask<string?> GetTypeAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return await Store.GetTypeAsync(token, cancellationToken) switch return await Store.GetTypeAsync(token, cancellationToken) switch
{ {
@ -752,15 +683,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token has the specified status, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the token has the specified status, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> HasStatusAsync(TToken token, string status, CancellationToken cancellationToken = default) public virtual async ValueTask<bool> HasStatusAsync(TToken token, string status, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{ ArgumentException.ThrowIfNullOrEmpty(status);
throw new ArgumentNullException(nameof(token));
}
if (string.IsNullOrEmpty(status))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status));
}
return string.Equals(await GetStatusAsync(token, cancellationToken), status, StringComparison.OrdinalIgnoreCase); return string.Equals(await GetStatusAsync(token, cancellationToken), status, StringComparison.OrdinalIgnoreCase);
} }
@ -774,15 +698,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token has the specified type, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the token has the specified type, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> HasTypeAsync(TToken token, string type, CancellationToken cancellationToken = default) public virtual async ValueTask<bool> HasTypeAsync(TToken token, string type, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{ ArgumentException.ThrowIfNullOrEmpty(type);
throw new ArgumentNullException(nameof(token));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type));
}
return string.Equals(await GetTypeAsync(token, cancellationToken), type, StringComparison.OrdinalIgnoreCase); return string.Equals(await GetTypeAsync(token, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
} }
@ -796,10 +713,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token has any of the specified types, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the token has any of the specified types, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> HasTypeAsync(TToken token, ImmutableArray<string> types, CancellationToken cancellationToken = default) public virtual async ValueTask<bool> HasTypeAsync(TToken token, ImmutableArray<string> types, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
var type = await GetTypeAsync(token, cancellationToken); var type = await GetTypeAsync(token, cancellationToken);
if (string.IsNullOrEmpty(type)) if (string.IsNullOrEmpty(type))
@ -839,10 +753,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual IAsyncEnumerable<TResult> ListAsync<TResult>( public virtual IAsyncEnumerable<TResult> ListAsync<TResult>(
Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default) Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return ListAsync(static (tokens, query) => query(tokens), query, cancellationToken); return ListAsync(static (tokens, query) => query(tokens), query, cancellationToken);
} }
@ -860,10 +771,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
Func<IQueryable<TToken>, TState, IQueryable<TResult>> query, Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default) TState state, CancellationToken cancellationToken = default)
{ {
if (query is null) ArgumentNullException.ThrowIfNull(query);
{
throw new ArgumentNullException(nameof(query));
}
return Store.ListAsync(query, state, cancellationToken); return Store.ListAsync(query, state, cancellationToken);
} }
@ -880,15 +788,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual async ValueTask PopulateAsync(TToken token, public virtual async ValueTask PopulateAsync(TToken token,
OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{ ArgumentNullException.ThrowIfNull(descriptor);
throw new ArgumentNullException(nameof(token));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
await Store.SetApplicationIdAsync(token, descriptor.ApplicationId, cancellationToken); await Store.SetApplicationIdAsync(token, descriptor.ApplicationId, cancellationToken);
await Store.SetAuthorizationIdAsync(token, descriptor.AuthorizationId, cancellationToken); await Store.SetAuthorizationIdAsync(token, descriptor.AuthorizationId, cancellationToken);
@ -916,15 +817,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
OpenIddictTokenDescriptor descriptor, OpenIddictTokenDescriptor descriptor,
TToken token, CancellationToken cancellationToken = default) TToken token, CancellationToken cancellationToken = default)
{ {
if (descriptor is null) ArgumentNullException.ThrowIfNull(descriptor);
{ ArgumentNullException.ThrowIfNull(token);
throw new ArgumentNullException(nameof(descriptor));
}
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
descriptor.ApplicationId = await Store.GetApplicationIdAsync(token, cancellationToken); descriptor.ApplicationId = await Store.GetApplicationIdAsync(token, cancellationToken);
descriptor.AuthorizationId = await Store.GetAuthorizationIdAsync(token, cancellationToken); descriptor.AuthorizationId = await Store.GetAuthorizationIdAsync(token, cancellationToken);
@ -974,10 +868,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns>The number of tokens associated with the specified application that were marked as revoked.</returns> /// <returns>The number of tokens associated with the specified application that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken = default) public virtual ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
return Store.RevokeByApplicationIdAsync(identifier, cancellationToken); return Store.RevokeByApplicationIdAsync(identifier, cancellationToken);
} }
@ -990,10 +881,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns>The number of tokens associated with the specified authorization that were marked as revoked.</returns> /// <returns>The number of tokens associated with the specified authorization that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken = default) public virtual ValueTask<long> RevokeByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
return Store.RevokeByAuthorizationIdAsync(identifier, cancellationToken); return Store.RevokeByAuthorizationIdAsync(identifier, cancellationToken);
} }
@ -1006,10 +894,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns>The number of tokens associated with the specified subject that were marked as revoked.</returns> /// <returns>The number of tokens associated with the specified subject that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken = default) public virtual ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(subject)) ArgumentException.ThrowIfNullOrEmpty(subject);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(subject));
}
return Store.RevokeBySubjectAsync(subject, cancellationToken); return Store.RevokeBySubjectAsync(subject, cancellationToken);
} }
@ -1022,10 +907,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token was successfully redemeed, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the token was successfully redemeed, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> TryRedeemAsync(TToken token, CancellationToken cancellationToken = default) public virtual async ValueTask<bool> TryRedeemAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
// If the token doesn't have a redemption date attached, this likely means it's // If the token doesn't have a redemption date attached, this likely means it's
// the first time the token is redeemed. In this case, attach the current date. // the first time the token is redeemed. In this case, attach the current date.
@ -1068,10 +950,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token was successfully redemeed, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the token was successfully redemeed, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> TryRejectAsync(TToken token, CancellationToken cancellationToken = default) public virtual async ValueTask<bool> TryRejectAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
await Store.SetStatusAsync(token, Statuses.Rejected, cancellationToken); await Store.SetStatusAsync(token, Statuses.Rejected, cancellationToken);
@ -1107,10 +986,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token was successfully revoked, <see langword="false"/> otherwise.</returns> /// <returns><see langword="true"/> if the token was successfully revoked, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> TryRevokeAsync(TToken token, CancellationToken cancellationToken = default) public virtual async ValueTask<bool> TryRevokeAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
await Store.SetStatusAsync(token, Statuses.Revoked, cancellationToken); await Store.SetStatusAsync(token, Statuses.Revoked, cancellationToken);
@ -1148,10 +1024,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken = default) public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
var results = await GetValidationResultsAsync(token, cancellationToken); var results = await GetValidationResultsAsync(token, cancellationToken);
if (results.Any(result => result != ValidationResult.Success)) if (results.Any(result => result != ValidationResult.Success))
@ -1206,15 +1079,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual async ValueTask UpdateAsync(TToken token, public virtual async ValueTask UpdateAsync(TToken token,
OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{ ArgumentNullException.ThrowIfNull(descriptor);
throw new ArgumentNullException(nameof(token));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
// Store the original reference identifier for later comparison. // Store the original reference identifier for later comparison.
var comparand = await Store.GetReferenceIdAsync(token, cancellationToken); var comparand = await Store.GetReferenceIdAsync(token, cancellationToken);
@ -1239,10 +1105,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns>The validation error encountered when validating the token.</returns> /// <returns>The validation error encountered when validating the token.</returns>
public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(TToken token, CancellationToken cancellationToken = default) public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(TToken token, CancellationToken cancellationToken = default)
{ {
if (token is null) ArgumentNullException.ThrowIfNull(token);
{
throw new ArgumentNullException(nameof(token));
}
return ExecuteAsync(cancellationToken); return ExecuteAsync(cancellationToken);
@ -1290,10 +1153,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns> /// </returns>
protected virtual ValueTask<string> ObfuscateReferenceIdAsync(string identifier, CancellationToken cancellationToken = default) protected virtual ValueTask<string> ObfuscateReferenceIdAsync(string identifier, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(identifier)) ArgumentException.ThrowIfNullOrEmpty(identifier);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
// Compute the digest of the generated identifier and use it as the hashed identifier of the reference token. // Compute the digest of the generated identifier and use it as the hashed identifier of the reference token.
// Doing that prevents token identifiers stolen from the database from being used as valid reference tokens. // Doing that prevents token identifiers stolen from the database from being used as valid reference tokens.

10
src/OpenIddict.Core/OpenIddictCoreBuilder.cs

@ -37,10 +37,7 @@ public sealed class OpenIddictCoreBuilder
/// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns>
public OpenIddictCoreBuilder Configure(Action<OpenIddictCoreOptions> configuration) public OpenIddictCoreBuilder Configure(Action<OpenIddictCoreOptions> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure(configuration); Services.Configure(configuration);
@ -447,10 +444,7 @@ public sealed class OpenIddictCoreBuilder
/// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns>
public OpenIddictCoreBuilder SetEntityCacheLimit(int limit) public OpenIddictCoreBuilder SetEntityCacheLimit(int limit)
{ {
if (limit < 10) ArgumentOutOfRangeException.ThrowIfLessThan(limit, 10);
{
throw new ArgumentException(SR.GetResourceString(SR.ID0233), nameof(limit));
}
return Configure(options => options.EntityCacheLimit = limit); return Configure(options => options.EntityCacheLimit = limit);
} }

16
src/OpenIddict.Core/OpenIddictCoreExtensions.cs

@ -23,10 +23,7 @@ public static class OpenIddictCoreExtensions
/// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns>
public static OpenIddictCoreBuilder AddCore(this OpenIddictBuilder builder) public static OpenIddictCoreBuilder AddCore(this OpenIddictBuilder builder)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddLogging(); builder.Services.AddLogging();
builder.Services.AddMemoryCache(); builder.Services.AddMemoryCache();
@ -70,15 +67,8 @@ public static class OpenIddictCoreExtensions
/// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns>
public static OpenIddictBuilder AddCore(this OpenIddictBuilder builder, Action<OpenIddictCoreBuilder> configuration) public static OpenIddictBuilder AddCore(this OpenIddictBuilder builder, Action<OpenIddictCoreBuilder> configuration)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(builder.AddCore()); configuration(builder.AddCore());

4
src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj

@ -6,11 +6,7 @@
$(NetCoreTargetFrameworks); $(NetCoreTargetFrameworks);
$(NetStandardTargetFrameworks) $(NetStandardTargetFrameworks)
</TargetFrameworks> </TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<IncludeInternalExtensions>false</IncludeInternalExtensions> <IncludeInternalExtensions>false</IncludeInternalExtensions>
<PolySharpIncludeGeneratedTypes>System.Diagnostics.CodeAnalysis.StringSyntaxAttribute</PolySharpIncludeGeneratedTypes>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

5
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs

@ -39,10 +39,7 @@ public sealed class OpenIddictEntityFrameworkBuilder
/// <returns>The <see cref="OpenIddictEntityFrameworkBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictEntityFrameworkBuilder"/> instance.</returns>
public OpenIddictEntityFrameworkBuilder Configure(Action<OpenIddictEntityFrameworkOptions> configuration) public OpenIddictEntityFrameworkBuilder Configure(Action<OpenIddictEntityFrameworkOptions> configuration)
{ {
if (configuration is null) ArgumentNullException.ThrowIfNull(configuration);
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure(configuration); Services.Configure(configuration);

16
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs

@ -24,10 +24,7 @@ public static class OpenIddictEntityFrameworkExtensions
/// <returns>The <see cref="OpenIddictEntityFrameworkBuilder"/> instance.</returns> /// <returns>The <see cref="OpenIddictEntityFrameworkBuilder"/> instance.</returns>
public static OpenIddictEntityFrameworkBuilder UseEntityFramework(this OpenIddictCoreBuilder builder) public static OpenIddictEntityFrameworkBuilder UseEntityFramework(this OpenIddictCoreBuilder builder)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder));
}
// Since Entity Framework 6.x may be used with databases performing case-insensitive // Since Entity Framework 6.x may be used with databases performing case-insensitive
// or culture-sensitive comparisons, ensure the additional filtering logic is enforced // or culture-sensitive comparisons, ensure the additional filtering logic is enforced
@ -64,15 +61,8 @@ public static class OpenIddictEntityFrameworkExtensions
public static OpenIddictCoreBuilder UseEntityFramework( public static OpenIddictCoreBuilder UseEntityFramework(
this OpenIddictCoreBuilder builder, Action<OpenIddictEntityFrameworkBuilder> configuration) this OpenIddictCoreBuilder builder, Action<OpenIddictEntityFrameworkBuilder> configuration)
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{ ArgumentNullException.ThrowIfNull(configuration);
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(builder.UseEntityFramework()); configuration(builder.UseEntityFramework());

15
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs

@ -52,10 +52,7 @@ public static class OpenIddictEntityFrameworkHelpers
where TToken : OpenIddictEntityFrameworkToken<TKey, TApplication, TAuthorization> where TToken : OpenIddictEntityFrameworkToken<TKey, TApplication, TAuthorization>
where TKey : notnull, IEquatable<TKey> where TKey : notnull, IEquatable<TKey>
{ {
if (builder is null) ArgumentNullException.ThrowIfNull(builder);
{
throw new ArgumentNullException(nameof(builder));
}
builder.Configurations builder.Configurations
.Add(new OpenIddictEntityFrameworkApplicationConfiguration<TApplication, TAuthorization, TToken, TKey>()) .Add(new OpenIddictEntityFrameworkApplicationConfiguration<TApplication, TAuthorization, TToken, TKey>())
@ -75,10 +72,7 @@ public static class OpenIddictEntityFrameworkHelpers
/// <returns>The streamed async enumeration containing the results.</returns> /// <returns>The streamed async enumeration containing the results.</returns>
internal static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this IQueryable<T> source, CancellationToken cancellationToken) internal static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this IQueryable<T> source, CancellationToken cancellationToken)
{ {
if (source is null) ArgumentNullException.ThrowIfNull(source);
{
throw new ArgumentNullException(nameof(source));
}
return ExecuteAsync(source, cancellationToken); return ExecuteAsync(source, cancellationToken);
@ -101,10 +95,7 @@ public static class OpenIddictEntityFrameworkHelpers
/// <returns>The <see cref="DbContextTransaction"/> if it could be created, <see langword="null"/> otherwise.</returns> /// <returns>The <see cref="DbContextTransaction"/> if it could be created, <see langword="null"/> otherwise.</returns>
internal static DbContextTransaction? CreateTransaction(this DbContext context, IsolationLevel level) internal static DbContextTransaction? CreateTransaction(this DbContext context, IsolationLevel level)
{ {
if (context is null) ArgumentNullException.ThrowIfNull(context);
{
throw new ArgumentNullException(nameof(context));
}
try try
{ {

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save